@wcstack/camera 4.0.0-rc.8 → 4.0.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +5 -1
- package/README.md +5 -1
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/index.d.ts +11 -12
- package/dist/index.esm.js +89 -22
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -46,9 +46,11 @@ $on: {
|
|
|
46
46
|
|
|
47
47
|
**属性:** `facing-mode`(`user`/`environment`)・`device-id`・`audio`(マイクを有効化)・`width`・`height`・`autostart`・`keep-alive`(ページ非表示時に停止しない・録画中に立てる)。
|
|
48
48
|
|
|
49
|
+
**`null` と `undefined`。** 入力(`audio`・`facingMode`・`deviceId`・`width`・`height`・`autostart`・`keepAlive`)はすべて属性に対応し、`null` を「クリア」として扱います。属性を外し、入力は既定値に戻ります(`facingMode` は `user`、デバイス指定なし、幅・高さの制約なし、boolean は off)。`undefined` は「値が無い」で、属性を最初の書き込みの前の状態 — マークアップに書かれた値、無ければ属性なし — に戻します。どちらも文字列 `"null"` / `"undefined"` として書くことはなく、どのカメラにも一致しない `deviceId` の exact 制約になることもありません(`@wcstack/state` は `undefined` を書きませんが、React 19 は値のあった prop を外したときに書き、直接の代入でも届きます)。
|
|
50
|
+
|
|
49
51
|
**コマンド:** `start()`・`stop()`・`switchCamera()`(前後カメラ切替)。
|
|
50
52
|
|
|
51
|
-
**バインド可能な値:** `active`(ストリーム生存)・`permission` / `audioPermission`(`prompt`/`granted`/`denied`/`unsupported`)・`deviceId
|
|
53
|
+
**バインド可能な値:** `active`(ストリーム生存)・`permission` / `audioPermission`(`prompt`/`granted`/`denied`/`unsupported`)・`deviceId`(ストリームが使っているデバイス。`wcs-camera:device-changed` で publish。プロパティを読むと、決まった後はこの値、それまでは要求した `device-id` を返す。要求そのものは属性に残る)・`devices`・`error`・`errorInfo`(`WcsIoErrorInfo | null`——`error` から派生するシリアライズ可能な失敗分類。`wcs-camera:error-info-changed` で publish。下記「注意・落とし穴」参照)。
|
|
52
54
|
|
|
53
55
|
**イベント(event-token):** `streamReady`(`wcs-camera:stream-ready`、detail = 生 `MediaStream`)・`error`・`ended`(OS によるトラック剥奪)。`streamReady` の「プロパティ」は event-token 配線用で、値としてバインドしないでください。
|
|
54
56
|
|
|
@@ -65,6 +67,8 @@ $on: {
|
|
|
65
67
|
|
|
66
68
|
**属性:** `mime-type`・`timeslice`(この間隔で `dataavailable` を出す。省略時は stop で 1 つの `Blob`)・`audio-bits`・`video-bits`。
|
|
67
69
|
|
|
70
|
+
**`null` と `undefined`** は `<wcs-camera>` と同じです。入力 `mimeType`(要求)・`timeslice`・`audioBitsPerSecond`・`videoBitsPerSecond` では、`null` は属性を外し(何も要求せず、ブラウザが選びます)、`undefined` はマークアップに書かれた属性、無ければ属性なしに戻します。どちらも文字列として書くことはありません。
|
|
71
|
+
|
|
68
72
|
**コマンド:** `attachStream(stream)`・`start()`・`stop()`・`pause()`・`resume()`。
|
|
69
73
|
|
|
70
74
|
**バインド可能な値:** `recording`・`paused`・`duration`(ms・下記注記参照)・`mimeType`(**解決後**の録画タイプ。要求した `mime-type` 属性と異なる、または未指定時にブラウザが補完した値)・`blob`・`objectURL`・`error`・`errorInfo`(`WcsIoErrorInfo | null`——`error` から派生するシリアライズ可能な失敗分類。`wcs-recorder:error-info-changed` で publish。下記「注意・落とし穴」参照)。
|
package/README.md
CHANGED
|
@@ -46,9 +46,11 @@ Acquires a camera stream and renders a preview. Acquisition is **explicit** —
|
|
|
46
46
|
|
|
47
47
|
**Attributes:** `facing-mode` (`user`/`environment`), `device-id`, `audio` (opt the microphone in), `width`, `height`, `autostart`, `keep-alive` (do not suspend on page-hidden — set while recording).
|
|
48
48
|
|
|
49
|
+
**`null` and `undefined`.** The inputs (`audio`, `facingMode`, `deviceId`, `width`, `height`, `autostart`, `keepAlive`) are all backed by an attribute and take `null` as "clear": the attribute is removed and the input falls back to its default (`facingMode` `user`, no device pinned, no width / height constraint, the booleans off). `undefined` means "no value supplied": the attribute goes back to what it was before the first write — the value written in the markup, or none. Neither is ever written as the string `"null"` / `"undefined"`, so neither becomes an exact `deviceId` constraint that no camera matches. (`@wcstack/state` never writes `undefined`; React 19 does when a prop that had a value is removed, and so can a direct assignment.)
|
|
50
|
+
|
|
49
51
|
**Commands:** `start()`, `stop()`, `switchCamera()` (toggle front/back).
|
|
50
52
|
|
|
51
|
-
**Bindable values:** `active` (a stream is live), `permission` / `audioPermission` (`prompt`/`granted`/`denied`/`unsupported`), `deviceId
|
|
53
|
+
**Bindable values:** `active` (a stream is live), `permission` / `audioPermission` (`prompt`/`granted`/`denied`/`unsupported`), `deviceId` (the device the stream uses, published with `wcs-camera:device-changed`; reading the property gives the same value once one is known, and the requested `device-id` until then — the request itself stays in the attribute), `devices`, `error`, `errorInfo` (`WcsIoErrorInfo | null` — a serializable failure taxonomy derived from `error`, published via `wcs-camera:error-info-changed`; see [Notes & gotchas](#notes--gotchas) below).
|
|
52
54
|
|
|
53
55
|
**Events (event-token):** `streamReady` (`wcs-camera:stream-ready`, detail = the live `MediaStream`), `error`, `ended` (a track was revoked by the OS). The `streamReady` "property" exists for event-token wiring only — never bind it as a value.
|
|
54
56
|
|
|
@@ -65,6 +67,8 @@ Records a **borrowed** stream received via `attachStream` (the direct channel fr
|
|
|
65
67
|
|
|
66
68
|
**Attributes:** `mime-type`, `timeslice` (emit `dataavailable` chunks on this interval; omit for one `Blob` on stop), `audio-bits`, `video-bits`.
|
|
67
69
|
|
|
70
|
+
**`null` and `undefined`** work as on `<wcs-camera>`: on the `mimeType` (the request), `timeslice`, `audioBitsPerSecond` and `videoBitsPerSecond` inputs, `null` removes the attribute — nothing is requested and the browser picks — and `undefined` restores the attribute written in the markup, or none. Neither is written as a string.
|
|
71
|
+
|
|
68
72
|
**Commands:** `attachStream(stream)`, `start()`, `stop()`, `pause()`, `resume()`.
|
|
69
73
|
|
|
70
74
|
**Bindable values:** `recording`, `paused`, `duration` (ms — see note below), `mimeType` (the **resolved** recording type, which may differ from the requested `mime-type` attribute or be filled in when none was requested), `blob`, `objectURL`, `error`, `errorInfo` (`WcsIoErrorInfo | null` — a serializable failure taxonomy derived from `error`, published via `wcs-recorder:error-info-changed`; see [Notes & gotchas](#notes--gotchas) below).
|
package/dist/auto.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={tagNames:{camera:"wcs-camera",recorder:"wcs-recorder"}};function t(){return"undefined"!=typeof navigator&&!!navigator.mediaDevices&&"function"==typeof navigator.mediaDevices.getUserMedia}function i(e){if(e&&"object"==typeof e&&"name"in e){const t=String(e.name)||"Error";return{name:t,message:"message"in e&&e.message?String(e.message):`Media request failed: ${t}.`}}return{name:"Error",message:"Media request failed."}}const s={name:"unsupported",message:"getUserMedia is not available (requires a secure context)."};function r(e){if(e)for(const t of e.getTracks())t.stop()}async function n(){if(!t()||"function"!=typeof navigator.mediaDevices.enumerateDevices)return[];try{return(await navigator.mediaDevices.enumerateDevices()).filter(e=>"videoinput"===e.kind).map(e=>({deviceId:e.deviceId,label:e.label,groupId:e.groupId,kind:e.kind}))}catch{return[]}}class a{_name;_onChange;_status=null;_gen=0;_subscribed=!1;constructor(e,t){this._name=e,this._onChange=t}observe(){if(this._subscribed)return Promise.resolve();if("undefined"==typeof navigator||!navigator.permissions||"function"!=typeof navigator.permissions.query)return this._onChange("unsupported"),Promise.resolve();this._subscribed=!0;const e=++this._gen;return navigator.permissions.query({name:this._name}).then(t=>{e===this._gen&&(this._status=t,this._onChange(t.state),t.addEventListener("change",this._onStatusChange))},()=>{e===this._gen&&this._onChange("unsupported")})}dispose(){this._subscribed=!1,this._gen++,this._status&&(this._status.removeEventListener("change",this._onStatusChange),this._status=null)}_onStatusChange=e=>{const t=e.target;this._onChange(t.state)}}const o="capability-missing",c="not-allowed",d="not-found",h="not-readable",u="invalid-argument",_="invalid-state",m="aborted",l="media-error";function g(e){const{name:t,message:i}=e;return"unsupported"===t?{code:o,phase:"probe",recoverable:!1,message:i}:"NotAllowedError"===t||"SecurityError"===t?{code:c,phase:"start",recoverable:!1,message:i}:"NotFoundError"===t?{code:d,phase:"start",recoverable:!1,message:i}:"NotReadableError"===t?{code:h,phase:"start",recoverable:!1,message:i}:"OverconstrainedError"===t||"NotSupportedError"===t?{code:u,phase:"start",recoverable:!1,message:i}:"NoStreamError"===t?{code:_,phase:"start",recoverable:!1,message:i}:"AbortError"===t?{code:m,phase:"execute",recoverable:!0,message:i}:{code:l,phase:"execute",recoverable:!1,message:i}}class v extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"active",event:"wcs-camera:active-changed",semantics:"state"},{name:"permission",event:"wcs-camera:permission-changed",semantics:"state"},{name:"audioPermission",event:"wcs-camera:audio-permission-changed",semantics:"state"},{name:"deviceId",event:"wcs-camera:device-changed",semantics:"state"},{name:"devices",event:"wcs-camera:devices-changed",semantics:"state"},{name:"error",event:"wcs-camera:error",semantics:"state"},{name:"errorInfo",event:"wcs-camera:error-info-changed",semantics:"state"},{name:"streamReady",event:"wcs-camera:stream-ready",semantics:"handle",getter:e=>e.detail},{name:"ended",event:"wcs-camera:ended",semantics:"event",getter:e=>e.detail}],commands:[{name:"start"},{name:"stop"},{name:"switchCamera"}]};_target;_active=!1;_permission="prompt";_audioPermission=null;_deviceId=null;_devices=[];_error=null;_errorInfo=null;_stream=null;_desired=!1;_constraints={};_gen=0;_subscribed=!1;_camWatcher=null;_micWatcher=null;_ready=Promise.resolve();constructor(e){super(),this._target=e??this}get active(){return this._active}get permission(){return this._permission}get audioPermission(){return this._audioPermission}get deviceId(){return this._deviceId}get devices(){return this._devices}get error(){return this._error}get errorInfo(){return this._errorInfo}get ready(){return this._ready}_setActive(e){this._active!==e&&(this._active=e,this._dispatch("wcs-camera:active-changed",e))}_setPermission(e){this._permission!==e&&(this._permission=e,this._dispatch("wcs-camera:permission-changed",e))}_setAudioPermission(e){this._audioPermission!==e&&(this._audioPermission=e,this._dispatch("wcs-camera:audio-permission-changed",e))}_setDeviceId(e){this._deviceId!==e&&(this._deviceId=e,this._dispatch("wcs-camera:device-changed",e))}_setDevices(e){this._devicesEqual(this._devices,e)||(this._devices=e,this._dispatch("wcs-camera:devices-changed",e))}_setError(e){null===e&&null===this._error||(this._error=e,this._commitErrorInfo(null===e?null:g(e)),this._dispatch("wcs-camera:error",e))}_commitErrorInfo(e){this._errorInfo=e,this._dispatch("wcs-camera:error-info-changed",e)}_dispatch(e,t){this._target.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0}))}_devicesEqual(e,t){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(e[i].deviceId!==t[i].deviceId||e[i].label!==t[i].label)return!1;return!0}observe(e){return this._constraints={...e},this._subscribed?this._ready=this._ready.then(()=>this._reconcileAudioWatcher()):(this._subscribed=!0,this._ready=this._initPermissions()),this._ready}start(){this._desired=!0,this._restart()}stop(){this._desired=!1,this._release(!1)}switchCamera(){const e="environment"===this._constraints.facingMode?"user":"environment";this._constraints={...this._constraints,facingMode:e,deviceId:void 0},this._desired&&this._restart()}suspend(){this._gen++,this._stream&&this._release(!1)}resume(){this._desired&&!this._active&&this._restart()}dispose(){this._subscribed=!1,this._gen++,this._desired=!1,this._release(!0),t()&&"function"==typeof navigator.mediaDevices.removeEventListener&&navigator.mediaDevices.removeEventListener("devicechange",this._onDeviceChange),this._camWatcher?.dispose(),this._micWatcher?.dispose(),this._camWatcher=null,this._micWatcher=null}_initPermissions(){if(!t())return this._setPermission("unsupported"),Promise.resolve();this._camWatcher=new a("camera",e=>this._setPermission(e));const e=[this._camWatcher.observe()];return this._constraints.audio&&(this._micWatcher=new a("microphone",e=>this._setAudioPermission(e)),e.push(this._micWatcher.observe())),"function"==typeof navigator.mediaDevices.addEventListener&&navigator.mediaDevices.addEventListener("devicechange",this._onDeviceChange),Promise.all(e).then(()=>{})}_onDeviceChange=()=>{n().then(e=>{this._subscribed&&this._setDevices(e)})};_reconcileAudioWatcher(){return this._constraints.audio&&!this._micWatcher&&t()?(this._micWatcher=new a("microphone",e=>this._setAudioPermission(e)),this._micWatcher.observe()):(!this._constraints.audio&&this._micWatcher&&(this._micWatcher.dispose(),this._micWatcher=null,this._setAudioPermission(null)),Promise.resolve())}_restart(){this._release(!1),this._acquire()}async _acquire(){const e=++this._gen,a=function(e){const t={};return e.deviceId?t.deviceId={exact:e.deviceId}:e.facingMode&&(t.facingMode=e.facingMode),"number"==typeof e.width&&(t.width=e.width),"number"==typeof e.height&&(t.height=e.height),{video:!(Object.keys(t).length>0)||t,audio:!0===e.audio}}(this._constraints),{stream:o,error:c}=await async function(e){if(!t())return{error:s};try{return{stream:await navigator.mediaDevices.getUserMedia(e)}}catch(e){return{error:i(e)}}}(a);if(e!==this._gen)return void r(o??null);if(c)return this._setError(c),"NotAllowedError"===c.name?(this._setPermission("denied"),this._desired=!1):"unsupported"===c.name&&(this._setPermission("unsupported"),this._desired=!1),void this._setActive(!1);const d=o;this._stream=d;for(const e of d.getTracks())e.addEventListener("ended",this._onTrackEnded);this._setError(null),this._setPermission("granted"),this._constraints.audio&&d.getAudioTracks().length>0&&this._setAudioPermission("granted"),this._updateDeviceId(d),this._setActive(!0),this._dispatch("wcs-camera:stream-ready",d);const h=await n();e===this._gen&&this._setDevices(h)}_release(e){if(this._stream){for(const e of this._stream.getTracks())e.removeEventListener("ended",this._onTrackEnded);r(this._stream),this._stream=null,e?this._active=!1:this._setActive(!1)}}_onTrackEnded=()=>{this._release(!1),this._dispatch("wcs-camera:ended",null)};_updateDeviceId(e){const t=e.getVideoTracks()[0];if(t&&"function"==typeof t.getSettings){const e=t.getSettings();this._setDeviceId(e.deviceId??null)}}}function b(e,t){let i=Object.getPrototypeOf(e);for(;null!==i;){const e=Object.getOwnPropertyDescriptor(i,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;i=Object.getPrototypeOf(i)}return!1}function p(e){const t=e.constructor?.wcBindable,i=t?.inputs;if(void 0!==i)for(const t of i){const i=t.name;if(!Object.prototype.hasOwnProperty.call(e,i))continue;if(!b(e,i))continue;const s=e,r=s[i];delete s[i],s[i]=r}}class f extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...v.wcBindable,inputs:[{name:"audio",attribute:"audio"},{name:"facingMode",attribute:"facing-mode"},{name:"deviceId",attribute:"device-id"},{name:"width",attribute:"width"},{name:"height",attribute:"height"},{name:"autostart",attribute:"autostart"},{name:"keepAlive",attribute:"keep-alive"}],commands:v.wcBindable.commands};static observedAttributes=["facing-mode","device-id","audio","width","height"];_core;_video;_connectedCallbackPromise=Promise.resolve();_connected=!1;_batchingAttrs=!1;_internals=null;constructor(){super(),this._core=new v(this);const e=this.attachShadow({mode:"open"}),t=document.createElement("style");t.textContent=":host{display:inline-block}video{display:block;width:100%;height:100%}",this._video=document.createElement("video"),this._video.autoplay=!0,this._video.muted=!0,this._video.setAttribute("playsinline",""),this._video.setAttribute("part","video"),e.append(t,this._video),this.addEventListener("wcs-camera:stream-ready",this._onStreamReady),this.addEventListener("wcs-camera:active-changed",this._onActiveChanged),this._internals=this._initInternals(),this._wireStates({"wcs-camera:active-changed":e=>({active:!0===e}),"wcs-camera:error":e=>({error:null!=e})})}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const e=this.attachInternals();return e.states.add("wcs-probe"),e.states.delete("wcs-probe"),e}catch{return null}}_wireStates(e){if(null===this._internals)return;const t=this._internals.states;for(const[i,s]of Object.entries(e))this.addEventListener(i,e=>{const i=this.hasAttribute("debug-states");for(const[r,n]of Object.entries(s(e.detail))){try{n?t.add(r):t.delete(r)}catch{}i&&this.toggleAttribute(`data-wcs-state-${r}`,n)}})}get audio(){return this.hasAttribute("audio")}set audio(e){this._toggleAttr("audio",e)}get facingMode(){return"environment"===this.getAttribute("facing-mode")?"environment":"user"}set facingMode(e){this.setAttribute("facing-mode",e)}get deviceId(){return this.getAttribute("device-id")??""}set deviceId(e){this.setAttribute("device-id",e)}get width(){return this._numberAttr("width")}set width(e){this.setAttribute("width",String(e))}get height(){return this._numberAttr("height")}set height(e){this.setAttribute("height",String(e))}get autostart(){return this.hasAttribute("autostart")}set autostart(e){this._toggleAttr("autostart",e)}get keepAlive(){return this.hasAttribute("keep-alive")}set keepAlive(e){this._toggleAttr("keep-alive",e)}get videoElement(){return this._video}get active(){return this._core.active}get permission(){return this._core.permission}get audioPermission(){return this._core.audioPermission}get devices(){return this._core.devices}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get connectedCallbackPromise(){return this._connectedCallbackPromise}start(){this._core.start()}stop(){this._core.stop()}switchCamera(){const e="environment"===this.facingMode?"user":"environment";this._batchingAttrs=!0;try{this.removeAttribute("device-id"),this.setAttribute("facing-mode",e)}finally{this._batchingAttrs=!1}this._core.observe(this._constraints()),this._core.active&&this._core.start()}_toggleAttr(e,t){t?this.setAttribute(e,""):this.removeAttribute(e)}_numberAttr(e){const t=this.getAttribute(e);if(null===t||""===t.trim())return NaN;const i=Number(t);return Number.isFinite(i)?i:NaN}_constraints(){const e={audio:this.audio,facingMode:this.facingMode};return this.deviceId&&(e.deviceId=this.deviceId),Number.isFinite(this.width)&&(e.width=this.width),Number.isFinite(this.height)&&(e.height=this.height),e}_onStreamReady=e=>{this._video.srcObject=e.detail};_onActiveChanged=e=>{!1===e.detail&&(this._video.srcObject=null)};connectedCallback(){p(this),this._connected=!0,this._connectedCallbackPromise=this._core.observe(this._constraints()),this.autostart&&this._core.start(),document.addEventListener("visibilitychange",this._onVisibilityChange)}disconnectedCallback(){this._connected=!1,document.removeEventListener("visibilitychange",this._onVisibilityChange),this._core.dispose()}attributeChangedCallback(e,t,i){this._connected&&t!==i&&(this._batchingAttrs||(this._core.observe(this._constraints()),this._core.active&&this._core.start()))}_onVisibilityChange=()=>{this.keepAlive||("hidden"===document.visibilityState?this._core.suspend():this._core.resume())}}class y extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"recording",event:"wcs-recorder:recording-changed",semantics:"state"},{name:"paused",event:"wcs-recorder:paused-changed",semantics:"state"},{name:"duration",event:"wcs-recorder:duration-changed",semantics:"state"},{name:"mimeType",event:"wcs-recorder:mimetype-changed",semantics:"state"},{name:"blob",event:"wcs-recorder:recorded",semantics:"state",getter:e=>e.detail?.blob??null},{name:"objectURL",event:"wcs-recorder:recorded",semantics:"state",getter:e=>e.detail?.objectURL??null},{name:"error",event:"wcs-recorder:error",semantics:"state"},{name:"errorInfo",event:"wcs-recorder:error-info-changed",semantics:"state"},{name:"recorded",event:"wcs-recorder:recorded",semantics:"event",getter:e=>e.detail},{name:"dataavailable",event:"wcs-recorder:dataavailable",semantics:"event",getter:e=>e.detail}],commands:[{name:"attachStream"},{name:"start"},{name:"stop"},{name:"pause"},{name:"resume"}]};_target;_recording=!1;_paused=!1;_duration=0;_mimeType="";_blob=null;_objectURL=null;_error=null;_errorInfo=null;_recorder=null;_stream=null;_chunks=[];_timeslice=!1;_startTime=0;_gen=0;_ready=Promise.resolve();constructor(e){super(),this._target=e??this}get recording(){return this._recording}get paused(){return this._paused}get duration(){return this._duration}get mimeType(){return this._mimeType}get blob(){return this._blob}get objectURL(){return this._objectURL}get error(){return this._error}get errorInfo(){return this._errorInfo}get ready(){return this._ready}_setRecording(e){this._recording!==e&&(this._recording=e,this._dispatch("wcs-recorder:recording-changed",e))}_setPaused(e){this._paused!==e&&(this._paused=e,this._dispatch("wcs-recorder:paused-changed",e))}_setDuration(e){this._duration!==e&&(this._duration=e,this._dispatch("wcs-recorder:duration-changed",e))}_setMimeType(e){this._mimeType!==e&&(this._mimeType=e,this._dispatch("wcs-recorder:mimetype-changed",e))}_setError(e){null===e&&null===this._error||(this._error=e,this._commitErrorInfo(null===e?null:g(e)),this._dispatch("wcs-recorder:error",e))}_commitErrorInfo(e){this._errorInfo=e,this._dispatch("wcs-recorder:error-info-changed",e)}_dispatch(e,t){this._target.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0}))}attachStream(e){this._stream=e}start(e={}){if("undefined"==typeof globalThis||"function"!=typeof globalThis.MediaRecorder)return void this._setError({name:"unsupported",message:"MediaRecorder is not available in this environment."});if(!this._stream)return void this._setError({name:"NoStreamError",message:"No stream attached. Wire a camera's stream-ready to attachStream first."});if(this._recording)return;const t={};let s;e.mimeType&&this._isTypeSupported(e.mimeType)&&(t.mimeType=e.mimeType),"number"==typeof e.audioBitsPerSecond&&(t.audioBitsPerSecond=e.audioBitsPerSecond),"number"==typeof e.videoBitsPerSecond&&(t.videoBitsPerSecond=e.videoBitsPerSecond);try{s=new MediaRecorder(this._stream,t)}catch(e){return void this._setError(i(e))}const r=++this._gen;this._chunks=[],this._timeslice="number"==typeof e.timeslice&&e.timeslice>0,s.ondataavailable=e=>{r===this._gen&&e.data&&e.data.size>0&&(this._chunks.push(e.data),this._timeslice&&this._dispatch("wcs-recorder:dataavailable",e.data))},s.onstop=()=>{r===this._gen&&(this._paused||this._setDuration(this._elapsed()),this._assembleBlob(),this._setPaused(!1),this._setRecording(!1))},s.onerror=e=>{if(r!==this._gen)return;const t=e.error;this._setError(i(t??{name:"RecorderError"}))},s.onpause=()=>{r===this._gen&&(this._setDuration(this._elapsed()),this._setPaused(!0))},s.onresume=()=>{r===this._gen&&(this._startTime=this._now()-this._duration,this._setPaused(!1))},this._recorder=s,this._setError(null),this._setMimeType(s.mimeType||t.mimeType||""),this._startTime=this._now(),this._setDuration(0),s.start(this._timeslice?e.timeslice:void 0),this._setRecording(!0)}stop(){this._recorder&&"inactive"!==this._recorder.state&&this._recorder.stop()}pause(){this._recorder&&"recording"===this._recorder.state&&this._recorder.pause()}resume(){this._recorder&&"paused"===this._recorder.state&&this._recorder.resume()}observe(){return this._ready}dispose(){if(this._gen++,this._recorder&&"inactive"!==this._recorder.state)try{this._recorder.stop()}catch{}this._recorder=null,this._revokeUrl(),this._stream=null,this._recording=!1,this._paused=!1}_assembleBlob(){const e=new Blob(this._chunks,this._mimeType?{type:this._mimeType}:void 0);this._chunks=[],this._revokeUrl();const t=this._createUrl(e);this._blob=e,this._objectURL=t;const i={blob:e,objectURL:t,mimeType:this._mimeType,duration:this._duration};this._dispatch("wcs-recorder:recorded",i)}_revokeUrl(){this._objectURL&&"undefined"!=typeof URL&&"function"==typeof URL.revokeObjectURL&&URL.revokeObjectURL(this._objectURL),this._objectURL=null}_createUrl(e){return"undefined"!=typeof URL&&"function"==typeof URL.createObjectURL?URL.createObjectURL(e):""}_isTypeSupported(e){return globalThis.MediaRecorder.isTypeSupported(e)}_now(){return performance.now()}_elapsed(){return Math.max(0,Math.round(this._now()-this._startTime))}}class w extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...y.wcBindable,inputs:[{name:"mimeType",attribute:"mime-type"},{name:"timeslice",attribute:"timeslice"},{name:"audioBitsPerSecond",attribute:"audio-bits"},{name:"videoBitsPerSecond",attribute:"video-bits"}],commands:y.wcBindable.commands};_core;_connectedCallbackPromise=Promise.resolve();_internals=null;constructor(){super(),this._core=new y(this),this._internals=this._initInternals(),this._wireStates({"wcs-recorder:recording-changed":e=>({recording:!0===e}),"wcs-recorder:paused-changed":e=>({paused:!0===e}),"wcs-recorder:error":e=>({error:null!=e})})}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const e=this.attachInternals();return e.states.add("wcs-probe"),e.states.delete("wcs-probe"),e}catch{return null}}_wireStates(e){if(null===this._internals)return;const t=this._internals.states;for(const[i,s]of Object.entries(e))this.addEventListener(i,e=>{const i=this.hasAttribute("debug-states");for(const[r,n]of Object.entries(s(e.detail))){try{n?t.add(r):t.delete(r)}catch{}i&&this.toggleAttribute(`data-wcs-state-${r}`,n)}})}get connectedCallbackPromise(){return this._connectedCallbackPromise}get mimeType(){return this._core.mimeType}set mimeType(e){this.setAttribute("mime-type",e)}get timeslice(){return this._numberAttr("timeslice")}set timeslice(e){this.setAttribute("timeslice",String(e))}get audioBitsPerSecond(){return this._numberAttr("audio-bits")}set audioBitsPerSecond(e){this.setAttribute("audio-bits",String(e))}get videoBitsPerSecond(){return this._numberAttr("video-bits")}set videoBitsPerSecond(e){this.setAttribute("video-bits",String(e))}get recording(){return this._core.recording}get paused(){return this._core.paused}get duration(){return this._core.duration}get blob(){return this._core.blob}get objectURL(){return this._core.objectURL}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}attachStream(e){this._core.attachStream(e)}start(){this._core.start(this._options())}stop(){this._core.stop()}pause(){this._core.pause()}resume(){this._core.resume()}_numberAttr(e){const t=this.getAttribute(e);if(null===t||""===t.trim())return NaN;const i=Number(t);return Number.isFinite(i)?i:NaN}_options(){const e={},t=this.getAttribute("mime-type")??"";return t&&(e.mimeType=t),Number.isFinite(this.timeslice)&&(e.timeslice=this.timeslice),Number.isFinite(this.audioBitsPerSecond)&&(e.audioBitsPerSecond=this.audioBitsPerSecond),Number.isFinite(this.videoBitsPerSecond)&&(e.videoBitsPerSecond=this.videoBitsPerSecond),e}connectedCallback(){p(this),this.style.display="none",this._connectedCallbackPromise=this._core.observe()}disconnectedCallback(){this._core.dispose()}}var P;!function(t=customElements){t.get(e.tagNames.camera)||t.define(e.tagNames.camera,f),t.get(e.tagNames.recorder)||t.define(e.tagNames.recorder,w)}(P);
|
|
1
|
+
const e={tagNames:{camera:"wcs-camera",recorder:"wcs-recorder"}};function t(){return"undefined"!=typeof navigator&&!!navigator.mediaDevices&&"function"==typeof navigator.mediaDevices.getUserMedia}function i(e){if(e&&"object"==typeof e&&"name"in e){const t=String(e.name)||"Error";return{name:t,message:"message"in e&&e.message?String(e.message):`Media request failed: ${t}.`}}return{name:"Error",message:"Media request failed."}}const s={name:"unsupported",message:"getUserMedia is not available (requires a secure context)."};function r(e){if(e)for(const t of e.getTracks())t.stop()}async function n(){if(!t()||"function"!=typeof navigator.mediaDevices.enumerateDevices)return[];try{return(await navigator.mediaDevices.enumerateDevices()).filter(e=>"videoinput"===e.kind).map(e=>({deviceId:e.deviceId,label:e.label,groupId:e.groupId,kind:e.kind}))}catch{return[]}}class a{_name;_onChange;_status=null;_gen=0;_subscribed=!1;constructor(e,t){this._name=e,this._onChange=t}observe(){if(this._subscribed)return Promise.resolve();if("undefined"==typeof navigator||!navigator.permissions||"function"!=typeof navigator.permissions.query)return this._onChange("unsupported"),Promise.resolve();this._subscribed=!0;const e=++this._gen;return navigator.permissions.query({name:this._name}).then(t=>{e===this._gen&&(this._status=t,this._onChange(t.state),t.addEventListener("change",this._onStatusChange))},()=>{e===this._gen&&this._onChange("unsupported")})}dispose(){this._subscribed=!1,this._gen++,this._status&&(this._status.removeEventListener("change",this._onStatusChange),this._status=null)}_onStatusChange=e=>{const t=e.target;this._onChange(t.state)}}const o="capability-missing",c="not-allowed",d="not-found",h="not-readable",u="invalid-argument",_="invalid-state",m="aborted",l="media-error";function g(e){const{name:t,message:i}=e;return"unsupported"===t?{code:o,phase:"probe",recoverable:!1,message:i}:"NotAllowedError"===t||"SecurityError"===t?{code:c,phase:"start",recoverable:!1,message:i}:"NotFoundError"===t?{code:d,phase:"start",recoverable:!1,message:i}:"NotReadableError"===t?{code:h,phase:"start",recoverable:!1,message:i}:"OverconstrainedError"===t||"NotSupportedError"===t?{code:u,phase:"start",recoverable:!1,message:i}:"NoStreamError"===t?{code:_,phase:"start",recoverable:!1,message:i}:"AbortError"===t?{code:m,phase:"execute",recoverable:!0,message:i}:{code:l,phase:"execute",recoverable:!1,message:i}}class v extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"active",event:"wcs-camera:active-changed",semantics:"state"},{name:"permission",event:"wcs-camera:permission-changed",semantics:"state"},{name:"audioPermission",event:"wcs-camera:audio-permission-changed",semantics:"state"},{name:"deviceId",event:"wcs-camera:device-changed",semantics:"state"},{name:"devices",event:"wcs-camera:devices-changed",semantics:"state"},{name:"error",event:"wcs-camera:error",semantics:"state"},{name:"errorInfo",event:"wcs-camera:error-info-changed",semantics:"state"},{name:"streamReady",event:"wcs-camera:stream-ready",semantics:"handle",getter:e=>e.detail},{name:"ended",event:"wcs-camera:ended",semantics:"event",getter:e=>e.detail}],commands:[{name:"start"},{name:"stop"},{name:"switchCamera"}]};_target;_active=!1;_permission="prompt";_audioPermission=null;_deviceId=null;_devices=[];_error=null;_errorInfo=null;_stream=null;_desired=!1;_constraints={};_gen=0;_subscribed=!1;_camWatcher=null;_micWatcher=null;_ready=Promise.resolve();constructor(e){super(),this._target=e??this}get active(){return this._active}get permission(){return this._permission}get audioPermission(){return this._audioPermission}get deviceId(){return this._deviceId}get devices(){return this._devices}get error(){return this._error}get errorInfo(){return this._errorInfo}get ready(){return this._ready}_setActive(e){this._active!==e&&(this._active=e,this._dispatch("wcs-camera:active-changed",e))}_setPermission(e){this._permission!==e&&(this._permission=e,this._dispatch("wcs-camera:permission-changed",e))}_setAudioPermission(e){this._audioPermission!==e&&(this._audioPermission=e,this._dispatch("wcs-camera:audio-permission-changed",e))}_setDeviceId(e){this._deviceId!==e&&(this._deviceId=e,this._dispatch("wcs-camera:device-changed",e))}_setDevices(e){this._devicesEqual(this._devices,e)||(this._devices=e,this._dispatch("wcs-camera:devices-changed",e))}_setError(e){null===e&&null===this._error||(this._error=e,this._commitErrorInfo(null===e?null:g(e)),this._dispatch("wcs-camera:error",e))}_commitErrorInfo(e){this._errorInfo=e,this._dispatch("wcs-camera:error-info-changed",e)}_dispatch(e,t){this._target.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0}))}_devicesEqual(e,t){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(e[i].deviceId!==t[i].deviceId||e[i].label!==t[i].label)return!1;return!0}observe(e){return this._constraints={...e},this._subscribed?this._ready=this._ready.then(()=>this._reconcileAudioWatcher()):(this._subscribed=!0,this._ready=this._initPermissions()),this._ready}start(){this._desired=!0,this._restart()}stop(){this._desired=!1,this._release(!1)}switchCamera(){const e="environment"===this._constraints.facingMode?"user":"environment";this._constraints={...this._constraints,facingMode:e,deviceId:void 0},this._desired&&this._restart()}suspend(){this._gen++,this._stream&&this._release(!1)}resume(){this._desired&&!this._active&&this._restart()}dispose(){this._subscribed=!1,this._gen++,this._desired=!1,this._release(!0),t()&&"function"==typeof navigator.mediaDevices.removeEventListener&&navigator.mediaDevices.removeEventListener("devicechange",this._onDeviceChange),this._camWatcher?.dispose(),this._micWatcher?.dispose(),this._camWatcher=null,this._micWatcher=null}_initPermissions(){if(!t())return this._setPermission("unsupported"),Promise.resolve();this._camWatcher=new a("camera",e=>this._setPermission(e));const e=[this._camWatcher.observe()];return this._constraints.audio&&(this._micWatcher=new a("microphone",e=>this._setAudioPermission(e)),e.push(this._micWatcher.observe())),"function"==typeof navigator.mediaDevices.addEventListener&&navigator.mediaDevices.addEventListener("devicechange",this._onDeviceChange),Promise.all(e).then(()=>{})}_onDeviceChange=()=>{n().then(e=>{this._subscribed&&this._setDevices(e)})};_reconcileAudioWatcher(){return this._constraints.audio&&!this._micWatcher&&t()?(this._micWatcher=new a("microphone",e=>this._setAudioPermission(e)),this._micWatcher.observe()):(!this._constraints.audio&&this._micWatcher&&(this._micWatcher.dispose(),this._micWatcher=null,this._setAudioPermission(null)),Promise.resolve())}_restart(){this._release(!1),this._acquire()}async _acquire(){const e=++this._gen,a=function(e){const t={};return e.deviceId?t.deviceId={exact:e.deviceId}:e.facingMode&&(t.facingMode=e.facingMode),"number"==typeof e.width&&(t.width=e.width),"number"==typeof e.height&&(t.height=e.height),{video:!(Object.keys(t).length>0)||t,audio:!0===e.audio}}(this._constraints),{stream:o,error:c}=await async function(e){if(!t())return{error:s};try{return{stream:await navigator.mediaDevices.getUserMedia(e)}}catch(e){return{error:i(e)}}}(a);if(e!==this._gen)return void r(o??null);if(c)return this._setError(c),"NotAllowedError"===c.name?(this._setPermission("denied"),this._desired=!1):"unsupported"===c.name&&(this._setPermission("unsupported"),this._desired=!1),void this._setActive(!1);const d=o;this._stream=d;for(const e of d.getTracks())e.addEventListener("ended",this._onTrackEnded);this._setError(null),this._setPermission("granted"),this._constraints.audio&&d.getAudioTracks().length>0&&this._setAudioPermission("granted"),this._updateDeviceId(d),this._setActive(!0),this._dispatch("wcs-camera:stream-ready",d);const h=await n();e===this._gen&&this._setDevices(h)}_release(e){if(this._stream){for(const e of this._stream.getTracks())e.removeEventListener("ended",this._onTrackEnded);r(this._stream),this._stream=null,e?this._active=!1:this._setActive(!1)}}_onTrackEnded=()=>{this._release(!1),this._dispatch("wcs-camera:ended",null)};_updateDeviceId(e){const t=e.getVideoTracks()[0];if(t&&"function"==typeof t.getSettings){const e=t.getSettings();this._setDeviceId(e.deviceId??null)}}}function p(e,t){let i=Object.getPrototypeOf(e);for(;null!==i;){const e=Object.getOwnPropertyDescriptor(i,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;i=Object.getPrototypeOf(i)}return!1}function b(e){const t=e.constructor?.wcBindable,i=t?.inputs;if(void 0!==i)for(const t of i){const i=t.name;if(!Object.prototype.hasOwnProperty.call(e,i))continue;if(!p(e,i))continue;const s=e,r=s[i];delete s[i],s[i]=r}}const f=new WeakMap;function y(e,t){let i=f.get(e);return void 0===i&&(i=new Map,f.set(e,i)),i.has(t)||i.set(t,e.getAttribute(t)),i.get(t)}function w(e,t,i){null===i?e.removeAttribute(t):e.setAttribute(t,i)}function P(e,t,i){const s=y(e,t);w(e,t,void 0===i?s:null===i?null:String(i))}function E(e,t,i){const s=y(e,t);w(e,t,void 0===i?s:i?"":null)}class A extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...v.wcBindable,inputs:[{name:"audio",attribute:"audio"},{name:"facingMode",attribute:"facing-mode"},{name:"deviceId",attribute:"device-id"},{name:"width",attribute:"width"},{name:"height",attribute:"height"},{name:"autostart",attribute:"autostart"},{name:"keepAlive",attribute:"keep-alive"}],commands:v.wcBindable.commands};static observedAttributes=["facing-mode","device-id","audio","width","height"];_core;_video;_connectedCallbackPromise=Promise.resolve();_connected=!1;_batchingAttrs=!1;_internals=null;constructor(){super(),this._core=new v(this);const e=this.attachShadow({mode:"open"}),t=document.createElement("style");t.textContent=":host{display:inline-block}video{display:block;width:100%;height:100%}",this._video=document.createElement("video"),this._video.autoplay=!0,this._video.muted=!0,this._video.setAttribute("playsinline",""),this._video.setAttribute("part","video"),e.append(t,this._video),this.addEventListener("wcs-camera:stream-ready",this._onStreamReady),this.addEventListener("wcs-camera:active-changed",this._onActiveChanged),this._internals=this._initInternals(),this._wireStates({"wcs-camera:active-changed":e=>({active:!0===e}),"wcs-camera:error":e=>({error:null!=e})})}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const e=this.attachInternals();return e.states.add("wcs-probe"),e.states.delete("wcs-probe"),e}catch{return null}}_wireStates(e){if(null===this._internals)return;const t=this._internals.states;for(const[i,s]of Object.entries(e))this.addEventListener(i,e=>{const i=this.hasAttribute("debug-states");for(const[r,n]of Object.entries(s(e.detail))){try{n?t.add(r):t.delete(r)}catch{}i&&this.toggleAttribute(`data-wcs-state-${r}`,n)}})}get audio(){return this.hasAttribute("audio")}set audio(e){E(this,"audio",e)}get facingMode(){return"environment"===this.getAttribute("facing-mode")?"environment":"user"}set facingMode(e){P(this,"facing-mode",e)}get deviceId(){return this._core.deviceId??this.getAttribute("device-id")??""}set deviceId(e){P(this,"device-id",e)}get width(){return this._numberAttr("width")}set width(e){P(this,"width",e)}get height(){return this._numberAttr("height")}set height(e){P(this,"height",e)}get autostart(){return this.hasAttribute("autostart")}set autostart(e){E(this,"autostart",e)}get keepAlive(){return this.hasAttribute("keep-alive")}set keepAlive(e){E(this,"keep-alive",e)}get videoElement(){return this._video}get active(){return this._core.active}get permission(){return this._core.permission}get audioPermission(){return this._core.audioPermission}get devices(){return this._core.devices}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get connectedCallbackPromise(){return this._connectedCallbackPromise}start(){this._core.start()}stop(){this._core.stop()}switchCamera(){const e="environment"===this.facingMode?"user":"environment";this._batchingAttrs=!0;try{this.removeAttribute("device-id"),this.setAttribute("facing-mode",e)}finally{this._batchingAttrs=!1}this._core.observe(this._constraints()),this._core.active&&this._core.start()}_numberAttr(e){const t=this.getAttribute(e);if(null===t||""===t.trim())return NaN;const i=Number(t);return Number.isFinite(i)?i:NaN}_constraints(){const e={audio:this.audio,facingMode:this.facingMode},t=this.getAttribute("device-id");return t&&(e.deviceId=t),Number.isFinite(this.width)&&(e.width=this.width),Number.isFinite(this.height)&&(e.height=this.height),e}_onStreamReady=e=>{this._video.srcObject=e.detail};_onActiveChanged=e=>{!1===e.detail&&(this._video.srcObject=null)};connectedCallback(){b(this),this._connected=!0,this._connectedCallbackPromise=this._core.observe(this._constraints()),this.autostart&&this._core.start(),document.addEventListener("visibilitychange",this._onVisibilityChange)}disconnectedCallback(){this._connected=!1,document.removeEventListener("visibilitychange",this._onVisibilityChange),this._core.dispose()}attributeChangedCallback(e,t,i){this._connected&&t!==i&&(this._batchingAttrs||(this._core.observe(this._constraints()),this._core.active&&this._core.start()))}_onVisibilityChange=()=>{this.keepAlive||("hidden"===document.visibilityState?this._core.suspend():this._core.resume())}}class I extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"recording",event:"wcs-recorder:recording-changed",semantics:"state"},{name:"paused",event:"wcs-recorder:paused-changed",semantics:"state"},{name:"duration",event:"wcs-recorder:duration-changed",semantics:"state"},{name:"mimeType",event:"wcs-recorder:mimetype-changed",semantics:"state"},{name:"blob",event:"wcs-recorder:recorded",semantics:"state",getter:e=>e.detail?.blob??null},{name:"objectURL",event:"wcs-recorder:recorded",semantics:"state",getter:e=>e.detail?.objectURL??null},{name:"error",event:"wcs-recorder:error",semantics:"state"},{name:"errorInfo",event:"wcs-recorder:error-info-changed",semantics:"state"},{name:"recorded",event:"wcs-recorder:recorded",semantics:"event",getter:e=>e.detail},{name:"dataavailable",event:"wcs-recorder:dataavailable",semantics:"event",getter:e=>e.detail}],commands:[{name:"attachStream"},{name:"start"},{name:"stop"},{name:"pause"},{name:"resume"}]};_target;_recording=!1;_paused=!1;_duration=0;_mimeType="";_blob=null;_objectURL=null;_error=null;_errorInfo=null;_recorder=null;_stream=null;_chunks=[];_timeslice=!1;_startTime=0;_gen=0;_ready=Promise.resolve();constructor(e){super(),this._target=e??this}get recording(){return this._recording}get paused(){return this._paused}get duration(){return this._duration}get mimeType(){return this._mimeType}get blob(){return this._blob}get objectURL(){return this._objectURL}get error(){return this._error}get errorInfo(){return this._errorInfo}get ready(){return this._ready}_setRecording(e){this._recording!==e&&(this._recording=e,this._dispatch("wcs-recorder:recording-changed",e))}_setPaused(e){this._paused!==e&&(this._paused=e,this._dispatch("wcs-recorder:paused-changed",e))}_setDuration(e){this._duration!==e&&(this._duration=e,this._dispatch("wcs-recorder:duration-changed",e))}_setMimeType(e){this._mimeType!==e&&(this._mimeType=e,this._dispatch("wcs-recorder:mimetype-changed",e))}_setError(e){null===e&&null===this._error||(this._error=e,this._commitErrorInfo(null===e?null:g(e)),this._dispatch("wcs-recorder:error",e))}_commitErrorInfo(e){this._errorInfo=e,this._dispatch("wcs-recorder:error-info-changed",e)}_dispatch(e,t){this._target.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0}))}attachStream(e){this._stream=e}start(e={}){if("undefined"==typeof globalThis||"function"!=typeof globalThis.MediaRecorder)return void this._setError({name:"unsupported",message:"MediaRecorder is not available in this environment."});if(!this._stream)return void this._setError({name:"NoStreamError",message:"No stream attached. Wire a camera's stream-ready to attachStream first."});if(this._recording)return;const t={};let s;e.mimeType&&this._isTypeSupported(e.mimeType)&&(t.mimeType=e.mimeType),"number"==typeof e.audioBitsPerSecond&&(t.audioBitsPerSecond=e.audioBitsPerSecond),"number"==typeof e.videoBitsPerSecond&&(t.videoBitsPerSecond=e.videoBitsPerSecond);try{s=new MediaRecorder(this._stream,t)}catch(e){return void this._setError(i(e))}const r=++this._gen;this._chunks=[],this._timeslice="number"==typeof e.timeslice&&e.timeslice>0,s.ondataavailable=e=>{r===this._gen&&e.data&&e.data.size>0&&(this._chunks.push(e.data),this._timeslice&&this._dispatch("wcs-recorder:dataavailable",e.data))},s.onstop=()=>{r===this._gen&&(this._paused||this._setDuration(this._elapsed()),this._assembleBlob(),this._setPaused(!1),this._setRecording(!1))},s.onerror=e=>{if(r!==this._gen)return;const t=e.error;this._setError(i(t??{name:"RecorderError"}))},s.onpause=()=>{r===this._gen&&(this._setDuration(this._elapsed()),this._setPaused(!0))},s.onresume=()=>{r===this._gen&&(this._startTime=this._now()-this._duration,this._setPaused(!1))},this._recorder=s,this._setError(null),this._setMimeType(s.mimeType||t.mimeType||""),this._startTime=this._now(),this._setDuration(0),s.start(this._timeslice?e.timeslice:void 0),this._setRecording(!0)}stop(){this._recorder&&"inactive"!==this._recorder.state&&this._recorder.stop()}pause(){this._recorder&&"recording"===this._recorder.state&&this._recorder.pause()}resume(){this._recorder&&"paused"===this._recorder.state&&this._recorder.resume()}observe(){return this._ready}dispose(){if(this._gen++,this._recorder&&"inactive"!==this._recorder.state)try{this._recorder.stop()}catch{}this._recorder=null,this._revokeUrl(),this._stream=null,this._recording=!1,this._paused=!1}_assembleBlob(){const e=new Blob(this._chunks,this._mimeType?{type:this._mimeType}:void 0);this._chunks=[],this._revokeUrl();const t=this._createUrl(e);this._blob=e,this._objectURL=t;const i={blob:e,objectURL:t,mimeType:this._mimeType,duration:this._duration};this._dispatch("wcs-recorder:recorded",i)}_revokeUrl(){this._objectURL&&"undefined"!=typeof URL&&"function"==typeof URL.revokeObjectURL&&URL.revokeObjectURL(this._objectURL),this._objectURL=null}_createUrl(e){return"undefined"!=typeof URL&&"function"==typeof URL.createObjectURL?URL.createObjectURL(e):""}_isTypeSupported(e){return globalThis.MediaRecorder.isTypeSupported(e)}_now(){return performance.now()}_elapsed(){return Math.max(0,Math.round(this._now()-this._startTime))}}class S extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...I.wcBindable,inputs:[{name:"mimeType",attribute:"mime-type"},{name:"timeslice",attribute:"timeslice"},{name:"audioBitsPerSecond",attribute:"audio-bits"},{name:"videoBitsPerSecond",attribute:"video-bits"}],commands:I.wcBindable.commands};_core;_connectedCallbackPromise=Promise.resolve();_internals=null;constructor(){super(),this._core=new I(this),this._internals=this._initInternals(),this._wireStates({"wcs-recorder:recording-changed":e=>({recording:!0===e}),"wcs-recorder:paused-changed":e=>({paused:!0===e}),"wcs-recorder:error":e=>({error:null!=e})})}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const e=this.attachInternals();return e.states.add("wcs-probe"),e.states.delete("wcs-probe"),e}catch{return null}}_wireStates(e){if(null===this._internals)return;const t=this._internals.states;for(const[i,s]of Object.entries(e))this.addEventListener(i,e=>{const i=this.hasAttribute("debug-states");for(const[r,n]of Object.entries(s(e.detail))){try{n?t.add(r):t.delete(r)}catch{}i&&this.toggleAttribute(`data-wcs-state-${r}`,n)}})}get connectedCallbackPromise(){return this._connectedCallbackPromise}get mimeType(){return this._core.mimeType}set mimeType(e){P(this,"mime-type",e)}get timeslice(){return this._numberAttr("timeslice")}set timeslice(e){P(this,"timeslice",e)}get audioBitsPerSecond(){return this._numberAttr("audio-bits")}set audioBitsPerSecond(e){P(this,"audio-bits",e)}get videoBitsPerSecond(){return this._numberAttr("video-bits")}set videoBitsPerSecond(e){P(this,"video-bits",e)}get recording(){return this._core.recording}get paused(){return this._core.paused}get duration(){return this._core.duration}get blob(){return this._core.blob}get objectURL(){return this._core.objectURL}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}attachStream(e){this._core.attachStream(e)}start(){this._core.start(this._options())}stop(){this._core.stop()}pause(){this._core.pause()}resume(){this._core.resume()}_numberAttr(e){const t=this.getAttribute(e);if(null===t||""===t.trim())return NaN;const i=Number(t);return Number.isFinite(i)?i:NaN}_options(){const e={},t=this.getAttribute("mime-type")??"";return t&&(e.mimeType=t),Number.isFinite(this.timeslice)&&(e.timeslice=this.timeslice),Number.isFinite(this.audioBitsPerSecond)&&(e.audioBitsPerSecond=this.audioBitsPerSecond),Number.isFinite(this.videoBitsPerSecond)&&(e.videoBitsPerSecond=this.videoBitsPerSecond),e}connectedCallback(){b(this),this.style.display="none",this._connectedCallbackPromise=this._core.observe()}disconnectedCallback(){this._core.dispose()}}var k;!function(t=customElements){t.get(e.tagNames.camera)||t.define(e.tagNames.camera,A),t.get(e.tagNames.recorder)||t.define(e.tagNames.recorder,S)}(k);
|
|
2
2
|
//# sourceMappingURL=auto.min.js.map
|