enableVideo - get rid of "requests"

This commit is contained in:
Corey Frang 2018-04-04 14:20:13 -04:00 committed by Michael "Z" Goddard
parent efa6b3a069
commit f19ae793c0
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
2 changed files with 5 additions and 32 deletions

View file

@ -345,7 +345,7 @@ class Scratch3VideoSensingBlocks {
if (args.VIDEO_STATE === 'off' || state === 1) { if (args.VIDEO_STATE === 'off' || state === 1) {
this.runtime.ioDevices.video.disableVideo(); this.runtime.ioDevices.video.disableVideo();
} else { } else {
this.runtime.ioDevices.video.requestVideo(); this.runtime.ioDevices.video.enableVideo();
this.runtime.ioDevices.video.mirror = args.VIDEO_STATE === 'on' || state === 2; this.runtime.ioDevices.video.mirror = args.VIDEO_STATE === 'on' || state === 2;
} }
} }

View file

@ -20,12 +20,6 @@ class Video {
*/ */
this._frameCacheTimeout = 16; this._frameCacheTimeout = 16;
/**
* Store each request for video, so when all are released we can disable preview/video feed.
* @type Array.<object>
*/
this._requests = [];
/** /**
* DOM Video element * DOM Video element
* @private * @private
@ -93,36 +87,15 @@ class Video {
* Request video be enabled. Sets up video, creates video skin and enables preview. * Request video be enabled. Sets up video, creates video skin and enables preview.
* *
* ioDevices.video.requestVideo() * ioDevices.video.requestVideo()
* .then(({ release }) => {
* this.releaseVideo = release;
* })
* *
* @return {Promise.<VideoRequest>} A request object with a "release" property that * @return {Promise.<Video>} resolves a promise to this IO device when video is ready.
* should be called when you are done with the video.
*/ */
requestVideo () { enableVideo () {
const io = this;
const request = {
release () {
const index = io._requests.indexOf(request);
if (index > -1) {
io._requests.splice(index, 1);
}
if (io._requests.length === 0) {
io._disableVideo();
}
}
};
if (this.videoReady) { if (this.videoReady) {
this._requests.push(request); return Promise.resolve(this);
return Promise.resolve(request);
} }
return this._setupVideo().then(() => { return this._setupVideo().then(() => this);
this._requests.push(request);
return request;
});
} }
/** /**