mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Guard against some issues that could happen with enable/disable video quickly
This commit is contained in:
parent
f19ae793c0
commit
825ff22fa4
1 changed files with 23 additions and 1 deletions
|
@ -201,6 +201,17 @@ class Video {
|
||||||
|
|
||||||
this._video = document.createElement('video');
|
this._video = document.createElement('video');
|
||||||
const video = new Promise((resolve, reject) => {
|
const video = new Promise((resolve, reject) => {
|
||||||
|
// if we disabledVideo in the same frame, just make sure singleSetup is cleared, never resolve
|
||||||
|
if (!this._video) {
|
||||||
|
this._singleSetup = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// in the event there was some second setup
|
||||||
|
if (this._track) {
|
||||||
|
return resolve(this._video);
|
||||||
|
}
|
||||||
|
|
||||||
navigator.getUserMedia({
|
navigator.getUserMedia({
|
||||||
audio: false,
|
audio: false,
|
||||||
video: {
|
video: {
|
||||||
|
@ -208,6 +219,16 @@ class Video {
|
||||||
height: {min: 360, ideal: 480}
|
height: {min: 360, ideal: 480}
|
||||||
}
|
}
|
||||||
}, stream => {
|
}, stream => {
|
||||||
|
// if we disabled video in the meantime...
|
||||||
|
if (!this._video) {
|
||||||
|
this._singleSetup = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// if we somehow got here with two user medias, stop the old stream
|
||||||
|
if (this._track) {
|
||||||
|
this._track.stop();
|
||||||
|
}
|
||||||
|
|
||||||
this._video.src = window.URL.createObjectURL(stream);
|
this._video.src = window.URL.createObjectURL(stream);
|
||||||
// Hint to the stream that it should load. A standard way to do this
|
// Hint to the stream that it should load. A standard way to do this
|
||||||
// is add the video tag to the DOM. Since this extension wants to
|
// is add the video tag to the DOM. Since this extension wants to
|
||||||
|
@ -259,11 +280,12 @@ class Video {
|
||||||
});
|
});
|
||||||
|
|
||||||
this._renderPreviewFrame = () => {
|
this._renderPreviewFrame = () => {
|
||||||
|
clearTimeout(this._renderPreviewTimeout);
|
||||||
if (!this._renderPreviewFrame) {
|
if (!this._renderPreviewFrame) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(this._renderPreviewFrame, this.runtime.currentStepTime);
|
this._renderPreviewTimeout = setTimeout(this._renderPreviewFrame, this.runtime.currentStepTime);
|
||||||
|
|
||||||
const canvas = this.getFrame({format: Video.FORMAT_CANVAS});
|
const canvas = this.getFrame({format: Video.FORMAT_CANVAS});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue