Allows to switch to desktop stream from the very beginning of the conference.

This commit is contained in:
paweldomas 2014-03-17 16:43:06 +01:00
parent d5a1fe636d
commit 1f51021041
3 changed files with 39 additions and 15 deletions

6
app.js
View File

@ -221,7 +221,9 @@ $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
} }
} else { } else {
if (data.stream.id !== 'mixedmslabel') { if (data.stream.id !== 'mixedmslabel') {
console.warn('can not associate stream', data.stream.id, 'with a participant'); console.error('can not associate stream', data.stream.id, 'with a participant');
// We don't want to add it here since it will cause troubles
return;
} }
// FIXME: for the mixed ms we dont need a video -- currently // FIXME: for the mixed ms we dont need a video -- currently
container = document.createElement('span'); container = document.createElement('span');
@ -448,6 +450,8 @@ $(document).bind('callactive.jingle', function (event, videoelem, sid) {
$(document).bind('callterminated.jingle', function (event, sid, reason) { $(document).bind('callterminated.jingle', function (event, sid, reason) {
// FIXME // FIXME
focus = null;
activecall = null;
}); });
$(document).bind('setLocalDescription.jingle', function (event, sid) { $(document).bind('setLocalDescription.jingle', function (event, sid) {

View File

@ -42,14 +42,17 @@ function setDesktopSharing(method) {
if(method == "ext") { if(method == "ext") {
if(RTC.browser === 'chrome') { if(RTC.browser === 'chrome') {
obtainDesktopStream = obtainScreenFromExtension; obtainDesktopStream = obtainScreenFromExtension;
console.info("Using Chrome extension for desktop sharing");
} else { } else {
console.log("Chrome is required to use extension method"); console.error("Chrome is required to use extension method");
obtainDesktopStream = null; obtainDesktopStream = null;
} }
} else if(method == "webrtc") { } else if(method == "webrtc") {
obtainDesktopStream = obtainWebRTCScreen; obtainDesktopStream = obtainWebRTCScreen;
console.info("Using WebRTC for desktop sharing");
} else { } else {
obtainDesktopStream = null; obtainDesktopStream = null;
console.info("Desktop sharing disabled");
} }
showDesktopSharingButton(); showDesktopSharingButton();
} }
@ -66,11 +69,8 @@ function showDesktopSharingButton() {
* Toggles screen sharing. * Toggles screen sharing.
*/ */
function toggleScreenSharing() { function toggleScreenSharing() {
if (!(connection && connection.connected if (switchInProgress || !obtainDesktopStream) {
&& !switchInProgress console.warn("Switch in progress or no method defined");
&& getConferenceHandler().peerconnection.signalingState == 'stable'
&& getConferenceHandler().peerconnection.iceConnectionState == 'connected'
&& obtainDesktopStream )) {
return; return;
} }
switchInProgress = true; switchInProgress = true;
@ -85,7 +85,7 @@ function toggleScreenSharing() {
// Hook 'ended' event to restore camera when screen stream stops // Hook 'ended' event to restore camera when screen stream stops
stream.addEventListener('ended', stream.addEventListener('ended',
function(e) { function(e) {
if(!switchInProgress) { if(!switchInProgress && isUsingScreenStream) {
toggleScreenSharing(); toggleScreenSharing();
} }
} }
@ -118,13 +118,24 @@ function newStreamCreated(stream) {
change_local_video(stream, !isUsingScreenStream); change_local_video(stream, !isUsingScreenStream);
// FIXME: will block switchInProgress on true value in case of exception var conferenceHandler = getConferenceHandler();
getConferenceHandler().switchStreams( if(conferenceHandler) {
stream, oldStream, console.info("Conference considered as started");
function() { // FIXME: will block switchInProgress on true value in case of exception
// Switch operation has finished conferenceHandler.switchStreams(stream, oldStream, streamSwitchDone);
} else {
// We are done immediately
console.error("No conference handler");
streamSwitchDone();
}
}
function streamSwitchDone() {
//window.setTimeout(
// function() {
switchInProgress = false; switchInProgress = false;
}); // }, 100
//);
} }
/** /**

View File

@ -49,7 +49,10 @@ SessionBase.prototype.switchStreams = function (new_stream, oldStream, success_c
var self = this; var self = this;
// Remember SDP to figure out added/removed SSRCs // Remember SDP to figure out added/removed SSRCs
var oldSdp = new SDP(self.peerconnection.localDescription.sdp); var oldSdp = null;
if(self.peerconnection.localDescription) {
oldSdp = new SDP(self.peerconnection.localDescription.sdp);
}
// Stop the stream to trigger onended event for old stream // Stop the stream to trigger onended event for old stream
oldStream.stop(); oldStream.stop();
@ -63,6 +66,12 @@ SessionBase.prototype.switchStreams = function (new_stream, oldStream, success_c
self.connection.jingle.localStreams.push(self.connection.jingle.localAudio); self.connection.jingle.localStreams.push(self.connection.jingle.localAudio);
self.connection.jingle.localStreams.push(self.connection.jingle.localVideo); self.connection.jingle.localStreams.push(self.connection.jingle.localVideo);
// Conference is not active
if(!oldSdp) {
success_callback();
return;
}
self.peerconnection.switchstreams = true; self.peerconnection.switchstreams = true;
self.modifySources(function() { self.modifySources(function() {
console.log('modify sources done'); console.log('modify sources done');