scrawl-canvas
Version:
Version 8.9.4 - 19 Nov 2022
1,168 lines (757 loc) • 65.4 kB
HTML
<!DOCTYPE html>
<html>
<head>
<title>VideoAsset factory</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="../../docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="../core/animationloop.html">
./source/core/animationloop.js
</a>
<a class="source" href="../core/document.html">
./source/core/document.js
</a>
<a class="source" href="../core/events.html">
./source/core/events.js
</a>
<a class="source" href="../core/init.html">
./source/core/init.js
</a>
<a class="source" href="../core/library.html">
./source/core/library.js
</a>
<a class="source" href="../core/random-seed.html">
./source/core/random-seed.js
</a>
<a class="source" href="../core/snippets.html">
./source/core/snippets.js
</a>
<a class="source" href="../core/userInteraction.html">
./source/core/userInteraction.js
</a>
<a class="source" href="../core/utilities.html">
./source/core/utilities.js
</a>
<a class="source" href="action.html">
./source/factory/action.js
</a>
<a class="source" href="anchor.html">
./source/factory/anchor.js
</a>
<a class="source" href="animation.html">
./source/factory/animation.js
</a>
<a class="source" href="bezier.html">
./source/factory/bezier.js
</a>
<a class="source" href="block.html">
./source/factory/block.js
</a>
<a class="source" href="canvas.html">
./source/factory/canvas.js
</a>
<a class="source" href="cell.html">
./source/factory/cell.js
</a>
<a class="source" href="cog.html">
./source/factory/cog.js
</a>
<a class="source" href="color.html">
./source/factory/color.js
</a>
<a class="source" href="conicGradient.html">
./source/factory/conicGradient.js
</a>
<a class="source" href="coordinate.html">
./source/factory/coordinate.js
</a>
<a class="source" href="crescent.html">
./source/factory/crescent.js
</a>
<a class="source" href="element.html">
./source/factory/element.js
</a>
<a class="source" href="emitter.html">
./source/factory/emitter.js
</a>
<a class="source" href="filter.html">
./source/factory/filter.js
</a>
<a class="source" href="filterEngine-bluenoiseData.html">
./source/factory/filterEngine-bluenoiseData.js
</a>
<a class="source" href="filterEngine.html">
./source/factory/filterEngine.js
</a>
<a class="source" href="fontAttributes.html">
./source/factory/fontAttributes.js
</a>
<a class="source" href="gradient.html">
./source/factory/gradient.js
</a>
<a class="source" href="grid.html">
./source/factory/grid.js
</a>
<a class="source" href="group.html">
./source/factory/group.js
</a>
<a class="source" href="imageAsset.html">
./source/factory/imageAsset.js
</a>
<a class="source" href="line.html">
./source/factory/line.js
</a>
<a class="source" href="lineSpiral.html">
./source/factory/lineSpiral.js
</a>
<a class="source" href="loom.html">
./source/factory/loom.js
</a>
<a class="source" href="mesh.html">
./source/factory/mesh.js
</a>
<a class="source" href="net.html">
./source/factory/net.js
</a>
<a class="source" href="noiseAsset.html">
./source/factory/noiseAsset.js
</a>
<a class="source" href="oval.html">
./source/factory/oval.js
</a>
<a class="source" href="palette.html">
./source/factory/palette.js
</a>
<a class="source" href="particle.html">
./source/factory/particle.js
</a>
<a class="source" href="particleForce.html">
./source/factory/particleForce.js
</a>
<a class="source" href="particleHistory.html">
./source/factory/particleHistory.js
</a>
<a class="source" href="particleSpring.html">
./source/factory/particleSpring.js
</a>
<a class="source" href="particleWorld.html">
./source/factory/particleWorld.js
</a>
<a class="source" href="pattern.html">
./source/factory/pattern.js
</a>
<a class="source" href="phrase.html">
./source/factory/phrase.js
</a>
<a class="source" href="picture.html">
./source/factory/picture.js
</a>
<a class="source" href="polygon.html">
./source/factory/polygon.js
</a>
<a class="source" href="polyline.html">
./source/factory/polyline.js
</a>
<a class="source" href="quadratic.html">
./source/factory/quadratic.js
</a>
<a class="source" href="quaternion.html">
./source/factory/quaternion.js
</a>
<a class="source" href="radialGradient.html">
./source/factory/radialGradient.js
</a>
<a class="source" href="rawAsset.html">
./source/factory/rawAsset.js
</a>
<a class="source" href="rdAsset.html">
./source/factory/rdAsset.js
</a>
<a class="source" href="rectangle.html">
./source/factory/rectangle.js
</a>
<a class="source" href="renderAnimation.html">
./source/factory/renderAnimation.js
</a>
<a class="source" href="shape.html">
./source/factory/shape.js
</a>
<a class="source" href="spiral.html">
./source/factory/spiral.js
</a>
<a class="source" href="spriteAsset.html">
./source/factory/spriteAsset.js
</a>
<a class="source" href="stack.html">
./source/factory/stack.js
</a>
<a class="source" href="star.html">
./source/factory/star.js
</a>
<a class="source" href="state.html">
./source/factory/state.js
</a>
<a class="source" href="tetragon.html">
./source/factory/tetragon.js
</a>
<a class="source" href="ticker.html">
./source/factory/ticker.js
</a>
<a class="source" href="tracer.html">
./source/factory/tracer.js
</a>
<a class="source" href="tween.html">
./source/factory/tween.js
</a>
<a class="source" href="unstackedElement.html">
./source/factory/unstackedElement.js
</a>
<a class="source" href="vector.html">
./source/factory/vector.js
</a>
<a class="source" href="videoAsset.html">
./source/factory/videoAsset.js
</a>
<a class="source" href="wheel.html">
./source/factory/wheel.js
</a>
<a class="source" href="../mixin/anchor.html">
./source/mixin/anchor.js
</a>
<a class="source" href="../mixin/asset.html">
./source/mixin/asset.js
</a>
<a class="source" href="../mixin/assetAdvancedFunctionality.html">
./source/mixin/assetAdvancedFunctionality.js
</a>
<a class="source" href="../mixin/assetConsumer.html">
./source/mixin/assetConsumer.js
</a>
<a class="source" href="../mixin/base.html">
./source/mixin/base.js
</a>
<a class="source" href="../mixin/cascade.html">
./source/mixin/cascade.js
</a>
<a class="source" href="../mixin/delta.html">
./source/mixin/delta.js
</a>
<a class="source" href="../mixin/displayShape.html">
./source/mixin/displayShape.js
</a>
<a class="source" href="../mixin/dom.html">
./source/mixin/dom.js
</a>
<a class="source" href="../mixin/entity.html">
./source/mixin/entity.js
</a>
<a class="source" href="../mixin/filter.html">
./source/mixin/filter.js
</a>
<a class="source" href="../mixin/mimic.html">
./source/mixin/mimic.js
</a>
<a class="source" href="../mixin/path.html">
./source/mixin/path.js
</a>
<a class="source" href="../mixin/pattern.html">
./source/mixin/pattern.js
</a>
<a class="source" href="../mixin/pivot.html">
./source/mixin/pivot.js
</a>
<a class="source" href="../mixin/position.html">
./source/mixin/position.js
</a>
<a class="source" href="../mixin/shapeBasic.html">
./source/mixin/shapeBasic.js
</a>
<a class="source" href="../mixin/shapeCurve.html">
./source/mixin/shapeCurve.js
</a>
<a class="source" href="../mixin/shapePathCalculation.html">
./source/mixin/shapePathCalculation.js
</a>
<a class="source" href="../mixin/styles.html">
./source/mixin/styles.js
</a>
<a class="source" href="../mixin/tween.html">
./source/mixin/tween.js
</a>
</div>
</div>
</li>
</ul>
<ul class="sections">
<li id="section-1">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-1">§</a>
</div>
<h1 id="videoasset-factory">VideoAsset factory</h1>
<p>The factory generates wrapper Objects around <video> elements which can either be pulled from the current document (DOM-based assets) or fetched from the server using an URL address.</p>
<p>Scrawl-canvas can also create VideoAssets from the Web API <a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaStream">MediaStream</a> interface - <em><strong>this is an experimental feature</strong></em>.</p>
<p>VideoAssets are used by <a href="./picture.html">Picture</a> and <a href="./grid.html">Grid</a> entitys, and <a href="./pattern.html">Pattern</a> styles (though not recommended).</p>
</div>
</li>
<li id="section-2">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-2">§</a>
</div>
<h4 id="demos">Demos:</h4>
<ul>
<li><a href="../../demo/canvas-010.html">Canvas-010</a> - Use video sources and media streams for Picture entitys</li>
<li><a href="../../demo/canvas-023.html">Canvas-023</a> - Grid entity - using picture-based assets (image, video, sprite)</li>
</ul>
</div>
</li>
<li id="section-3">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-3">§</a>
</div>
<h4 id="imports">Imports</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> { constructors } <span class="hljs-keyword">from</span> <span class="hljs-string">'../core/library.js'</span>;
<span class="hljs-keyword">import</span> { generateUniqueString, xt, λ<span class="hljs-variable language_">this</span>, λ<span class="hljs-literal">null</span>, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">'../core/utilities.js'</span>;
<span class="hljs-keyword">import</span> baseMix <span class="hljs-keyword">from</span> <span class="hljs-string">'../mixin/base.js'</span>;
<span class="hljs-keyword">import</span> assetMix <span class="hljs-keyword">from</span> <span class="hljs-string">'../mixin/asset.js'</span>;</pre></div></div>
</li>
<li id="section-4">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-4">§</a>
</div>
<h4 id="videoasset-constructor">VideoAsset constructor</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> <span class="hljs-title class_">VideoAsset</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items = Ωempty</span>) {
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">assetConstructor</span>(items);
};</pre></div></div>
</li>
<li id="section-5">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-5">§</a>
</div>
<h4 id="videoasset-prototype">VideoAsset prototype</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> P = <span class="hljs-title class_">VideoAsset</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span> = <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">create</span>(<span class="hljs-title class_">Object</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span>);
P.<span class="hljs-property">type</span> = <span class="hljs-string">'Video'</span>;
P.<span class="hljs-property">lib</span> = <span class="hljs-string">'asset'</span>;
P.<span class="hljs-property">isArtefact</span> = <span class="hljs-literal">false</span>;
P.<span class="hljs-property">isAsset</span> = <span class="hljs-literal">true</span>;</pre></div></div>
</li>
<li id="section-6">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-6">§</a>
</div>
<h4 id="mixins">Mixins</h4>
</div>
<div class="content"><div class='highlight'><pre>P = <span class="hljs-title function_">baseMix</span>(P);
P = <span class="hljs-title function_">assetMix</span>(P);</pre></div></div>
</li>
<li id="section-7">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-7">§</a>
</div>
<h4 id="videoasset-attributes">VideoAsset attributes</h4>
<ul>
<li>Attributes defined in the <a href="../mixin/base.html">base mixin</a>: <strong>name</strong>.</li>
<li>Attributes defined in the <a href="../mixin/asset.html">asset mixin</a>: <strong>source, subscribers</strong>.</li>
</ul>
<p>No additional attributes required beyond those supplied by the mixins</p>
</div>
</li>
<li id="section-8">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-8">§</a>
</div>
<h4 id="packet-management">Packet management</h4>
<p>Assets do not take part in the packet or clone systems; they can, however, be used for importing and actioning packets as they retain those base functions</p>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">saveAsPacket</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) {
<span class="hljs-keyword">return</span> [<span class="hljs-variable language_">this</span>.<span class="hljs-property">name</span>, <span class="hljs-variable language_">this</span>.<span class="hljs-property">type</span>, <span class="hljs-variable language_">this</span>.<span class="hljs-property">lib</span>, {}];
};
P.<span class="hljs-property">stringifyFunction</span> = λ<span class="hljs-literal">null</span>;
P.<span class="hljs-property">processPacketOut</span> = λ<span class="hljs-literal">null</span>;
P.<span class="hljs-property">finalizePacketOut</span> = λ<span class="hljs-literal">null</span>;</pre></div></div>
</li>
<li id="section-9">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-9">§</a>
</div>
<h4 id="clone-management">Clone management</h4>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">clone</span> = λ<span class="hljs-variable language_">this</span>;</pre></div></div>
</li>
<li id="section-10">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-10">§</a>
</div>
<h4 id="kill-management">Kill management</h4>
<p>No additional kill functionality required</p>
</div>
</li>
<li id="section-11">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-11">§</a>
</div>
<h4 id="get-set-deltaset">Get, Set, deltaSet</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> G = P.<span class="hljs-property">getters</span>,
S = P.<span class="hljs-property">setters</span>,
D = P.<span class="hljs-property">deltaSetters</span>;</pre></div></div>
</li>
<li id="section-12">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-12">§</a>
</div>
<p><strong>source</strong></p>
</div>
<div class="content"><div class='highlight'><pre>S.<span class="hljs-property">source</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">if</span> (item) {
<span class="hljs-keyword">if</span> (item.<span class="hljs-property">tagName</span>.<span class="hljs-title function_">toUpperCase</span>() === <span class="hljs-string">'VIDEO'</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span> = item;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceNaturalWidth</span> = item.<span class="hljs-property">videoWidth</span> || <span class="hljs-number">0</span>;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceNaturalHeight</span> = item.<span class="hljs-property">videoHeight</span> || <span class="hljs-number">0</span>;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceLoaded</span> = (item.<span class="hljs-property">readyState</span> > <span class="hljs-number">2</span>) ? <span class="hljs-literal">true</span> : <span class="hljs-literal">false</span>;
}
<span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceLoaded</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">notifySubscribers</span>();
}
};</pre></div></div>
</li>
<li id="section-13">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-13">§</a>
</div>
<h4 id="prototype-functions">Prototype functions</h4>
</div>
</li>
<li id="section-14">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-14">§</a>
</div>
<p><code>checkSource</code></p>
<ul>
<li>Gets invoked by subscribers (who have a handle to the asset instance object) as part of the display cycle.</li>
<li>If any of the source <video> element’s relevant attributes have changed, the asset wrapper will immediately notify/update ALL of its subscribers by changing attributes on their objects.</li>
<li>TODO: there may be a more efficient way of doing this? If the first subscriber triggers a notify action, which propagates to all subscribers, then subsequent subscribers don’t need to invoke this function for the remainder of this display cycle.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">checkSource</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">width, height</span>) {
<span class="hljs-keyword">let</span> source = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>;
<span class="hljs-keyword">if</span> (source && source.<span class="hljs-property">readyState</span> > <span class="hljs-number">2</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceLoaded</span> = <span class="hljs-literal">true</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceNaturalWidth</span> !== source.<span class="hljs-property">videoWidth</span> ||
<span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceNaturalHeight</span> !== source.<span class="hljs-property">videoHeight</span> ||
<span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceNaturalWidth</span> !== width ||
<span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceNaturalHeight</span> !== height) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceNaturalWidth</span> = source.<span class="hljs-property">videoWidth</span>;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceNaturalHeight</span> = source.<span class="hljs-property">videoHeight</span>;
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">notifySubscribers</span>();
}
}
<span class="hljs-keyword">else</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceLoaded</span> = <span class="hljs-literal">false</span>;
};</pre></div></div>
</li>
<li id="section-15">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-15">§</a>
</div>
<h4 id="managing-video-sources">Managing video sources</h4>
<p>The following functions invoke their <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement">namesake functions on the source <video> element</a>. </p>
<ul>
<li>Note that some of the functions are defined as being asynchronous; for these functions, we wrap the invocations in Promises which cascade back to the original invocation (probably in user code).</li>
<li>All of these functions are also mapped onto the factories which consume the videoAsset - Picture entitys and Pattern styles - so they can be invoked on those objects instead on the videoAsset instance.</li>
</ul>
</div>
</li>
<li id="section-16">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-16">§</a>
</div>
<p><code>addTextTrack</code></p>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">addTextTrack</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">kind, label, language</span>) {
<span class="hljs-keyword">let</span> source = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>;
<span class="hljs-keyword">if</span> (source && source.<span class="hljs-property">addTextTrack</span>) source.<span class="hljs-title function_">addTextTrack</span>(kind, label, language);
};</pre></div></div>
</li>
<li id="section-17">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-17">§</a>
</div>
<p><code>captureStream</code></p>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">captureStream</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) {
<span class="hljs-keyword">let</span> source = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>;
<span class="hljs-keyword">if</span> (source && source.<span class="hljs-property">captureStream</span>) <span class="hljs-keyword">return</span> source.<span class="hljs-title function_">captureStream</span>();
<span class="hljs-keyword">else</span> <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
};</pre></div></div>
</li>
<li id="section-18">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-18">§</a>
</div>
<p><code>canPlayType</code></p>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">canPlayType</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">mytype</span>) {
<span class="hljs-keyword">let</span> source = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>;
<span class="hljs-keyword">if</span> (source) <span class="hljs-keyword">return</span> source.<span class="hljs-title function_">canPlayType</span>(mytype);
<span class="hljs-keyword">else</span> <span class="hljs-keyword">return</span> <span class="hljs-string">'maybe'</span>;
};</pre></div></div>
</li>
<li id="section-19">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-19">§</a>
</div>
<p><code>fastSeek</code></p>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">fastSeek</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">time</span>) {
<span class="hljs-keyword">let</span> source = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>;
<span class="hljs-keyword">if</span> (source && source.<span class="hljs-property">fastSeek</span>) source.<span class="hljs-title function_">fastSeek</span>(time);
};</pre></div></div>
</li>
<li id="section-20">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-20">§</a>
</div>
<p><code>load</code></p>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">load</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) {
<span class="hljs-keyword">let</span> source = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>;
<span class="hljs-keyword">if</span> (source) source.<span class="hljs-title function_">load</span>();
};</pre></div></div>
</li>
<li id="section-21">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-21">§</a>
</div>
<p><code>pause</code></p>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">pause</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) {
<span class="hljs-keyword">let</span> source = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>;
<span class="hljs-keyword">if</span> (source) source.<span class="hljs-title function_">pause</span>();
};</pre></div></div>
</li>
<li id="section-22">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-22">§</a>
</div>
<p><code>play</code></p>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">play</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) {
<span class="hljs-keyword">let</span> source = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>;
<span class="hljs-keyword">if</span> (source) <span class="hljs-keyword">return</span> source.<span class="hljs-title function_">play</span>().<span class="hljs-title function_">catch</span>(<span class="hljs-function">(<span class="hljs-params">e</span>) =></span> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(e.<span class="hljs-property">code</span>, e.<span class="hljs-property">name</span>, e.<span class="hljs-property">message</span>));
<span class="hljs-keyword">else</span> <span class="hljs-keyword">return</span> <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">reject</span>(<span class="hljs-string">'Source not defined'</span>);
};</pre></div></div>
</li>
<li id="section-23">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-23">§</a>
</div>
<p><code>setMediaKeys</code></p>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">setMediaKeys</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">keys</span>) {
<span class="hljs-keyword">let</span> source = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>;
<span class="hljs-keyword">if</span> (source) {
<span class="hljs-keyword">if</span> (source.<span class="hljs-property">setMediaKeys</span>) <span class="hljs-keyword">return</span> source.<span class="hljs-title function_">setMediaKeys</span>(keys);
<span class="hljs-keyword">else</span> <span class="hljs-keyword">return</span> <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">reject</span>(<span class="hljs-string">'setMediaKeys not supported'</span>);
}
<span class="hljs-keyword">else</span> <span class="hljs-keyword">return</span> <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">reject</span>(<span class="hljs-string">'Source not defined'</span>);
};</pre></div></div>
</li>
<li id="section-24">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-24">§</a>
</div>
<p><code>setSinkId</code></p>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">setSinkId</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) {
<span class="hljs-keyword">let</span> source = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>;
<span class="hljs-keyword">if</span> (source) {
<span class="hljs-keyword">if</span> (source.<span class="hljs-property">setSinkId</span>) <span class="hljs-keyword">return</span> source.<span class="hljs-title function_">setSinkId</span>();
<span class="hljs-keyword">else</span> <span class="hljs-keyword">return</span> <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">reject</span>(<span class="hljs-string">'setSinkId not supported'</span>);
}
<span class="hljs-keyword">else</span> <span class="hljs-keyword">return</span> <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">reject</span>(<span class="hljs-string">'Source not defined'</span>);
};</pre></div></div>
</li>
<li id="section-25">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-25">§</a>
</div>
<p><code>gettableVideoAssetAtributes</code>, <code>settableVideoAssetAtributes</code> - exported Arrays.</p>
<ul>
<li>TODO - I was planning to make the <video> element’s attributes accessible to Picture entitys and Pattern styles - need to check if work has been completed at their end.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> gettableVideoAssetAtributes = [
<span class="hljs-string">'video_audioTracks'</span>,
<span class="hljs-string">'video_autoPlay'</span>,
<span class="hljs-string">'video_buffered'</span>,
<span class="hljs-string">'video_controller'</span>,
<span class="hljs-string">'video_controls'</span>,
<span class="hljs-string">'video_controlsList'</span>,
<span class="hljs-string">'video_crossOrigin'</span>,
<span class="hljs-string">'video_currentSrc'</span>,
<span class="hljs-string">'video_currentTime'</span>,
<span class="hljs-string">'video_defaultMuted'</span>,
<span class="hljs-string">'video_defaultPlaybackRate'</span>,
<span class="hljs-string">'video_disableRemotePlayback'</span>,
<span class="hljs-string">'video_duration'</span>,
<span class="hljs-string">'video_ended'</span>,
<span class="hljs-string">'video_error'</span>,
<span class="hljs-string">'video_loop'</span>,
<span class="hljs-string">'video_mediaGroup'</span>,
<span class="hljs-string">'video_mediaKeys'</span>,
<span class="hljs-string">'video_muted'</span>,
<span class="hljs-string">'video_networkState'</span>,
<span class="hljs-string">'video_paused'</span>,
<span class="hljs-string">'video_playbackRate'</span>,
<span class="hljs-string">'video_readyState'</span>,
<span class="hljs-string">'video_seekable'</span>,
<span class="hljs-string">'video_seeking'</span>,
<span class="hljs-string">'video_sinkId'</span>,
<span class="hljs-string">'video_src'</span>,
<span class="hljs-string">'video_srcObject'</span>,
<span class="hljs-string">'video_textTracks'</span>,
<span class="hljs-string">'video_videoTracks'</span>,
<span class="hljs-string">'video_volume'</span>,
];
<span class="hljs-keyword">const</span> settableVideoAssetAtributes = [
<span class="hljs-string">'video_autoPlay'</span>,
<span class="hljs-string">'video_controller'</span>,
<span class="hljs-string">'video_controls'</span>,
<span class="hljs-string">'video_crossOrigin'</span>,
<span class="hljs-string">'video_currentTime'</span>,
<span class="hljs-string">'video_defaultMuted'</span>,
<span class="hljs-string">'video_defaultPlaybackRate'</span>,
<span class="hljs-string">'video_disableRemotePlayback'</span>,
<span class="hljs-string">'video_loop'</span>,
<span class="hljs-string">'video_mediaGroup'</span>,
<span class="hljs-string">'video_muted'</span>,
<span class="hljs-string">'video_playbackRate'</span>,
<span class="hljs-string">'video_src'</span>,
<span class="hljs-string">'video_srcObject'</span>,
<span class="hljs-string">'video_volume'</span>,
];</pre></div></div>
</li>
<li id="section-26">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-26">§</a>
</div>
<h4 id="import-videos">Import videos</h4>
</div>
</li>
<li id="section-27">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-27">§</a>
</div>
<p><code>importDomVideo</code> - import videos defined in the web page HTML code</p>
<ul>
<li>Required argument is a query string used to search the dom for matching elements</li>
<li>Scrawl-canvas does not remove <video> elements from the DOM.</li>
<li>If <video> elements should not appear, developers need to hide them in some way - for instance by positioning them (or their parent element) absolutely to the top or left of the display; or by giving their parent element zero width/height; or by setting their CSS: <code>display: none;</code>, <code>opacity: 0;</code>, etc.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> importDomVideo = <span class="hljs-keyword">function</span> (<span class="hljs-params">query</span>) {
<span class="hljs-keyword">let</span> reg = <span class="hljs-regexp">/.*\/(.*?)\./</span>;
<span class="hljs-keyword">let</span> items = <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">querySelectorAll</span>(query);
items.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">item</span> =></span> {
<span class="hljs-keyword">let</span> name;
<span class="hljs-keyword">if</span> (item.<span class="hljs-property">tagName</span>.<span class="hljs-title function_">toUpperCase</span>() === <span class="hljs-string">'VIDEO'</span>) {
<span class="hljs-keyword">if</span> (item.<span class="hljs-property">id</span> || item.<span class="hljs-property">name</span>) name = item.<span class="hljs-property">id</span> || item.<span class="hljs-property">name</span>;
<span class="hljs-keyword">else</span> {
<span class="hljs-keyword">let</span> match = reg.<span class="hljs-title function_">exec</span>(item.<span class="hljs-property">src</span>);
name = (match && match[<span class="hljs-number">1</span>]) ? match[<span class="hljs-number">1</span>] : <span class="hljs-string">''</span>;
}
<span class="hljs-keyword">let</span> vid = <span class="hljs-title function_">makeVideoAsset</span>({
<span class="hljs-attr">name</span>: name,
<span class="hljs-attr">source</span>: item,
});
<span class="hljs-keyword">if</span> (item.<span class="hljs-property">readyState</span> <= <span class="hljs-number">2</span>) {
item.<span class="hljs-property">oncanplay</span> = <span class="hljs-function">() =></span> {
vid.<span class="hljs-title function_">set</span>({
<span class="hljs-attr">source</span>: item,
});
};
}
}
});
};</pre></div></div>
</li>
<li id="section-28">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-28">§</a>
</div>
<p><code>importMediaStream</code> - <strong>Warning: experimental!</strong></p>
<ul>
<li>This function will attempt to link a mediaStream - for instance from a device’s camera - to an offscreen <video> element, which then gets wrapped in a videoAsset instance which can be displayed in a canvas via a Picture entity (or even a Pattern style).</li>
<li>TODO - extend functionality so users can manipulate the mediaStream via the Picture entity using it as its asset</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> importMediaStream = <span class="hljs-keyword">function</span> (<span class="hljs-params">items = Ωempty</span>) {</pre></div></div>
</li>
<li id="section-29">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-29">§</a>
</div>
<p>Setup the constraints object with user-supplied data in the items argument</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> constraints = {};</pre></div></div>
</li>
<li id="section-30">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-30">§</a>
</div>
<p>For proof-of-concept, only interested in wheter to include or exclude audio in the capture</p>
</div>
<div class="content"><div class='highlight'><pre> constraints.<span class="hljs-property">audio</span> = (<span class="hljs-title function_">xt</span>(items.<span class="hljs-property">audio</span>)) ? items.<span class="hljs-property">audio</span> : <span class="hljs-literal">true</span>;</pre></div></div>
</li>
<li id="section-31">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-31">§</a>
</div>
<p>For video, limiting functionality to accepting user values for video width and height (as minDIMENSION, maxDIMENSION and the ideal DIMENSION, and a preference for which camera to use - where applicable</p>
</div>
<div class="content"><div class='highlight'><pre> constraints.<span class="hljs-property">video</span> = {};
<span class="hljs-keyword">let</span> width = constraints.<span class="hljs-property">video</span>.<span class="hljs-property">width</span> = {};
<span class="hljs-