kopia lustrzana https://github.com/backface/turtlestitch
catch missing https support for camera in Chrome
rodzic
556f264319
commit
251db7d473
47
gui.js
47
gui.js
|
@ -8402,13 +8402,10 @@ CamSnapshotDialogMorph.prototype = new DialogBoxMorph();
|
||||||
CamSnapshotDialogMorph.prototype.constructor = CamSnapshotDialogMorph;
|
CamSnapshotDialogMorph.prototype.constructor = CamSnapshotDialogMorph;
|
||||||
CamSnapshotDialogMorph.uber = DialogBoxMorph.prototype;
|
CamSnapshotDialogMorph.uber = DialogBoxMorph.prototype;
|
||||||
|
|
||||||
// CamSnapshotDialogMorph instance creation
|
// CamSnapshotDialogMorph settings
|
||||||
|
|
||||||
function CamSnapshotDialogMorph(ide, sprite, onCancel, onAccept) {
|
|
||||||
this.init(ide, sprite, onCancel, onAccept);
|
|
||||||
}
|
|
||||||
|
|
||||||
CamSnapshotDialogMorph.prototype.enabled = true;
|
CamSnapshotDialogMorph.prototype.enabled = true;
|
||||||
|
|
||||||
CamSnapshotDialogMorph.prototype.notSupportedMessage =
|
CamSnapshotDialogMorph.prototype.notSupportedMessage =
|
||||||
'Due to browser security policies, you need to\n' +
|
'Due to browser security policies, you need to\n' +
|
||||||
'access Snap! through HTTPS to use the camera.\n\n' +
|
'access Snap! through HTTPS to use the camera.\n\n' +
|
||||||
|
@ -8417,26 +8414,29 @@ CamSnapshotDialogMorph.prototype.notSupportedMessage =
|
||||||
'Please also make sure your camera is properly\n' +
|
'Please also make sure your camera is properly\n' +
|
||||||
'connected and configured.';
|
'connected and configured.';
|
||||||
|
|
||||||
|
// CamSnapshotDialogMorph instance creation
|
||||||
|
|
||||||
|
function CamSnapshotDialogMorph(ide, sprite, onCancel, onAccept) {
|
||||||
|
this.init(ide, sprite, onCancel, onAccept);
|
||||||
|
}
|
||||||
|
|
||||||
CamSnapshotDialogMorph.prototype.init = function (
|
CamSnapshotDialogMorph.prototype.init = function (
|
||||||
ide,
|
ide,
|
||||||
sprite,
|
sprite,
|
||||||
onCancel,
|
onCancel,
|
||||||
onAccept) {
|
onAccept
|
||||||
|
) {
|
||||||
this.ide = ide;
|
this.ide = ide;
|
||||||
this.sprite = sprite;
|
this.sprite = sprite;
|
||||||
this.padding = 10;
|
this.padding = 10;
|
||||||
|
|
||||||
this.oncancel = onCancel;
|
this.oncancel = onCancel;
|
||||||
this.accept = onAccept;
|
this.accept = onAccept;
|
||||||
|
|
||||||
this.videoElement = null; // an HTML5 video element
|
this.videoElement = null; // an HTML5 video element
|
||||||
this.videoView = new Morph(); // a morph where we'll copy the video contents
|
this.videoView = new Morph(); // a morph where we'll copy the video contents
|
||||||
|
|
||||||
CamSnapshotDialogMorph.uber.init.call(this);
|
CamSnapshotDialogMorph.uber.init.call(this);
|
||||||
|
|
||||||
this.labelString = 'Camera';
|
this.labelString = 'Camera';
|
||||||
this.createLabel();
|
this.createLabel();
|
||||||
|
|
||||||
this.buildContents();
|
this.buildContents();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8444,6 +8444,15 @@ CamSnapshotDialogMorph.prototype.buildContents = function () {
|
||||||
var myself = this,
|
var myself = this,
|
||||||
stage = this.sprite.parentThatIsA(StageMorph);
|
stage = this.sprite.parentThatIsA(StageMorph);
|
||||||
|
|
||||||
|
function noCameraSupport() {
|
||||||
|
myself.disable();
|
||||||
|
myself.ide.inform(
|
||||||
|
'Camera not supported',
|
||||||
|
CamSnapshotDialogMorph.prototype.notSupportedMessage
|
||||||
|
);
|
||||||
|
myself.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
this.videoElement = document.createElement('video');
|
this.videoElement = document.createElement('video');
|
||||||
this.videoElement.hidden = true;
|
this.videoElement.hidden = true;
|
||||||
this.videoElement.width = stage.dimensions.x;
|
this.videoElement.width = stage.dimensions.x;
|
||||||
|
@ -8455,24 +8464,10 @@ CamSnapshotDialogMorph.prototype.buildContents = function () {
|
||||||
navigator.mediaDevices.getUserMedia({ video: true })
|
navigator.mediaDevices.getUserMedia({ video: true })
|
||||||
.then(function (stream) {
|
.then(function (stream) {
|
||||||
myself.videoElement.src = window.URL.createObjectURL(stream);
|
myself.videoElement.src = window.URL.createObjectURL(stream);
|
||||||
myself.videoElement.play().catch(function (error) {
|
myself.videoElement.play().catch(noCameraSupport);
|
||||||
myself.disable();
|
|
||||||
myself.ide.inform(
|
|
||||||
'Camera not supported',
|
|
||||||
CamSnapshotDialogMorph.prototype.notSupportedMessage
|
|
||||||
);
|
|
||||||
myself.cancel();
|
|
||||||
});
|
|
||||||
myself.videoElement.stream = stream;
|
myself.videoElement.stream = stream;
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(noCameraSupport);
|
||||||
myself.ide.inform(
|
|
||||||
'Failed to initialize camera',
|
|
||||||
'Please make sure your camera is connected and\n' +
|
|
||||||
'accept the browser request to access it.'
|
|
||||||
);
|
|
||||||
myself.cancel();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.videoView.setExtent(stage.dimensions);
|
this.videoView.setExtent(stage.dimensions);
|
||||||
|
|
Ładowanie…
Reference in New Issue