From c79d67bf1bb65de3ddc1e9d151a49e9d28f93eea Mon Sep 17 00:00:00 2001 From: Pin Zhang Date: Tue, 9 Dec 2014 17:53:47 +0800 Subject: [PATCH] VM stops if no camera is found. --- index.js | 1 + midp/media.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index aec4291d..41463c82 100644 --- a/index.js +++ b/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) { diff --git a/midp/media.js b/midp/media.js index 8d6fe2e2..8303a05b 100644 --- a/midp/media.js +++ b/midp/media.js @@ -421,17 +421,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": @@ -579,7 +592,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);