]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11287: Provide option for user managed streams in Verto
authorChad Phillips <chad@apartmentlines.com>
Thu, 26 Jul 2018 22:03:24 +0000 (17:03 -0500)
committerChad Phillips <chad@apartmentlines.com>
Thu, 26 Jul 2018 22:03:24 +0000 (17:03 -0500)
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
html5/verto/js/src/jquery.verto.js

index c2ea803d0bc232478cc884ddf5eb0560a20714ba..7d6fcf900965e66399d2088fd5c09bc6a6bacdfb 100644 (file)
@@ -88,6 +88,7 @@
                 onICE: function() {},
                 onOfferSDP: function() {}
             },
+      useStream: null,
         }, options);
 
        this.audioEnabled = true;
             self.options.useVideo['src'] = '';
         }
 
-        if (self.localStream) {
+        if (self.localStream && !self.options.useStream) {
             if(typeof self.localStream.stop == 'function') {
                 self.localStream.stop();
             } else {
         }
 
         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 {
        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,
             });
        }
 
-        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
+      });
+    }
 
     };
 
            }
        }
 
-       if (obj.options.useVideo && obj.options.localVideo) {
+    if (obj.options.useVideo && obj.options.localVideo && !obj.options.useStream) {
             getUserMedia({
                constraints: {
                     audio: false,
        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: {
         //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;
 
         function streaming(stream) {
             if (options.localVideo) {
-                options.localVideo['srcObject'] = stream;
-               options.localVideo.style.display = 'block';
+        activateLocalVideo(options.localVideo, stream);
             }
 
             if (options.onsuccess) {
index c913ca41404ed45275a15b18f2f97e0e22fd99ed..2741f4a596999fa626a1b9090fb88d50df4f87e6 100644 (file)
@@ -80,7 +80,8 @@
            userVariables: {},
             iceServers: false,
             ringSleep: 6000,
-           sessid: null
+      sessid: null,
+      useStream: null
         }, options);
 
        if (verto.options.deviceParams.useCamera) {
             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);
        
 
             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;