const log = require('../util/log'); class Video { constructor (runtime) { /** * Reference to the owning Runtime. * @type{!Runtime} */ this.runtime = runtime; /** * Default value for mirrored frames. * @type boolean */ this.mirror = true; /** * Cache frames for this many ms. * @type number */ this._frameCacheTimeout = 16; /** * DOM Video element * @private */ this._video = null; /** * Usermedia stream track * @private */ this._track = null; /** * Stores some canvas/frame data per resolution/mirror states */ this._workspace = []; /** * Id representing a Scratch Renderer skin the video is rendered to for * previewing. * @type {number} */ this._skinId = -1; /** * The Scratch Renderer Skin object. * @type {Skin} */ this._skin = null; /** * Id for a drawable using the video's skin that will render as a video * preview. * @type {Drawable} */ this._drawable = -1; /** * Store the last state of the video transparency ghost effect * @type {number} */ this._ghost = 0; } static get FORMAT_IMAGE_DATA () { return 'image-data'; } static get FORMAT_CANVAS () { return 'canvas'; } /** * Dimensions the video stream is analyzed at after its rendered to the * sample canvas. * @type {Array.} */ static get DIMENSIONS () { return [480, 360]; } /** * Order preview drawable is inserted at in the renderer. * @type {number} */ static get ORDER () { return 1; } /** * Request video be enabled. Sets up video, creates video skin and enables preview. * * ioDevices.video.requestVideo() * * @return {Promise.