mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-13 12:51:16 +00:00
sendrecv/js: Simplify local stream management
Just use the fulfilled value of the promise directly instead of storing it separately
This commit is contained in:
parent
9f4783fb60
commit
fe40c70536
1 changed files with 2 additions and 7 deletions
|
@ -21,8 +21,6 @@ var peer_connection;
|
||||||
var ws_conn;
|
var ws_conn;
|
||||||
// Promise for local stream after constraints are approved by the user
|
// Promise for local stream after constraints are approved by the user
|
||||||
var local_stream_promise;
|
var local_stream_promise;
|
||||||
// MediaStream: the local stream
|
|
||||||
var local_stream;
|
|
||||||
|
|
||||||
function getOurId() {
|
function getOurId() {
|
||||||
return Math.floor(Math.random() * (9000 - 10) + 10).toString();
|
return Math.floor(Math.random() * (9000 - 10) + 10).toString();
|
||||||
|
@ -59,9 +57,7 @@ function setError(text) {
|
||||||
|
|
||||||
function resetVideo() {
|
function resetVideo() {
|
||||||
// Release the webcam and mic
|
// Release the webcam and mic
|
||||||
if (local_stream != null)
|
local_stream_promise.then(stream => { stream.stop(); });
|
||||||
local_stream.stop();
|
|
||||||
local_stream = null;
|
|
||||||
|
|
||||||
// Reset the video element and stop showing the last received frame
|
// Reset the video element and stop showing the last received frame
|
||||||
var videoElement = getVideoElement();
|
var videoElement = getVideoElement();
|
||||||
|
@ -219,7 +215,6 @@ function errorUserMediaHandler() {
|
||||||
function createCall(msg) {
|
function createCall(msg) {
|
||||||
// Reset connection attempts because we connected successfully
|
// Reset connection attempts because we connected successfully
|
||||||
connect_attempts = 0;
|
connect_attempts = 0;
|
||||||
local_stream = null;
|
|
||||||
|
|
||||||
console.log('Creating RTCPeerConnection');
|
console.log('Creating RTCPeerConnection');
|
||||||
|
|
||||||
|
@ -229,7 +224,7 @@ function createCall(msg) {
|
||||||
local_stream_promise = getLocalStream().then((stream) => {
|
local_stream_promise = getLocalStream().then((stream) => {
|
||||||
console.log('Adding local stream');
|
console.log('Adding local stream');
|
||||||
peer_connection.addStream(stream);
|
peer_connection.addStream(stream);
|
||||||
local_stream = stream;
|
return stream;
|
||||||
}).catch(setError);
|
}).catch(setError);
|
||||||
|
|
||||||
if (!msg.sdp) {
|
if (!msg.sdp) {
|
||||||
|
|
Loading…
Reference in a new issue