зеркало из https://github.com/mozilla/pluotsorbet.git
Merge pull request #698 from PinZhang/pzhang/no-camera
VM stops if no camera is found.
This commit is contained in:
Коммит
f14d593c1f
1
index.js
1
index.js
|
@ -375,6 +375,7 @@ DumbPipe.registerOpener("camera", function(message, sender) {
|
|||
video.play();
|
||||
}, function(err) {
|
||||
console.log("Error: " + err);
|
||||
sender({ type: "initerror", name: err.name, message: err.message });
|
||||
});
|
||||
|
||||
return function(message) {
|
||||
|
|
|
@ -422,17 +422,30 @@ function ImageRecorder(playerContainer) {
|
|||
ImageRecorder.prototype.realize = function() {
|
||||
return new Promise((function(resolve, reject) {
|
||||
this.realizeResolver = resolve;
|
||||
this.realizeRejector = reject;
|
||||
this.sender = DumbPipe.open("camera", {}, this.recipient.bind(this));
|
||||
}).bind(this));
|
||||
}
|
||||
|
||||
ImageRecorder.prototype.recipient = function(message) {
|
||||
switch (message.type) {
|
||||
case "initerror":
|
||||
if (message.name == "PermissionDeniedError") {
|
||||
this.realizeRejector(new JavaException("java/lang/SecurityException", "Not permitted to init camera"));
|
||||
} else {
|
||||
this.realizeRejector(new JavaException("javax/microedition/media/MediaException", "Failed to init camera, no camera?"));
|
||||
}
|
||||
this.realizeResolver = null;
|
||||
this.realizeRejector = null;
|
||||
this.sender({ type: "close" });
|
||||
break;
|
||||
|
||||
case "gotstream":
|
||||
this.width = message.width;
|
||||
this.height = message.height;
|
||||
this.realizeResolver(true);
|
||||
this.realizeResolver = null;
|
||||
this.realizeRejector = null;
|
||||
break;
|
||||
|
||||
case "snapshot":
|
||||
|
@ -580,7 +593,7 @@ PlayerContainer.prototype.realize = function(contentType) {
|
|||
} else {
|
||||
this.player = new ImagePlayer(this);
|
||||
}
|
||||
this.player.realize().then(resolve);
|
||||
this.player.realize().then(resolve, reject);
|
||||
} else {
|
||||
console.warn("Unsupported media format (" + this.mediaFormat + ") for " + this.url);
|
||||
resolve(false);
|
||||
|
|
Загрузка…
Ссылка в новой задаче