@urun-sh/core 0.1.24 → 0.1.25

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/index.mjs CHANGED
@@ -1 +1 @@
1
- import{a as I,b as R,c as E}from"./chunk-X4NT3Y3F.mjs";function y(s,e){let r={...s};for(let t of Object.keys(e)){let n=e[t],o=r[t];n!==null&&typeof n=="object"&&!Array.isArray(n)&&o!==null&&typeof o=="object"&&!Array.isArray(o)?r[t]=y(o,n):r[t]=n}return r}function C(s,e){let r=e.split("."),t=s;for(let n of r){if(t==null||typeof t!="object")return;t=t[n]}return t}var _=class{_state={};_listeners=new Set;_key;_sessionId;_multiplexer;_unsubscribe=null;constructor(e,r,t){this._key=e,this._sessionId=r,this._multiplexer=t,this.subscribe()}setSessionId(e){e!==this._sessionId&&(this._unsubscribe?.(),this._sessionId=e,this.subscribe())}subscribe(){this._unsubscribe=this._multiplexer.on(this._channel,e=>{if(e.type==="doc_update"&&e.patch&&typeof e.patch=="object"){this._state=y(this._state,e.patch);let r={...this._state};for(let t of this._listeners)t(r)}})}get _channel(){return`session:${this._sessionId}:doc:${this._key}`}set(e){this._state=y(this._state,e),this._multiplexer.emit(this._channel,{type:"doc_update",patch:e,snapshot:this._state});let r={...this._state};for(let t of this._listeners)t(r)}get(e,r){return e?C(this._state,e)??r:{...this._state}}on(e,r){return this._listeners.add(r),()=>this._listeners.delete(r)}};var v=class{constructor(e,r){this._name=e;this._transport=r;this._track=this._transport.getTrackByName(this._name)??null,this._unsubscribeTransport=this._transport.on("track",()=>{let t=this._transport.getTrackByName(this._name)??null;t!==this._track&&this._setTrack(t)})}_name;_transport;_track=null;_handlers=new Map;_unsubscribeTransport=null;get track(){let e=this._transport.getTrackByName(this._name)??this._track;return e!==this._track&&this._setTrack(e),this._track}async attach(e){await this._transport.addTrack(e)}async detach(){this._transport.removeTrack()}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)}on(e,r){let t=this._handlers.get(e);return t||(t=new Set,this._handlers.set(e,t)),t.add(r),()=>{t?.delete(r),t?.size===0&&this._handlers.delete(e)}}dispose(){this._unsubscribeTransport?.(),this._unsubscribeTransport=null,this._handlers.clear()}_setTrack(e){this._track=e,e&&e.addEventListener("ended",()=>{this._track===e&&this._setTrack(null)},{once:!0});let r=this._handlers.get("track");if(r)for(let t of r)t(e)}},m=class{_sessionId;_multiplexer;_transport;_docs=new Map;_streams=new Map;constructor(e,r,t){this._sessionId=e,this._multiplexer=r,this._transport=t}get id(){return this._sessionId}setSessionId(e){if(e===this._sessionId)return;this._multiplexer.rewriteSessionChannels?.call(this._multiplexer,this._sessionId,e),this._sessionId=e;for(let t of this._docs.values())t.setSessionId(e)}stream(e){let r=this._streams.get(e);return r||(r=new v(e,this._transport),this._streams.set(e,r)),r}doc(e){let r=this._docs.get(e);return r||(r=new _(e,this._sessionId,this._multiplexer),this._docs.set(e,r)),r}disconnect(){for(let e of this._streams.values())e.dispose();this._streams.clear(),this._transport.disconnect()}};var $="session-api.prod.cloud.urun.sh",j=["https://session-api.use2.prod.cloud.urun.sh","https://session-api.usw2.prod.cloud.urun.sh"];function N(s){return s.trim().replace(/\/+$/,"")}function B(s,e){let r=[],t=n=>{if(!n)return;let o=N(n);o&&!r.includes(o)&&r.push(o)};t(s);for(let n of e??[])t(n);for(let n of V(s))t(n);return r}var F=120,D=2,G=1e3;async function x(s){let e=B(s.baseUrl,s.fallbackUrls),r=null,t=e.length>1;for(let n of e)try{return await q(n,s,{pollAttempts:t?D:F,retryAfterLimitMs:t?G:void 0})}catch(o){if(r=o instanceof Error?o:new Error(String(o)),r instanceof h)throw r}throw r??new Error("[urun] session allocation failed")}async function q(s,e,r){let t,n=await A(e),o=new Set;for(let u=0;u<r.pollAttempts;u++){let a=t?await fetch(`${s}/api/session-requests/${encodeURIComponent(t)}`,{headers:T(e,n)}):await fetch(`${s}/api/sessions/create`,{method:"POST",headers:{...T(e,n),"Content-Type":"application/json","Idempotency-Key":e.idempotencyKey},body:JSON.stringify(K(e))}),i=await z(a);if(a.ok&&(i.status==="allocated"||!i.status&&!!i.session_id)&&!!i.session_id){let l=i.session_id;if(!i.ws_url)throw new h(`[urun] gateway allocated session ${l} without ws_url`);if(!H(i.ws_url))throw new h(`[urun] gateway allocated session ${l} with non-absolute ws_url`);return{baseUrl:s,sessionId:l,wsUrl:i.ws_url,response:i}}if(a.status===202||i.status==="pending"||i.status==="queued"||i.queued){if(t=i.request_id||t,!t)throw new Error("[urun] gateway queued session without request_id");await J(W(a,i,r.retryAfterLimitMs));continue}if((a.status===401||a.status===403)&&e.getAccessToken){let l=n??"";o.add(l);let c=await A(e,{forceRefresh:!0,reason:"unauthorized"});if(c&&!o.has(c)){n=c,t=void 0;continue}}let d=i.error_message||i.error_code||`HTTP ${a.status}`;throw new Error(`[urun] session allocation failed at ${s}: ${d}`)}throw new Error(`[urun] timed out waiting for session allocation at ${s}`)}function T(s,e){let r={"X-Tenant-Id":s.orgId,"X-Auth-Provider":s.authProvider||"default","X-User-Id":"anonymous"};return e&&(r.Authorization=`Bearer ${e}`),r}async function A(s,e){return s.getAccessToken?await s.getAccessToken(e)??void 0:s.jwt}function K(s){let e=Number(s.args?.gpus??1),r={app:s.app,function:s.functionName,gpus:Number.isFinite(e)&&e>0?e:1,idempotency_key:s.idempotencyKey},t=s.args?.preferred_zone;return typeof t=="string"&&t&&(r.preferred_zone=t),r}async function z(s){try{let e=await s.json();return e&&typeof e=="object"?e:{}}catch{return{}}}function W(s,e,r){let t=Number(s.headers.get("Retry-After")||""),n=Number(e.retry_after_seconds??t),o=r??1e4;return Number.isFinite(n)&&n>0?Math.min(n*1e3,o):1e3}function J(s){return new Promise(e=>setTimeout(e,s))}var h=class extends Error{};function H(s){try{let e=new URL(s);return e.protocol==="ws:"||e.protocol==="wss:"}catch{return!1}}function V(s){try{return new URL(s).hostname!==$?[]:j}catch{return[]}}var X=new Set(["then","catch","finally","toJSON",Symbol.toPrimitive]);function Y(s,e){return new Proxy({},{get(r,t){if(!(X.has(t)||typeof t!="string"))return n=>{let o=n??{},u=`s_${Date.now()}_${Math.random().toString(36).slice(2)}`,a=new R,i=new E({url:"",orgId:e.orgId,jwt:e.jwt,authProvider:e.authProvider,sessionId:u}),f=new m(u,a,i);return(async()=>{let d=await x({baseUrl:e.baseUrl,fallbackUrls:e.fallbackUrls,app:s,functionName:t,args:o,orgId:e.orgId,jwt:e.jwt,getAccessToken:e.getAccessToken,authProvider:e.authProvider,idempotencyKey:u}),l=e.getAccessToken?await e.getAccessToken()??void 0:e.jwt;i.setAuth({jwt:l,authProvider:e.authProvider,orgId:e.orgId}),f.setSessionId(d.sessionId),i.setConnection({url:d.wsUrl,sessionId:d.sessionId}),await i.connect({app:s,functionName:t,args:o}),i.multiplexer&&a.setTarget(i.multiplexer)})().catch(d=>{console.error(`[urun] Failed to connect session for ${t}:`,d)}),f}}})}var P=3e4,M="stream:",k=class{_ws;_multiplexer;_pendingRpc=new Map;_rpcId=0;constructor(e,r){this._ws=e,this._multiplexer=r,this._ws.addEventListener("message",t=>{let n;try{n=JSON.parse(typeof t.data=="string"?t.data:"")}catch{return}if(n.rpcId&&this._pendingRpc.has(n.rpcId)){let o=this._pendingRpc.get(n.rpcId);this._pendingRpc.delete(n.rpcId),clearTimeout(o.timer),n.error?o.reject(new Error(n.error)):o.resolve(n.result)}})}async get(e){return this._sendRpc("store.get",{key:e})}async has(e){return await this._sendRpc("store.has",{key:e})}on(e,r){let t=`${M}${e}`;return this._multiplexer.on(t,n=>{r(n)})}emit(e,r){let t=`${M}${e}`,n=typeof r=="object"&&r!==null&&!Array.isArray(r)?r:{data:r};this._multiplexer.emit(t,n)}_getInternals(){return{multiplexer:this._multiplexer,ws:this._ws}}_sendRpc(e,r){return new Promise((t,n)=>{if(!this._ws||this._ws.readyState!==WebSocket.OPEN){n(new Error("WebSocket not open"));return}let o=String(++this._rpcId),u=setTimeout(()=>{this._pendingRpc.has(o)&&(this._pendingRpc.delete(o),n(new Error(`RPC request "${e}" timed out after ${P}ms`)))},P);this._pendingRpc.set(o,{resolve:t,reject:n,timer:u}),this._ws.send(JSON.stringify({rpcId:o,type:e,...r}))})}};function Q(s){let t=`${s.baseUrl.replace(/\/$/,"").replace(/^http/,"ws")}/store/${encodeURIComponent(s.orgId)}`,n=new WebSocket(t);(s.jwt||s.apiKey)&&n.addEventListener("open",()=>{n.send(JSON.stringify({type:"auth",orgId:s.orgId,jwt:s.jwt,authProvider:s.authProvider,apiKey:s.apiKey}))});let o=new I(n);return new k(n,o)}var Z='video/mp4; codecs="avc1.42E01E"';function ee(s,e){let r=e?.codec??Z,t=document.createElement("video");t.muted=!0,t.playsInline=!0;let n=new MediaSource,o=URL.createObjectURL(n);t.src=o,n.addEventListener("sourceopen",()=>{let c;try{c=n.addSourceBuffer(r)}catch(p){throw p instanceof DOMException&&p.name==="NotSupportedError"?new Error(`Codec not supported: "${r}". 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).`):p}let O=s.getReader();function w(){return c.updating?new Promise(p=>{c.addEventListener("updateend",()=>p(),{once:!0})}):Promise.resolve()}async function L(){try{for(;;){let{done:p,value:b}=await O.read();if(p){await w(),n.readyState==="open"&&n.endOfStream();return}await w();try{c.appendBuffer(b)}catch(g){if(g instanceof DOMException&&g.name==="QuotaExceededError"){let S=c.buffered;if(S.length>0){let U=S.start(S.length-1);c.remove(0,U),await w(),c.appendBuffer(b)}else throw g}else throw g}}}catch{if(n.readyState==="open")try{n.endOfStream("decode")}catch{}}}L()}),t.play().catch(()=>{});let u=t,a=u.captureStream??u.mozCaptureStream;if(!a)throw new Error("captureStream() is not supported in this browser. videoStream() requires HTMLMediaElement.captureStream() support.");let i=a.call(t),f=i.getTracks(),d=0,l=f.length;if(l===0)t.addEventListener("emptied",()=>{URL.revokeObjectURL(o)},{once:!0});else for(let c of f)c.addEventListener("ended",()=>{d++,d>=l&&URL.revokeObjectURL(o)});return i}export{Y as App,m as Session,Q as createStore,ee as videoStream};
1
+ import{a as R,b as T,c as E}from"./chunk-WWA2JABQ.mjs";function v(s,e){let r={...s};for(let t of Object.keys(e)){let n=e[t],o=r[t];n!==null&&typeof n=="object"&&!Array.isArray(n)&&o!==null&&typeof o=="object"&&!Array.isArray(o)?r[t]=v(o,n):r[t]=n}return r}function U(s,e){let r=e.split("."),t=s;for(let n of r){if(t==null||typeof t!="object")return;t=t[n]}return t}var S=class{_state={};_listeners=new Set;_key;_sessionId;_multiplexer;_unsubscribe=null;constructor(e,r,t){this._key=e,this._sessionId=r,this._multiplexer=t,this.subscribe()}setSessionId(e){e!==this._sessionId&&(this._unsubscribe?.(),this._sessionId=e,this.subscribe())}subscribe(){this._unsubscribe=this._multiplexer.on(this._channel,e=>{if(e.type==="doc_update"&&e.patch&&typeof e.patch=="object"){this._state=v(this._state,e.patch);let r={...this._state};for(let t of this._listeners)t(r)}})}get _channel(){return`session:${this._sessionId}:doc:${this._key}`}set(e){this._state=v(this._state,e),this._multiplexer.emit(this._channel,{type:"doc_update",patch:e,snapshot:this._state});let r={...this._state};for(let t of this._listeners)t(r)}get(e,r){return e?U(this._state,e)??r:{...this._state}}on(e,r){return this._listeners.add(r),()=>this._listeners.delete(r)}};var k=class{constructor(e,r){this._name=e;this._transport=r;this._track=this._transport.getTrackByName(this._name)??null,this._unsubscribeTransport=this._transport.on("track",()=>{let t=this._transport.getTrackByName(this._name)??null;t!==this._track&&this._setTrack(t)})}_name;_transport;_track=null;_handlers=new Map;_unsubscribeTransport=null;get track(){let e=this._transport.getTrackByName(this._name)??this._track;return e!==this._track&&this._setTrack(e),this._track}async attach(e){await this._transport.addTrack(e)}async detach(){this._transport.removeTrack()}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)}on(e,r){let t=this._handlers.get(e);return t||(t=new Set,this._handlers.set(e,t)),t.add(r),()=>{t?.delete(r),t?.size===0&&this._handlers.delete(e)}}dispose(){this._unsubscribeTransport?.(),this._unsubscribeTransport=null,this._handlers.clear()}_setTrack(e){this._track=e,e&&e.addEventListener("ended",()=>{this._track===e&&this._setTrack(null)},{once:!0});let r=this._handlers.get("track");if(r)for(let t of r)t(e)}},g=class{_sessionId;_multiplexer;_transport;_docs=new Map;_streams=new Map;constructor(e,r,t){this._sessionId=e,this._multiplexer=r,this._transport=t}get id(){return this._sessionId}setSessionId(e){if(e===this._sessionId)return;this._multiplexer.rewriteSessionChannels?.call(this._multiplexer,this._sessionId,e),this._sessionId=e;for(let t of this._docs.values())t.setSessionId(e)}stream(e){let r=this._streams.get(e);return r||(r=new k(e,this._transport),this._streams.set(e,r)),r}doc(e){let r=this._docs.get(e);return r||(r=new S(e,this._sessionId,this._multiplexer),this._docs.set(e,r)),r}disconnect(){for(let e of this._streams.values())e.dispose();this._streams.clear(),this._transport.disconnect()}};var j="session-api.prod.cloud.urun.sh",$=["https://session-api.use2.prod.cloud.urun.sh","https://session-api.usw2.prod.cloud.urun.sh"];function N(s){return s.trim().replace(/\/+$/,"")}function B(s,e){let r=[],t=n=>{if(!n)return;let o=N(n);o&&!r.includes(o)&&r.push(o)};t(s);for(let n of e??[])t(n);for(let n of V(s))t(n);return r}var F=120,D=2,G=1e3;async function P(s){let e=B(s.baseUrl,s.fallbackUrls),r=null,t=e.length>1;for(let n of e)try{return await q(n,s,{pollAttempts:t?D:F,retryAfterLimitMs:t?G:void 0})}catch(o){if(r=o instanceof Error?o:new Error(String(o)),r instanceof w)throw r}throw r??new Error("[urun] session allocation failed")}async function q(s,e,r){let t,n=await x(e),o=new Set;for(let d=0;d<r.pollAttempts;d++){let c=t?await fetch(`${s}/api/session-requests/${encodeURIComponent(t)}`,{headers:A(e,n)}):await fetch(`${s}/api/sessions/create`,{method:"POST",headers:{...A(e,n),"Content-Type":"application/json","Idempotency-Key":e.idempotencyKey},body:JSON.stringify(K(e))}),i=await z(c);if(c.ok&&(i.status==="allocated"||!i.status&&!!i.session_id)&&!!i.session_id){let l=i.session_id;if(!i.ws_url)throw new w(`[urun] gateway allocated session ${l} without ws_url`);if(!H(i.ws_url))throw new w(`[urun] gateway allocated session ${l} with non-absolute ws_url`);return{baseUrl:s,sessionId:l,wsUrl:i.ws_url,response:i}}if(c.status===202||i.status==="pending"||i.status==="queued"||i.queued){if(t=i.request_id||t,!t)throw new Error("[urun] gateway queued session without request_id");await J(W(c,i,r.retryAfterLimitMs));continue}if((c.status===401||c.status===403)&&e.getAccessToken){let l=n??"";o.add(l);let a=await x(e,{forceRefresh:!0,reason:"unauthorized"});if(a&&!o.has(a)){n=a,t=void 0;continue}}let m=i.error_message||i.error_code||`HTTP ${c.status}`;throw new Error(`[urun] session allocation failed at ${s}: ${m}`)}throw new Error(`[urun] timed out waiting for session allocation at ${s}`)}function A(s,e){let r={"X-Tenant-Id":s.orgId,"X-Auth-Provider":s.authProvider||"default","X-User-Id":"anonymous"};return e&&(r.Authorization=`Bearer ${e}`),r}async function x(s,e){return s.getAccessToken?await s.getAccessToken(e)??void 0:s.jwt}function K(s){let e=Number(s.args?.gpus??1),r={app:s.app,function:s.functionName,gpus:Number.isFinite(e)&&e>0?e:1,idempotency_key:s.idempotencyKey},t=s.args?.preferred_zone;return typeof t=="string"&&t&&(r.preferred_zone=t),r}async function z(s){try{let e=await s.json();return e&&typeof e=="object"?e:{}}catch{return{}}}function W(s,e,r){let t=Number(s.headers.get("Retry-After")||""),n=Number(e.retry_after_seconds??t),o=r??1e4;return Number.isFinite(n)&&n>0?Math.min(n*1e3,o):1e3}function J(s){return new Promise(e=>setTimeout(e,s))}var w=class extends Error{};function H(s){try{let e=new URL(s);return e.protocol==="ws:"||e.protocol==="wss:"}catch{return!1}}function V(s){try{return new URL(s).hostname!==j?[]:$}catch{return[]}}var X=new Set(["then","catch","finally","toJSON",Symbol.toPrimitive]);function Y(s,e){return new Proxy({},{get(r,t){if(!(X.has(t)||typeof t!="string"))return n=>{let o=n??{},d=()=>`s_${Date.now()}_${Math.random().toString(36).slice(2)}`,c=d(),i=new T,u=new E({url:"",orgId:e.orgId,jwt:e.jwt,authProvider:e.authProvider,sessionId:c}),m=new g(c,i,u),l=async a=>{let f=await P({baseUrl:e.baseUrl,fallbackUrls:e.fallbackUrls,app:s,functionName:t,args:o,orgId:e.orgId,jwt:e.jwt,getAccessToken:e.getAccessToken,authProvider:e.authProvider,idempotencyKey:a}),h=e.getAccessToken?await e.getAccessToken()??void 0:e.jwt;return m.setSessionId(f.sessionId),{url:f.wsUrl,sessionId:f.sessionId,jwt:h}};return u.setConnectionResolver(()=>l(d())),u.on("connected",()=>{u.multiplexer&&i.setTarget(u.multiplexer)}),(async()=>{let a=await l(c);u.setAuth({jwt:a.jwt,authProvider:e.authProvider,orgId:e.orgId}),u.setConnection({url:a.url,sessionId:a.sessionId}),await u.connect({app:s,functionName:t,args:o})})().catch(a=>{console.error(`[urun] Failed to connect session for ${t}:`,a)}),m}}})}var M=3e4,O="stream:",b=class{_ws;_multiplexer;_pendingRpc=new Map;_rpcId=0;constructor(e,r){this._ws=e,this._multiplexer=r,this._ws.addEventListener("message",t=>{let n;try{n=JSON.parse(typeof t.data=="string"?t.data:"")}catch{return}if(n.rpcId&&this._pendingRpc.has(n.rpcId)){let o=this._pendingRpc.get(n.rpcId);this._pendingRpc.delete(n.rpcId),clearTimeout(o.timer),n.error?o.reject(new Error(n.error)):o.resolve(n.result)}})}async get(e){return this._sendRpc("store.get",{key:e})}async has(e){return await this._sendRpc("store.has",{key:e})}on(e,r){let t=`${O}${e}`;return this._multiplexer.on(t,n=>{r(n)})}emit(e,r){let t=`${O}${e}`,n=typeof r=="object"&&r!==null&&!Array.isArray(r)?r:{data:r};this._multiplexer.emit(t,n)}_getInternals(){return{multiplexer:this._multiplexer,ws:this._ws}}_sendRpc(e,r){return new Promise((t,n)=>{if(!this._ws||this._ws.readyState!==WebSocket.OPEN){n(new Error("WebSocket not open"));return}let o=String(++this._rpcId),d=setTimeout(()=>{this._pendingRpc.has(o)&&(this._pendingRpc.delete(o),n(new Error(`RPC request "${e}" timed out after ${M}ms`)))},M);this._pendingRpc.set(o,{resolve:t,reject:n,timer:d}),this._ws.send(JSON.stringify({rpcId:o,type:e,...r}))})}};function Q(s){let t=`${s.baseUrl.replace(/\/$/,"").replace(/^http/,"ws")}/store/${encodeURIComponent(s.orgId)}`,n=new WebSocket(t);(s.jwt||s.apiKey)&&n.addEventListener("open",()=>{n.send(JSON.stringify({type:"auth",orgId:s.orgId,jwt:s.jwt,authProvider:s.authProvider,apiKey:s.apiKey}))});let o=new R(n);return new b(n,o)}var Z='video/mp4; codecs="avc1.42E01E"';function ee(s,e){let r=e?.codec??Z,t=document.createElement("video");t.muted=!0,t.playsInline=!0;let n=new MediaSource,o=URL.createObjectURL(n);t.src=o,n.addEventListener("sourceopen",()=>{let a;try{a=n.addSourceBuffer(r)}catch(p){throw p instanceof DOMException&&p.name==="NotSupportedError"?new Error(`Codec not supported: "${r}". 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).`):p}let f=s.getReader();function h(){return a.updating?new Promise(p=>{a.addEventListener("updateend",()=>p(),{once:!0})}):Promise.resolve()}async function C(){try{for(;;){let{done:p,value:I}=await f.read();if(p){await h(),n.readyState==="open"&&n.endOfStream();return}await h();try{a.appendBuffer(I)}catch(_){if(_ instanceof DOMException&&_.name==="QuotaExceededError"){let y=a.buffered;if(y.length>0){let L=y.start(y.length-1);a.remove(0,L),await h(),a.appendBuffer(I)}else throw _}else throw _}}}catch{if(n.readyState==="open")try{n.endOfStream("decode")}catch{}}}C()}),t.play().catch(()=>{});let d=t,c=d.captureStream??d.mozCaptureStream;if(!c)throw new Error("captureStream() is not supported in this browser. videoStream() requires HTMLMediaElement.captureStream() support.");let i=c.call(t),u=i.getTracks(),m=0,l=u.length;if(l===0)t.addEventListener("emptied",()=>{URL.revokeObjectURL(o)},{once:!0});else for(let a of u)a.addEventListener("ended",()=>{m++,m>=l&&URL.revokeObjectURL(o)});return i}export{Y as App,g as Session,Q as createStore,ee as videoStream};
@@ -197,6 +197,11 @@ declare class ChannelMultiplexer implements ChannelEndpoint {
197
197
  private listenForOpen;
198
198
  }
199
199
 
200
+ interface TransportConnection {
201
+ url: string;
202
+ sessionId: string;
203
+ jwt?: string;
204
+ }
200
205
  interface TransportEvents {
201
206
  connected: () => void;
202
207
  disconnected: () => void;
@@ -237,6 +242,8 @@ declare class TransportSession {
237
242
  private _intentionalDisconnect;
238
243
  private _reconnectTimer;
239
244
  private _generation;
245
+ private _lastStartOptions;
246
+ private _resolveConnection;
240
247
  get state(): TransportState;
241
248
  get sessionId(): string | null;
242
249
  get tracks(): Map<string, MediaStreamTrack>;
@@ -247,6 +254,7 @@ declare class TransportSession {
247
254
  setAuth(options: Pick<TransportSessionOptions, 'orgId' | 'jwt' | 'authProvider'>): void;
248
255
  constructor(options?: TransportSessionOptions);
249
256
  setConnection(options: Pick<TransportSessionOptions, 'url' | 'fallbackUrls' | 'sessionId'>): void;
257
+ setConnectionResolver(resolveConnection: (() => Promise<TransportConnection>) | null): void;
250
258
  connect(startOptions?: SessionStartOptions): Promise<void>;
251
259
  disconnect(): void;
252
260
  on<E extends keyof TransportEvents>(event: E, handler: TransportEvents[E]): () => void;
@@ -197,6 +197,11 @@ declare class ChannelMultiplexer implements ChannelEndpoint {
197
197
  private listenForOpen;
198
198
  }
199
199
 
200
+ interface TransportConnection {
201
+ url: string;
202
+ sessionId: string;
203
+ jwt?: string;
204
+ }
200
205
  interface TransportEvents {
201
206
  connected: () => void;
202
207
  disconnected: () => void;
@@ -237,6 +242,8 @@ declare class TransportSession {
237
242
  private _intentionalDisconnect;
238
243
  private _reconnectTimer;
239
244
  private _generation;
245
+ private _lastStartOptions;
246
+ private _resolveConnection;
240
247
  get state(): TransportState;
241
248
  get sessionId(): string | null;
242
249
  get tracks(): Map<string, MediaStreamTrack>;
@@ -247,6 +254,7 @@ declare class TransportSession {
247
254
  setAuth(options: Pick<TransportSessionOptions, 'orgId' | 'jwt' | 'authProvider'>): void;
248
255
  constructor(options?: TransportSessionOptions);
249
256
  setConnection(options: Pick<TransportSessionOptions, 'url' | 'fallbackUrls' | 'sessionId'>): void;
257
+ setConnectionResolver(resolveConnection: (() => Promise<TransportConnection>) | null): void;
250
258
  connect(startOptions?: SessionStartOptions): Promise<void>;
251
259
  disconnect(): void;
252
260
  on<E extends keyof TransportEvents>(event: E, handler: TransportEvents[E]): () => void;
@@ -1 +1 @@
1
- export { b as ChannelMessage, c as ChannelMultiplexer, d as ChannelName, j as SessionStartOptions, T as TransportSession, n as TransportSessionOptions } from './internal-BdJ_07DT.mjs';
1
+ export { b as ChannelMessage, c as ChannelMultiplexer, d as ChannelName, j as SessionStartOptions, T as TransportSession, n as TransportSessionOptions } from './internal-Cg-H8Adt.mjs';
@@ -1 +1 @@
1
- export { b as ChannelMessage, c as ChannelMultiplexer, d as ChannelName, j as SessionStartOptions, T as TransportSession, n as TransportSessionOptions } from './internal-BdJ_07DT.js';
1
+ export { b as ChannelMessage, c as ChannelMultiplexer, d as ChannelName, j as SessionStartOptions, T as TransportSession, n as TransportSessionOptions } from './internal-Cg-H8Adt.js';