From 96af587bf325ce35459cbd82e2e79bda0133a810 Mon Sep 17 00:00:00 2001 From: Chad Phillips Date: Thu, 26 Jul 2018 17:03:24 -0500 Subject: [PATCH] FS-11287: Provide option for user managed streams in Verto The Verto libs currently have total control over the streams associated with placing any kind of call, handling both their creation and teardown automatically. This patch provides the option for a developer to instead pass pre-created MediaStream objects when instantiating the Verto object, or when calling Verto.newCall(), and the library will bypass the work of creating those streams, and of destroying those streams when the call is torn down. This is particularly useful if the application wants to manage its own streams, such as re-using them in other non-Verto aspects of the application. The patch also creates some internal convenience functions for managing the video element related to a local video stream. --- html5/verto/js/src/jquery.FSRTC.js | 67 +++++++++++++++++++++--------- html5/verto/js/src/jquery.verto.js | 9 ++-- 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/html5/verto/js/src/jquery.FSRTC.js b/html5/verto/js/src/jquery.FSRTC.js index c2ea803d0b..7d6fcf9009 100644 --- a/html5/verto/js/src/jquery.FSRTC.js +++ b/html5/verto/js/src/jquery.FSRTC.js @@ -88,6 +88,7 @@ onICE: function() {}, onOfferSDP: function() {} }, + useStream: null, }, options); this.audioEnabled = true; @@ -290,7 +291,7 @@ self.options.useVideo['src'] = ''; } - if (self.localStream) { + if (self.localStream && !self.options.useStream) { if(typeof self.localStream.stop == 'function') { self.localStream.stop(); } else { @@ -307,11 +308,10 @@ } if (self.options.localVideo) { - self.options.localVideo.style.display = 'none'; - self.options.localVideo['src'] = ''; + deactivateLocalVideo(self.options.localVideo); } - if (self.options.localVideoStream) { + if (self.options.localVideoStream && !self.options.useStream) { if(typeof self.options.localVideoStream.stop == 'function') { self.options.localVideoStream.stop(); } else { @@ -444,7 +444,7 @@ console.log("Audio constraints", mediaParams.audio); console.log("Video constraints", mediaParams.video); - if (self.options.useVideo && self.options.localVideo) { + if (self.options.useVideo && self.options.localVideo && !self.options.useStream) { getUserMedia({ constraints: { audio: false, @@ -456,17 +456,26 @@ }); } - getUserMedia({ - constraints: { - audio: mediaParams.audio, - video: mediaParams.video - }, - video: mediaParams.useVideo, - onsuccess: onSuccess, - onerror: onError - }); - - + if (self.options.useStream) { + if (self.options.useVideo) { + self.options.localVideoStream = self.options.useStream; + if (self.options.localVideo) { + activateLocalVideo(self.options.localVideo, self.options.useStream); + } + } + onSuccess(self.options.useStream); + } + else { + getUserMedia({ + constraints: { + audio: mediaParams.audio, + video: mediaParams.video + }, + video: mediaParams.useVideo, + onsuccess: onSuccess, + onerror: onError + }); + } }; @@ -494,7 +503,7 @@ } } - if (obj.options.useVideo && obj.options.localVideo) { + if (obj.options.useVideo && obj.options.localVideo && !obj.options.useStream) { getUserMedia({ constraints: { audio: false, @@ -635,7 +644,16 @@ console.log("Audio constraints", mediaParams.audio); console.log("Video constraints", mediaParams.video); - if (mediaParams.audio || mediaParams.video) { + if (self.options.useStream) { + if (self.options.useVideo) { + self.options.localVideoStream = self.options.useStream; + if (self.options.localVideo) { + activateLocalVideo(self.options.localVideo, self.options.useStream); + } + } + onSuccess(self.options.useStream); + } + else if (mediaParams.audio || mediaParams.video) { getUserMedia({ constraints: { @@ -941,6 +959,16 @@ //optional: [] }; + function activateLocalVideo(el, stream) { + el.srcObject = stream; + el.style.display = 'block'; + } + + function deactivateLocalVideo(el) { + el.srcObject = null; + el.style.display = 'none'; + } + function getUserMedia(options) { var n = navigator, media; @@ -956,8 +984,7 @@ function streaming(stream) { if (options.localVideo) { - options.localVideo['srcObject'] = stream; - options.localVideo.style.display = 'block'; + activateLocalVideo(options.localVideo, stream); } if (options.onsuccess) { diff --git a/html5/verto/js/src/jquery.verto.js b/html5/verto/js/src/jquery.verto.js index c913ca4140..2741f4a596 100644 --- a/html5/verto/js/src/jquery.verto.js +++ b/html5/verto/js/src/jquery.verto.js @@ -80,7 +80,8 @@ userVariables: {}, iceServers: false, ringSleep: 6000, - sessid: null + sessid: null, + useStream: null }, options); if (verto.options.deviceParams.useCamera) { @@ -1939,7 +1940,8 @@ tag: verto.options.tag, localTag: verto.options.localTag, login: verto.options.login, - videoParams: verto.options.videoParams + videoParams: verto.options.videoParams, + useStream: verto.options.useStream, }, params); @@ -2082,7 +2084,8 @@ useCamera: dialog.useCamera, useMic: dialog.useMic, useSpeak: dialog.useSpeak, - turnServer: verto.options.turnServer + turnServer: verto.options.turnServer, + useStream: dialog.params.useStream }); dialog.rtc.verto = dialog.verto;