你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

如何检测使用 Azure 通信服务 SDK 的应用程序是否在浏览器的多个选项卡中处于活动状态

根据最佳实践,应用程序不得同时连接到来自多个浏览器标签页的调用。 由于设备上的麦克风和摄像头的资源分配,在移动设备上的浏览器的多个标签页上处理多个呼叫可能会导致未定义的行为。 为了检测应用程序在浏览器的多个标签页中是否处于活动状态,开发人员可以使用 CallClient 实例的 isCallClientActiveInAnotherTab 方法和 isCallClientActiveInAnotherTabChanged 事件。

const callClient = new CallClient();
// Check if an application is active in multiple tabs of a browser
const isCallClientActiveInAnotherTab = callClient.feature(SDK.Features.DebugInfo).isCallClientActiveInAnotherTab;
...
// Subscribe to the event to listen for changes 
callClient.feature(Features.DebugInfo).on('isCallClientActiveInAnotherTabChanged', () => {
    // callback();
});
...
// Unsubscribe from the event to stop listening for changes 
callClient.feature(Features.DebugInfo).off('isCallClientActiveInAnotherTabChanged', () => {
    // callback();
});