加入 Teams 會議

Warning

Azure 通訊服務 正在推出突破性變更,部分服務也將被淘汰。 想了解更多,請參閱退休 與變更指南。

Azure 通訊服務 SDK 可讓您的使用者加入一般 Microsoft Teams 會議。 方法如下!

必要條件

安裝 SDK

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

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

初始化必要的物件

大部分通話作業都需要 CallClient 執行個體。 當您建立新的 CallClient 執行個體時,您可以使用自訂選項加以設定,如同 Logger 執行個體一樣。

使用 CallClient 執行個體,您可以藉由呼叫 CallAgent 來建立 createCallAgent 執行個體。 此方法會以非同步的方式傳回 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()

管理與Microsoft基礎結構的 SDK 連線

Call Agent 執行個體可協助您管理通話 (加入或啟動通話)。 若要運作,您的通話 SDK 必須連線到 Microsoft 基礎結構以取得來電通知,並協調其他通話詳細資料。 您的 Call Agent 有兩種可能的狀態:

已連線 - Call Agent 的 Connected connectionStatue 值表示用戶端 SDK 已連線且能夠接收來自 Microsoft 基礎結構的通知。

已中斷連線 - Call Agent 狀態的 Disconnected connectionStatue 值指出有問題導致 SDK 無法正確連線。 Call Agent 應該重新建立。

  • invalidToken:如果權杖已過期或無效,Call Agent 執行個體會中斷連線,並顯示此錯誤。
  • connectionIssue:如果客戶端連線到Microsoft基礎結構時發生問題,在多次重試 Call Agent 后,就會公開 connectionIssue 錯誤。

您可以藉由檢查 Call Agent 屬性的目前值,檢查本機 connectionState 是否已連線到 Microsoft 基礎結構。 在作用中通話期間,您可以接聽 connectionStateChanged 事件,以判斷 Call Agent 是否從已連線變更為已中斷連線狀態。

const connectionState = callAgentInstance.connectionState;
console.log(connectionState); // it may return either of 'Connected' | 'Disconnected'

const connectionStateCallback = (args) => {
    console.log(args); // it will return an object with oldState and newState, each of having a value of either of 'Connected' | 'Disconnected'
    // it will also return reason, either of 'invalidToken' | 'connectionIssue'
}
callAgentInstance.on('connectionStateChanged', connectionStateCallback);

會議加入方法

若要加入 Teams 會議,請使用 join 方法並傳送會議連結或會議的座標。

使用會議連結加入:

const locator = { meetingLink: '<MEETING_LINK>'}
const call = callAgent.join(locator);

使用會議座標加入會議(目前僅提供有限預覽):

const locator = {
    threadId: <thread id>,
    organizerId: <organizer id>,
    tenantId: <tenant id>,
    messageId: <message id>
}
const call = callAgent.join(locator);

設定您的系統

請遵循下列步驟來設定系統。

建立 Visual Studio 專案

針對 通用 Windows 平台 應用程式,請在 Visual Studio 2022 中建立新的空白應用程式 (通用 Windows) 專案。 在輸入專案名稱之後,隨意選擇高於 10.0.17763.0 的任何 Windows SDK。

針對 WinUI 3 應用程式,使用空白應用程式、封裝 (桌面中的 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.WindowsClient 1.4.0-beta.1] 或更新版本。
  5. 選取對應至右窗格中 Azure 通訊服務 項目的複選框。
  6. 選取 安裝。

會議聯結方法

若要加入 Teams 會議,請使用 CallAgent.join 方法並傳遞應用程式內容、 JoinMeetingLocator和 JoinCallOptions。

會議標識碼和密碼

TeamsMeetingIdLocator 會使用會議 ID 和密碼來尋找會議。 這些可在 Teams 會議的加入資訊中找到。 Teams 會議 ID 的長度為 12 個字元,並且由每三個一組的數字組成(亦即 000 000 000 000)。 密碼將包含6個字元(亦即 aBcDeF)。 密碼區分大小寫。

String meetingId, passcode; 
TeamsMeetingIdLocator locator = new TeamsMeetingIdLocator(meetingId, passcode);

The TeamsMeetingLinkLocator會使用 Teams 會議的連結來定位會議。 這可在 Teams 會議的加入資訊中找到。

String meetingLink; 
TeamsMeetingLinkLocator locator = new TeamsMeetingLinkLocator(meetingLink);

會議座標

TeamsMeetingCoordinatesLocator 會使用召集人識別碼、租用戶識別碼、執行緒識別碼以及訊息識別碼來找出會議。 您可以使用 Microsoft Graph 找到此資訊。

Guid organizerId, tenantId;
String threadId, messageId;
TeamsMeetingCoordinatesLocator locator = new TeamsMeetingCoordinatesLocator(threadId, organizerId, tenantId, messageId);

使用定位器加入會議

建立這些 Teams 會議定位器之後,您可以使用它,透過CallAgent.join加入 Teams 會議,如下方所示。

JoinCallOptions options = new JoinCallOptions();
call = agent.join(
        getApplicationContext(),
        locator,
        options);

設定您的系統

請遵循下列步驟來設定系統。

建立 Visual Studio 專案

針對 通用 Windows 平台 應用程式,請在 Visual Studio 2022 中建立新的空白應用程式 (通用 Windows) 專案。 在輸入專案名稱之後,隨意選擇高於 10.0.17763.0 的任何 Windows SDK。

針對 WinUI 3 應用程式,使用空白應用程式、封裝 (桌面中的 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.WindowsClient 1.4.0-beta.1] 或更新版本。
  5. 選取對應至右窗格中 Azure 通訊服務 項目的複選框。
  6. 選取 安裝。

會議加入方法

若要加入 Teams 會議,請使用 CallAgent.join 方法並傳遞 JoinMeetingLocator 和 JoinCallOptions。

會議標識碼和密碼

TeamsMeetingIdLocator 會使用會議 ID 和密碼來尋找會議。 這些可在 Teams 會議的加入資訊中找到。 Teams 會議識別碼的長度為 12 個字元,並由每三個一組的數字組成(亦即 000 000 000 000)。 密碼將包含6個字元(亦即 aBcDeF)。 密碼區分大小寫。

String meetingId, passcode
let locator = TeamsMeetingIdLocator(meetingId: meetingId, passcode: passcode)

The TeamsMeetingLinkLocator會使用 Teams 會議的連結來定位會議。 這可在 Teams 會議的加入資訊中找到。

String meetingLink
let locator = TeamsMeetingLinkLocator(meetingLink: meetingLink)

使用定位器加入會議

建立這些 Teams 會議定位資訊後,您可以使用 CallAgent.join 加入 Teams 會議,如下所示。

func joinTeamsMeeting() {
    // Ask permissions
    AVAudioSession.sharedInstance().requestRecordPermission { (granted) in
        if granted {
            let joinCallOptions = JoinCallOptions()
            
            // Insert meeting locator code for specific join methods here

            // for CallAgent callAgent
            self.callAgent?.join(with: teamsMeetingLinkLocator, joinCallOptions: joinCallOptions) 
        }
    }
}

設定您的系統

請遵循下列步驟來設定系統。

建立 Visual Studio 專案

針對 通用 Windows 平台 應用程式,請在 Visual Studio 2022 中建立新的空白應用程式 (通用 Windows) 專案。 在輸入專案名稱之後,隨意選擇高於 10.0.17763.0 的任何 Windows SDK。

針對 WinUI 3 應用程式,使用空白應用程式、封裝 (桌面中的 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.WindowsClient 1.4.0-beta.1] 或更新版本。
  5. 選取對應至右窗格中 Azure 通訊服務 項目的複選框。
  6. 選取 安裝。

會議聯結方法

若要加入 Teams 會議,請使用 CallAgent.JoinAsync 方法並傳遞 JoinMeetingLocator 和 JoinCallOptions。

會議標識碼和密碼

TeamsMeetingIdLocator 會使用會議 ID 和密碼來尋找會議。 這些可以在 Teams 會議的加入資訊中找到。 Teams 會議識別碼的長度為 12 個字元,且由數字組成,每三個數字為一組(亦即 000 000 000 000)。 密碼將包含6個字元(亦即 aBcDeF)。 密碼區分大小寫。

string meetingId, passcode; 
TeamsMeetingIdLocator locator = new TeamsMeetingIdLocator(meetingId, passcode);

The TeamsMeetingLinkLocator會使用 Teams 會議的連結來定位會議。 您可以在 Teams 會議的加入資訊中找到此項目。

string meetingLink; 
TeamsMeetingLinkLocator locator = new TeamsMeetingLinkLocator(meetingLink);

會議座標

TeamsMeetingCoordinatesLocator 會使用召集人識別碼、租用戶識別碼、執行緒識別碼和訊息識別碼來找出會議。 您可以使用 Microsoft Graph 找到此資訊。

Guid organizerId, tenantId;
string threadId, messageId;
TeamsMeetingCoordinatesLocator locator = new TeamsMeetingCoordinatesLocator(threadId, organizerId, tenantId, messageId);

使用定位器加入會議

建立這些 Teams 會議定位器之後,您可以使用它,透過CallAgent.JoinAsync加入 Teams 會議,如下方所示。

var joinCallOptions = new JoinCallOptions() {
        OutgoingAudioOptions = new OutgoingAudioOptions() { IsMuted = true },
        OutgoingVideoOptions = new OutgoingVideoOptions() { Streams = new OutgoingVideoStream[] { cameraStream } }
    };
var call = await callAgent.JoinAsync(locator, joinCallOptions);

下一步