diff --git a/public/webrtc.js b/public/webrtc.js index c84ac3d..968f2f4 100755 --- a/public/webrtc.js +++ b/public/webrtc.js @@ -104,7 +104,7 @@ class Entropy { static local = null; static pageReady() { - Entropy.local = new Local("video"); + Entropy.local = Local.build("video"); } static start(isCaller) { @@ -166,41 +166,54 @@ 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); + static build(type) { + switch(type) { + case "audio": return new Audio(); + case "video": return new Video(); + case "text": return new Text(); + default: View.error("unknown build", type); } } + constructor() { + var constraints = { + video: this.gettype() == "video", + audio: this.gettype() == "audio", + }; + if(!navigator.mediaDevices.getUserMedia) { + View.error('Your browser does not support getUserMedia API'); + } + navigator.mediaDevices.getUserMedia(constraints) + .then((stream) => { + if (this.gettype() == "video") { + new Preview('preview', stream); + } + this.stream = stream; + }) + .catch(View.error); + } + + gettype() { + View.error("not impl"); + } + start() {} stop() {} } class Audio extends Local { + gettype() { + return "audio"; + } } class Video extends Local { + gettype() { + return "video"; + } } class Text extends Local {