From 861210c941753c7064748caa7398727a1477fdee Mon Sep 17 00:00:00 2001 From: bel Date: Sun, 10 May 2020 12:33:26 -0600 Subject: [PATCH] local --- public/webrtc.js | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/public/webrtc.js b/public/webrtc.js index 88fb563..c84ac3d 100755 --- a/public/webrtc.js +++ b/public/webrtc.js @@ -100,35 +100,18 @@ class Controller { } class Entropy { - static preview = null; - static localStream = null; static peerConnection = null; - static remote = null; + static local = null; static pageReady() { - - var constraints = { - video: true, - audio: false, - }; - - if(navigator.mediaDevices.getUserMedia) { - navigator.mediaDevices.getUserMedia(constraints) - .then((stream) => { - new Preview('preview', stream); - Entropy.localStream = stream; - }) - .catch(View.error); - } else { - alert('Your browser does not support getUserMedia API'); - } + Entropy.local = new Local("video"); } static start(isCaller) { Entropy.peerConnection = new RTCPeerConnection(Config.peerConnectionConfig); Entropy.peerConnection.onicecandidate = Entropy.gotIceCandidate; Entropy.peerConnection.ontrack = (event) => new Remote('remoteVideo', event.streams[0]); - Entropy.peerConnection.addStream(Entropy.localStream); + Entropy.peerConnection.addStream(Entropy.local.stream); if(isCaller) { Entropy.peerConnection @@ -184,9 +167,29 @@ class Entropy { class Local { type = null; + stream = null; constructor(type) { this.type = type; + switch (type) { + case "video": + case "audio": + var constraints = { + video: type == "video", + audio: type == "audio", + }; + if(!navigator.mediaDevices.getUserMedia) { + View.error('Your browser does not support getUserMedia API'); + } + navigator.mediaDevices.getUserMedia(constraints) + .then((stream) => { + if (type == "video") { + new Preview('preview', stream); + } + this.stream = stream; + }) + .catch(View.error); + } } start() {}