Establish connection to remote before getting user media

This commit is contained in:
Pierre HUBERT 2019-02-25 12:56:03 +01:00
parent 6e1e05845b
commit be22b55f89

View File

@ -50,7 +50,19 @@ ComunicWeb.components.calls.callWindow = {
/** /**
* @type {SignalExchangerClient} * @type {SignalExchangerClient}
*/ */
signalClient: undefined signalClient: undefined,
/**
* @type {Boolean}
*/
isRequestingUserMedia: false,
/**
* @type {() : any}
*
* Request user media again
*/
requestUserMedia: undefined
}; };
@ -126,6 +138,10 @@ ComunicWeb.components.calls.callWindow = {
call.setLocalVideoEnabled = function(enabled){ call.setLocalVideoEnabled = function(enabled){
if(call.localStream) if(call.localStream)
call.localStream.getVideoTracks()[0].enabled = enabled; call.localStream.getVideoTracks()[0].enabled = enabled;
//Request user media
else if(!call.isRequestingUserMedia)
call.requestUserMedia();
} }
/** /**
@ -136,6 +152,10 @@ ComunicWeb.components.calls.callWindow = {
call.setLocalStreamVisibility = function(visible){ call.setLocalStreamVisibility = function(visible){
if(call.localStreamVideo) if(call.localStreamVideo)
call.localStreamVideo.style.display = visible ? "block" : "none"; call.localStreamVideo.style.display = visible ? "block" : "none";
//Request user media
else if(!call.isRequestingUserMedia)
call.requestUserMedia();
} }
/** /**
@ -469,31 +489,9 @@ ComunicWeb.components.calls.callWindow = {
//Load user media //Load user media
call.setLoadingMessage("Waiting for your microphone and camera..."); call.setLoadingMessage("Waiting for your microphone and camera...");
ComunicWeb.components.calls.userMedia.get().then(function(stream){
//Check if connection has already been closed
if(!call.open)
return;
call.localStream = stream;
//Initialize signaling server connection //Initialize signaling server connection
ComunicWeb.components.calls.callWindow.initializeConnectionToSignalingServer(call); ComunicWeb.components.calls.callWindow.initializeConnectionToSignalingServer(call);
//Add local stream to the list of visible stream
call.localStreamVideo = ComunicWeb.components.calls.callWindow.addVideoStream(call, true, stream);
//Mark as connecting
call.setLoadingMessage("Connecting...");
return true;
}).catch(function(e){
console.error("Get user media error: ", e);
call.setLoadingMessageVisibility(false);
return notify("Could not get your microphone and camera!", "danger");
});
/** /**
* Start to automaticaly refresh information about the call * Start to automaticaly refresh information about the call
*/ */
@ -512,6 +510,43 @@ ComunicWeb.components.calls.callWindow = {
}, 4000); }, 4000);
//Request user media
call.requestUserMedia = function(){
call.isRequestingUserMedia = true;
ComunicWeb.components.calls.userMedia.get().then(function(stream){
call.isRequestingUserMedia = false;
//Check if connection has already been closed
if(!call.open)
return;
call.localStream = stream;
//Add stream to existing peer connections
for (var s in call.streams) {
if (call.streams.hasOwnProperty(s)) {
call.streams[s].peer.addStream(stream);
}
}
//Add local stream to the list of visible stream
call.localStreamVideo = ComunicWeb.components.calls.callWindow.addVideoStream(call, true, stream);
return true;
}).catch(function(e){
call.isRequestingUserMedia = false;
console.error("Get user media error: ", e);
call.setLoadingMessageVisibility(false);
return notify("Could not get your microphone and camera!", "danger");
});
};
call.requestUserMedia();
}, },
@ -540,6 +575,14 @@ ComunicWeb.components.calls.callWindow = {
); );
/**
* Connection established
*/
call.signalClient.onConnected = function(){
//Mark as connecting
call.setLoadingMessage("Connecting...");
}
/** /**
* Error when connecting to signaling server * Error when connecting to signaling server
*/ */
@ -601,7 +644,7 @@ ComunicWeb.components.calls.callWindow = {
//Check if we are connected to signaling server and we have got local //Check if we are connected to signaling server and we have got local
//streams //streams
if(!call.signalClient || !call.signalClient.isConnected() || !call.localStream) if(!call.signalClient || !call.signalClient.isConnected())
return; return;
//Check if all other members rejected call //Check if all other members rejected call