用于视频通话的 Azure 通信服务 - 功能未定义

问题描述 投票:0回答:1

通过 Azure 通信调用库,我尝试获得网络质量。

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

我尝试了这两个代码,但我有同样的错误“功能未定义”。

编辑:我将功能的代码放入 subscribeToCall 函数中。

我忘记导入什么东西了吗?

编辑更多详细信息:

我的功能是在开始或接受时订阅呼叫。

subscribeToCall = (call) => {
    try {
        // Subscribe to call's 'stateChanged' event for value changes.
        call.on('stateChanged', async () => {
            // If ringing / Connected / Disconnected ...
        });

        call.on('isLocalVideoStartedChanged', () => {
            console.log(`------------- isLocalVideoStarted changed: ${call.isLocalVideoStarted}`);
        });
        call.localVideoStreams.forEach(async (lvs) => {
            localVideoStream = lvs;
            await displayLocalVideoStream();
        });
        call.on('localVideoStreamsUpdated', e => {
            e.added.forEach(async (lvs) => {
                localVideoStream = lvs;
                await displayLocalVideoStream();
            });
            e.removed.forEach(lvs => {
               removeLocalVideoStream();
            });
        });
        call.remoteParticipants.forEach(remoteParticipant => {
            subscribeToRemoteParticipant(remoteParticipant);
        });
        // Subscribe to the call's 'remoteParticipantsUpdated' event to be
        // notified when new participants are added to the call or removed from the call.
        call.on('remoteParticipantsUpdated', e => {
            // Subscribe to new remote participants that are added to the call.
            e.added.forEach(remoteParticipant => {
                subscribeToRemoteParticipant(remoteParticipant)
            });
            // Unsubscribe from participants that are removed from the call
            e.removed.forEach(remoteParticipant => {
                console.log('Remote participant removed from the call.');
            });
        });

        // CALL FEATURE TESTS ::::::::
        // First example
        /*const userFacingDiagnostics = call.feature(Features.UserFacingDiagnostics);

        userFacingDiagnostics.media.on("diagnosticChanged", (diagnosticInfo) => {
          console.log(diagnosticInfo);
        });

        userFacingDiagnostics.network.on("diagnosticChanged", (diagnosticInfo) => {
           console.log(diagnosticInfo);
        });*/

        // Second example

        /*call.feature(Features.UserFacingDiagnostics).network.on('diagnosticChanged', (diagnosticInfo) => {
            if (diagnosticInfo.diagnostic === 'networkReceiveQuality') {
                if (diagnosticInfo.value === DiagnosticQuality.Bad) {
                    console.log("Network quality = BAD");
                } else if (diagnosticInfo.value === DiagnosticQuality.Poor) {
                    console.log("Network quality = POOR");
                } else if (diagnosticInfo.value === DiagnosticQuality.Good) {
                    console.log("Network quality = GOOD");
                }
            }
        });*/


    } catch (error) {
        console.error(error);
    }
}

编辑2024/04/24

第一个示例源链接:Stackoverflow - 无法加载 Features.Diagnostics

第二个示例源链接:networkReceiveQuality,UFD

azure video-conferencing videocall azure-communication-services
1个回答
0
投票

错误“功能未定义”表示在您的代码范围内无法识别

Features
对象。

特征对象应该像这样使用:

const callQualityApi = call.api(Features.Diagnostics);
callQualityApi.network.on('diagnosticChanged', diagnosticChangedListener);
callQualityApi.media.on('diagnosticChanged', diagnosticChangedListener);

要为 Azure 通信服务资源启用呼叫诊断,请按照以下步骤操作:

  • 创建 Azure Log Analytics 工作区。
  • 为您的资源添加诊断设置。您可以按照此处提供的说明执行此操作。确保通过 Azure Monitor 中的诊断设置启用日志。

enter image description here

  • 添加诊断设置时,选择“allLogs”来收集所有日志和指标。
  • 选择目标详细信息将日志流式传输到 Log Analytics 工作区并保存。

enter image description here

设置诊断设置后,您可以从 Azure 门户中的任何 Azure 通信服务资源访问呼叫诊断。

  • 导航到 Azure 通信服务资源并找到界面左侧的“监控”部分。
  • 从可用选项中选择“呼叫诊断”。

下面的示例代码是 Azure 通信服务调用 Node.js 中的 SDK 来为各种呼叫和网络诊断事件设置事件处理程序和侦听器。它会检查

DiagnosticQuality.Bad
DiagnosticQuality.Poor
DiagnosticQuality.Good

  • Web applications的 Azure 通信服务呼叫诊断功能的代码取自此参考doc
const { CallClient, VideoStreamRenderer, LocalVideoStream, Features } = require('@azure/communication-calling');
const { AzureCommunicationTokenCredential } = require('@azure/communication-common');
const { AzureLogger, setLogLevel } = require("@azure/logger");


const subscribeToCall = (call) => {
    try {
       
        call.on('stateChanged', async () => {
            // If ringing / Connected / Disconnected ...
        });

        call.on('isLocalVideoStartedChanged', () => {
            console.log(`------------- isLocalVideoStarted changed: ${call.isLocalVideoStarted}`);
        });
        call.localVideoStreams.forEach(async (lvs) => {
            localVideoStream = lvs;
            await displayLocalVideoStream();
        });
        call.on('localVideoStreamsUpdated', e => {
            e.added.forEach(async (lvs) => {
                localVideoStream = lvs;
                await displayLocalVideoStream();
            });
            e.removed.forEach(lvs => {
               removeLocalVideoStream();
            });
        });
        call.remoteParticipants.forEach(remoteParticipant => {
            subscribeToRemoteParticipant(remoteParticipant);
        });
      
        call.on('remoteParticipantsUpdated', e => {
          
            e.added.forEach(remoteParticipant => {
                subscribeToRemoteParticipant(remoteParticipant)
            });
           
            e.removed.forEach(remoteParticipant => {
                console.log('Remote participant removed from the call.');
            });
        });

        
        call.api(Features.Diagnostics).network.on('diagnosticChanged', (diagnosticInfo) => {
            console.log(diagnosticInfo);
      
        });

      
        call.api(Features.UserFacingDiagnostics).network.on('diagnosticChanged', (diagnosticInfo) => {
            if (diagnosticInfo.diagnostic === 'networkReceiveQuality') {
                if (diagnosticInfo.value === DiagnosticQuality.Bad) {
                    console.log("Network quality = BAD");
                } else if (diagnosticInfo.value === DiagnosticQuality.Poor) {
                    console.log("Network quality = POOR");
                } else if (diagnosticInfo.value === DiagnosticQuality.Good) {
                    console.log("Network quality = GOOD");
                }
            }
        });

    } catch (error) {
        console.error(error);
    }
}

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.