master
bel 2020-05-10 12:38:34 -06:00
parent 861210c941
commit 71053a1851
1 changed files with 35 additions and 22 deletions

View File

@ -104,7 +104,7 @@ class Entropy {
static local = null; static local = null;
static pageReady() { static pageReady() {
Entropy.local = new Local("video"); Entropy.local = Local.build("video");
} }
static start(isCaller) { static start(isCaller) {
@ -166,30 +166,37 @@ class Entropy {
} }
class Local { class Local {
type = null;
stream = null; stream = null;
constructor(type) { static build(type) {
this.type = type; switch(type) {
switch (type) { case "audio": return new Audio();
case "video": case "video": return new Video();
case "audio": case "text": return new Text();
default: View.error("unknown build", type);
}
}
constructor() {
var constraints = { var constraints = {
video: type == "video", video: this.gettype() == "video",
audio: type == "audio", audio: this.gettype() == "audio",
}; };
if(!navigator.mediaDevices.getUserMedia) { if(!navigator.mediaDevices.getUserMedia) {
View.error('Your browser does not support getUserMedia API'); View.error('Your browser does not support getUserMedia API');
} }
navigator.mediaDevices.getUserMedia(constraints) navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => { .then((stream) => {
if (type == "video") { if (this.gettype() == "video") {
new Preview('preview', stream); new Preview('preview', stream);
} }
this.stream = stream; this.stream = stream;
}) })
.catch(View.error); .catch(View.error);
} }
gettype() {
View.error("not impl");
} }
start() {} start() {}
@ -198,9 +205,15 @@ class Local {
} }
class Audio extends Local { class Audio extends Local {
gettype() {
return "audio";
}
} }
class Video extends Local { class Video extends Local {
gettype() {
return "video";
}
} }
class Text extends Local { class Text extends Local {