管理用戶端上的通話錄製

重要

本文所述的功能目前為公開預覽狀態。 此預覽版本在沒有服務等級協議的情況下提供,不建議用於生產工作負載。 可能不支援特定功能,或可能已經限制功能。 如需詳細資訊,請參閱 Microsoft Azure 預覽版增補使用條款

通話錄製可讓您的用戶記錄他們與 Azure 通訊服務 的通話。 在本文中,您將瞭解如何管理用戶端上的錄製。 開始之前,您必須在伺服器端設定錄製

必要條件

安裝 SDK

npm install使用 命令來安裝適用於 JavaScript 的 Azure 通訊服務 Common 和 Calling SDK:

npm install @azure/communication-common --save
npm install @azure/communication-calling --save

初始化必要的物件

CallClient大部分呼叫作業都需要 實例。 在這裡,您會建立新的 CallClient 實例。 您可以使用實例之類的 Logger 自訂選項進行設定。

當您有 CallClient 實例時,您可以在 實例上CallClient呼叫 createCallAgent 方法來建立 CallAgent 實例。 這個方法會以異步方式傳 CallAgent 回實例物件。

方法 createCallAgent 會使用 CommunicationTokenCredential 做為自變數。 它接受 使用者存取令牌

您可以在 getDeviceManager 實體上使用 CallClient 方法來存取 deviceManager

const { CallClient } = require('@azure/communication-calling');
const { AzureCommunicationTokenCredential} = require('@azure/communication-common');
const { AzureLogger, setLogLevel } = require("@azure/logger");

// Set the logger's log level
setLogLevel('verbose');

// Redirect log output to console, file, buffer, REST API, or whatever location you want
AzureLogger.log = (...args) => {
    console.log(...args); // Redirect log output to console
};

const userToken = '<USER_TOKEN>';
callClient = new CallClient(options);
const tokenCredential = new AzureCommunicationTokenCredential(userToken);
const callAgent = await callClient.createCallAgent(tokenCredential, {displayName: 'optional Azure Communication Services user name'});
const deviceManager = await callClient.getDeviceManager()

注意

此 API 是以開發人員預覽的形式提供,可能會根據我們收到的意見反應而變更。 請勿在生產環境中使用此 API。 若要使用此 API,請使用 Azure 通訊服務 呼叫 Web SDK 的 Beta 版本。

雲端錄製

通話錄製是核心呼叫 API 的擴充功能。 您必須先從通話 SDK 匯入通話功能:

import { Features} from "@azure/communication-calling";

然後,您可以從呼叫實例取得錄製功能的 API 物件:

const callRecordingApi = call.feature(Features.Recording);

若要檢查是否已記錄呼叫,請檢查 isRecordingActivecallRecordingApi屬性。 它會傳回 Boolean

const isRecordingActive = callRecordingApi.isRecordingActive;

您也可以訂閱錄製變更:

const isRecordingActiveChangedHandler = () => {
    console.log(callRecordingApi.isRecordingActive);
};

callRecordingApi.on('isRecordingActiveChanged', isRecordingActiveChangedHandler);

您可以使用 的callRecordingApi屬性來取得錄製recordings清單。 它會傳 RecordingInfo[]回 ,其中包含使用者的顯示名稱,以及雲端錄製的目前狀態。

const recordings = callRecordingApi.recordings;

recordings.forEach(r => {
    console.log("User: ${r.displayName}, State: ${r.state});

您也可以訂閱 recordingsUpdated 並取得更新錄製的集合。 每當有錄製更新時,就會觸發此事件。

const cloudRecordingsUpdatedHandler = (args: { added: SDK.RecordingInfo[], removed: SDK.RecordingInfo[]}) => {
                        console.log('Recording started by: ');
                        args.added?.forEach(a => {
                            console.log('User: ${a.displayName}');
                        });

                        console.log('Recording stopped by: ');
                        args.removed?.forEach(r => {
                            console.log('User: ${r.displayName});
                        });
                    };
callRecordingApi.on('recordingsUpdated', cloudRecordingsUpdatedHandler );

Teams 的本機錄製通知

Azure 通訊服務 使用規定要求開發人員向正在錄製的用戶顯示通知。 Microsoft Teams 應用程式可讓使用者在雲端和 Teams 桌面應用程式上錄製通話和會議。 開發人員可以使用 Azure 通訊服務 通話 SDK 來識別雲端或本機錄製是否已啟動或停止。

Azure 通訊服務呼叫 SDK 提供Call物件來管理呼叫。 它具有本機錄製 (LocalRecordingCallFeature) 和雲端錄製 (RecordingCallFeature) 的專用功能。 開發人員必須實作這兩項功能,以提供相容的解決方案。

您必須先從通話 SDK 匯入通話功能:

import { Features} from "@azure/communication-calling";

然後,您可以從呼叫實例取得本機錄製功能的 API 物件:

const localCallRecordingApi = call.feature(Features.LocalRecording);

若要檢查呼叫是否記錄在本機,請檢查 isLocalRecordingActivelocalCallRecordingApi屬性。 它會傳回 Boolean

const isLocalRecordingActive = localCallRecordingApi.isLocalRecordingActive;

您也可以使用 localRecordingslocalCallRecordingApi屬性來取得本機錄製的清單。 它會傳 LocalRecordingInfo[]回 ,其中包含使用者的顯示名稱,以及本機錄製的目前狀態。

const recordings = localCallRecordingApi.localRecordings;

recordings.forEach(r => {
    console.log("User: ${r.displayName}, State: ${r.state});

您可以訂閱錄製變更:

const isLocalRecordingActiveChangedHandler = () => {
    console.log(localCallRecordingApi.isLocalRecordingActive);
};    

localCallRecordingApi.on('isLocalRecordingActiveChanged', isLocalRecordingActiveChangedHandler);

您也可以訂閱 localRecordingsUpdated 並取得更新錄製的集合。 每當有錄製更新時,就會觸發此事件。

const localRecordingsUpdatedHandler = (args: { added: SDK.LocalRecordingInfo[], removed: SDK.LocalRecordingInfo[]}) => {
                        console.log('Local recording started by: ');
                        args.added?.forEach(a => {
                            console.log('User: ${a.displayName}');
                        });

                        console.log('Local recording stopped by: ');
                        args.removed?.forEach(r => {
                            console.log('User: ${r.displayName});
                        });
                    };
localCallRecordingApi.on('localRecordingsUpdated', localRecordingsUpdatedHandler);

安裝 SDK

找出您的專案層級 build.gradle 檔案,並將 新增mavenCentral()至 和 allprojects下的buildscript存放庫清單:

buildscript {
    repositories {
    ...
        mavenCentral()
    ...
    }
}
allprojects {
    repositories {
    ...
        mavenCentral()
    ...
    }
}

然後,在您的模組層級 build.gradle 檔案中,將下列幾行新增至 dependencies 區段:

dependencies {
    ...
    implementation 'com.azure.android:azure-communication-calling:1.0.0'
    ...
}

初始化必要的物件

若要建立CallAgent實例,您必須在 實例上CallClient呼叫 createCallAgent 方法。 這個呼叫會以異步方式傳 CallAgent 回實例物件。

方法 createCallAgent 會採用 CommunicationUserCredential 作為自變數,其會 封裝存取令牌

若要存取 DeviceManager,您必須先建立 callAgent 實例。 然後,您可以使用 CallClient.getDeviceManager 方法來取得 DeviceManager

String userToken = '<user token>';
CallClient callClient = new CallClient();
CommunicationTokenCredential tokenCredential = new CommunicationTokenCredential(userToken);
android.content.Context appContext = this.getApplicationContext(); // From within an activity, for instance
CallAgent callAgent = callClient.createCallAgent(appContext, tokenCredential).get();
DeviceManager deviceManager = callClient.getDeviceManager(appContext).get();

若要設定呼叫者的顯示名稱,請使用下列替代方法:

String userToken = '<user token>';
CallClient callClient = new CallClient();
CommunicationTokenCredential tokenCredential = new CommunicationTokenCredential(userToken);
android.content.Context appContext = this.getApplicationContext(); // From within an activity, for instance
CallAgentOptions callAgentOptions = new CallAgentOptions();
callAgentOptions.setDisplayName("Alice Bob");
DeviceManager deviceManager = callClient.getDeviceManager(appContext).get();
CallAgent callAgent = callClient.createCallAgent(appContext, tokenCredential, callAgentOptions).get();

錄製通話

注意

此 API 是以開發人員預覽的形式提供,可能會根據我們收到的意見反應而變更。 請勿在生產環境中使用此 API。 若要使用此 API,請使用 Azure 通訊服務 呼叫 Android SDK 的 Beta 版本。

通話錄製是核心 Call 對象的擴充功能。

警告

直到 1.1.0 版和 beta 版本 1.1.0-beta.1 的 Azure 通訊服務 呼叫 Android SDK 為止,isRecordingActiveaddOnIsRecordingActiveChangedListener屬於 物件的一Call部分。 針對新的 Beta 版本,這些 API 已移動為 的 Call擴充功能。

您必須先取得錄製功能物件:

RecordingCallFeature callRecordingFeature = call.feature(Features.RECORDING);

然後,若要檢查是否已記錄呼叫,請檢查 isRecordingActivecallRecordingFeature屬性。 它會傳回 boolean

boolean isRecordingActive = callRecordingFeature.isRecordingActive();

您也可以訂閱錄製變更:

private void handleCallOnIsRecordingChanged(PropertyChangedEvent args) {
  boolean isRecordingActive = callRecordingFeature.isRecordingActive();
}

callRecordingFeature.addOnIsRecordingActiveChangedListener(handleCallOnIsRecordingChanged);

如果您想要從應用程式開始錄製,請先遵循 通話錄製概觀 ,以取得設定通話錄製的步驟。

在伺服器上設定通話錄製之後,您必須從 Android 應用程式取得 ServerCallId 值,然後將它傳送到您的伺服器以開始錄製程式。 您可以使用 類別CallInfo中的 來尋找ServerCallIdgetServerCallId()。 您可以使用 CallInfo ,在類別物件 getInfo()中找到 類別。

try {
    String serverCallId = call.getInfo().getServerCallId().get();
    // Send serverCallId to your recording server to start the call recording.
} catch (ExecutionException | InterruptedException e) {

} catch (UnsupportedOperationException unsupportedOperationException) {

}

當您從伺服器開始錄製時,會觸發事件 handleCallOnIsRecordingChanged ,且的值 callRecordingFeature.isRecordingActive()true

就像開始通話錄製一樣,如果您想要停止通話錄製,您需要取得 ServerCallId 並將它傳送到錄製伺服器,以便停止錄製:

try {
    String serverCallId = call.getInfo().getServerCallId().get();
    // Send serverCallId to your recording server to stop the call recording.
} catch (ExecutionException | InterruptedException e) {

} catch (UnsupportedOperationException unsupportedOperationException) {

}

當您停止從伺服器錄製時,會觸發事件 handleCallOnIsRecordingChanged ,且的值 callRecordingFeature.isRecordingActive()false

設定系統

建立 Xcode 專案

在 Xcode 中,建立新的 iOS 專案,然後選取 [單一檢視應用程式 ] 範本。 本快速入門使用 SwiftUI 架構,因此您應該將 Language 設定Swift,並將 Interface 設定SwiftUI

在本快速入門期間,您不會建立測試。 您可以隨意清除 [ 包含測試 ] 複選框。

Screenshot that shows the window for creating a project within Xcode.

使用 CocoaPods 安裝套件和相依性

  1. 為您的應用程式建立 Podfile,如下列範例所示:

    platform :ios, '13.0'
    use_frameworks!
    target 'AzureCommunicationCallingSample' do
        pod 'AzureCommunicationCalling', '~> 1.0.0'
    end
    
  2. 執行 pod install

  3. 使用 Xcode 開啟 .xcworkspace

要求存取麥克風

若要存取裝置的麥克風,您必須使用 NSMicrophoneUsageDescription更新應用程式的資訊屬性清單。 您可以將相關聯的值設定為字串,此字串將包含在系統用來要求使用者存取的對話框中。

以滑鼠右鍵按兩下專案樹狀結構的Info.plist專案,然後選取[開啟為>原始程式碼]。 在最上層 <dict> 區段中新增下列幾行,然後儲存盤案。

<key>NSMicrophoneUsageDescription</key>
<string>Need microphone access for VOIP calling.</string>

設定應用程式架構

開啟專案的 ContentView.swift 檔案。 import將宣告新增至檔案頂端以匯入連結AzureCommunicationCalling庫。 此外,匯入 AVFoundation。 您需要它才能在程式代碼中要求音訊許可權。

import AzureCommunicationCalling
import AVFoundation

初始化 CallAgent

若要從 建立 CallAgent 實例,您必須使用callClient.createCallAgent方法,以異步方式在物件初始化之後傳回CallAgent物件。CallClient

若要建立呼叫用戶端,請傳遞 CommunicationTokenCredential 物件:

import AzureCommunication

let tokenString = "token_string"
var userCredential: CommunicationTokenCredential?
do {
    let options = CommunicationTokenRefreshOptions(initialToken: token, refreshProactively: true, tokenRefresher: self.fetchTokenSync)
    userCredential = try CommunicationTokenCredential(withOptions: options)
} catch {
    updates("Couldn't created Credential object", false)
    initializationDispatchGroup!.leave()
    return
}

// tokenProvider needs to be implemented by Contoso, which fetches a new token
public func fetchTokenSync(then onCompletion: TokenRefreshOnCompletion) {
    let newToken = self.tokenProvider!.fetchNewToken()
    onCompletion(newToken, nil)
}

CommunicationTokenCredential 您建立的物件傳遞至 CallClient,並設定顯示名稱:

self.callClient = CallClient()
let callAgentOptions = CallAgentOptions()
options.displayName = " iOS Azure Communication Services User"

self.callClient!.createCallAgent(userCredential: userCredential!,
    options: callAgentOptions) { (callAgent, error) in
        if error == nil {
            print("Create agent succeeded")
            self.callAgent = callAgent
        } else {
            print("Create agent failed")
        }
})

錄製通話

注意

此 API 是以開發人員預覽的形式提供,可能會根據我們收到的意見反應而變更。 請勿在生產環境中使用此 API。 若要使用此 API,請使用 Azure 通訊服務 呼叫 iOS SDK 的 Beta 版本。

通話錄製是核心 Call 對象的擴充功能。

警告

直到 1.1.0 版和 beta 版本 1.1.0-beta.1 的 Azure 通訊服務 呼叫 iOS SDK 為止,isRecordingActive是 物件的一部分Call,而且didChangeRecordingState是委派的CallDelegate一部分。 針對新的 Beta 版本,這些 API 已移動為 的 Call擴充功能。

您必須先取得錄製功能物件:

let callRecordingFeature = call.feature(Features.recording)

然後,若要檢查是否已記錄呼叫,請檢查 isRecordingActivecallRecordingFeature屬性。 它會傳回 Bool

let isRecordingActive = callRecordingFeature.isRecordingActive;

您也可以使用 事件didChangeRecordingState在 類別上實RecordingCallFeatureDelegate作委派,以訂閱錄製變更:

callRecordingFeature.delegate = self

// didChangeRecordingState is a member of RecordingCallFeatureDelegate
public func recordingCallFeature(_ recordingCallFeature: RecordingCallFeature, didChangeRecordingState args: PropertyChangedEventArgs) {
    let isRecordingActive = recordingFeature.isRecordingActive
}

如果您想要從應用程式開始錄製,請先遵循 通話錄製概觀 ,以取得設定通話錄製的步驟。

在伺服器上設定通話錄製之後,您必須從iOS應用程式中取得 ServerCallId 值,然後將它傳送至您的伺服器,以開始錄製程式。 您可以使用 類別CallInfo中的 來尋找ServerCallIdgetServerCallId()。 您可以使用 CallInfo ,在類別物件 getInfo()中找到 類別。

// Send serverCallId to your recording server to start the call recording.
let serverCallId = call.info.getServerCallId(){ (serverId, error) in }

當您從伺服器開始錄製時,會觸發事件 didChangeRecordingState ,且的值 recordingFeature.isRecordingActivetrue

就像開始通話錄製一樣,如果您想要停止通話錄製,您需要取得 ServerCallId 並將它傳送到錄製伺服器,以便停止錄製:

// Send serverCallId to your recording server to stop the call recording.
let serverCallId = call.info.getServerCallId(){ (serverId, error) in }

當您停止從伺服器錄製時,會觸發事件 didChangeRecordingState ,且的值 recordingFeature.isRecordingActivefalse

設定系統

建立 Visual Studio 專案

針對 UWP 應用程式,在 Visual Studio 2022 中建立新的 空白應用程式 (通用 Windows) 專案。 輸入專案名稱之後,您可以選擇 10.0.17763.0 之後的任何 Windows SDK。

針對 WinUI 3 應用程式,使用 [空白應用程式]、[傳統型] 範本建立新的專案,以設定單頁 WinUI 3 應用程式。 需要 Windows 應用程式 SDK 1.3 版或更新版本。

使用 NuGet 封裝管理員 安裝套件和相依性

呼叫 SDK API 和連結庫可透過 NuGet 套件公開使用。

下列步驟示範如何尋找、下載及安裝呼叫 SDK NuGet 套件:

  1. 選取 [工具>][NuGet 封裝管理員 管理方案的 NuGet 套件],以開啟 NuGet 封裝管理員。>
  2. 選取 [ 瀏覽],然後在搜尋方塊中輸入 Azure.Communication.Calling.WindowsClient
  3. 請確定已選取 [ 包含發行前版本 ] 複選框。
  4. 選取套件 Azure.Communication.Calling.WindowsClient ,然後選取 Azure.Communication.Calling.WindowsClient1.4.0-beta.1 或更新版本。
  5. 選取對應至右側索引標籤上 [通訊服務] 項目的複選框。
  6. 選取 [安裝] 按鈕。

錄製通話

通話錄製是核心 Call 對象的擴充功能。 您必須先取得錄製功能物件:

RecordingCallFeature recordingFeature = call.Features.Recording;

然後,若要檢查是否已記錄呼叫,請檢查 IsRecordingActiverecordingFeature屬性。 它會傳回 boolean

boolean isRecordingActive = recordingFeature.IsRecordingActive;

您也可以訂閱錄製變更:

private async void Call__OnIsRecordingActiveChanged(object sender, PropertyChangedEventArgs args)
  boolean isRecordingActive = recordingFeature.IsRecordingActive;
}

recordingFeature.IsRecordingActiveChanged += Call__OnIsRecordingActiveChanged;

合規性記錄

合規性錄製是以 Microsoft Teams 原則為基礎的錄製。 您可以使用本教學課程來啟用此功能: 通話的Teams原則型錄製簡介。

原則型錄製會在有原則的使用者加入通話時自動啟動。 若要從 Azure 通訊服務 取得有關錄製的通知,請使用下列程式代碼:

const callRecordingApi = call.feature(Features.Recording);

const isComplianceRecordingActive = callRecordingApi.isRecordingActive;

const isComplianceRecordingActiveChangedHandler = () => {
    console.log(callRecordingApi.isRecordingActive);
};

callRecordingApi.on('isRecordingActiveChanged', isComplianceRecordingActiveChangedHandler);

您也可以使用自定義錄製 Bot 來實作合規性錄製。 請參閱 GitHub 範例

下一步