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.
This commit is contained in:
Chad Phillips 2018-07-26 17:03:24 -05:00
parent a380f125e1
commit 96af587bf3
2 changed files with 53 additions and 23 deletions

View File

@ -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) {

View File

@ -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;