共用方式為


從 JavaScript 應用程式取得 serverCallId 作為呼叫錄製伺服器 API 的需求

在使用通話用戶端 SDK 的對等通話案例中,若要使用來自 Azure 通訊的通話錄製,您必須取得 serverCallId。 下列範例示範如何從 JavaScript 伺服器應用程式取得 serverCallId

通話錄音是核心 Call API 的擴充功能。 您必須先從通話 SDK 匯入通話功能。

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

然後,您可以從呼叫執行個體取得錄製功能 API 物件:

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

訂閱錄製變更:

const recordingStateChanged = () => {
    let recordings = callRecordingApi.recordings;

    let state = SDK.RecordingState.None;
    if (recordings.length > 0) {
        state = recordings.some(r => r.state == SDK.RecordingState.Started)
            ? SDK.RecordingState.Started
            : SDK.RecordingState.Paused;
    }
    
	console.log(`RecordingState: ${state}`);
}

const recordingsChangedHandler = (args: { added: SDK.RecordingInfo[], removed: SDK.RecordingInfo[]}) => {
    args.added?.forEach(a => {
        a.on('recordingStateChanged', recordingStateChanged);
    });

    args.removed?.forEach(r => {
        r.off('recordingStateChanged', recordingStateChanged);
    });

    recordingStateChanged();
};

callRecordingApi.on('recordingsUpdated', recordingsChangedHandler);

取得 servercallId,可用來啟動/停止/暫停/繼續錄製工作階段。 呼叫連線之後,請使用 getServerCallId 方法來取得伺服器呼叫識別碼。

callAgent.on('callsUpdated', (e: { added: Call[]; removed: Call[] }): void => {
    e.added.forEach((addedCall) => {
        addedCall.on('stateChanged', (): void => {
            if (addedCall.state === 'Connected') {
                addedCall.info.getServerCallId().then(result => {
                    dispatch(setServerCallId(result));
                }).catch(err => {
                    console.log(err);
                });
            }
        });
    });
});

另請參閱

如需詳細資訊,請參閱下列文章: