Closed alxx28 closed 3 years ago
We have this check inside 'accept' method:
accept(extension) {
Helpers.trace('Accept, extension: ' + JSON.stringify(ext.userInfo));
if (this.state === SessionState.ACTIVE) {
Helpers.traceError("Can't accept, the session is already active, return.");
return;
}
So when you already have an active call, you can't accept a new one.
You have to use a diff session for each new call.
So just call ConnectyCube.videochat.createNewSession
for all the new call
@DaveLomber Excuse me, I don't know how to apply what you said in my case. In my case only the sender(Medic) starts a call, the recipient(Patient) only receives a call, no more.
Sender Fragment:
function startVideo() {
console.log('Start Video');
$('#btn_mutesound').hide();
$('#btn_unmutesound').show();
$('#btn_mutevideo').hide();
$('#btn_unmutevideo').show();
const id_paciente = $('#hd_idpaciente').val();
const calleesIds = [id_paciente]; /*User's ids*/
const sessionType = ConnectyCube.videochat.CallType.VIDEO;
const additionalOptions = {};
const session = ConnectyCube.videochat.createNewSession(calleesIds, sessionType, additionalOptions);
const mediaParams = {
audio: true,
video: true,
options: {
muted: true,
mirror: true
}
};
session.getUserMedia(mediaParams).then((localStream) => {
console.log(JSON.stringify(localStream));
session.attachMediaStream('vd_video1', localStream);
const extension = {};
session.call(extension, (error) => {
console.log(JSON.stringify(error));
});
/*sendNotification(id_paciente);*/
$('#dv_msjconexion').html('Marcando....');
$('#btn_colgar').off('click').on('click', {x: session}, finishCall);
}).catch((error) => {
console.log(JSON.stringify(error));
});
}
Recipient Fragment:
function acceptCall(e) {
const mediaParams = {
audio: true,
video: true,
options: {
muted: true,
mirror: true
}
};
e.data.x.getUserMedia(mediaParams).then((localStream) => {
console.log(JSON.stringify(localStream));
e.data.x.attachMediaStream('vd_video2', localStream);
console.log('session=>' + e.data.x);
const extension = {};
e.data.x.accept(extension);
}).catch((error) => {
console.log(JSON.stringify(error));
});
$('#dv_llamada').modal('hide');
}
As you can see the function startVideo() from sender side always uses ConnectyCube.videochat.createNewSession
@alxx28 how do you handle ConnectyCube.videochat.onCallListener = function (session, extension) {
?
do you always use a new session received via session
params when call session.accept
?
I mean it should be like this
ConnectyCube.videochat.onCallListener = function (session, extension) {
// Here we need to show a dialog with 2 buttons - Accept & Reject.
// By accepting -> run the following code:
//
// 1. await session.getUserMedia (...)
//
// 2. Accept call request:
const extension = {};
session.accept(extension);
};
@DaveLomber I am doing this: Sender
function startVideo() {
console.log('Start Video');
$('#btn_mutesound').hide();
$('#btn_unmutesound').show();
$('#btn_mutevideo').hide();
$('#btn_unmutevideo').show();
const id_paciente = $('#hd_idpaciente').val();
const calleesIds = [id_paciente]; /*User's ids*/
const sessionType = ConnectyCube.videochat.CallType.VIDEO;
const additionalOptions = {};
const session = ConnectyCube.videochat.createNewSession(calleesIds, sessionType, additionalOptions);
const mediaParams = {
audio: true,
video: true,
options: {
muted: true,
mirror: true
}
};
session.getUserMedia(mediaParams).then((localStream) => {
console.log(JSON.stringify(localStream));
session.attachMediaStream('vd_video1', localStream);
const extension = {};
session.call(extension, (error) => {
console.log(JSON.stringify(error));
});
/*sendNotification(id_paciente);*/
$('#dv_msjconexion').html('Marcando....');
$('#btn_colgar').off('click').on('click', {x: session}, finishCall);
}).catch((error) => {
console.log(JSON.stringify(error));
});
}
Recipient
function acceptCall(e) {
const mediaParams = {
audio: true,
video: true,
options: {
muted: true,
mirror: true
}
};
e.data.x.getUserMedia(mediaParams).then((localStream) => {
console.log(JSON.stringify(localStream));
e.data.x.attachMediaStream('vd_video2', localStream);
console.log('session=>' + e.data.x);
const extension = {};
e.data.x.accept(extension);
}).catch((error) => {
console.log(JSON.stringify(error));
});
$('#dv_llamada').modal('hide');
}
function finishCall(e) {
console.log('Finished Call');
const extension = {};
e.data.x.stop(extension);
cleanVideo();
}
function setStream(session, userID, remoteStream) {
console.log('Remote Stream Assigned');
$('#dv_msjconexion').html('Accepted call');
session.attachMediaStream('vd_video1', remoteStream);
}
function bindCall(session, extension) {
console.log('Session=>' + session);
console.log('Session=>' + JSON.stringify(extension));
$('#dv_msjconexion').html('Someone is calling...');
$('#dv_llamada').modal('show');/*This is the modal with the two buttons to accept and reject a call*/
/*This buttons are located in the modal #dv_llamada*/
$('#btn_aceptar').on('click', {x: session}, acceptCall);/*Button to accept the call*/
$('#btn_finalizar').on('click', {x: session}, finishCall);/*Button to reject the call*/
}
function onStopCall(session, userId, extension) {
console.log('Finished Call');
session.stop(extension);
cleanVideo();
$('#dv_msjconexion').html('Finished Call');
}
ConnectyCube.videochat.onCallListener = bindCall;
ConnectyCube.videochat.onRemoteStreamListener = setStream;
ConnectyCube.videochat.onStopCallListener = onStopCall;
@alxx28 I checked again your first message
What worries me the most is this double accept log
Any chance your code can call accept
double times one by one ?
@DaveLomber Yes, you are right the click was triggering twice or more times.
I solved like this before to assing the "click" event it's necessary to unbind the earlier event:
function bindCall(session, extension) {
console.log('Session=>' + session);
console.log('Session=>' + JSON.stringify(extension));
$('#dv_msjconexion').html('Someone is calling...');
$('#dv_llamada').modal('show');
$('#btn_aceptar').off('click').on('click', {x: session}, acceptCall);
$('#btn_finalizar').off('click').on('click', {x: session}, finishCall);
}
I am developing a web for medics(sender) and patients(recipient), the problem is that the video call the first time works in the recipient(patient), after to hung up and call again, the second time the remote stream(patient) does not work anymore and the message in the console is: "Cant Accept, the session is already active, return"
In Addtion to that, this fragment is not being executed:
Here is PDF document to help to reproduce the error: connectycube.pdf