From dbcfc92dc4744e3540fd90be5f98700c442df49c Mon Sep 17 00:00:00 2001 From: hristoterezov Date: Tue, 24 Mar 2015 17:43:33 +0200 Subject: [PATCH] Changes the implementation to allow users without audio and video to join the conferences. Fixes issue with switching off desktop sharing for audio only users. --- index.html | 2 +- libs/app.bundle.js | 75 ++++++++++++++++++------ modules/RTC/RTC.js | 5 +- modules/RTC/RTCUtils.js | 53 +++++++++++++---- modules/desktopsharing/desktopsharing.js | 2 + modules/xmpp/JingleSession.js | 3 +- 6 files changed, 104 insertions(+), 36 deletions(-) diff --git a/index.html b/index.html index 18de365e6..b32cb8357 100644 --- a/index.html +++ b/index.html @@ -19,7 +19,7 @@ - + diff --git a/libs/app.bundle.js b/libs/app.bundle.js index 9b58e3f5a..961e66e48 100644 --- a/libs/app.bundle.js +++ b/libs/app.bundle.js @@ -869,10 +869,11 @@ var RTC = { callback(); }; } - this.localVideo = this.createLocalStream(stream, "video", true, type); + var videoStream = this.rtcUtils.createVideoStream(stream); + this.localVideo = this.createLocalStream(videoStream, "video", true, type); // Stop the stream to trigger onended event for old stream oldStream.stop(); - APP.xmpp.switchStreams(stream, oldStream,localCallback); + APP.xmpp.switchStreams(videoStream, oldStream,localCallback); }, /** * Checks if video identified by given src is desktop stream. @@ -1220,8 +1221,9 @@ RTCUtils.prototype.obtainAudioAndVideoPermissions = function(devices, callback) } RTCUtils.prototype.successCallback = function (stream) { - console.log('got', stream, stream.getAudioTracks().length, - stream.getVideoTracks().length); + if(stream) + console.log('got', stream, stream.getAudioTracks().length, + stream.getVideoTracks().length); this.handleLocalStream(stream); }; @@ -1253,8 +1255,9 @@ RTCUtils.prototype.errorCallback = function (error) { function (error) { console.error('failed to obtain audio/video stream - stop', error); - APP.UI.messageHandler.showError("dialog.error", - "dialog.failedpermissions"); +// APP.UI.messageHandler.showError("dialog.error", +// "dialog.failedpermissions"); + return self.successCallback(null); } ); } @@ -1267,19 +1270,22 @@ RTCUtils.prototype.handleLocalStream = function(stream) { var audioStream = new webkitMediaStream(); var videoStream = new webkitMediaStream(); - var audioTracks = stream.getAudioTracks(); - var videoTracks = stream.getVideoTracks(); - for (var i = 0; i < audioTracks.length; i++) { - audioStream.addTrack(audioTracks[i]); + if(stream) { + var audioTracks = stream.getAudioTracks(); + + for (var i = 0; i < audioTracks.length; i++) { + audioStream.addTrack(audioTracks[i]); + } + + var videoTracks = stream.getVideoTracks(); + + for (i = 0; i < videoTracks.length; i++) { + videoStream.addTrack(videoTracks[i]); + } } this.service.createLocalStream(audioStream, "audio"); - for (i = 0; i < videoTracks.length; i++) { - videoStream.addTrack(videoTracks[i]); - } - - this.service.createLocalStream(videoStream, "video"); } else @@ -1289,6 +1295,28 @@ RTCUtils.prototype.handleLocalStream = function(stream) }; +RTCUtils.prototype.createVideoStream = function(stream) +{ + var videoStream = null; + if(window.webkitMediaStream) + { + videoStream = new webkitMediaStream(); + if(stream) + { + var videoTracks = stream.getVideoTracks(); + + for (i = 0; i < videoTracks.length; i++) { + videoStream.addTrack(videoTracks[i]); + } + } + + } + else + videoStream = stream; + + return videoStream; +}; + module.exports = RTCUtils; },{"../../service/RTC/RTCBrowserType.js":88,"../../service/RTC/Resolutions":90}],8:[function(require,module,exports){ @@ -9472,6 +9500,8 @@ function initInlineInstalls() function getSwitchStreamFailed(error) { console.error("Failed to obtain the stream to switch to", error); switchInProgress = false; + isUsingScreenStream = false; + newStreamCreated(null); } function streamSwitchDone() { @@ -13125,7 +13155,8 @@ JingleSession.prototype.switchStreams = function (new_stream, oldStream, success oldSdp = new SDP(self.peerconnection.localDescription.sdp); } self.peerconnection.removeStream(oldStream, true); - self.peerconnection.addStream(new_stream); + if(new_stream) + self.peerconnection.addStream(new_stream); } APP.RTC.switchVideoStreams(new_stream, oldStream); @@ -19345,6 +19376,7 @@ var strings = require('./utils/strings'); var msg = require('./zlib/messages'); var zstream = require('./zlib/zstream'); +var toString = Object.prototype.toString; /* Public constants ==========================================================*/ /* ===========================================================================*/ @@ -19500,8 +19532,8 @@ var Deflate = function(options) { /** * Deflate#push(data[, mode]) -> Boolean - * - data (Uint8Array|Array|String): input data. Strings will be converted to - * utf8 byte sequence. + * - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will be + * converted to utf8 byte sequence. * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes. * See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH. * @@ -19539,6 +19571,8 @@ Deflate.prototype.push = function(data, mode) { if (typeof data === 'string') { // If we need to compress text, change encoding to utf8. strm.input = strings.string2buf(data); + } else if (toString.call(data) === '[object ArrayBuffer]') { + strm.input = new Uint8Array(data); } else { strm.input = data; } @@ -19709,6 +19743,7 @@ var msg = require('./zlib/messages'); var zstream = require('./zlib/zstream'); var gzheader = require('./zlib/gzheader'); +var toString = Object.prototype.toString; /** * class Inflate @@ -19843,7 +19878,7 @@ var Inflate = function(options) { /** * Inflate#push(data[, mode]) -> Boolean - * - data (Uint8Array|Array|String): input data + * - data (Uint8Array|Array|ArrayBuffer|String): input data * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes. * See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH. * @@ -19881,6 +19916,8 @@ Inflate.prototype.push = function(data, mode) { if (typeof data === 'string') { // Only binary strings can be decompressed on practice strm.input = strings.binstring2buf(data); + } else if (toString.call(data) === '[object ArrayBuffer]') { + strm.input = new Uint8Array(data); } else { strm.input = data; } diff --git a/modules/RTC/RTC.js b/modules/RTC/RTC.js index ad4071bf5..e57226759 100644 --- a/modules/RTC/RTC.js +++ b/modules/RTC/RTC.js @@ -174,10 +174,11 @@ var RTC = { callback(); }; } - this.localVideo = this.createLocalStream(stream, "video", true, type); + var videoStream = this.rtcUtils.createVideoStream(stream); + this.localVideo = this.createLocalStream(videoStream, "video", true, type); // Stop the stream to trigger onended event for old stream oldStream.stop(); - APP.xmpp.switchStreams(stream, oldStream,localCallback); + APP.xmpp.switchStreams(videoStream, oldStream,localCallback); }, /** * Checks if video identified by given src is desktop stream. diff --git a/modules/RTC/RTCUtils.js b/modules/RTC/RTCUtils.js index c12053c99..71fc59f85 100644 --- a/modules/RTC/RTCUtils.js +++ b/modules/RTC/RTCUtils.js @@ -294,8 +294,9 @@ RTCUtils.prototype.obtainAudioAndVideoPermissions = function(devices, callback) } RTCUtils.prototype.successCallback = function (stream) { - console.log('got', stream, stream.getAudioTracks().length, - stream.getVideoTracks().length); + if(stream) + console.log('got', stream, stream.getAudioTracks().length, + stream.getVideoTracks().length); this.handleLocalStream(stream); }; @@ -327,8 +328,9 @@ RTCUtils.prototype.errorCallback = function (error) { function (error) { console.error('failed to obtain audio/video stream - stop', error); - APP.UI.messageHandler.showError("dialog.error", - "dialog.failedpermissions"); +// APP.UI.messageHandler.showError("dialog.error", +// "dialog.failedpermissions"); + return self.successCallback(null); } ); } @@ -341,19 +343,22 @@ RTCUtils.prototype.handleLocalStream = function(stream) { var audioStream = new webkitMediaStream(); var videoStream = new webkitMediaStream(); - var audioTracks = stream.getAudioTracks(); - var videoTracks = stream.getVideoTracks(); - for (var i = 0; i < audioTracks.length; i++) { - audioStream.addTrack(audioTracks[i]); + if(stream) { + var audioTracks = stream.getAudioTracks(); + + for (var i = 0; i < audioTracks.length; i++) { + audioStream.addTrack(audioTracks[i]); + } + + var videoTracks = stream.getVideoTracks(); + + for (i = 0; i < videoTracks.length; i++) { + videoStream.addTrack(videoTracks[i]); + } } this.service.createLocalStream(audioStream, "audio"); - for (i = 0; i < videoTracks.length; i++) { - videoStream.addTrack(videoTracks[i]); - } - - this.service.createLocalStream(videoStream, "video"); } else @@ -363,4 +368,26 @@ RTCUtils.prototype.handleLocalStream = function(stream) }; +RTCUtils.prototype.createVideoStream = function(stream) +{ + var videoStream = null; + if(window.webkitMediaStream) + { + videoStream = new webkitMediaStream(); + if(stream) + { + var videoTracks = stream.getVideoTracks(); + + for (i = 0; i < videoTracks.length; i++) { + videoStream.addTrack(videoTracks[i]); + } + } + + } + else + videoStream = stream; + + return videoStream; +}; + module.exports = RTCUtils; diff --git a/modules/desktopsharing/desktopsharing.js b/modules/desktopsharing/desktopsharing.js index f9114b1d6..be9af2341 100644 --- a/modules/desktopsharing/desktopsharing.js +++ b/modules/desktopsharing/desktopsharing.js @@ -240,6 +240,8 @@ function initInlineInstalls() function getSwitchStreamFailed(error) { console.error("Failed to obtain the stream to switch to", error); switchInProgress = false; + isUsingScreenStream = false; + newStreamCreated(null); } function streamSwitchDone() { diff --git a/modules/xmpp/JingleSession.js b/modules/xmpp/JingleSession.js index 3d39d2239..796fb04c3 100644 --- a/modules/xmpp/JingleSession.js +++ b/modules/xmpp/JingleSession.js @@ -971,7 +971,8 @@ JingleSession.prototype.switchStreams = function (new_stream, oldStream, success oldSdp = new SDP(self.peerconnection.localDescription.sdp); } self.peerconnection.removeStream(oldStream, true); - self.peerconnection.addStream(new_stream); + if(new_stream) + self.peerconnection.addStream(new_stream); } APP.RTC.switchVideoStreams(new_stream, oldStream);