如何在 ConnectyCube 中接听视频通话?
How to accept a videochat call in ConnectyCube?
我有两个简单的 HTML/Javascript 页面。一种用于发起视频通话(呼叫者),一种用于接受视频通话(被叫方)。
在 ConnectyCube 的文档中,我首先登录并连接聊天。
在调用方,我执行调用功能:
function callNow(session) {
var extension = {};
session.call(extension, function(error)
{
console.log('calling - ring ring');
//Get calling ringtone ringing
document.getElementById('callingSignal').play();
// work with callbacks
handlingCallReactions();
});
}
//Function for handling the reactions
function handlingCallReactions() {
ConnectyCube.videochat.onUserNotAnswerListener = function onUserNotAnswerListener(
session,
userId
) {
console.group('onUserNotAnswerListener.');
console.log('UserId: ', userId);
console.log('Session: ', session);
console.groupEnd();
};
//If user takes call
//After this, your opponents will get a confirmation in the following callback:
ConnectyCube.videochat.onAcceptCallListener = function(
session,
userId,
extension
) {
console.log('other user accepted call');
};
ConnectyCube.videochat.onRemoteStreamListener = function(
session,
userID,
remoteStream
) {
// attach the remote stream to DOM element
session.attachMediaStream('remoteOpponentVideoElementId', remoteStream);
};
}
观察浏览器控制台,我得到以下输出:
[VideoChat]: _dialingCallback, answerTimeInterval: 60000
所以我认为这部分工作正常,因为该过程正在等待某些事情发生。
在被叫方的另一边,我也登录并连接聊天(直到这里它运行良好),然后我使用以下代码等待呼叫到达。
//After this, your opponents will receive a callback call:
//Function for accepting videocalling by callback
ConnectyCube.videochat.onCallListener = function(session, extension) {
var extension = {};
session.accept(extension);
console.log('Im waiting and can take call');
};
ConnectyCube.videochat.onRemoteStreamListener = function(
session,
userID,
remoteStream
) {
// attach the remote stream to DOM element
session.attachMediaStream('remoteOpponentVideoElementId', remoteStream);
};
所述页面(被调用者)的控制台给出以下输出。
[Chat] Connect with parameters {"userId":22222,"password":"bbbbbbbb"}
[Chat] Status.CONNECTING (Chat Protocol - WebSocket) connectycube.min.js:1:454409
[Chat] SENT: <unavailable>
[Chat] RECV: <unavailable>
[Chat] SENT: <unavailable>
[Chat] RECV: <unavailable>
[Chat] SENT: <unavailable>
[Chat] RECV: <unavailable>
[Chat] SENT: <unavailable>
[Chat] RECV: <unavailable>
[Chat] SENT: <unavailable>
[Chat] RECV: <unavailable>
[Chat] Status.CONNECTED at
[Chat] SENT: <unavailable>
[Chat] RECV: <unavailable>
[Chat] SENT: <unavailable>
logged into chat
[Chat] RECV: <unavailable>
我在这里错过了什么才能真正看到电话到达?
你的代码是正确的,
我可以推荐检查的是你如何创建 session object
var calleesIds = [56, 76, 34]; // User's ids
var sessionType = ConnectyCube.videochat.CallType.VIDEO; // AUDIO is also possible
var additionalOptions = {};
var session = ConnectyCube.videochat.createNewSession(calleesIds, sessionType, additionalOptions);
我建议您检查一下 calleesIds 里面有什么。我猜被叫方没有收到任何东西,因为他的用户 ID 不在来电方的 calleesIds 数组中。
https://developers.connectycube.com/js/videocalling?id=create-video-session
我有两个简单的 HTML/Javascript 页面。一种用于发起视频通话(呼叫者),一种用于接受视频通话(被叫方)。
在 ConnectyCube 的文档中,我首先登录并连接聊天。
在调用方,我执行调用功能:
function callNow(session) {
var extension = {};
session.call(extension, function(error)
{
console.log('calling - ring ring');
//Get calling ringtone ringing
document.getElementById('callingSignal').play();
// work with callbacks
handlingCallReactions();
});
}
//Function for handling the reactions
function handlingCallReactions() {
ConnectyCube.videochat.onUserNotAnswerListener = function onUserNotAnswerListener(
session,
userId
) {
console.group('onUserNotAnswerListener.');
console.log('UserId: ', userId);
console.log('Session: ', session);
console.groupEnd();
};
//If user takes call
//After this, your opponents will get a confirmation in the following callback:
ConnectyCube.videochat.onAcceptCallListener = function(
session,
userId,
extension
) {
console.log('other user accepted call');
};
ConnectyCube.videochat.onRemoteStreamListener = function(
session,
userID,
remoteStream
) {
// attach the remote stream to DOM element
session.attachMediaStream('remoteOpponentVideoElementId', remoteStream);
};
}
观察浏览器控制台,我得到以下输出:
[VideoChat]: _dialingCallback, answerTimeInterval: 60000
所以我认为这部分工作正常,因为该过程正在等待某些事情发生。
在被叫方的另一边,我也登录并连接聊天(直到这里它运行良好),然后我使用以下代码等待呼叫到达。
//After this, your opponents will receive a callback call:
//Function for accepting videocalling by callback
ConnectyCube.videochat.onCallListener = function(session, extension) {
var extension = {};
session.accept(extension);
console.log('Im waiting and can take call');
};
ConnectyCube.videochat.onRemoteStreamListener = function(
session,
userID,
remoteStream
) {
// attach the remote stream to DOM element
session.attachMediaStream('remoteOpponentVideoElementId', remoteStream);
};
所述页面(被调用者)的控制台给出以下输出。
[Chat] Connect with parameters {"userId":22222,"password":"bbbbbbbb"}
[Chat] Status.CONNECTING (Chat Protocol - WebSocket) connectycube.min.js:1:454409
[Chat] SENT: <unavailable>
[Chat] RECV: <unavailable>
[Chat] SENT: <unavailable>
[Chat] RECV: <unavailable>
[Chat] SENT: <unavailable>
[Chat] RECV: <unavailable>
[Chat] SENT: <unavailable>
[Chat] RECV: <unavailable>
[Chat] SENT: <unavailable>
[Chat] RECV: <unavailable>
[Chat] Status.CONNECTED at
[Chat] SENT: <unavailable>
[Chat] RECV: <unavailable>
[Chat] SENT: <unavailable>
logged into chat
[Chat] RECV: <unavailable>
我在这里错过了什么才能真正看到电话到达?
你的代码是正确的,
我可以推荐检查的是你如何创建 session object
var calleesIds = [56, 76, 34]; // User's ids
var sessionType = ConnectyCube.videochat.CallType.VIDEO; // AUDIO is also possible
var additionalOptions = {};
var session = ConnectyCube.videochat.createNewSession(calleesIds, sessionType, additionalOptions);
我建议您检查一下 calleesIds 里面有什么。我猜被叫方没有收到任何东西,因为他的用户 ID 不在来电方的 calleesIds 数组中。
https://developers.connectycube.com/js/videocalling?id=create-video-session