Guard against some issues that could happen with enable/disable video quickly

This commit is contained in:
Corey Frang 2018-04-05 13:19:03 -04:00 committed by Michael "Z" Goddard
parent f19ae793c0
commit 825ff22fa4
No known key found for this signature in database
GPG key ID: 762CD40DD5349872

View file

@ -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});