提交 96af587b authored 作者: Chad Phillips's avatar Chad Phillips

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.
上级 a380f125
...@@ -88,6 +88,7 @@ ...@@ -88,6 +88,7 @@
onICE: function() {}, onICE: function() {},
onOfferSDP: function() {} onOfferSDP: function() {}
}, },
useStream: null,
}, options); }, options);
this.audioEnabled = true; this.audioEnabled = true;
...@@ -290,7 +291,7 @@ ...@@ -290,7 +291,7 @@
self.options.useVideo['src'] = ''; self.options.useVideo['src'] = '';
} }
if (self.localStream) { if (self.localStream && !self.options.useStream) {
if(typeof self.localStream.stop == 'function') { if(typeof self.localStream.stop == 'function') {
self.localStream.stop(); self.localStream.stop();
} else { } else {
...@@ -307,11 +308,10 @@ ...@@ -307,11 +308,10 @@
} }
if (self.options.localVideo) { if (self.options.localVideo) {
self.options.localVideo.style.display = 'none'; deactivateLocalVideo(self.options.localVideo);
self.options.localVideo['src'] = '';
} }
if (self.options.localVideoStream) { if (self.options.localVideoStream && !self.options.useStream) {
if(typeof self.options.localVideoStream.stop == 'function') { if(typeof self.options.localVideoStream.stop == 'function') {
self.options.localVideoStream.stop(); self.options.localVideoStream.stop();
} else { } else {
...@@ -444,7 +444,7 @@ ...@@ -444,7 +444,7 @@
console.log("Audio constraints", mediaParams.audio); console.log("Audio constraints", mediaParams.audio);
console.log("Video constraints", mediaParams.video); console.log("Video constraints", mediaParams.video);
if (self.options.useVideo && self.options.localVideo) { if (self.options.useVideo && self.options.localVideo && !self.options.useStream) {
getUserMedia({ getUserMedia({
constraints: { constraints: {
audio: false, audio: false,
...@@ -456,17 +456,26 @@ ...@@ -456,17 +456,26 @@
}); });
} }
getUserMedia({ if (self.options.useStream) {
constraints: { if (self.options.useVideo) {
audio: mediaParams.audio, self.options.localVideoStream = self.options.useStream;
video: mediaParams.video if (self.options.localVideo) {
}, activateLocalVideo(self.options.localVideo, self.options.useStream);
video: mediaParams.useVideo, }
onsuccess: onSuccess, }
onerror: onError onSuccess(self.options.useStream);
}); }
else {
getUserMedia({
constraints: {
audio: mediaParams.audio,
video: mediaParams.video
},
video: mediaParams.useVideo,
onsuccess: onSuccess,
onerror: onError
});
}
}; };
...@@ -494,7 +503,7 @@ ...@@ -494,7 +503,7 @@
} }
} }
if (obj.options.useVideo && obj.options.localVideo) { if (obj.options.useVideo && obj.options.localVideo && !obj.options.useStream) {
getUserMedia({ getUserMedia({
constraints: { constraints: {
audio: false, audio: false,
...@@ -635,7 +644,16 @@ ...@@ -635,7 +644,16 @@
console.log("Audio constraints", mediaParams.audio); console.log("Audio constraints", mediaParams.audio);
console.log("Video constraints", mediaParams.video); 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({ getUserMedia({
constraints: { constraints: {
...@@ -941,6 +959,16 @@ ...@@ -941,6 +959,16 @@
//optional: [] //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) { function getUserMedia(options) {
var n = navigator, var n = navigator,
media; media;
...@@ -956,8 +984,7 @@ ...@@ -956,8 +984,7 @@
function streaming(stream) { function streaming(stream) {
if (options.localVideo) { if (options.localVideo) {
options.localVideo['srcObject'] = stream; activateLocalVideo(options.localVideo, stream);
options.localVideo.style.display = 'block';
} }
if (options.onsuccess) { if (options.onsuccess) {
......
...@@ -80,7 +80,8 @@ ...@@ -80,7 +80,8 @@
userVariables: {}, userVariables: {},
iceServers: false, iceServers: false,
ringSleep: 6000, ringSleep: 6000,
sessid: null sessid: null,
useStream: null
}, options); }, options);
if (verto.options.deviceParams.useCamera) { if (verto.options.deviceParams.useCamera) {
...@@ -1939,7 +1940,8 @@ ...@@ -1939,7 +1940,8 @@
tag: verto.options.tag, tag: verto.options.tag,
localTag: verto.options.localTag, localTag: verto.options.localTag,
login: verto.options.login, login: verto.options.login,
videoParams: verto.options.videoParams videoParams: verto.options.videoParams,
useStream: verto.options.useStream,
}, params); }, params);
...@@ -2082,7 +2084,8 @@ ...@@ -2082,7 +2084,8 @@
useCamera: dialog.useCamera, useCamera: dialog.useCamera,
useMic: dialog.useMic, useMic: dialog.useMic,
useSpeak: dialog.useSpeak, useSpeak: dialog.useSpeak,
turnServer: verto.options.turnServer turnServer: verto.options.turnServer,
useStream: dialog.params.useStream
}); });
dialog.rtc.verto = dialog.verto; dialog.rtc.verto = dialog.verto;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论