@urun-sh/core 0.2.5 → 0.2.6
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/dist/{chunk-GSLGCYDQ.mjs → chunk-D4OLDMKT.mjs} +5 -5
- package/dist/{chunk-XOU67U3G.mjs → chunk-H23H4OCS.mjs} +5 -5
- package/dist/index.browser.d.mts +2 -2
- package/dist/index.browser.d.ts +2 -2
- package/dist/index.browser.js +5 -5
- package/dist/index.browser.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -5
- package/dist/index.mjs +1 -1
- package/dist/internal.browser.d.mts +1 -1
- package/dist/internal.browser.d.ts +1 -1
- package/dist/internal.browser.js +5 -5
- package/dist/internal.browser.mjs +1 -1
- package/dist/internal.d.mts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +5 -5
- package/dist/internal.mjs +1 -1
- package/dist/{stream-data-Bv0WmUUA.d.mts → stream-data-u76USIkQ.d.mts} +12 -4
- package/dist/{stream-data-Bv0WmUUA.d.ts → stream-data-u76USIkQ.d.ts} +12 -4
- package/package.json +1 -1
package/dist/index.browser.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as Ie,b as X,c as Q,e as Z,f as Ce,h as Oe,j as ee,k as Ee,l as Ue,m as Me,n as qe,o as $e}from"./chunk-GSLGCYDQ.mjs";var S=class extends Error{requestId;code;constructor(e,t){super(e),this.name="RequestError",this.requestId=t?.requestId,this.code=t?.code,t?.cause!==void 0&&(this.cause=t.cause),Object.setPrototypeOf(this,new.target.prototype)}},j=class extends S{timeoutMs;constructor(e,t){super(`[urun] request timed out after ${e}ms`,{requestId:t}),this.name="RequestTimeoutError",this.timeoutMs=e,Object.setPrototypeOf(this,new.target.prototype)}},L=class extends S{timeoutMs;constructor(e,t){super(`[urun] request doc-sync did not establish within ${e}ms \u2014 the request was never delivered to the runtime (the session doc never synced with the session-server; check the doc-sync transport / connection)`,{requestId:t}),this.name="RequestDocSyncError",this.timeoutMs=e,Object.setPrototypeOf(this,new.target.prototype)}},B=class extends Error{stream;owner;attempted;constructor(e,t,n){super(`[urun] stream "${e}" is already produced by the ${t}; this (${n}) peer cannot also produce it \u2014 a named stream has exactly one producer (consume it instead, or use a distinct name for the reverse direction)`),this.name="StreamDirectionConflict",this.stream=e,this.owner=t,this.attempted=n,Object.setPrototypeOf(this,new.target.prototype)}},U=class extends S{constructor(e){super("[urun] request aborted",{requestId:e}),this.name="RequestAbortError",Object.setPrototypeOf(this,new.target.prototype)}},F=class extends S{constructor(e){super("[urun] request cancelled: session disconnected",{requestId:e}),this.name="RequestCancelledError",Object.setPrototypeOf(this,new.target.prototype)}};function De(r,e){let t=e.error?.reason,n=e.elapsedMs!==void 0?Math.round(e.elapsedMs/1e3):void 0;switch(r){case"create-failed":return{message:`[urun] session create failed${e.error?.httpStatus!==void 0?` (HTTP ${e.error.httpStatus})`:""}${t?`: ${t}`:""}`,hint:e.error?.httpStatus===401||e.error?.httpStatus===403?"The backend rejected this client \u2014 sign in again or check the auth token / org access.":"The backend could not create a session \u2014 check the app/function name and auth, then retry."};case"never-live":{let s=n!==void 0?` after ${n}s`:"",o=` (last server status: ${e.lastServerStatus??"none"})`;return e.error?.code==="expired"?{message:`[urun] session${e.sessionId?` ${e.sessionId}`:""} expired before media connected${s} \u2014 the control plane reclaims sessions whose media transport never establishes (~80s after create)`,hint:"Retry to mint a fresh session, and connect promptly after start (a backgrounded tab or paused debugger can miss the window)."}:e.sessionId?{message:`[urun] session ${e.sessionId} was created but never went live${s}${o} \u2014 the backend is busy or wedged (no runtime picked the session up)`,hint:"The backend is at capacity or stuck. Retry in a moment; if it persists, the session id above is what to report."}:{message:`[urun] no session went live${s} (phase=${e.phase}${e.lastServerStatus?`, last server status: ${e.lastServerStatus}`:""})`,hint:"The session never got past admission. Retry; if it persists, check the backend deployment."}}case"transport-failed":return e.error?.code==="transport-consumed"?{message:`[urun] the retry reused a session whose media transport was already connected${e.sessionId?` (id ${e.sessionId})`:""} \u2014 the session was consumed by an earlier attempt`,hint:"Start a fresh session (reload the page) \u2014 this session leg cannot be connected again."}:{message:`[urun] media/transport connection failed${t?`: ${t}`:""} (transport state: ${e.transportState})`,hint:"The network is likely blocking the media connection (WebRTC/WebSocket) \u2014 try a different network or disable VPN/proxy, then retry."};case"media-permission":return{message:`[urun] microphone/camera unavailable${t?`: ${t}`:""}`,hint:e.error?.code==="NotFoundError"||e.error?.code==="OverconstrainedError"?"No matching input device was found \u2014 connect or select a microphone/camera and retry.":"Allow microphone/camera access for this site (browser permission \u2014 or, when embedded, the parent page's permissions policy), then retry."};case"ended":return{message:`[urun] session ended before going live${e.sessionId?` (id ${e.sessionId})`:""}`,hint:"The session was closed (server-side, or superseded by another connection). Start a new session."}}}var b=class extends Error{kind;status;hint;constructor(e,t,n){let{message:s,hint:o}=De(e,t);super(s),this.name="SessionFailedError",this.kind=e,this.status=t,this.hint=o,n?.cause!==void 0&&(this.cause=n.cause),Object.setPrototypeOf(this,new.target.prototype)}};function tt(r,e){if(r instanceof b)return r;let t=r instanceof Error?r:new Error(String(r)),n={phase:e?.phase??"idle",transportState:e?.transportState??"disconnected",...e,error:{reason:t.message,code:t.name,kind:"media-permission"}};return new b("media-permission",n,{cause:r})}var v=class extends Error{httpStatus;constructor(e,t){super(e),this.name="SessionAllocationError",this.httpStatus=t?.httpStatus,t?.cause!==void 0&&(this.cause=t.cause),Object.setPrototypeOf(this,new.target.prototype)}};var je=45e3;function le(r,e={}){let{timeout:t=je,signal:n}=e;return new Promise((s,o)=>{if(n?.aborted){o(n.reason instanceof Error?n.reason:new Error("whenLive aborted"));return}if(r.phase?.name==="live"){s();return}if(r.phase?.name==="error"||r.phase?.name==="ended"){let c=r.phase,h=r.status??{phase:c.name,transportState:"disconnected",sessionId:c.sessionId,requestId:c.requestId,queue:c.queue,error:c.error};o(new b(c.name==="ended"?"ended":c.error?.kind??"transport-failed",h));return}let i,a,m=!1,f=c=>{m||(m=!0,a!==void 0&&clearTimeout(a),n?.removeEventListener("abort",l),i?.(),c?o(c):s())},l=()=>{f(n?.reason instanceof Error?n.reason:new Error("whenLive aborted"))};n?.addEventListener("abort",l,{once:!0});let p=()=>{let c=r.phase;return r.status??{phase:c?.name??"idle",transportState:"disconnected",sessionId:c?.sessionId,requestId:c?.requestId,queue:c?.queue,error:c?.error}},u=c=>f(new b(c,p()));t>0&&(a=setTimeout(()=>{let c=p();c.elapsedMs===void 0&&(c.elapsedMs=t),f(new b("never-live",c))},t)),i=r.onPhase(c=>{c?.name==="live"?f():c?.name==="error"?u(c.error?.kind??"transport-failed"):c?.name==="ended"&&u("ended")}),m&&i()})}var rt="session-api.prod.cloud.urun.sh",nt=["https://session-api.use2.prod.cloud.urun.sh","https://session-api.usw2.prod.cloud.urun.sh"];function A(r){return r.trim().replace(/\/+$/,"")}function te(r,e){let t=[],n=s=>{if(!s)return;let o=A(s);o&&!t.includes(o)&&t.push(o)};n(r);for(let s of e??[])n(s);for(let s of pt(r))n(s);return t}var st=120,ot=1e3,it=3;function at(r){if(!r)return null;try{let e=new URL(r),t=e.pathname.replace(/\/api\/sessions\/create\/?$/,"");return A(`${e.origin}${t}`)}catch{return null}}async function Le(r){let e=te(r.baseUrl,r.fallbackUrls),t=null,n=e.length>1;for(let s of e)try{return await ct(s,r,{pollAttempts:st,retryAfterLimitMs:n?ot:void 0})}catch(o){if(t=o instanceof Error?o:new Error(String(o)),t instanceof I)throw t}throw t??new Error("[urun] session allocation failed")}async function ct(r,e,t){let n,s,o,i=r,a=0,m=new Set;for(let f=0;f<t.pollAttempts;f++){s=o??await fe(e),o=void 0;let l=n?await fetch(`${i}/api/session-requests/${encodeURIComponent(n)}`,{headers:pe(e,s)}):await fetch(`${i}/api/sessions/create`,{method:"POST",redirect:"manual",headers:{...pe(e,s),"Content-Type":"application/json","Idempotency-Key":e.idempotencyKey},body:JSON.stringify(ut(e))});if(!n&&(l.status===307||l.status===308)){let h=at(l.headers.get("location"));if(h&&h!==i&&a<it){a+=1,i=h;continue}throw new v(`[urun] session create redirected from ${i} without a usable target`,{httpStatus:l.status})}let p=await Fe(l);if(l.ok&&(p.status==="allocated"||!p.status&&!!p.session_id)&&!!p.session_id){let h=p.session_id;if(!p.ws_url)throw new I(`[urun] gateway allocated session ${h} without ws_url`);if(!Ne(p.ws_url))throw new I(`[urun] gateway allocated session ${h} with non-absolute ws_url`);return{baseUrl:i,sessionId:h,wsUrl:p.ws_url,response:p}}if(l.status===202||p.status==="pending"||p.status==="queued"||p.queued){if(n=p.request_id||n,!n)throw new Error("[urun] gateway queued session without request_id");await lt(dt(l,p,t.retryAfterLimitMs));continue}if((l.status===401||l.status===403)&&e.getAccessToken){let h=s??"";m.add(h);let y=await fe(e,{forceRefresh:!0,reason:"unauthorized"});if(y&&!m.has(y)){o=y,n=void 0;continue}}let c=p.error_message||p.error_code||`HTTP ${l.status}`;throw new v(`[urun] session allocation failed at ${i}: ${c}`,{httpStatus:l.status})}throw new v(`[urun] timed out waiting for session allocation at ${i}`)}function pe(r,e){let t={"X-Tenant-Id":r.orgId,"X-Auth-Provider":r.authProvider||"default","X-User-Id":"anonymous"};return e&&(t.Authorization=`Bearer ${e}`),t}async function fe(r,e){return r.getAccessToken?await r.getAccessToken(e)??void 0:r.jwt}function ut(r){return{app:r.app,function:r.functionName,gpus:1,idempotency_key:r.idempotencyKey}}async function Be(r){let e=te(r.baseUrl,r.fallbackUrls),t=null;for(let n of e)try{let s={baseUrl:n,app:"",functionName:"",orgId:r.orgId,jwt:r.jwt,getAccessToken:r.getAccessToken,authProvider:r.authProvider,idempotencyKey:""},o=await fe(s),i=await fetch(`${A(n)}/api/sessions/${encodeURIComponent(r.sessionId)}/viewer-connect`,{headers:pe(s,o)});if(!i.ok)throw new Error(`[urun] viewer-connect for ${r.sessionId} failed: HTTP ${i.status}`);let a=await Fe(i);if(!a.ws_url||!Ne(a.ws_url))throw new I(`[urun] viewer-connect returned no usable ws_url for ${r.sessionId}`);return{baseUrl:A(n),sessionId:r.sessionId,wsUrl:a.ws_url,response:a}}catch(s){if(t=s instanceof Error?s:new Error(String(s)),t instanceof I)throw t}throw t??new Error("[urun] viewer-connect failed")}async function Fe(r){try{let e=await r.json();return e&&typeof e=="object"?e:{}}catch{return{}}}function dt(r,e,t){let n=Number(r.headers.get("Retry-After")||""),s=Number(e.retry_after_seconds??n),o=t??1e4;return Number.isFinite(s)&&s>0?Math.min(s*1e3,o):1e3}function lt(r){return new Promise(e=>setTimeout(e,r))}var I=class extends Error{};function Ne(r){try{let e=new URL(r);return e.protocol==="ws:"||e.protocol==="wss:"}catch{return!1}}function pt(r){try{return new URL(r).hostname!==rt?[]:nt}catch{return[]}}var w=class extends Error{status;code;constructor(e,t,n=t>0?`http_${t}`:"runtime_artifacts_error",s){super(e),this.name="RuntimeArtifactsError",this.status=t,this.code=n,s!==void 0&&(this.cause=s),Object.setPrototypeOf(this,new.target.prototype)}},re=class extends w{constructor(e="[urun] runtime artifacts: unauthorized",t="unauthorized"){super(e,401,t),this.name="RuntimeArtifactsUnauthorizedError",Object.setPrototypeOf(this,new.target.prototype)}},ne=class extends w{constructor(e="[urun] runtime artifacts: not found",t="not_found"){super(e,404,t),this.name="RuntimeArtifactNotFoundError",Object.setPrototypeOf(this,new.target.prototype)}};function N(r){return{baseUrl:r.baseUrl,fallbackUrls:r.fallbackUrls,orgId:r.orgId,jwt:r.jwt,getAccessToken:r.getAccessToken,authProvider:r.authProvider}}function ft(r){return new C(r)}var C=class{_options;constructor(e){this._options=e}async list(e){let n=ze(await this._request(e,"")).artifacts;if(!Array.isArray(n))throw new w("[urun] runtime artifacts: response missing `artifacts`",0,"bad_response");return n.map(We)}async getDownloadUrl(e,t){let n=ze(await this._request(t,`/${encodeURIComponent(e)}/download`)),s=n.download_url;if(typeof s!="string"||!ht(s))throw new w("[urun] runtime artifacts: response missing HTTPS download_url",0,"bad_response");return{artifact:We(n.artifact),downloadUrl:s}}async _request(e,t){let n=te(this._options.baseUrl,this._options.fallbackUrls),s=null;for(let o of n)try{return await this._requestFromBase(o,e,t)}catch(i){if(s=i instanceof Error?i:new Error(String(i)),s instanceof w&>(s.status))throw s}throw s??new w("[urun] runtime artifacts request failed",0)}async _requestFromBase(e,t,n){let s=`${A(e)}/api/sessions/${encodeURIComponent(t)}/artifacts${n}`,o=await this._resolveToken(),i=await fetch(s,{method:"GET",headers:this._headers(o)});if(i.status===401&&this._options.getAccessToken){let a=await this._options.getAccessToken({forceRefresh:!0,reason:"unauthorized"});a&&a!==o&&(o=a,i=await fetch(s,{method:"GET",headers:this._headers(o)}))}if(!i.ok){let{code:a,message:m}=await this._readError(i,e);throw wt(i.status,a,m)}try{return await i.json()}catch(a){throw new w(`[urun] runtime artifacts: invalid JSON response from ${A(e)}`,0,"bad_response",a)}}async _resolveToken(){return this._options.getAccessToken?await this._options.getAccessToken()??void 0:this._options.jwt}_headers(e){let t={Accept:"application/json","X-Tenant-Id":this._options.orgId,"X-Auth-Provider":this._options.authProvider||"default"};return e&&(t.Authorization=`Bearer ${e}`),t}async _readError(e,t){let n=A(t);try{let o=(await e.json()).error;if(o&&typeof o=="object"){let{code:i,message:a}=o;return{code:typeof i=="string"&&i.length>0?i:`http_${e.status}`,message:typeof a=="string"&&a.length>0?`[urun] runtime artifacts request failed at ${n}: ${a}`:`[urun] runtime artifacts request failed at ${n}: HTTP ${e.status}`}}}catch{}return{code:`http_${e.status}`,message:`[urun] runtime artifacts request failed at ${n}: HTTP ${e.status}`}}};function We(r){if(!r||typeof r!="object")throw new w("[urun] runtime artifacts: malformed artifact",0,"malformed_artifact");let e=r,t=k(e,"artifact_id")||k(e,"id"),n=k(e,"filename"),s=k(e,"kind"),o=k(e,"status")||"ready",i=mt(e,"size_bytes"),a=k(e,"sha256");if(!t||!n||!s||i==null||!a)throw new w("[urun] runtime artifacts: malformed artifact metadata",0,"malformed_artifact");return{artifactId:t,kind:s,filename:n,contentType:k(e,"content_type")||"application/octet-stream",sizeBytes:i,sha256:a,status:o,createdAt:k(e,"created_at"),expiresAt:k(e,"expires_at")}}function k(r,e){let t=r[e];return typeof t=="string"&&t.length>0?t:void 0}function mt(r,e){let t=r[e];return typeof t=="number"&&Number.isFinite(t)&&Number.isInteger(t)&&t>=0?t:void 0}function ht(r){try{return new URL(r).protocol==="https:"}catch{return!1}}function gt(r){return r===401||r===403}function wt(r,e,t){return r===401?new re(t,e):r===404?new ne(t,e):new w(t,r,e)}function ze(r){if(!r||typeof r!="object"||Array.isArray(r))throw new w("[urun] runtime artifacts: malformed response",0,"bad_response");return r}var _=class extends Error{status;code;constructor(e,t){super(e),this.name="RecordingsError",this.status=t.status,this.code=t.code,t.cause!==void 0&&(this.cause=t.cause),Object.setPrototypeOf(this,new.target.prototype)}},W=class extends _{constructor(e="[urun] recordings: unauthorized",t="unauthorized"){super(e,{status:401,code:t}),this.name="RecordingsUnauthorizedError",Object.setPrototypeOf(this,new.target.prototype)}},se=class extends _{constructor(e="[urun] recordings: not found",t="not_found"){super(e,{status:404,code:t}),this.name="RecordingNotFoundError",Object.setPrototypeOf(this,new.target.prototype)}},oe=class extends _{constructor(e="[urun] recordings: retain requires a temp recording",t="retain_not_temp"){super(e,{status:409,code:t}),this.name="RetainNotTempError",Object.setPrototypeOf(this,new.target.prototype)}},ie=class extends _{constructor(e="[urun] recordings: pin requires an active temp recording",t="pin_requires_active_temp"){super(e,{status:409,code:t}),this.name="PinRequiresActiveTempError",Object.setPrototypeOf(this,new.target.prototype)}},ae=class extends _{constructor(e="[urun] recordings: recording is permanent and locked",t="permanent_locked"){super(e,{status:409,code:t}),this.name="PermanentLockedError",Object.setPrototypeOf(this,new.target.prototype)}},M=class extends _{constructor(e="[urun] recordings: invalid retention duration",t="bad_duration",n=400){super(e,{status:n,code:t}),this.name="InvalidDurationError",Object.setPrototypeOf(this,new.target.prototype)}};function me(r){return/^(\d+[smhdw])+$/.test(r)}function yt(r){if(r==="pin")return{action:"pin"};if(me(r))return{action:"retain",duration:r};throw new M(`[urun] recordings: "${r}" is not a duration or "pin"`)}function _t(r,e,t){let n=t||e||`HTTP ${r}`;if(r===401)return new W(n,e??"unauthorized");if(r===404)return new se(n,e??"not_found");if(r===400)return new M(n,e??"bad_request",400);if(r===409)switch(e){case"retain_not_temp":return new oe(n,e);case"pin_requires_active_temp":return new ie(n,e);case"permanent_locked":return new ae(n,e)}return new _(n,{status:r,code:e??`http_${r}`})}var q=class{constructor(e){this._options=e;this._base=`${e.functionsUrl.replace(/\/+$/,"")}/recordings`}_options;_base;async list(e){let n=(await this._request("GET","",{params:e?{session_id:e}:void 0})).recordings;return Array.isArray(n)?n:[]}async get(e){return this._one(await this._request("GET",`/${encodeURIComponent(e)}`))}async retain(e,t){if(!me(t))throw new M(`[urun] recordings: "${t}" is not a valid retention duration`);return this._one(await this._request("POST",`/${encodeURIComponent(e)}/retain`,{body:{duration:t}}))}async pin(e){return this._one(await this._request("POST",`/${encodeURIComponent(e)}/pin`))}async unpin(e){return this._one(await this._request("POST",`/${encodeURIComponent(e)}/unpin`))}async permanent(e){return this._one(await this._request("POST",`/${encodeURIComponent(e)}/permanent`))}async delete(e){return this._one(await this._request("POST",`/${encodeURIComponent(e)}/delete`))}_one(e){let t=e.recording;if(!t||typeof t!="object")throw new _("[urun] recordings: response missing `recording`",{status:0,code:"bad_response"});return t}async _request(e,t,n={}){let s=this._buildUrl(t,n.params),o=await this._resolveToken(),i=await this._fetch(s,e,o,n.body);if(i.status===401&&this._options.getAccessToken){let a=await this._options.getAccessToken({forceRefresh:!0,reason:"unauthorized"});a&&a!==o&&(o=a,i=await this._fetch(s,e,o,n.body))}if(!i.ok){let{code:a,message:m}=await this._readError(i);throw _t(i.status,a,m)}return this._readJson(i)}_buildUrl(e,t){let n=`${this._base}${e}`,s=Object.entries(t??{}).filter(([,o])=>o!=null&&o!=="").map(([o,i])=>`${encodeURIComponent(o)}=${encodeURIComponent(i)}`).join("&");return s&&(n+=`?${s}`),n}_fetch(e,t,n,s){let o={Authorization:`Bearer ${n}`,apikey:n,Accept:"application/json","X-Tenant-Id":this._options.orgId};this._options.authProvider&&(o["X-Auth-Provider"]=this._options.authProvider);let i={method:t,headers:o};return s!==void 0&&(o["Content-Type"]="application/json",i.body=JSON.stringify(s)),fetch(e,i)}async _resolveToken(){if(this._options.getAccessToken){let t=await this._options.getAccessToken();if(t)return t}let e=this._options.jwt??this._options.apiKey;if(!e)throw new W("[urun] recordings: no credential \u2014 provide one of apiKey, jwt, or getAccessToken");return e}async _readJson(e){try{return await e.json()}catch{return{}}}async _readError(e){try{let n=(await e.json()).error;if(n&&typeof n=="object"){let{code:s,message:o}=n;return{code:typeof s=="string"?s:void 0,message:typeof o=="string"?o:`HTTP ${e.status}`}}}catch{}return{message:`HTTP ${e.status}`}}};function St(r){return new q(r)}import*as K from"yjs";function G(r){if(r===null||typeof r!="object"||Array.isArray(r))return!1;let e=Object.getPrototypeOf(r);return e===Object.prototype||e===null}var ce="$bytes";function bt(r){return r instanceof Uint8Array||r instanceof ArrayBuffer}function vt(r){if(!G(r))return!1;let e=Object.keys(r);return e.length===1&&e[0]===ce&&typeof r[ce]=="string"}function kt(r){return r instanceof ArrayBuffer?new Uint8Array(r):r}function Rt(r){if(typeof Buffer<"u")return Buffer.from(r).toString("base64");let e="";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return btoa(e)}function At(r){if(typeof Buffer<"u")return new Uint8Array(Buffer.from(r,"base64"));let e=atob(r),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return t}function he(r){if(bt(r))return{[ce]:Rt(kt(r))};if(Array.isArray(r))return r.map(he);if(G(r)){let e={};for(let[t,n]of Object.entries(r))e[t]=he(n);return e}return r}function z(r){if(vt(r))return At(r[ce]);if(Array.isArray(r))return r.map(z);if(G(r)){let e={};for(let[t,n]of Object.entries(r))e[t]=z(n);return e}return r}var Ke=Symbol("urun:doc:path-absent");function Tt(r,e){let t=e.split("."),n=r;for(let s of t){if(n===null||typeof n!="object"||!(s in n))return Ke;n=n[s]}return n}function Pt(r,e){return r===e?!0:JSON.stringify(r)===JSON.stringify(e)}function ge(r,e){for(let[t,n]of Object.entries(e))if(G(n)){let s=r.get(t);if(!(s instanceof K.Map)){let o=s;s=new K.Map,r.set(t,s),G(o)&&ge(s,o)}ge(s,n)}else{if(Pt(r.get(t),n))continue;r.set(t,n)}}var xt=Symbol("urun:doc:local"),ue=class{_doc=new K.Doc;_root=this._doc.getMap("session");_awareness=new Ee(this._doc);_listeners=new Set;_key;_sessionId;_connection=null;_connUnsub=null;_synced;_syncWaiters=new Set;_texts=new Map;_observer=()=>this.notify();constructor(e,t,n){this._key=e,this._sessionId=t,this._root.observeDeep(this._observer),n?(this._connection=n(e,this._doc,this._awareness),this._synced=this._connection.synced,this._connUnsub=this._connection.onSync(s=>{s&&this._markSynced()}),this._synced&&this._markSynced()):this._synced=!0}get awareness(){return this._awareness}setSessionId(e){this._sessionId=e}get synced(){return this._synced}onSynced(e){return this._synced?(e(),()=>{}):(this._syncWaiters.add(e),()=>this._syncWaiters.delete(e))}set(e){e=he(e),this.applyPatch(e)}get(e,t){let n=this.snapshot();if(!e)return z(n);let s=Tt(n,e);return s===Ke?t:z(s)}on(e,t){return this._listeners.add(t),()=>this._listeners.delete(t)}text(e){let t=this._texts.get(e);return t||(t=new we(this._doc.getText(`text:${e}`)),this._texts.set(e,t)),t}dispose(){this._root.unobserveDeep(this._observer),this._connUnsub?.(),this._connUnsub=null,this._connection?.destroy(),this._connection=null,this._listeners.clear(),this._syncWaiters.clear();for(let e of this._texts.values())e.dispose();this._texts.clear(),this._awareness.destroy(),this._doc.destroy()}_markSynced(){let e=[...this._syncWaiters];this._synced=!0,this._syncWaiters.clear();for(let t of e)t()}applyPatch(e){this._doc.transact(()=>{ge(this._root,e)},xt)}snapshot(){return this._root.toJSON()}notify(){let e=z(this.snapshot());for(let t of this._listeners)t(e)}},we=class{constructor(e){this._ytext=e;this._observer=t=>{for(let n of t.delta)if(typeof n.insert=="string"&&n.insert.length>0){let s=n.insert;for(let o of this._delta)o(s)}},this._ytext.observe(this._observer)}_ytext;_delta=new Set;_observer;append(e){e.length!==0&&this._ytext.insert(this._ytext.length,e)}toString(){return this._ytext.toString()}get length(){return this._ytext.length}on(e,t){return this._delta.add(t),()=>this._delta.delete(t)}dispose(){this._ytext.unobserve(this._observer),this._delta.clear()}};var Ge="video/mp4";function ye(r,e={}){let t=e.timesliceMs??1e3,n=null,s=null,o=!1,i=(a,m,f)=>{let l=typeof MediaRecorder>"u"?void 0:MediaRecorder;if(!l)throw new Error("[urun] stream.chunks(): MediaRecorder is unavailable in this runtime. Pass { source } to chunks() to inject a byte-tap (e.g. a Node/werift consumer).");let p=e.mimeType??(typeof l.isTypeSupported=="function"&&l.isTypeSupported(Ge)?Ge:void 0),u=new MediaStream([a]),c=new l(u,p?{mimeType:p}:void 0);n=c;let h=Promise.resolve();c.ondataavailable=y=>{let g=y.data;o||!g||g.size===0||(h=h.then(async()=>{let T=new Uint8Array(await g.arrayBuffer());o||m(T)}))},c.onstop=()=>{h.then(()=>{o||f()})},c.onerror=()=>{h.then(()=>{o||f()})},c.start(t)};return{start(a,m){if(n||o)return;let f=r.track();if(f){i(f,a,m);return}s=r.onTrack(l=>{!l||n||o||(s?.(),s=null,i(l,a,m))})},stop(){if(o)return;o=!0,s?.(),s=null;let a=n;if(n=null,a&&a.state!=="inactive")try{a.stop()}catch{}}}}function It(r){let e=r;return typeof e[Symbol.asyncIterator]=="function"||(e[Symbol.asyncIterator]=function(){let t=r.getReader();return{next(){return t.read()},async return(){try{await t.cancel()}catch{}try{t.releaseLock()}catch{}return{value:void 0,done:!0}},[Symbol.asyncIterator](){return this}}}),e}function Ye(r,e){let t=null,n=!1,s=!1,o=new ReadableStream({pull(i){n||(n=!0,t=r(e),t.start(a=>{if(!s)try{i.enqueue(a)}catch{}},()=>{if(!s){s=!0;try{i.close()}catch{}}}))},cancel(){s=!0,t?.stop(),t=null}},new CountQueuingStrategy({highWaterMark:0}));return It(o)}var Ct=new Set;function be(r){if(r.functionsUrl)return{functionsUrl:r.functionsUrl,orgId:r.orgId,apiKey:r.apiKey,jwt:r.jwt,getAccessToken:r.getAccessToken,authProvider:r.authProvider}}var Ot="rpc",Ve=3e4,Et="rpc-resp";function Ut(r){return`${Et}:${r}`}function _e(){return Ce()}function Mt(r){if(r&&typeof r=="object"){let e=r.error;if(e&&typeof e=="object"){let{message:t,code:n}=e;return{message:typeof t=="string"?t:JSON.stringify(e),code:typeof n=="string"?n:void 0}}if(typeof e=="string")return{message:e}}return{message:typeof r=="string"?r:JSON.stringify(r)}}function qt(r,e,t,n,s,o,i,a,m,f){let l=[],p=null,u=!1,c=null,h=!1,y,g,T=new Promise((d,R)=>{y=d,g=R});T.catch(()=>{});let P=i(),x=null,$=null,D=null,H=null,V=!0,ke=()=>{D&&(clearTimeout(D),D=null),H&&(H(),H=null)},Re=!1,Ae=()=>{Re||!h||(Re=!0,r.set({rpc:{[e]:null}}))},J=()=>{V=!1,ke(),x?.(),x=null,$?.(),$=null,a?.removeEventListener("abort",Pe),P.dispose(),Ae()},de=()=>{if(p){if(l.length>0){let d=p;p=null,d.resolve({value:l.shift(),done:!1})}else if(c!==null){let d=p;p=null,d.reject(c)}else if(u){let d=p;p=null,d.resolve({value:void 0,done:!0})}}},Qe=d=>{u||(l.push(d),de())},O=d=>{u||(c=d,u=!0,g(d),J(),de())},Te=d=>{u||(u=!0,y(d),J(),de())},Pe=()=>{let d=a?.reason;O(d instanceof S?d:new U(e))},Ze=d=>{if(!(u||!d||typeof d!="object"))switch(Ae(),d.t){case"delta":typeof d.delta=="string"&&Qe(d.delta);break;case"response":Te(d.body);break;case"error":{let{message:R,code:E}=Mt(d.body);O(new S(R,{requestId:e,code:d.code??E}));break}}},et=()=>{let d=P.messages()[Symbol.asyncIterator]();x=()=>{d.return?.(void 0)};let R=()=>{V&&d.next().then(E=>{if(V){if(E.done){u||Te(void 0);return}Ze(E.value),R()}},E=>{V&&O(E)})};R()},xe=()=>{if(!h){if(h=!0,a){if(a.aborted){O(new U(e));return}a.addEventListener("abort",Pe,{once:!0})}$=m?.(d=>O(d))??null,et(),r.set({rpc:{[e]:{args:t,respond_on:n,consumer_id:s,stream:o}}}),f&&f>0&&!r.synced&&(D=setTimeout(()=>{D=null,!u&&!r.synced&&O(new L(f,e))},f),H=r.onSynced(()=>ke()))}};return{deltas:{[Symbol.asyncIterator](){return{next(){if(xe(),l.length>0)return Promise.resolve({value:l.shift(),done:!1});if(c!==null){let d=c;return c=null,Promise.reject(d)}return u?Promise.resolve({value:void 0,done:!0}):new Promise((d,R)=>{p={resolve:d,reject:R}})},return(){return u||(u=!0,y(void 0),J()),Promise.resolve({value:void 0,done:!0})},throw(d){return u||(u=!0,g(d),J()),Promise.reject(d)}}}},body:T,start:xe}}function He(r){if(r&&typeof r=="object"){let{epoch:e,by:t}=r,n={epoch:typeof e=="number"?e:0};return(t==="runtime"||t==="browser")&&(n.by=t),n}}function $t(r,e){let n=r.get("streams")?.[e];if(!n||typeof n!="object")return null;let{kind:s,rt:o,br:i}=n,a={};(s==="audio"||s==="video"||s==="data")&&(a.kind=s);let m=He(o);m&&(a.rt=m);let f=He(i);return f&&(a.br=f),a}var Se=class{constructor(e,t,n,s){this._name=e;this._transport=t;this._streamData=n;this._controlDoc=s;this._track=this._transport.getTrackByName(this._name)??null,this._unsubscribeTransport=this._transport.on("track",()=>{let o=this._transport.getTrackByName(this._name)??null;o!==this._track&&this._setTrack(o)})}_name;_transport;_streamData;_controlDoc;_track=null;_handlers=new Map;_unsubscribeTransport=null;_subscribed=!1;_messageConsumers=new Set;_dataUnsub=null;_replay=[];_disposed=!1;messages(){this._ensureSubscribed();let e=this;return{[Symbol.asyncIterator](){let t=[...e._replay],n=null,s=!1,o={push(a){if(!s)if(n){let m=n;n=null,m({value:a,done:!1})}else t.push(a)},end(){if(s=!0,n){let a=n;n=null,a({value:void 0,done:!0})}}};e._messageConsumers.add(o);let i=()=>{s=!0,e._messageConsumers.delete(o)};return{next(){return t.length>0?Promise.resolve({value:t.shift(),done:!1}):s?Promise.resolve({value:void 0,done:!0}):new Promise(a=>{n=a})},return(){return i(),Promise.resolve({value:void 0,done:!0})}}}}}_ensureSubscribed(){this._subscribed||this._disposed||(this._subscribed=!0,this._transport.subscribeStream(this._name),this._streamData&&(this._dataUnsub=this._streamData.onData(this._name,e=>this._deliver(e))))}_deliver(e){this._replay.push(e);for(let t of this._messageConsumers)t.push(e)}get track(){let e=this._transport.getTrackByName(this._name)??this._track;return e!==this._track&&this._setTrack(e),this._track}_claimBrowserProducer(e){if(!this._controlDoc)return;let t=this._controlDoc(),n=$t(t,this._name),s=n?.br;if(s?.by==="runtime")throw new B(this._name,"runtime","browser");if(s)return;let o={br:{epoch:1}};n?.rt&&(o.rt=n.rt);let i=n?.kind??e;i&&(o.kind=i),t.set({streams:{[this._name]:o}})}async attach(e){this._claimBrowserProducer("audio"),await this._transport.addTrack(e,this._name)}async attachVideo(e){this._claimBrowserProducer("video"),await this._transport.addVideoTrack(e,this._name)}async emit(e,t={}){if(this._claimBrowserProducer("data"),!this._streamData)throw new Error("[urun] stream.emit requires the data-stream transport (no streamData wired)");this._streamData.sendData(this._name,e,t)}async detach(){this._transport.removeTrack()}async detachVideo(){this._transport.stopVideo()}async seek(e){if(e!=="live"&&(!Number.isFinite(e)||e<0))throw new Error('[urun] stream.seek target must be "live" or a non-negative number of seconds');this._transport.seekStream(this._name,e)}chunks(e={}){let t=e.source??ye;return Ye(t,{track:()=>this.track,onTrack:s=>this.on("track",s)})}onSeeked(e){return this._transport.on("seeked",(t,n)=>{t===this._name&&e(n)})}on(e,t){let n=this._handlers.get(e);return n||(n=new Set,this._handlers.set(e,n)),n.add(t),()=>{n?.delete(t),n?.size===0&&this._handlers.delete(e)}}dispose(){this._disposed=!0,this._unsubscribeTransport?.(),this._unsubscribeTransport=null,this._handlers.clear(),this._subscribed&&this._transport.unsubscribeStream(this._name),this._dataUnsub?.(),this._dataUnsub=null;for(let e of this._messageConsumers)e.end();this._messageConsumers.clear()}_setTrack(e){this._track=e,e&&e.addEventListener("ended",()=>{this._track===e&&this._setTrack(null)},{once:!0});let t=this._handlers.get("track");if(t)for(let n of t)n(e)}},Y=class r{_sessionId;_multiplexer;_transport;_docs=new Map;_streams=new Map;_docConnector=new qe;_streamData;_presence=null;_activeRequests=new Set;_recordingsAuth;_artifactsAuth;_recordingsAccessor=null;_artifactsAccessor=null;constructor(e,t,n,s,o){this._sessionId=e,this._multiplexer=t,this._transport=n,this._recordingsAuth=s,this._artifactsAuth=o,this._streamData=Oe(n),this._wireControlDocIncarnation()}_wireControlDocIncarnation(){let e=this.doc("control");this._transport.applyControlDocState(e.get()),e.on("change",t=>{this._transport.applyControlDocState(t)})}static async attach(e,t){let n=await Be({baseUrl:t.baseUrl,fallbackUrls:t.fallbackUrls,sessionId:e,orgId:t.orgId,jwt:t.jwt,getAccessToken:t.getAccessToken,authProvider:t.authProvider}),s=t.getAccessToken?await t.getAccessToken()??void 0:t.jwt,o=new X,i=new ee({url:n.wsUrl,orgId:t.orgId,jwt:s,authProvider:t.authProvider,sessionId:e,iceServers:n.response.ice_servers}),a=new r(e,o,i,be(t),N({...t,baseUrl:n.baseUrl}));return i.on("connected",()=>{i.multiplexer&&o.setTarget(i.multiplexer)}),i.setConnection({url:n.wsUrl,sessionId:e,iceServers:n.response.ice_servers}),Q()&&await Z(),a.setDocTransport({wsUrl:n.wsUrl,token:s}),await i.connect({role:"viewer"}),a}get id(){return this._sessionId}get phase(){return this._transport.phase}get status(){return this._transport.status}onPhase(e){return e(this._transport.phase),this._transport.on("phase",e)}whenLive(e){return le(this,e)}get recordings(){if(this._recordingsAccessor)return this._recordingsAccessor;let e=this._recordingsAuth;if(!e)throw new Error("[urun] session.recordings requires `functionsUrl` to be configured on the App()/Session.attach() options (the eensx /functions/v1 base URL).");let t=new q(e);return this._recordingsAccessor={list:n=>t.list(n??this._sessionId),get:n=>t.get(n),retain:(n,s)=>t.retain(n,s),pin:n=>t.pin(n),unpin:n=>t.unpin(n),permanent:n=>t.permanent(n),delete:n=>t.delete(n)},this._recordingsAccessor}get artifacts(){return this._artifactsAccessor?this._artifactsAccessor:(this._requireArtifactsAuth(),this._artifactsAccessor={list:e=>new C(this._requireArtifactsAuth()).list(e??this._sessionId),getDownloadUrl:(e,t)=>new C(this._requireArtifactsAuth()).getDownloadUrl(e,t??this._sessionId)},this._artifactsAccessor)}setArtifactsAuth(e){this._artifactsAuth=e}_requireArtifactsAuth(){let e=this._artifactsAuth;if(!e)throw new Error("[urun] session.artifacts requires a session-api `baseUrl` auth bag.");return e}setSessionId(e){if(e===this._sessionId)return;this._multiplexer.rewriteSessionChannels?.call(this._multiplexer,this._sessionId,e),this._sessionId=e;for(let n of this._docs.values())n.setSessionId(e)}stream(e){let t=this._streams.get(e);return t||(t=new Se(e,this._transport,this._streamData,()=>this.doc("control")),this._streams.set(e,t)),t}doc(e){let t=this._docs.get(e);return t||(t=new ue(e,this._sessionId,Ct.has(e)?null:this._docConnector.connect),this._docs.set(e,t)),t}get presence(){return this._presence||(this._presence=$e(this.doc("control").awareness)),this._presence}connectDocs(e){this._docConnector.setTarget(e)}setDocTransport(e){this.connectDocs(Me({serverUrl:Ue(e.wsUrl),sessionId:this._sessionId,token:e.token,WebSocketPolyfill:e.webSocket}))}useStreamDataTransport(e){if(this._streams.size>0)throw new Error("[urun] useStreamDataTransport must be called before opening any stream");this._streamData=e}sendImage(e){return this.request({reference_image:{value:e}})}sendImageLegacyDesired(e){this.doc("control").set({desired:{reference_image:{value:e}}})}request(e,t={}){let n=_e(),s=new AbortController;t.signal&&(t.signal.aborted?s.abort(t.signal.reason):t.signal.addEventListener("abort",()=>s.abort(t.signal.reason),{once:!0}));let o=null;if(typeof t.timeout=="number"&&t.timeout>=0){let a=t.timeout;o=setTimeout(()=>s.abort(new j(a,n)),a)}let i=this._consumeResponse(n,e,!1,s.signal);return i.start(),i.body.finally(()=>{o&&clearTimeout(o)})}_consumeResponse(e,t,n,s,o){let i=this.doc(Ot),a=Ut(e);return qt(i,e,t,a,this._streamData.consumerId,n,()=>this.stream(a),s,m=>(this._activeRequests.add(m),()=>this._activeRequests.delete(m)),o??Ve)}requestStream(e,t={}){let n=_e();return this._consumeResponse(n,e,!0,t.signal,t.docSyncTimeout).deltas}complete(e,t={}){let n=_e(),s=this._consumeResponse(n,e,!1,t.signal,t.docSyncTimeout);return s.start(),s.body}disconnect(){let e=Array.from(this._activeRequests);this._activeRequests.clear();for(let t of e)try{t(new F)}catch{}for(let t of this._docs.values())t.dispose();this._docs.clear();for(let t of this._streams.values())t.dispose();this._streams.clear(),this._transport.disconnect()}};var Dt=new Set(["then","catch","finally","toJSON",Symbol.toPrimitive]);function jt(r,e){return new Proxy({},{get(t,n){if(!(Dt.has(n)||typeof n!="string"))return s=>{let o=s??{},i=()=>`s_${Date.now()}_${Math.random().toString(36).slice(2)}`,a=i(),m=new X,f=new ee({url:"",orgId:e.orgId,jwt:e.jwt,authProvider:e.authProvider,sessionId:a}),l=new Y(a,m,f,be(e),N(e)),p=async u=>{let c=await Le({baseUrl:e.baseUrl,fallbackUrls:e.fallbackUrls,app:r,functionName:n,orgId:e.orgId,jwt:e.jwt,getAccessToken:e.getAccessToken,authProvider:e.authProvider,idempotencyKey:u}),h=e.getAccessToken?await e.getAccessToken()??void 0:e.jwt;return l.setSessionId(c.sessionId),l.setArtifactsAuth(N({...e,baseUrl:c.baseUrl})),{url:c.wsUrl,sessionId:c.sessionId,jwt:h,iceServers:c.response.ice_servers}};return f.setConnectionResolver(()=>p(i())),f.on("connected",()=>{f.multiplexer&&m.setTarget(f.multiplexer)}),(async()=>{let u;try{u=await p(a)}catch(c){console.error(`[urun] Failed to create session for ${n}:`,c);let h=c instanceof Error?c:new Error(String(c)),y=c instanceof v?c.httpStatus:void 0;f.reportAllocationFailure(h,y);return}f.setAuth({jwt:u.jwt,authProvider:e.authProvider,orgId:e.orgId}),f.setConnection({url:u.url,sessionId:u.sessionId,iceServers:u.iceServers}),Q()&&await Z(),l.setDocTransport({wsUrl:u.url,token:u.jwt}),await f.connect({app:r,functionName:n,args:o})})().catch(u=>{console.error(`[urun] Failed to connect session for ${n}:`,u)}),l}}})}var Je=3e4,Xe="stream:",ve=class{_ws;_multiplexer;_pendingRpc=new Map;_rpcId=0;constructor(e,t){this._ws=e,this._multiplexer=t,this._ws.addEventListener("message",n=>{let s;try{s=JSON.parse(typeof n.data=="string"?n.data:"")}catch{return}if(s.rpcId&&this._pendingRpc.has(s.rpcId)){let o=this._pendingRpc.get(s.rpcId);this._pendingRpc.delete(s.rpcId),clearTimeout(o.timer),s.error?o.reject(new Error(s.error)):o.resolve(s.result)}})}async get(e){return this._sendRpc("store.get",{key:e})}async has(e){return await this._sendRpc("store.has",{key:e})}on(e,t){let n=`${Xe}${e}`;return this._multiplexer.on(n,s=>{t(s)})}emit(e,t){let n=`${Xe}${e}`,s=typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{data:t};this._multiplexer.emit(n,s)}_getInternals(){return{multiplexer:this._multiplexer,ws:this._ws}}_sendRpc(e,t){return new Promise((n,s)=>{if(!this._ws||this._ws.readyState!==WebSocket.OPEN){s(new Error("WebSocket not open"));return}let o=String(++this._rpcId),i=setTimeout(()=>{this._pendingRpc.has(o)&&(this._pendingRpc.delete(o),s(new Error(`RPC request "${e}" timed out after ${Je}ms`)))},Je);this._pendingRpc.set(o,{resolve:n,reject:s,timer:i}),this._ws.send(JSON.stringify({rpcId:o,type:e,...t}))})}};function Lt(r){let n=`${r.baseUrl.replace(/\/$/,"").replace(/^http/,"ws")}/store/${encodeURIComponent(r.orgId)}`,s=new WebSocket(n);(r.jwt||r.apiKey)&&s.addEventListener("open",()=>{s.send(JSON.stringify({type:"auth",orgId:r.orgId,jwt:r.jwt,authProvider:r.authProvider,apiKey:r.apiKey}))});let o=new Ie(s);return new ve(s,o)}var Bt='video/mp4; codecs="avc1.42E01E"';function Ft(r,e){let t=e?.codec??Bt,n=document.createElement("video");n.muted=!0,n.playsInline=!0;let s=new MediaSource,o=URL.createObjectURL(s);n.src=o,s.addEventListener("sourceopen",()=>{let u;try{u=s.addSourceBuffer(t)}catch(g){throw g instanceof DOMException&&g.name==="NotSupportedError"?new Error(`Codec not supported: "${t}". Ensure the codec string matches the fMP4 container format. Common values: video/mp4; codecs="avc1.42E01E" (H.264 Baseline), video/mp4; codecs="avc1.4D401F" (H.264 Main).`):g}let c=r.getReader();function h(){return u.updating?new Promise(g=>{u.addEventListener("updateend",()=>g(),{once:!0})}):Promise.resolve()}async function y(){try{for(;;){let{done:g,value:T}=await c.read();if(g){await h(),s.readyState==="open"&&s.endOfStream();return}await h();try{u.appendBuffer(T)}catch(P){if(P instanceof DOMException&&P.name==="QuotaExceededError"){let x=u.buffered;if(x.length>0){let $=x.start(x.length-1);u.remove(0,$),await h(),u.appendBuffer(T)}else throw P}else throw P}}}catch{if(s.readyState==="open")try{s.endOfStream("decode")}catch{}}}y()}),n.play().catch(()=>{});let i=n,a=i.captureStream??i.mozCaptureStream;if(!a)throw new Error("captureStream() is not supported in this browser. videoStream() requires HTMLMediaElement.captureStream() support.");let m=a.call(n),f=m.getTracks(),l=0,p=f.length;if(p===0)n.addEventListener("emptied",()=>{URL.revokeObjectURL(o)},{once:!0});else for(let u of f)u.addEventListener("ended",()=>{l++,l>=p&&URL.revokeObjectURL(o)});return m}function Nt(r){return r.status.startsWith("pending_")}export{jt as App,Ve as DEFAULT_DOC_SYNC_TIMEOUT_MS,je as DEFAULT_WHEN_LIVE_TIMEOUT_MS,M as InvalidDurationError,ae as PermanentLockedError,ie as PinRequiresActiveTempError,se as RecordingNotFoundError,q as RecordingsClient,_ as RecordingsError,W as RecordingsUnauthorizedError,U as RequestAbortError,F as RequestCancelledError,L as RequestDocSyncError,S as RequestError,j as RequestTimeoutError,oe as RetainNotTempError,ne as RuntimeArtifactNotFoundError,C as RuntimeArtifactsClient,w as RuntimeArtifactsError,re as RuntimeArtifactsUnauthorizedError,Y as Session,v as SessionAllocationError,b as SessionFailedError,B as StreamDirectionConflict,St as createRecordingsClient,ft as createRuntimeArtifactsClient,Lt as createStore,De as describeSessionFailure,me as isDurationString,Nt as isPendingRecording,ye as mediaRecorderChunkSource,yt as normalizeRetention,tt as sessionFailureFromMediaError,Ft as videoStream,le as whenLive};
|
|
1
|
+
import{a as Ie,b as X,c as Q,e as Z,f as Ce,h as Oe,j as ee,k as Ee,l as Ue,m as Me,n as qe,o as $e}from"./chunk-D4OLDMKT.mjs";var S=class extends Error{requestId;code;constructor(e,t){super(e),this.name="RequestError",this.requestId=t?.requestId,this.code=t?.code,t?.cause!==void 0&&(this.cause=t.cause),Object.setPrototypeOf(this,new.target.prototype)}},j=class extends S{timeoutMs;constructor(e,t){super(`[urun] request timed out after ${e}ms`,{requestId:t}),this.name="RequestTimeoutError",this.timeoutMs=e,Object.setPrototypeOf(this,new.target.prototype)}},L=class extends S{timeoutMs;constructor(e,t){super(`[urun] request doc-sync did not establish within ${e}ms \u2014 the request was never delivered to the runtime (the session doc never synced with the session-server; check the doc-sync transport / connection)`,{requestId:t}),this.name="RequestDocSyncError",this.timeoutMs=e,Object.setPrototypeOf(this,new.target.prototype)}},B=class extends Error{stream;owner;attempted;constructor(e,t,n){super(`[urun] stream "${e}" is already produced by the ${t}; this (${n}) peer cannot also produce it \u2014 a named stream has exactly one producer (consume it instead, or use a distinct name for the reverse direction)`),this.name="StreamDirectionConflict",this.stream=e,this.owner=t,this.attempted=n,Object.setPrototypeOf(this,new.target.prototype)}},U=class extends S{constructor(e){super("[urun] request aborted",{requestId:e}),this.name="RequestAbortError",Object.setPrototypeOf(this,new.target.prototype)}},F=class extends S{constructor(e){super("[urun] request cancelled: session disconnected",{requestId:e}),this.name="RequestCancelledError",Object.setPrototypeOf(this,new.target.prototype)}};function De(r,e){let t=e.error?.reason,n=e.elapsedMs!==void 0?Math.round(e.elapsedMs/1e3):void 0;switch(r){case"create-failed":return{message:`[urun] session create failed${e.error?.httpStatus!==void 0?` (HTTP ${e.error.httpStatus})`:""}${t?`: ${t}`:""}`,hint:e.error?.httpStatus===401||e.error?.httpStatus===403?"The backend rejected this client \u2014 sign in again or check the auth token / org access.":"The backend could not create a session \u2014 check the app/function name and auth, then retry."};case"never-live":{let s=n!==void 0?` after ${n}s`:"",o=` (last server status: ${e.lastServerStatus??"none"})`;return e.error?.code==="expired"?{message:`[urun] session${e.sessionId?` ${e.sessionId}`:""} expired before media connected${s} \u2014 the control plane reclaims sessions whose media transport never establishes (~80s after create)`,hint:"Retry to mint a fresh session, and connect promptly after start (a backgrounded tab or paused debugger can miss the window)."}:e.sessionId?{message:`[urun] session ${e.sessionId} was created but never went live${s}${o} \u2014 the backend is busy or wedged (no runtime picked the session up)`,hint:"The backend is at capacity or stuck. Retry in a moment; if it persists, the session id above is what to report."}:{message:`[urun] no session went live${s} (phase=${e.phase}${e.lastServerStatus?`, last server status: ${e.lastServerStatus}`:""})`,hint:"The session never got past admission. Retry; if it persists, check the backend deployment."}}case"transport-failed":return e.error?.code==="transport-consumed"?{message:`[urun] the retry reused a session whose media transport was already connected${e.sessionId?` (id ${e.sessionId})`:""} \u2014 the session was consumed by an earlier attempt`,hint:"Start a fresh session (reload the page) \u2014 this session leg cannot be connected again."}:{message:`[urun] media/transport connection failed${t?`: ${t}`:""} (transport state: ${e.transportState})`,hint:"The network is likely blocking the media connection (WebRTC/WebSocket) \u2014 try a different network or disable VPN/proxy, then retry."};case"media-permission":return{message:`[urun] microphone/camera unavailable${t?`: ${t}`:""}`,hint:e.error?.code==="NotFoundError"||e.error?.code==="OverconstrainedError"?"No matching input device was found \u2014 connect or select a microphone/camera and retry.":"Allow microphone/camera access for this site (browser permission \u2014 or, when embedded, the parent page's permissions policy), then retry."};case"ended":return{message:`[urun] session ended before going live${e.sessionId?` (id ${e.sessionId})`:""}`,hint:"The session was closed (server-side, or superseded by another connection). Start a new session."}}}var b=class extends Error{kind;status;hint;constructor(e,t,n){let{message:s,hint:o}=De(e,t);super(s),this.name="SessionFailedError",this.kind=e,this.status=t,this.hint=o,n?.cause!==void 0&&(this.cause=n.cause),Object.setPrototypeOf(this,new.target.prototype)}};function tt(r,e){if(r instanceof b)return r;let t=r instanceof Error?r:new Error(String(r)),n={phase:e?.phase??"idle",transportState:e?.transportState??"disconnected",...e,error:{reason:t.message,code:t.name,kind:"media-permission"}};return new b("media-permission",n,{cause:r})}var v=class extends Error{httpStatus;constructor(e,t){super(e),this.name="SessionAllocationError",this.httpStatus=t?.httpStatus,t?.cause!==void 0&&(this.cause=t.cause),Object.setPrototypeOf(this,new.target.prototype)}};var je=45e3;function le(r,e={}){let{timeout:t=je,signal:n}=e;return new Promise((s,o)=>{if(n?.aborted){o(n.reason instanceof Error?n.reason:new Error("whenLive aborted"));return}if(r.phase?.name==="live"){s();return}if(r.phase?.name==="error"||r.phase?.name==="ended"){let c=r.phase,h=r.status??{phase:c.name,transportState:"disconnected",sessionId:c.sessionId,requestId:c.requestId,queue:c.queue,error:c.error};o(new b(c.name==="ended"?"ended":c.error?.kind??"transport-failed",h));return}let i,a,m=!1,f=c=>{m||(m=!0,a!==void 0&&clearTimeout(a),n?.removeEventListener("abort",l),i?.(),c?o(c):s())},l=()=>{f(n?.reason instanceof Error?n.reason:new Error("whenLive aborted"))};n?.addEventListener("abort",l,{once:!0});let p=()=>{let c=r.phase;return r.status??{phase:c?.name??"idle",transportState:"disconnected",sessionId:c?.sessionId,requestId:c?.requestId,queue:c?.queue,error:c?.error}},u=c=>f(new b(c,p()));t>0&&(a=setTimeout(()=>{let c=p();c.elapsedMs===void 0&&(c.elapsedMs=t),f(new b("never-live",c))},t)),i=r.onPhase(c=>{c?.name==="live"?f():c?.name==="error"?u(c.error?.kind??"transport-failed"):c?.name==="ended"&&u("ended")}),m&&i()})}var rt="session-api.prod.cloud.urun.sh",nt=["https://session-api.use2.prod.cloud.urun.sh","https://session-api.usw2.prod.cloud.urun.sh"];function A(r){return r.trim().replace(/\/+$/,"")}function te(r,e){let t=[],n=s=>{if(!s)return;let o=A(s);o&&!t.includes(o)&&t.push(o)};n(r);for(let s of e??[])n(s);for(let s of pt(r))n(s);return t}var st=120,ot=1e3,it=3;function at(r){if(!r)return null;try{let e=new URL(r),t=e.pathname.replace(/\/api\/sessions\/create\/?$/,"");return A(`${e.origin}${t}`)}catch{return null}}async function Le(r){let e=te(r.baseUrl,r.fallbackUrls),t=null,n=e.length>1;for(let s of e)try{return await ct(s,r,{pollAttempts:st,retryAfterLimitMs:n?ot:void 0})}catch(o){if(t=o instanceof Error?o:new Error(String(o)),t instanceof I)throw t}throw t??new Error("[urun] session allocation failed")}async function ct(r,e,t){let n,s,o,i=r,a=0,m=new Set;for(let f=0;f<t.pollAttempts;f++){s=o??await fe(e),o=void 0;let l=n?await fetch(`${i}/api/session-requests/${encodeURIComponent(n)}`,{headers:pe(e,s)}):await fetch(`${i}/api/sessions/create`,{method:"POST",redirect:"manual",headers:{...pe(e,s),"Content-Type":"application/json","Idempotency-Key":e.idempotencyKey},body:JSON.stringify(ut(e))});if(!n&&(l.status===307||l.status===308)){let h=at(l.headers.get("location"));if(h&&h!==i&&a<it){a+=1,i=h;continue}throw new v(`[urun] session create redirected from ${i} without a usable target`,{httpStatus:l.status})}let p=await Fe(l);if(l.ok&&(p.status==="allocated"||!p.status&&!!p.session_id)&&!!p.session_id){let h=p.session_id;if(!p.ws_url)throw new I(`[urun] gateway allocated session ${h} without ws_url`);if(!Ne(p.ws_url))throw new I(`[urun] gateway allocated session ${h} with non-absolute ws_url`);return{baseUrl:i,sessionId:h,wsUrl:p.ws_url,response:p}}if(l.status===202||p.status==="pending"||p.status==="queued"||p.queued){if(n=p.request_id||n,!n)throw new Error("[urun] gateway queued session without request_id");await lt(dt(l,p,t.retryAfterLimitMs));continue}if((l.status===401||l.status===403)&&e.getAccessToken){let h=s??"";m.add(h);let y=await fe(e,{forceRefresh:!0,reason:"unauthorized"});if(y&&!m.has(y)){o=y,n=void 0;continue}}let c=p.error_message||p.error_code||`HTTP ${l.status}`;throw new v(`[urun] session allocation failed at ${i}: ${c}`,{httpStatus:l.status})}throw new v(`[urun] timed out waiting for session allocation at ${i}`)}function pe(r,e){let t={"X-Tenant-Id":r.orgId,"X-Auth-Provider":r.authProvider||"default","X-User-Id":"anonymous"};return e&&(t.Authorization=`Bearer ${e}`),t}async function fe(r,e){return r.getAccessToken?await r.getAccessToken(e)??void 0:r.jwt}function ut(r){return{app:r.app,function:r.functionName,gpus:1,idempotency_key:r.idempotencyKey}}async function Be(r){let e=te(r.baseUrl,r.fallbackUrls),t=null;for(let n of e)try{let s={baseUrl:n,app:"",functionName:"",orgId:r.orgId,jwt:r.jwt,getAccessToken:r.getAccessToken,authProvider:r.authProvider,idempotencyKey:""},o=await fe(s),i=await fetch(`${A(n)}/api/sessions/${encodeURIComponent(r.sessionId)}/viewer-connect`,{headers:pe(s,o)});if(!i.ok)throw new Error(`[urun] viewer-connect for ${r.sessionId} failed: HTTP ${i.status}`);let a=await Fe(i);if(!a.ws_url||!Ne(a.ws_url))throw new I(`[urun] viewer-connect returned no usable ws_url for ${r.sessionId}`);return{baseUrl:A(n),sessionId:r.sessionId,wsUrl:a.ws_url,response:a}}catch(s){if(t=s instanceof Error?s:new Error(String(s)),t instanceof I)throw t}throw t??new Error("[urun] viewer-connect failed")}async function Fe(r){try{let e=await r.json();return e&&typeof e=="object"?e:{}}catch{return{}}}function dt(r,e,t){let n=Number(r.headers.get("Retry-After")||""),s=Number(e.retry_after_seconds??n),o=t??1e4;return Number.isFinite(s)&&s>0?Math.min(s*1e3,o):1e3}function lt(r){return new Promise(e=>setTimeout(e,r))}var I=class extends Error{};function Ne(r){try{let e=new URL(r);return e.protocol==="ws:"||e.protocol==="wss:"}catch{return!1}}function pt(r){try{return new URL(r).hostname!==rt?[]:nt}catch{return[]}}var w=class extends Error{status;code;constructor(e,t,n=t>0?`http_${t}`:"runtime_artifacts_error",s){super(e),this.name="RuntimeArtifactsError",this.status=t,this.code=n,s!==void 0&&(this.cause=s),Object.setPrototypeOf(this,new.target.prototype)}},re=class extends w{constructor(e="[urun] runtime artifacts: unauthorized",t="unauthorized"){super(e,401,t),this.name="RuntimeArtifactsUnauthorizedError",Object.setPrototypeOf(this,new.target.prototype)}},ne=class extends w{constructor(e="[urun] runtime artifacts: not found",t="not_found"){super(e,404,t),this.name="RuntimeArtifactNotFoundError",Object.setPrototypeOf(this,new.target.prototype)}};function N(r){return{baseUrl:r.baseUrl,fallbackUrls:r.fallbackUrls,orgId:r.orgId,jwt:r.jwt,getAccessToken:r.getAccessToken,authProvider:r.authProvider}}function ft(r){return new C(r)}var C=class{_options;constructor(e){this._options=e}async list(e){let n=ze(await this._request(e,"")).artifacts;if(!Array.isArray(n))throw new w("[urun] runtime artifacts: response missing `artifacts`",0,"bad_response");return n.map(We)}async getDownloadUrl(e,t){let n=ze(await this._request(t,`/${encodeURIComponent(e)}/download`)),s=n.download_url;if(typeof s!="string"||!ht(s))throw new w("[urun] runtime artifacts: response missing HTTPS download_url",0,"bad_response");return{artifact:We(n.artifact),downloadUrl:s}}async _request(e,t){let n=te(this._options.baseUrl,this._options.fallbackUrls),s=null;for(let o of n)try{return await this._requestFromBase(o,e,t)}catch(i){if(s=i instanceof Error?i:new Error(String(i)),s instanceof w&>(s.status))throw s}throw s??new w("[urun] runtime artifacts request failed",0)}async _requestFromBase(e,t,n){let s=`${A(e)}/api/sessions/${encodeURIComponent(t)}/artifacts${n}`,o=await this._resolveToken(),i=await fetch(s,{method:"GET",headers:this._headers(o)});if(i.status===401&&this._options.getAccessToken){let a=await this._options.getAccessToken({forceRefresh:!0,reason:"unauthorized"});a&&a!==o&&(o=a,i=await fetch(s,{method:"GET",headers:this._headers(o)}))}if(!i.ok){let{code:a,message:m}=await this._readError(i,e);throw wt(i.status,a,m)}try{return await i.json()}catch(a){throw new w(`[urun] runtime artifacts: invalid JSON response from ${A(e)}`,0,"bad_response",a)}}async _resolveToken(){return this._options.getAccessToken?await this._options.getAccessToken()??void 0:this._options.jwt}_headers(e){let t={Accept:"application/json","X-Tenant-Id":this._options.orgId,"X-Auth-Provider":this._options.authProvider||"default"};return e&&(t.Authorization=`Bearer ${e}`),t}async _readError(e,t){let n=A(t);try{let o=(await e.json()).error;if(o&&typeof o=="object"){let{code:i,message:a}=o;return{code:typeof i=="string"&&i.length>0?i:`http_${e.status}`,message:typeof a=="string"&&a.length>0?`[urun] runtime artifacts request failed at ${n}: ${a}`:`[urun] runtime artifacts request failed at ${n}: HTTP ${e.status}`}}}catch{}return{code:`http_${e.status}`,message:`[urun] runtime artifacts request failed at ${n}: HTTP ${e.status}`}}};function We(r){if(!r||typeof r!="object")throw new w("[urun] runtime artifacts: malformed artifact",0,"malformed_artifact");let e=r,t=k(e,"artifact_id")||k(e,"id"),n=k(e,"filename"),s=k(e,"kind"),o=k(e,"status")||"ready",i=mt(e,"size_bytes"),a=k(e,"sha256");if(!t||!n||!s||i==null||!a)throw new w("[urun] runtime artifacts: malformed artifact metadata",0,"malformed_artifact");return{artifactId:t,kind:s,filename:n,contentType:k(e,"content_type")||"application/octet-stream",sizeBytes:i,sha256:a,status:o,createdAt:k(e,"created_at"),expiresAt:k(e,"expires_at")}}function k(r,e){let t=r[e];return typeof t=="string"&&t.length>0?t:void 0}function mt(r,e){let t=r[e];return typeof t=="number"&&Number.isFinite(t)&&Number.isInteger(t)&&t>=0?t:void 0}function ht(r){try{return new URL(r).protocol==="https:"}catch{return!1}}function gt(r){return r===401||r===403}function wt(r,e,t){return r===401?new re(t,e):r===404?new ne(t,e):new w(t,r,e)}function ze(r){if(!r||typeof r!="object"||Array.isArray(r))throw new w("[urun] runtime artifacts: malformed response",0,"bad_response");return r}var _=class extends Error{status;code;constructor(e,t){super(e),this.name="RecordingsError",this.status=t.status,this.code=t.code,t.cause!==void 0&&(this.cause=t.cause),Object.setPrototypeOf(this,new.target.prototype)}},W=class extends _{constructor(e="[urun] recordings: unauthorized",t="unauthorized"){super(e,{status:401,code:t}),this.name="RecordingsUnauthorizedError",Object.setPrototypeOf(this,new.target.prototype)}},se=class extends _{constructor(e="[urun] recordings: not found",t="not_found"){super(e,{status:404,code:t}),this.name="RecordingNotFoundError",Object.setPrototypeOf(this,new.target.prototype)}},oe=class extends _{constructor(e="[urun] recordings: retain requires a temp recording",t="retain_not_temp"){super(e,{status:409,code:t}),this.name="RetainNotTempError",Object.setPrototypeOf(this,new.target.prototype)}},ie=class extends _{constructor(e="[urun] recordings: pin requires an active temp recording",t="pin_requires_active_temp"){super(e,{status:409,code:t}),this.name="PinRequiresActiveTempError",Object.setPrototypeOf(this,new.target.prototype)}},ae=class extends _{constructor(e="[urun] recordings: recording is permanent and locked",t="permanent_locked"){super(e,{status:409,code:t}),this.name="PermanentLockedError",Object.setPrototypeOf(this,new.target.prototype)}},M=class extends _{constructor(e="[urun] recordings: invalid retention duration",t="bad_duration",n=400){super(e,{status:n,code:t}),this.name="InvalidDurationError",Object.setPrototypeOf(this,new.target.prototype)}};function me(r){return/^(\d+[smhdw])+$/.test(r)}function yt(r){if(r==="pin")return{action:"pin"};if(me(r))return{action:"retain",duration:r};throw new M(`[urun] recordings: "${r}" is not a duration or "pin"`)}function _t(r,e,t){let n=t||e||`HTTP ${r}`;if(r===401)return new W(n,e??"unauthorized");if(r===404)return new se(n,e??"not_found");if(r===400)return new M(n,e??"bad_request",400);if(r===409)switch(e){case"retain_not_temp":return new oe(n,e);case"pin_requires_active_temp":return new ie(n,e);case"permanent_locked":return new ae(n,e)}return new _(n,{status:r,code:e??`http_${r}`})}var q=class{constructor(e){this._options=e;this._base=`${e.functionsUrl.replace(/\/+$/,"")}/recordings`}_options;_base;async list(e){let n=(await this._request("GET","",{params:e?{session_id:e}:void 0})).recordings;return Array.isArray(n)?n:[]}async get(e){return this._one(await this._request("GET",`/${encodeURIComponent(e)}`))}async retain(e,t){if(!me(t))throw new M(`[urun] recordings: "${t}" is not a valid retention duration`);return this._one(await this._request("POST",`/${encodeURIComponent(e)}/retain`,{body:{duration:t}}))}async pin(e){return this._one(await this._request("POST",`/${encodeURIComponent(e)}/pin`))}async unpin(e){return this._one(await this._request("POST",`/${encodeURIComponent(e)}/unpin`))}async permanent(e){return this._one(await this._request("POST",`/${encodeURIComponent(e)}/permanent`))}async delete(e){return this._one(await this._request("POST",`/${encodeURIComponent(e)}/delete`))}_one(e){let t=e.recording;if(!t||typeof t!="object")throw new _("[urun] recordings: response missing `recording`",{status:0,code:"bad_response"});return t}async _request(e,t,n={}){let s=this._buildUrl(t,n.params),o=await this._resolveToken(),i=await this._fetch(s,e,o,n.body);if(i.status===401&&this._options.getAccessToken){let a=await this._options.getAccessToken({forceRefresh:!0,reason:"unauthorized"});a&&a!==o&&(o=a,i=await this._fetch(s,e,o,n.body))}if(!i.ok){let{code:a,message:m}=await this._readError(i);throw _t(i.status,a,m)}return this._readJson(i)}_buildUrl(e,t){let n=`${this._base}${e}`,s=Object.entries(t??{}).filter(([,o])=>o!=null&&o!=="").map(([o,i])=>`${encodeURIComponent(o)}=${encodeURIComponent(i)}`).join("&");return s&&(n+=`?${s}`),n}_fetch(e,t,n,s){let o={Authorization:`Bearer ${n}`,apikey:n,Accept:"application/json","X-Tenant-Id":this._options.orgId};this._options.authProvider&&(o["X-Auth-Provider"]=this._options.authProvider);let i={method:t,headers:o};return s!==void 0&&(o["Content-Type"]="application/json",i.body=JSON.stringify(s)),fetch(e,i)}async _resolveToken(){if(this._options.getAccessToken){let t=await this._options.getAccessToken();if(t)return t}let e=this._options.jwt??this._options.apiKey;if(!e)throw new W("[urun] recordings: no credential \u2014 provide one of apiKey, jwt, or getAccessToken");return e}async _readJson(e){try{return await e.json()}catch{return{}}}async _readError(e){try{let n=(await e.json()).error;if(n&&typeof n=="object"){let{code:s,message:o}=n;return{code:typeof s=="string"?s:void 0,message:typeof o=="string"?o:`HTTP ${e.status}`}}}catch{}return{message:`HTTP ${e.status}`}}};function St(r){return new q(r)}import*as K from"yjs";function G(r){if(r===null||typeof r!="object"||Array.isArray(r))return!1;let e=Object.getPrototypeOf(r);return e===Object.prototype||e===null}var ce="$bytes";function bt(r){return r instanceof Uint8Array||r instanceof ArrayBuffer}function vt(r){if(!G(r))return!1;let e=Object.keys(r);return e.length===1&&e[0]===ce&&typeof r[ce]=="string"}function kt(r){return r instanceof ArrayBuffer?new Uint8Array(r):r}function Rt(r){if(typeof Buffer<"u")return Buffer.from(r).toString("base64");let e="";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return btoa(e)}function At(r){if(typeof Buffer<"u")return new Uint8Array(Buffer.from(r,"base64"));let e=atob(r),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return t}function he(r){if(bt(r))return{[ce]:Rt(kt(r))};if(Array.isArray(r))return r.map(he);if(G(r)){let e={};for(let[t,n]of Object.entries(r))e[t]=he(n);return e}return r}function z(r){if(vt(r))return At(r[ce]);if(Array.isArray(r))return r.map(z);if(G(r)){let e={};for(let[t,n]of Object.entries(r))e[t]=z(n);return e}return r}var Ke=Symbol("urun:doc:path-absent");function Tt(r,e){let t=e.split("."),n=r;for(let s of t){if(n===null||typeof n!="object"||!(s in n))return Ke;n=n[s]}return n}function Pt(r,e){return r===e?!0:JSON.stringify(r)===JSON.stringify(e)}function ge(r,e){for(let[t,n]of Object.entries(e))if(G(n)){let s=r.get(t);if(!(s instanceof K.Map)){let o=s;s=new K.Map,r.set(t,s),G(o)&&ge(s,o)}ge(s,n)}else{if(Pt(r.get(t),n))continue;r.set(t,n)}}var xt=Symbol("urun:doc:local"),ue=class{_doc=new K.Doc;_root=this._doc.getMap("session");_awareness=new Ee(this._doc);_listeners=new Set;_key;_sessionId;_connection=null;_connUnsub=null;_synced;_syncWaiters=new Set;_texts=new Map;_observer=()=>this.notify();constructor(e,t,n){this._key=e,this._sessionId=t,this._root.observeDeep(this._observer),n?(this._connection=n(e,this._doc,this._awareness),this._synced=this._connection.synced,this._connUnsub=this._connection.onSync(s=>{s&&this._markSynced()}),this._synced&&this._markSynced()):this._synced=!0}get awareness(){return this._awareness}setSessionId(e){this._sessionId=e}get synced(){return this._synced}onSynced(e){return this._synced?(e(),()=>{}):(this._syncWaiters.add(e),()=>this._syncWaiters.delete(e))}set(e){e=he(e),this.applyPatch(e)}get(e,t){let n=this.snapshot();if(!e)return z(n);let s=Tt(n,e);return s===Ke?t:z(s)}on(e,t){return this._listeners.add(t),()=>this._listeners.delete(t)}text(e){let t=this._texts.get(e);return t||(t=new we(this._doc.getText(`text:${e}`)),this._texts.set(e,t)),t}dispose(){this._root.unobserveDeep(this._observer),this._connUnsub?.(),this._connUnsub=null,this._connection?.destroy(),this._connection=null,this._listeners.clear(),this._syncWaiters.clear();for(let e of this._texts.values())e.dispose();this._texts.clear(),this._awareness.destroy(),this._doc.destroy()}_markSynced(){let e=[...this._syncWaiters];this._synced=!0,this._syncWaiters.clear();for(let t of e)t()}applyPatch(e){this._doc.transact(()=>{ge(this._root,e)},xt)}snapshot(){return this._root.toJSON()}notify(){let e=z(this.snapshot());for(let t of this._listeners)t(e)}},we=class{constructor(e){this._ytext=e;this._observer=t=>{for(let n of t.delta)if(typeof n.insert=="string"&&n.insert.length>0){let s=n.insert;for(let o of this._delta)o(s)}},this._ytext.observe(this._observer)}_ytext;_delta=new Set;_observer;append(e){e.length!==0&&this._ytext.insert(this._ytext.length,e)}toString(){return this._ytext.toString()}get length(){return this._ytext.length}on(e,t){return this._delta.add(t),()=>this._delta.delete(t)}dispose(){this._ytext.unobserve(this._observer),this._delta.clear()}};var Ge="video/mp4";function ye(r,e={}){let t=e.timesliceMs??1e3,n=null,s=null,o=!1,i=(a,m,f)=>{let l=typeof MediaRecorder>"u"?void 0:MediaRecorder;if(!l)throw new Error("[urun] stream.chunks(): MediaRecorder is unavailable in this runtime. Pass { source } to chunks() to inject a byte-tap (e.g. a Node/werift consumer).");let p=e.mimeType??(typeof l.isTypeSupported=="function"&&l.isTypeSupported(Ge)?Ge:void 0),u=new MediaStream([a]),c=new l(u,p?{mimeType:p}:void 0);n=c;let h=Promise.resolve();c.ondataavailable=y=>{let g=y.data;o||!g||g.size===0||(h=h.then(async()=>{let T=new Uint8Array(await g.arrayBuffer());o||m(T)}))},c.onstop=()=>{h.then(()=>{o||f()})},c.onerror=()=>{h.then(()=>{o||f()})},c.start(t)};return{start(a,m){if(n||o)return;let f=r.track();if(f){i(f,a,m);return}s=r.onTrack(l=>{!l||n||o||(s?.(),s=null,i(l,a,m))})},stop(){if(o)return;o=!0,s?.(),s=null;let a=n;if(n=null,a&&a.state!=="inactive")try{a.stop()}catch{}}}}function It(r){let e=r;return typeof e[Symbol.asyncIterator]=="function"||(e[Symbol.asyncIterator]=function(){let t=r.getReader();return{next(){return t.read()},async return(){try{await t.cancel()}catch{}try{t.releaseLock()}catch{}return{value:void 0,done:!0}},[Symbol.asyncIterator](){return this}}}),e}function Ye(r,e){let t=null,n=!1,s=!1,o=new ReadableStream({pull(i){n||(n=!0,t=r(e),t.start(a=>{if(!s)try{i.enqueue(a)}catch{}},()=>{if(!s){s=!0;try{i.close()}catch{}}}))},cancel(){s=!0,t?.stop(),t=null}},new CountQueuingStrategy({highWaterMark:0}));return It(o)}var Ct=new Set;function be(r){if(r.functionsUrl)return{functionsUrl:r.functionsUrl,orgId:r.orgId,apiKey:r.apiKey,jwt:r.jwt,getAccessToken:r.getAccessToken,authProvider:r.authProvider}}var Ot="rpc",Ve=3e4,Et="rpc-resp";function Ut(r){return`${Et}:${r}`}function _e(){return Ce()}function Mt(r){if(r&&typeof r=="object"){let e=r.error;if(e&&typeof e=="object"){let{message:t,code:n}=e;return{message:typeof t=="string"?t:JSON.stringify(e),code:typeof n=="string"?n:void 0}}if(typeof e=="string")return{message:e}}return{message:typeof r=="string"?r:JSON.stringify(r)}}function qt(r,e,t,n,s,o,i,a,m,f){let l=[],p=null,u=!1,c=null,h=!1,y,g,T=new Promise((d,R)=>{y=d,g=R});T.catch(()=>{});let P=i(),x=null,$=null,D=null,H=null,V=!0,ke=()=>{D&&(clearTimeout(D),D=null),H&&(H(),H=null)},Re=!1,Ae=()=>{Re||!h||(Re=!0,r.set({rpc:{[e]:null}}))},J=()=>{V=!1,ke(),x?.(),x=null,$?.(),$=null,a?.removeEventListener("abort",Pe),P.dispose(),Ae()},de=()=>{if(p){if(l.length>0){let d=p;p=null,d.resolve({value:l.shift(),done:!1})}else if(c!==null){let d=p;p=null,d.reject(c)}else if(u){let d=p;p=null,d.resolve({value:void 0,done:!0})}}},Qe=d=>{u||(l.push(d),de())},O=d=>{u||(c=d,u=!0,g(d),J(),de())},Te=d=>{u||(u=!0,y(d),J(),de())},Pe=()=>{let d=a?.reason;O(d instanceof S?d:new U(e))},Ze=d=>{if(!(u||!d||typeof d!="object"))switch(Ae(),d.t){case"delta":typeof d.delta=="string"&&Qe(d.delta);break;case"response":Te(d.body);break;case"error":{let{message:R,code:E}=Mt(d.body);O(new S(R,{requestId:e,code:d.code??E}));break}}},et=()=>{let d=P.messages()[Symbol.asyncIterator]();x=()=>{d.return?.(void 0)};let R=()=>{V&&d.next().then(E=>{if(V){if(E.done){u||Te(void 0);return}Ze(E.value),R()}},E=>{V&&O(E)})};R()},xe=()=>{if(!h){if(h=!0,a){if(a.aborted){O(new U(e));return}a.addEventListener("abort",Pe,{once:!0})}$=m?.(d=>O(d))??null,et(),r.set({rpc:{[e]:{args:t,respond_on:n,consumer_id:s,stream:o}}}),f&&f>0&&!r.synced&&(D=setTimeout(()=>{D=null,!u&&!r.synced&&O(new L(f,e))},f),H=r.onSynced(()=>ke()))}};return{deltas:{[Symbol.asyncIterator](){return{next(){if(xe(),l.length>0)return Promise.resolve({value:l.shift(),done:!1});if(c!==null){let d=c;return c=null,Promise.reject(d)}return u?Promise.resolve({value:void 0,done:!0}):new Promise((d,R)=>{p={resolve:d,reject:R}})},return(){return u||(u=!0,y(void 0),J()),Promise.resolve({value:void 0,done:!0})},throw(d){return u||(u=!0,g(d),J()),Promise.reject(d)}}}},body:T,start:xe}}function He(r){if(r&&typeof r=="object"){let{epoch:e,by:t}=r,n={epoch:typeof e=="number"?e:0};return(t==="runtime"||t==="browser")&&(n.by=t),n}}function $t(r,e){let n=r.get("streams")?.[e];if(!n||typeof n!="object")return null;let{kind:s,rt:o,br:i}=n,a={};(s==="audio"||s==="video"||s==="data")&&(a.kind=s);let m=He(o);m&&(a.rt=m);let f=He(i);return f&&(a.br=f),a}var Se=class{constructor(e,t,n,s){this._name=e;this._transport=t;this._streamData=n;this._controlDoc=s;this._track=this._transport.getTrackByName(this._name)??null,this._unsubscribeTransport=this._transport.on("track",()=>{let o=this._transport.getTrackByName(this._name)??null;o!==this._track&&this._setTrack(o)})}_name;_transport;_streamData;_controlDoc;_track=null;_handlers=new Map;_unsubscribeTransport=null;_subscribed=!1;_messageConsumers=new Set;_dataUnsub=null;_replay=[];_disposed=!1;messages(){this._ensureSubscribed();let e=this;return{[Symbol.asyncIterator](){let t=[...e._replay],n=null,s=!1,o={push(a){if(!s)if(n){let m=n;n=null,m({value:a,done:!1})}else t.push(a)},end(){if(s=!0,n){let a=n;n=null,a({value:void 0,done:!0})}}};e._messageConsumers.add(o);let i=()=>{s=!0,e._messageConsumers.delete(o)};return{next(){return t.length>0?Promise.resolve({value:t.shift(),done:!1}):s?Promise.resolve({value:void 0,done:!0}):new Promise(a=>{n=a})},return(){return i(),Promise.resolve({value:void 0,done:!0})}}}}}_ensureSubscribed(){this._subscribed||this._disposed||(this._subscribed=!0,this._transport.subscribeStream(this._name),this._streamData&&(this._dataUnsub=this._streamData.onData(this._name,e=>this._deliver(e))))}_deliver(e){this._replay.push(e);for(let t of this._messageConsumers)t.push(e)}get track(){let e=this._transport.getTrackByName(this._name)??this._track;return e!==this._track&&this._setTrack(e),this._track}_claimBrowserProducer(e){if(!this._controlDoc)return;let t=this._controlDoc(),n=$t(t,this._name),s=n?.br;if(s?.by==="runtime")throw new B(this._name,"runtime","browser");if(s)return;let o={br:{epoch:1}};n?.rt&&(o.rt=n.rt);let i=n?.kind??e;i&&(o.kind=i),t.set({streams:{[this._name]:o}})}async attach(e){this._claimBrowserProducer("audio"),await this._transport.addTrack(e,this._name)}async attachVideo(e){this._claimBrowserProducer("video"),await this._transport.addVideoTrack(e,this._name)}async emit(e,t={}){if(this._claimBrowserProducer("data"),!this._streamData)throw new Error("[urun] stream.emit requires the data-stream transport (no streamData wired)");await this._streamData.sendData(this._name,e,t)}async detach(){this._transport.removeTrack()}async detachVideo(){this._transport.stopVideo()}async seek(e){if(e!=="live"&&(!Number.isFinite(e)||e<0))throw new Error('[urun] stream.seek target must be "live" or a non-negative number of seconds');this._transport.seekStream(this._name,e)}chunks(e={}){let t=e.source??ye;return Ye(t,{track:()=>this.track,onTrack:s=>this.on("track",s)})}onSeeked(e){return this._transport.on("seeked",(t,n)=>{t===this._name&&e(n)})}on(e,t){let n=this._handlers.get(e);return n||(n=new Set,this._handlers.set(e,n)),n.add(t),()=>{n?.delete(t),n?.size===0&&this._handlers.delete(e)}}dispose(){this._disposed=!0,this._unsubscribeTransport?.(),this._unsubscribeTransport=null,this._handlers.clear(),this._subscribed&&this._transport.unsubscribeStream(this._name),this._dataUnsub?.(),this._dataUnsub=null;for(let e of this._messageConsumers)e.end();this._messageConsumers.clear()}_setTrack(e){this._track=e,e&&e.addEventListener("ended",()=>{this._track===e&&this._setTrack(null)},{once:!0});let t=this._handlers.get("track");if(t)for(let n of t)n(e)}},Y=class r{_sessionId;_multiplexer;_transport;_docs=new Map;_streams=new Map;_docConnector=new qe;_streamData;_presence=null;_activeRequests=new Set;_recordingsAuth;_artifactsAuth;_recordingsAccessor=null;_artifactsAccessor=null;constructor(e,t,n,s,o){this._sessionId=e,this._multiplexer=t,this._transport=n,this._recordingsAuth=s,this._artifactsAuth=o,this._streamData=Oe(n),this._wireControlDocIncarnation()}_wireControlDocIncarnation(){let e=this.doc("control");this._transport.applyControlDocState(e.get()),e.on("change",t=>{this._transport.applyControlDocState(t)})}static async attach(e,t){let n=await Be({baseUrl:t.baseUrl,fallbackUrls:t.fallbackUrls,sessionId:e,orgId:t.orgId,jwt:t.jwt,getAccessToken:t.getAccessToken,authProvider:t.authProvider}),s=t.getAccessToken?await t.getAccessToken()??void 0:t.jwt,o=new X,i=new ee({url:n.wsUrl,orgId:t.orgId,jwt:s,authProvider:t.authProvider,sessionId:e,iceServers:n.response.ice_servers}),a=new r(e,o,i,be(t),N({...t,baseUrl:n.baseUrl}));return i.on("connected",()=>{i.multiplexer&&o.setTarget(i.multiplexer)}),i.setConnection({url:n.wsUrl,sessionId:e,iceServers:n.response.ice_servers}),Q()&&await Z(),a.setDocTransport({wsUrl:n.wsUrl,token:s}),await i.connect({role:"viewer"}),a}get id(){return this._sessionId}get phase(){return this._transport.phase}get status(){return this._transport.status}onPhase(e){return e(this._transport.phase),this._transport.on("phase",e)}whenLive(e){return le(this,e)}get recordings(){if(this._recordingsAccessor)return this._recordingsAccessor;let e=this._recordingsAuth;if(!e)throw new Error("[urun] session.recordings requires `functionsUrl` to be configured on the App()/Session.attach() options (the eensx /functions/v1 base URL).");let t=new q(e);return this._recordingsAccessor={list:n=>t.list(n??this._sessionId),get:n=>t.get(n),retain:(n,s)=>t.retain(n,s),pin:n=>t.pin(n),unpin:n=>t.unpin(n),permanent:n=>t.permanent(n),delete:n=>t.delete(n)},this._recordingsAccessor}get artifacts(){return this._artifactsAccessor?this._artifactsAccessor:(this._requireArtifactsAuth(),this._artifactsAccessor={list:e=>new C(this._requireArtifactsAuth()).list(e??this._sessionId),getDownloadUrl:(e,t)=>new C(this._requireArtifactsAuth()).getDownloadUrl(e,t??this._sessionId)},this._artifactsAccessor)}setArtifactsAuth(e){this._artifactsAuth=e}_requireArtifactsAuth(){let e=this._artifactsAuth;if(!e)throw new Error("[urun] session.artifacts requires a session-api `baseUrl` auth bag.");return e}setSessionId(e){if(e===this._sessionId)return;this._multiplexer.rewriteSessionChannels?.call(this._multiplexer,this._sessionId,e),this._sessionId=e;for(let n of this._docs.values())n.setSessionId(e)}stream(e){let t=this._streams.get(e);return t||(t=new Se(e,this._transport,this._streamData,()=>this.doc("control")),this._streams.set(e,t)),t}doc(e){let t=this._docs.get(e);return t||(t=new ue(e,this._sessionId,Ct.has(e)?null:this._docConnector.connect),this._docs.set(e,t)),t}get presence(){return this._presence||(this._presence=$e(this.doc("control").awareness)),this._presence}connectDocs(e){this._docConnector.setTarget(e)}setDocTransport(e){this.connectDocs(Me({serverUrl:Ue(e.wsUrl),sessionId:this._sessionId,token:e.token,WebSocketPolyfill:e.webSocket}))}useStreamDataTransport(e){if(this._streams.size>0)throw new Error("[urun] useStreamDataTransport must be called before opening any stream");this._streamData=e}sendImage(e){return this.request({reference_image:{value:e}})}sendImageLegacyDesired(e){this.doc("control").set({desired:{reference_image:{value:e}}})}request(e,t={}){let n=_e(),s=new AbortController;t.signal&&(t.signal.aborted?s.abort(t.signal.reason):t.signal.addEventListener("abort",()=>s.abort(t.signal.reason),{once:!0}));let o=null;if(typeof t.timeout=="number"&&t.timeout>=0){let a=t.timeout;o=setTimeout(()=>s.abort(new j(a,n)),a)}let i=this._consumeResponse(n,e,!1,s.signal);return i.start(),i.body.finally(()=>{o&&clearTimeout(o)})}_consumeResponse(e,t,n,s,o){let i=this.doc(Ot),a=Ut(e);return qt(i,e,t,a,this._streamData.consumerId,n,()=>this.stream(a),s,m=>(this._activeRequests.add(m),()=>this._activeRequests.delete(m)),o??Ve)}requestStream(e,t={}){let n=_e();return this._consumeResponse(n,e,!0,t.signal,t.docSyncTimeout).deltas}complete(e,t={}){let n=_e(),s=this._consumeResponse(n,e,!1,t.signal,t.docSyncTimeout);return s.start(),s.body}disconnect(){let e=Array.from(this._activeRequests);this._activeRequests.clear();for(let t of e)try{t(new F)}catch{}for(let t of this._docs.values())t.dispose();this._docs.clear();for(let t of this._streams.values())t.dispose();this._streams.clear(),this._transport.disconnect()}};var Dt=new Set(["then","catch","finally","toJSON",Symbol.toPrimitive]);function jt(r,e){return new Proxy({},{get(t,n){if(!(Dt.has(n)||typeof n!="string"))return s=>{let o=s??{},i=()=>`s_${Date.now()}_${Math.random().toString(36).slice(2)}`,a=i(),m=new X,f=new ee({url:"",orgId:e.orgId,jwt:e.jwt,authProvider:e.authProvider,sessionId:a}),l=new Y(a,m,f,be(e),N(e)),p=async u=>{let c=await Le({baseUrl:e.baseUrl,fallbackUrls:e.fallbackUrls,app:r,functionName:n,orgId:e.orgId,jwt:e.jwt,getAccessToken:e.getAccessToken,authProvider:e.authProvider,idempotencyKey:u}),h=e.getAccessToken?await e.getAccessToken()??void 0:e.jwt;return l.setSessionId(c.sessionId),l.setArtifactsAuth(N({...e,baseUrl:c.baseUrl})),{url:c.wsUrl,sessionId:c.sessionId,jwt:h,iceServers:c.response.ice_servers}};return f.setConnectionResolver(()=>p(i())),f.on("connected",()=>{f.multiplexer&&m.setTarget(f.multiplexer)}),(async()=>{let u;try{u=await p(a)}catch(c){console.error(`[urun] Failed to create session for ${n}:`,c);let h=c instanceof Error?c:new Error(String(c)),y=c instanceof v?c.httpStatus:void 0;f.reportAllocationFailure(h,y);return}f.setAuth({jwt:u.jwt,authProvider:e.authProvider,orgId:e.orgId}),f.setConnection({url:u.url,sessionId:u.sessionId,iceServers:u.iceServers}),Q()&&await Z(),l.setDocTransport({wsUrl:u.url,token:u.jwt}),await f.connect({app:r,functionName:n,args:o})})().catch(u=>{console.error(`[urun] Failed to connect session for ${n}:`,u)}),l}}})}var Je=3e4,Xe="stream:",ve=class{_ws;_multiplexer;_pendingRpc=new Map;_rpcId=0;constructor(e,t){this._ws=e,this._multiplexer=t,this._ws.addEventListener("message",n=>{let s;try{s=JSON.parse(typeof n.data=="string"?n.data:"")}catch{return}if(s.rpcId&&this._pendingRpc.has(s.rpcId)){let o=this._pendingRpc.get(s.rpcId);this._pendingRpc.delete(s.rpcId),clearTimeout(o.timer),s.error?o.reject(new Error(s.error)):o.resolve(s.result)}})}async get(e){return this._sendRpc("store.get",{key:e})}async has(e){return await this._sendRpc("store.has",{key:e})}on(e,t){let n=`${Xe}${e}`;return this._multiplexer.on(n,s=>{t(s)})}emit(e,t){let n=`${Xe}${e}`,s=typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{data:t};this._multiplexer.emit(n,s)}_getInternals(){return{multiplexer:this._multiplexer,ws:this._ws}}_sendRpc(e,t){return new Promise((n,s)=>{if(!this._ws||this._ws.readyState!==WebSocket.OPEN){s(new Error("WebSocket not open"));return}let o=String(++this._rpcId),i=setTimeout(()=>{this._pendingRpc.has(o)&&(this._pendingRpc.delete(o),s(new Error(`RPC request "${e}" timed out after ${Je}ms`)))},Je);this._pendingRpc.set(o,{resolve:n,reject:s,timer:i}),this._ws.send(JSON.stringify({rpcId:o,type:e,...t}))})}};function Lt(r){let n=`${r.baseUrl.replace(/\/$/,"").replace(/^http/,"ws")}/store/${encodeURIComponent(r.orgId)}`,s=new WebSocket(n);(r.jwt||r.apiKey)&&s.addEventListener("open",()=>{s.send(JSON.stringify({type:"auth",orgId:r.orgId,jwt:r.jwt,authProvider:r.authProvider,apiKey:r.apiKey}))});let o=new Ie(s);return new ve(s,o)}var Bt='video/mp4; codecs="avc1.42E01E"';function Ft(r,e){let t=e?.codec??Bt,n=document.createElement("video");n.muted=!0,n.playsInline=!0;let s=new MediaSource,o=URL.createObjectURL(s);n.src=o,s.addEventListener("sourceopen",()=>{let u;try{u=s.addSourceBuffer(t)}catch(g){throw g instanceof DOMException&&g.name==="NotSupportedError"?new Error(`Codec not supported: "${t}". Ensure the codec string matches the fMP4 container format. Common values: video/mp4; codecs="avc1.42E01E" (H.264 Baseline), video/mp4; codecs="avc1.4D401F" (H.264 Main).`):g}let c=r.getReader();function h(){return u.updating?new Promise(g=>{u.addEventListener("updateend",()=>g(),{once:!0})}):Promise.resolve()}async function y(){try{for(;;){let{done:g,value:T}=await c.read();if(g){await h(),s.readyState==="open"&&s.endOfStream();return}await h();try{u.appendBuffer(T)}catch(P){if(P instanceof DOMException&&P.name==="QuotaExceededError"){let x=u.buffered;if(x.length>0){let $=x.start(x.length-1);u.remove(0,$),await h(),u.appendBuffer(T)}else throw P}else throw P}}}catch{if(s.readyState==="open")try{s.endOfStream("decode")}catch{}}}y()}),n.play().catch(()=>{});let i=n,a=i.captureStream??i.mozCaptureStream;if(!a)throw new Error("captureStream() is not supported in this browser. videoStream() requires HTMLMediaElement.captureStream() support.");let m=a.call(n),f=m.getTracks(),l=0,p=f.length;if(p===0)n.addEventListener("emptied",()=>{URL.revokeObjectURL(o)},{once:!0});else for(let u of f)u.addEventListener("ended",()=>{l++,l>=p&&URL.revokeObjectURL(o)});return m}function Nt(r){return r.status.startsWith("pending_")}export{jt as App,Ve as DEFAULT_DOC_SYNC_TIMEOUT_MS,je as DEFAULT_WHEN_LIVE_TIMEOUT_MS,M as InvalidDurationError,ae as PermanentLockedError,ie as PinRequiresActiveTempError,se as RecordingNotFoundError,q as RecordingsClient,_ as RecordingsError,W as RecordingsUnauthorizedError,U as RequestAbortError,F as RequestCancelledError,L as RequestDocSyncError,S as RequestError,j as RequestTimeoutError,oe as RetainNotTempError,ne as RuntimeArtifactNotFoundError,C as RuntimeArtifactsClient,w as RuntimeArtifactsError,re as RuntimeArtifactsUnauthorizedError,Y as Session,v as SessionAllocationError,b as SessionFailedError,B as StreamDirectionConflict,St as createRecordingsClient,ft as createRuntimeArtifactsClient,Lt as createStore,De as describeSessionFailure,me as isDurationString,Nt as isPendingRecording,ye as mediaRecorderChunkSource,yt as normalizeRetention,tt as sessionFailureFromMediaError,Ft as videoStream,le as whenLive};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as AppOptions, a as App$1, H as SessionPhase, N as SessionStatus, A as AccessTokenOptions, x as RuntimeArtifact, y as RuntimeArtifactDownload, R as Recording, F as SessionDocument, j as DocConnector, Q as SessionText, E as Session$1, C as ChannelEndpoint, X as TransportSession, c as AttachOptions, u as RecordingsAccessor, z as RuntimeArtifactsAccessor, O as SessionStream$1, W as StreamDataTransport, V as StreamChunkOptions, g as ChunkReadable, P as Presence, v as RequestOptions, w as RequestStreamOptions, U as StoreOptions, T as Store, e as ChannelMultiplexer, G as SessionFailureKind } from './stream-data-
|
|
2
|
-
export { L as Layer, k as LayoutConfig, l as LayoutContext, M as MediaChunkBinding, n as MediaChunkSource, o as MediaChunkSourceFactory, p as MediaRecorderChunkSourceOptions, q as PresenceState, r as RecordingBucket, s as RecordingLifecycle, t as RecordingStatus, S as SceneContext, B as SceneGraph, I as SessionPhaseError, J as SessionPhaseName, Z as TransportState, a1 as isPendingRecording, a2 as mediaRecorderChunkSource } from './stream-data-
|
|
1
|
+
import { b as AppOptions, a as App$1, H as SessionPhase, N as SessionStatus, A as AccessTokenOptions, x as RuntimeArtifact, y as RuntimeArtifactDownload, R as Recording, F as SessionDocument, j as DocConnector, Q as SessionText, E as Session$1, C as ChannelEndpoint, X as TransportSession, c as AttachOptions, u as RecordingsAccessor, z as RuntimeArtifactsAccessor, O as SessionStream$1, W as StreamDataTransport, V as StreamChunkOptions, g as ChunkReadable, P as Presence, v as RequestOptions, w as RequestStreamOptions, U as StoreOptions, T as Store, e as ChannelMultiplexer, G as SessionFailureKind } from './stream-data-u76USIkQ.mjs';
|
|
2
|
+
export { L as Layer, k as LayoutConfig, l as LayoutContext, M as MediaChunkBinding, n as MediaChunkSource, o as MediaChunkSourceFactory, p as MediaRecorderChunkSourceOptions, q as PresenceState, r as RecordingBucket, s as RecordingLifecycle, t as RecordingStatus, S as SceneContext, B as SceneGraph, I as SessionPhaseError, J as SessionPhaseName, Z as TransportState, a1 as isPendingRecording, a2 as mediaRecorderChunkSource } from './stream-data-u76USIkQ.mjs';
|
|
3
3
|
import * as Y from 'yjs';
|
|
4
4
|
import { Awareness } from 'y-protocols/awareness';
|
|
5
5
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as AppOptions, a as App$1, H as SessionPhase, N as SessionStatus, A as AccessTokenOptions, x as RuntimeArtifact, y as RuntimeArtifactDownload, R as Recording, F as SessionDocument, j as DocConnector, Q as SessionText, E as Session$1, C as ChannelEndpoint, X as TransportSession, c as AttachOptions, u as RecordingsAccessor, z as RuntimeArtifactsAccessor, O as SessionStream$1, W as StreamDataTransport, V as StreamChunkOptions, g as ChunkReadable, P as Presence, v as RequestOptions, w as RequestStreamOptions, U as StoreOptions, T as Store, e as ChannelMultiplexer, G as SessionFailureKind } from './stream-data-
|
|
2
|
-
export { L as Layer, k as LayoutConfig, l as LayoutContext, M as MediaChunkBinding, n as MediaChunkSource, o as MediaChunkSourceFactory, p as MediaRecorderChunkSourceOptions, q as PresenceState, r as RecordingBucket, s as RecordingLifecycle, t as RecordingStatus, S as SceneContext, B as SceneGraph, I as SessionPhaseError, J as SessionPhaseName, Z as TransportState, a1 as isPendingRecording, a2 as mediaRecorderChunkSource } from './stream-data-
|
|
1
|
+
import { b as AppOptions, a as App$1, H as SessionPhase, N as SessionStatus, A as AccessTokenOptions, x as RuntimeArtifact, y as RuntimeArtifactDownload, R as Recording, F as SessionDocument, j as DocConnector, Q as SessionText, E as Session$1, C as ChannelEndpoint, X as TransportSession, c as AttachOptions, u as RecordingsAccessor, z as RuntimeArtifactsAccessor, O as SessionStream$1, W as StreamDataTransport, V as StreamChunkOptions, g as ChunkReadable, P as Presence, v as RequestOptions, w as RequestStreamOptions, U as StoreOptions, T as Store, e as ChannelMultiplexer, G as SessionFailureKind } from './stream-data-u76USIkQ.js';
|
|
2
|
+
export { L as Layer, k as LayoutConfig, l as LayoutContext, M as MediaChunkBinding, n as MediaChunkSource, o as MediaChunkSourceFactory, p as MediaRecorderChunkSourceOptions, q as PresenceState, r as RecordingBucket, s as RecordingLifecycle, t as RecordingStatus, S as SceneContext, B as SceneGraph, I as SessionPhaseError, J as SessionPhaseName, Z as TransportState, a1 as isPendingRecording, a2 as mediaRecorderChunkSource } from './stream-data-u76USIkQ.js';
|
|
3
3
|
import * as Y from 'yjs';
|
|
4
4
|
import { Awareness } from 'y-protocols/awareness';
|
|
5
5
|
|