用于视频通话的 Azure 通信服务 - 同时传入/传出呼叫

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

我正在使用 Azure 通信服务在 2 个人(第 1 个人和第 2 个人)之间创建视频通话。

第一个连接的人(对于示例 1)等待第二个连接(对于示例 2)。 当第二个人接通时,他们发起呼叫。 因此,人员 1 会收到通知,并且必须使用此功能接听电话:

callAgent.on('incomingCall', async (args) => {
    try {
        //show the button accept call
    } catch (error) {
    }
});

无人接听则自动呼叫不成功。

我的问题是,当 2 人同时发起呼叫时,2 个人中的一个应答,但另一个已连接到呼叫,无法应答,因此呼叫被断开,就好像没有应答一样。

是否可以在通话开始时销毁传入呼叫?

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

当双方尝试同时发起呼叫时同时处理来电和活动呼叫的步骤:

  • 使用
    incomingCall
    事件处理程序来监听来电。如果此人已经在通话中,您可能需要驳回或拒绝来电。
  • 如果用户已在通话中并接到来电,您可以自动拒接来电。在
    args.call.reject()
    事件处理程序中使用
    incomingCall
    拒绝来电。
  • 为每个呼叫分配唯一的标识符,以确保来自同一参与者的呼叫可以单独管理。这样,当用户正在进行通话时,可以根据唯一标识符拒绝任何来电。
  • 代码取自git。使用此 doc 进行
    incomingCall
    和在 Azure 通信中进行管理。

let activeCall = null;

callAgent.on('incomingCall', async (args) => {
    try {
        // Check if there is an active call already
        if (activeCall) {
            // Decline the incoming call automatically if the user is in an active call
            await args.call.reject();
            console.log('Incoming call declined because the user is in an active call.');
        } else {
            // Show the button to accept the incoming call
            // If accepted, set the call as activeCall
            activeCall = await args.accept();
        }
    } catch (error) {
        console.error('Error handling incoming call:', error);
    }
});

// Sample code for initiating a call
async function initiateCall() {
    if (activeCall) {
        console.log('Already in a call, cannot initiate a new call.');
        return;
    }

    // Assuming you have a target user ID or phone number to call
    const targetUserIdentifier = { communicationUserId: '<USER_ID>' };
    try {
        activeCall = await callAgent.startCall([targetUserIdentifier]);
        console.log('Call initiated successfully');
    } catch (error) {
        console.error('Error initiating call:', error);
    }
}


enter image description here

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