openrtc 3.1.0 → 3.1.1

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.
Files changed (31) hide show
  1. package/dist/{WasmBridge-CJNESUGJ.js → WasmBridge-3HYLCY5Y.js} +1 -1
  2. package/dist/{chunk-LVLU4YQY.js → chunk-AZ74VBU2.js} +1 -1
  3. package/dist/{chunk-RLPWFHOY.js → chunk-IVNXIG7J.js} +1 -1
  4. package/dist/{chunk-5LNRJE6L.js → chunk-KN7DF3NH.js} +1 -1
  5. package/dist/{chunk-SADNIMUO.js → chunk-M4KL5XZU.js} +1 -1
  6. package/dist/{chunk-5LO6PLWZ.js → chunk-PA4WT4QM.js} +1 -1
  7. package/dist/{chunk-VARKDQGM.js → chunk-TSMMRR5V.js} +1 -1
  8. package/dist/chunk-WTOA6B2A.js +2 -0
  9. package/dist/coreClient.js +1 -1
  10. package/dist/{deviceHandle-Y2XA57WF.js → deviceHandle-URNIFFXC.js} +1 -1
  11. package/dist/external-broadcast.js +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/{ipcFactory-F75IXEIE.js → ipcFactory-6XD3J2UU.js} +1 -1
  14. package/dist/native.js +1 -1
  15. package/dist/node.js +2 -2
  16. package/dist/{room-E4NRHQFD.js → room-7ZEAAY7Z.js} +1 -1
  17. package/dist/runtime/WasmRuntimeAdapter.js +1 -1
  18. package/dist/runtime/factories.js +1 -1
  19. package/dist/runtime/index.js +1 -1
  20. package/dist/server.js +1 -1
  21. package/dist/service-node.js +1 -1
  22. package/dist/testing/native.js +1 -1
  23. package/dist/testing.js +1 -1
  24. package/native/darwin-arm64/openrtc-node-host +0 -0
  25. package/native/darwin-arm64/openrtc-node-host.manifest.json +4 -4
  26. package/native/darwin-x64/openrtc-node-host +0 -0
  27. package/native/darwin-x64/openrtc-node-host.manifest.json +4 -4
  28. package/native/linux-x64/openrtc-node-host +0 -0
  29. package/native/linux-x64/openrtc-node-host.manifest.json +4 -4
  30. package/package.json +1 -1
  31. package/dist/chunk-L4HWDDXL.js +0 -2
@@ -1 +1 @@
1
- import {h,e,g,f}from'./chunk-5LNRJE6L.js';import'./chunk-FKAQDDUM.js';import'./chunk-RLPWFHOY.js';import {a}from'./chunk-IUU6JCLK.js';import'./chunk-CCCYE3XN.js';import'./chunk-JPBW67B3.js';import {b}from'./chunk-ZA44REGI.js';import'./chunk-L7N4T2PX.js';import'./chunk-72MN7BNQ.js';import'./chunk-2GX6GB6L.js';function D(r){let e=r.architecture??(r.advancedFanout===true?"sparse":"auto");if(r.advancedFanout===true&&e!=="sparse")throw new Error("[OpenRTC] advancedFanout conflicts with architecture; use architecture: sparse only.");return {architecture:e,delivery:r.payload??(r.advancedFanout===true?"latest-state":"reliable")}}var R=class{constructor(e){this.mode=e==="sparse"?"sparse":"direct";}create(e){return new w(e,()=>this.mode)}setArchitecture(e){e.phase==="settled"&&(this.mode=e.effective==="sparse"?"sparse":e.effective==="managed"?"managed":"direct");}},w=class{constructor(e,t){this.host=e;this.mode=t;this.stateSenders=new Map;this.sparseForwardQueue=[];this.sparseForwardRunning=false;this.sparseForwardQueueDropsPending=0;this.sparseForwardDropReport=null;this.closed=false;let i=e.client.advanced.runtime.onManagedRoomMessage;this.stopManagedMessage=typeof i=="function"?i.call(e.client.advanced.runtime,o=>{e.deliver(o.senderId,o.payload,o.channel);}):()=>{};}isSparse(){return this.mode()==="sparse"}publishState(e,t){if(this.mode()!=="managed")return false;let i=this.stateSenders.get(e);return i||(i=new a(o=>this.publishManaged(e,o)),this.stateSenders.set(e,i)),i.send(t).catch(()=>{}),true}async sendChannel(e,t){let i=this.mode();if(i==="managed")return await this.publishManaged(e,t),true;if(i!=="sparse")return false;let o=this.host.connections();if(o.length===0)return true;let a=await this.host.client.advanced.runtime.encodeSparseFanoutMessage(this.host.capabilityKey,t);return await Promise.all(o.map(n=>n.send(a))),true}assertTargetedSendAllowed(){if(this.mode()==="managed")throw new Error("[OpenRTC] Targeted messages are not available in managed fanout rooms; use authority mode for targeted request semantics.")}receive(e,t,i){return this.mode()!=="sparse"?false:(i instanceof Uint8Array&&this.receiveSparseBroadcast(e,t,i),true)}close(){if(!this.closed){this.closed=true,this.stopManagedMessage();for(let e of this.stateSenders.values())e.close();this.stateSenders.clear(),this.sparseForwardQueue.length=0;}}publishManaged(e,t){return this.host.client.advanced.runtime.publishManagedRoomMessage({messageId:crypto.randomUUID(),channel:e,priority:1,payload:t})}async receiveSparseBroadcast(e,t,i){let o;try{o=await this.host.client.advanced.runtime.acceptSparseFanoutMessage(this.host.capabilityKey,t,i);}catch{return}if(o.forward){let a=Number.isSafeInteger(o.forwardPeerLimit)&&o.forwardPeerLimit>0?o.forwardPeerLimit:0,n=Number.isSafeInteger(o.forwardQueueCapacity)&&o.forwardQueueCapacity>0?Math.min(o.forwardQueueCapacity,64):0,d=new Set(Array.isArray(o.forwardPeerIds)?o.forwardPeerIds.slice(0,a):[]),s=this.host.connections().filter(u=>u.id!==e.id).filter(u=>d.has(u.remoteNodeId)).slice(0,a);this.enqueueSparseForward(o.forward,s,n);}this.host.deliver(o.authorDeviceId,o.payload);}enqueueSparseForward(e,t,i){if(i===0||t.length===0||this.closed)return;if(this.sparseForwardQueue.length+(this.sparseForwardRunning?1:0)>=i){this.sparseForwardQueueDropsPending+=1,this.flushSparseForwardDropReport();return}this.sparseForwardQueue.push({payload:e,targets:t}),this.sparseForwardRunning||this.drainSparseForwardQueue();}async drainSparseForwardQueue(){if(!this.sparseForwardRunning){this.sparseForwardRunning=true;try{for(;!this.closed;){let e=this.sparseForwardQueue.shift();if(!e)break;await Promise.allSettled(e.targets.map(t=>t.send(e.payload)));}}finally{this.sparseForwardRunning=false,!this.closed&&this.sparseForwardQueue.length>0&&this.drainSparseForwardQueue();}}}flushSparseForwardDropReport(){if(this.sparseForwardDropReport||this.sparseForwardQueueDropsPending===0)return;let e=this.sparseForwardQueueDropsPending;this.sparseForwardQueueDropsPending=0,this.sparseForwardDropReport=this.host.client.advanced.runtime.recordSparseFanoutForwardQueueDrop(this.host.capabilityKey,e).catch(()=>{}).finally(()=>{this.sparseForwardDropReport=null,this.flushSparseForwardDropReport();});}};function F(r){return Object.freeze(r.filter(e=>!!(e.deviceId||e.nodeId)).map(e=>Object.freeze({deviceId:e.deviceId||e.nodeId,...e.nodeId?{nodeId:e.nodeId}:{},...typeof e.userId=="string"?{userId:e.userId}:{},...Number.isFinite(e.joinedAt)?{joinedAt:e.joinedAt}:{}})))}var y=class extends h{constructor(t,i,o,a,n,d="auto"){let s=new R(d);super("room",t,i,o,s);this.membership=a;this.onLeave=n;this.kind="room";this.left=false;this.memberWatches=new Map;this.members={list:async()=>{if(this.closed)return [];let t=await this.client.rooms.members(this.id);return this.closed?[]:F(t)},watch:t=>{if(this.closed)return t([]),()=>{};let i=true,o=this.client.rooms.watch(this.id,n=>{i&&!this.closed&&t(F(n));}),a=()=>{i&&(i=false,this.memberWatches.delete(a),o());};return this.memberWatches.set(a,t),a}};this.architectureListeners=new Set;this.authorityAssignmentSnapshot=null;this.authorityAssignmentListeners=new Set;this.architectureSnapshot=Q(d);let u=i.advanced.runtime.onRoomArchitectureChange;this.stopArchitecture=typeof u=="function"?u.call(i.advanced.runtime,c=>{if(!(c.epoch<this.architectureSnapshot.epoch)){this.architectureSnapshot=Object.freeze({...c}),this.setArchitecture(c);for(let h of this.architectureListeners)h(this.architectureSnapshot);}}):()=>{};let l=i.advanced.runtime.onRoomAuthorityAssignmentChange;this.stopAuthorityAssignment=typeof l=="function"?l.call(i.advanced.runtime,c=>{this.authorityAssignmentSnapshot=c?E(c):null;for(let h of this.authorityAssignmentListeners)h(M(this.authorityAssignmentSnapshot));}):()=>{};}architecture(){return {...this.architectureSnapshot}}onArchitectureChanged(t){return this.architectureListeners.add(t),t(this.architecture()),()=>this.architectureListeners.delete(t)}authorityAssignment(){return M(this.authorityAssignmentSnapshot)}onAuthorityAssignmentChanged(t){return this.authorityAssignmentListeners.add(t),t(this.authorityAssignment()),()=>this.authorityAssignmentListeners.delete(t)}async leave(){this.left||(this.left=true,await this.onLeave?.()),await this.close();}async close(){this.fenceProductAccess();let t=[...this.memberWatches];this.memberWatches.clear();for(let[i,o]of t)i(),o([]);this.stopArchitecture(),this.stopAuthorityAssignment(),this.architectureListeners.clear(),this.authorityAssignmentListeners.clear(),await super.close();}};async function j(r,e$1,t){r.assertOpen();let i=e(e$1),o=t.access??"capability",{architecture:a,delivery:n}=D(t);return r.activateOnce(`room:${i}`,JSON.stringify({access:o,membership:t.membership??"ephemeral",identity:t.identity??null,maxPeers:t.maxPeers??null,payload:n,architecture:a,advancedFanout:t.advancedFanout===true}),o==="authenticated"?t.auth??r.options.auth:void 0,()=>x(r,i,t,a,n))}async function x(r,e,t,i,o){let a=t.membership??"ephemeral",n=t.access??"capability";if(i==="sparse"&&o!=="latest-state")throw new Error("[OpenRTC] Sparse rooms require payload: latest-state.");if(a==="durable"&&n!=="authenticated")throw new Error("[OpenRTC] Durable room membership requires access: authenticated.");if(t.identity==="session"&&n!=="capability")throw new Error("[OpenRTC] Session room identity requires access: capability.");if(n==="authenticated"){let h=t.auth??r.options.auth;if(!h)throw new Error("[OpenRTC] Authenticated rooms require an auth provider.");let A=await r.deviceId(),v=await r.controlPlane(),m=await v.deviceCertificate(h,A,{kind:"room",id:e});a==="durable"&&await v.durableRoomMembership(m.source,e,"join");let f;try{f=await r.activate({kind:"room",id:e,source:m.source,principalId:m.principalId,deviceId:A,maxPeers:t.maxPeers,autoConnect:!0,durableMembership:a==="durable",advancedFanout:t.advancedFanout,architecture:i,defaultDelivery:o});}catch(O){throw a==="durable"&&await v.durableRoomMembership(m.source,e,"leave").catch(()=>{}),O}let g;return g=new y(e,f,()=>{r.channels.detach(f),r.onClosed(g);},a,a==="durable"?async()=>{await v.durableRoomMembership(m.source,e,"leave");}:void 0,i),r.trackHandle(g)}let d=await(t.identity==="session"?r.sessionPlane():r.controlPlane()),s=await d.capability("room",e,t.maxPeers,t.advancedFanout,i,o),u=String(b(s.token).principalId),l=await r.activate({kind:"room",id:e,source:s,principalId:u,deviceId:g(s),maxPeers:t.maxPeers,autoConnect:true,advancedFanout:t.advancedFanout,architecture:i,defaultDelivery:o,controlPlane:d}),c;return c=new y(e,l,()=>{r.channels.detach(l),r.onClosed(c);},"ephemeral",void 0,i),r.trackHandle(c)}function z(r,e$1){r.assertOpen();let t=e(e$1.roomId),i=e(e$1.serviceId),o=f(e$1.deviceId);if(!Number.isSafeInteger(e$1.generation)||e$1.generation<1)throw new Error("[OpenRTC] Authority service generation is invalid.");let a=[...e$1.shardIds].map(e).sort();if(a.length<1||a.length>64||new Set(a).size!==a.length)throw new Error("[OpenRTC] Authority service shards are invalid.");if(!/^[A-Za-z0-9_-]{43}$/.test(e$1.devicePublicKeyX))throw new Error("[OpenRTC] Authority service device public key is invalid.");if(!/^[A-Za-z0-9_-]{43}$/.test(e$1.assignmentPublicKeyX))throw new Error("[OpenRTC] Authority assignment public key is invalid.");if(e$1.maxPeers!==void 0&&(!Number.isSafeInteger(e$1.maxPeers)||e$1.maxPeers<1||e$1.maxPeers>50))throw new Error("[OpenRTC] Authority service maxPeers must be within 1..50.");return r.activateOnce(`room:${t}`,JSON.stringify({architecture:"authority",serviceId:i,generation:e$1.generation,shardIds:a,deviceId:o,maxPeers:e$1.maxPeers??null,irohRelay:e$1.irohRelay,devicePublicKeyX:e$1.devicePublicKeyX,assignmentPublicKeyX:e$1.assignmentPublicKeyX,deviceSignerId:r.authorityCallableId(e$1.deviceSign),grantProviderId:r.authorityCallableId(e$1.grantProvider)}),void 0,async()=>{let n={type:"capability",token:"",avenue:{kind:"room",id:t},expiresAtMs:Number.MAX_SAFE_INTEGER,irohRelay:e$1.irohRelay,managedTurn:false},d=await r.activate({kind:"room",id:t,source:n,principalId:i,deviceId:o,maxPeers:e$1.maxPeers,autoConnect:true,architecture:"authority",defaultDelivery:"reliable",authority:{serviceId:i,generation:e$1.generation,shardIds:a,deviceId:o,irohRelay:e$1.irohRelay,devicePublicKeyX:e$1.devicePublicKeyX,assignmentPublicKeyX:e$1.assignmentPublicKeyX,deviceSign:e$1.deviceSign,grantProvider:e$1.grantProvider}}),s;return s=new y(t,d,()=>{r.channels.detach(d),r.onClosed(s);},"ephemeral",void 0,"authority"),r.trackHandle(s)})}function E(r){return Object.freeze({...r,priorityDeviceIds:Object.freeze([...r.priorityDeviceIds]),relevantEntityIds:Object.freeze([...r.relevantEntityIds])})}function M(r){return r?{...r,priorityDeviceIds:[...r.priorityDeviceIds],relevantEntityIds:[...r.relevantEntityIds]}:null}function Q(r){return {requested:r,effective:r==="sparse"?"sparse":"mesh",epoch:0,phase:r==="mesh"||r==="sparse"?"settled":"preparing",reason:r==="auto"?"size":"manual"}}export{y as RoomHandle,j as joinRoom,z as openAuthorityRoom,D as resolveRoomJoinOptions};
1
+ import {h,e,g,f}from'./chunk-KN7DF3NH.js';import'./chunk-FKAQDDUM.js';import'./chunk-IVNXIG7J.js';import {a}from'./chunk-IUU6JCLK.js';import'./chunk-CCCYE3XN.js';import'./chunk-JPBW67B3.js';import {b}from'./chunk-ZA44REGI.js';import'./chunk-L7N4T2PX.js';import'./chunk-72MN7BNQ.js';import'./chunk-2GX6GB6L.js';function D(r){let e=r.architecture??(r.advancedFanout===true?"sparse":"auto");if(r.advancedFanout===true&&e!=="sparse")throw new Error("[OpenRTC] advancedFanout conflicts with architecture; use architecture: sparse only.");return {architecture:e,delivery:r.payload??(r.advancedFanout===true?"latest-state":"reliable")}}var R=class{constructor(e){this.mode=e==="sparse"?"sparse":"direct";}create(e){return new w(e,()=>this.mode)}setArchitecture(e){e.phase==="settled"&&(this.mode=e.effective==="sparse"?"sparse":e.effective==="managed"?"managed":"direct");}},w=class{constructor(e,t){this.host=e;this.mode=t;this.stateSenders=new Map;this.sparseForwardQueue=[];this.sparseForwardRunning=false;this.sparseForwardQueueDropsPending=0;this.sparseForwardDropReport=null;this.closed=false;let i=e.client.advanced.runtime.onManagedRoomMessage;this.stopManagedMessage=typeof i=="function"?i.call(e.client.advanced.runtime,o=>{e.deliver(o.senderId,o.payload,o.channel);}):()=>{};}isSparse(){return this.mode()==="sparse"}publishState(e,t){if(this.mode()!=="managed")return false;let i=this.stateSenders.get(e);return i||(i=new a(o=>this.publishManaged(e,o)),this.stateSenders.set(e,i)),i.send(t).catch(()=>{}),true}async sendChannel(e,t){let i=this.mode();if(i==="managed")return await this.publishManaged(e,t),true;if(i!=="sparse")return false;let o=this.host.connections();if(o.length===0)return true;let a=await this.host.client.advanced.runtime.encodeSparseFanoutMessage(this.host.capabilityKey,t);return await Promise.all(o.map(n=>n.send(a))),true}assertTargetedSendAllowed(){if(this.mode()==="managed")throw new Error("[OpenRTC] Targeted messages are not available in managed fanout rooms; use authority mode for targeted request semantics.")}receive(e,t,i){return this.mode()!=="sparse"?false:(i instanceof Uint8Array&&this.receiveSparseBroadcast(e,t,i),true)}close(){if(!this.closed){this.closed=true,this.stopManagedMessage();for(let e of this.stateSenders.values())e.close();this.stateSenders.clear(),this.sparseForwardQueue.length=0;}}publishManaged(e,t){return this.host.client.advanced.runtime.publishManagedRoomMessage({messageId:crypto.randomUUID(),channel:e,priority:1,payload:t})}async receiveSparseBroadcast(e,t,i){let o;try{o=await this.host.client.advanced.runtime.acceptSparseFanoutMessage(this.host.capabilityKey,t,i);}catch{return}if(o.forward){let a=Number.isSafeInteger(o.forwardPeerLimit)&&o.forwardPeerLimit>0?o.forwardPeerLimit:0,n=Number.isSafeInteger(o.forwardQueueCapacity)&&o.forwardQueueCapacity>0?Math.min(o.forwardQueueCapacity,64):0,d=new Set(Array.isArray(o.forwardPeerIds)?o.forwardPeerIds.slice(0,a):[]),s=this.host.connections().filter(u=>u.id!==e.id).filter(u=>d.has(u.remoteNodeId)).slice(0,a);this.enqueueSparseForward(o.forward,s,n);}this.host.deliver(o.authorDeviceId,o.payload);}enqueueSparseForward(e,t,i){if(i===0||t.length===0||this.closed)return;if(this.sparseForwardQueue.length+(this.sparseForwardRunning?1:0)>=i){this.sparseForwardQueueDropsPending+=1,this.flushSparseForwardDropReport();return}this.sparseForwardQueue.push({payload:e,targets:t}),this.sparseForwardRunning||this.drainSparseForwardQueue();}async drainSparseForwardQueue(){if(!this.sparseForwardRunning){this.sparseForwardRunning=true;try{for(;!this.closed;){let e=this.sparseForwardQueue.shift();if(!e)break;await Promise.allSettled(e.targets.map(t=>t.send(e.payload)));}}finally{this.sparseForwardRunning=false,!this.closed&&this.sparseForwardQueue.length>0&&this.drainSparseForwardQueue();}}}flushSparseForwardDropReport(){if(this.sparseForwardDropReport||this.sparseForwardQueueDropsPending===0)return;let e=this.sparseForwardQueueDropsPending;this.sparseForwardQueueDropsPending=0,this.sparseForwardDropReport=this.host.client.advanced.runtime.recordSparseFanoutForwardQueueDrop(this.host.capabilityKey,e).catch(()=>{}).finally(()=>{this.sparseForwardDropReport=null,this.flushSparseForwardDropReport();});}};function F(r){return Object.freeze(r.filter(e=>!!(e.deviceId||e.nodeId)).map(e=>Object.freeze({deviceId:e.deviceId||e.nodeId,...e.nodeId?{nodeId:e.nodeId}:{},...typeof e.userId=="string"?{userId:e.userId}:{},...Number.isFinite(e.joinedAt)?{joinedAt:e.joinedAt}:{}})))}var y=class extends h{constructor(t,i,o,a,n,d="auto"){let s=new R(d);super("room",t,i,o,s);this.membership=a;this.onLeave=n;this.kind="room";this.left=false;this.memberWatches=new Map;this.members={list:async()=>{if(this.closed)return [];let t=await this.client.rooms.members(this.id);return this.closed?[]:F(t)},watch:t=>{if(this.closed)return t([]),()=>{};let i=true,o=this.client.rooms.watch(this.id,n=>{i&&!this.closed&&t(F(n));}),a=()=>{i&&(i=false,this.memberWatches.delete(a),o());};return this.memberWatches.set(a,t),a}};this.architectureListeners=new Set;this.authorityAssignmentSnapshot=null;this.authorityAssignmentListeners=new Set;this.architectureSnapshot=Q(d);let u=i.advanced.runtime.onRoomArchitectureChange;this.stopArchitecture=typeof u=="function"?u.call(i.advanced.runtime,c=>{if(!(c.epoch<this.architectureSnapshot.epoch)){this.architectureSnapshot=Object.freeze({...c}),this.setArchitecture(c);for(let h of this.architectureListeners)h(this.architectureSnapshot);}}):()=>{};let l=i.advanced.runtime.onRoomAuthorityAssignmentChange;this.stopAuthorityAssignment=typeof l=="function"?l.call(i.advanced.runtime,c=>{this.authorityAssignmentSnapshot=c?E(c):null;for(let h of this.authorityAssignmentListeners)h(M(this.authorityAssignmentSnapshot));}):()=>{};}architecture(){return {...this.architectureSnapshot}}onArchitectureChanged(t){return this.architectureListeners.add(t),t(this.architecture()),()=>this.architectureListeners.delete(t)}authorityAssignment(){return M(this.authorityAssignmentSnapshot)}onAuthorityAssignmentChanged(t){return this.authorityAssignmentListeners.add(t),t(this.authorityAssignment()),()=>this.authorityAssignmentListeners.delete(t)}async leave(){this.left||(this.left=true,await this.onLeave?.()),await this.close();}async close(){this.fenceProductAccess();let t=[...this.memberWatches];this.memberWatches.clear();for(let[i,o]of t)i(),o([]);this.stopArchitecture(),this.stopAuthorityAssignment(),this.architectureListeners.clear(),this.authorityAssignmentListeners.clear(),await super.close();}};async function j(r,e$1,t){r.assertOpen();let i=e(e$1),o=t.access??"capability",{architecture:a,delivery:n}=D(t);return r.activateOnce(`room:${i}`,JSON.stringify({access:o,membership:t.membership??"ephemeral",identity:t.identity??null,maxPeers:t.maxPeers??null,payload:n,architecture:a,advancedFanout:t.advancedFanout===true}),o==="authenticated"?t.auth??r.options.auth:void 0,()=>x(r,i,t,a,n))}async function x(r,e,t,i,o){let a=t.membership??"ephemeral",n=t.access??"capability";if(i==="sparse"&&o!=="latest-state")throw new Error("[OpenRTC] Sparse rooms require payload: latest-state.");if(a==="durable"&&n!=="authenticated")throw new Error("[OpenRTC] Durable room membership requires access: authenticated.");if(t.identity==="session"&&n!=="capability")throw new Error("[OpenRTC] Session room identity requires access: capability.");if(n==="authenticated"){let h=t.auth??r.options.auth;if(!h)throw new Error("[OpenRTC] Authenticated rooms require an auth provider.");let A=await r.deviceId(),v=await r.controlPlane(),m=await v.deviceCertificate(h,A,{kind:"room",id:e});a==="durable"&&await v.durableRoomMembership(m.source,e,"join");let f;try{f=await r.activate({kind:"room",id:e,source:m.source,principalId:m.principalId,deviceId:A,maxPeers:t.maxPeers,autoConnect:!0,durableMembership:a==="durable",advancedFanout:t.advancedFanout,architecture:i,defaultDelivery:o});}catch(O){throw a==="durable"&&await v.durableRoomMembership(m.source,e,"leave").catch(()=>{}),O}let g;return g=new y(e,f,()=>{r.channels.detach(f),r.onClosed(g);},a,a==="durable"?async()=>{await v.durableRoomMembership(m.source,e,"leave");}:void 0,i),r.trackHandle(g)}let d=await(t.identity==="session"?r.sessionPlane():r.controlPlane()),s=await d.capability("room",e,t.maxPeers,t.advancedFanout,i,o),u=String(b(s.token).principalId),l=await r.activate({kind:"room",id:e,source:s,principalId:u,deviceId:g(s),maxPeers:t.maxPeers,autoConnect:true,advancedFanout:t.advancedFanout,architecture:i,defaultDelivery:o,controlPlane:d}),c;return c=new y(e,l,()=>{r.channels.detach(l),r.onClosed(c);},"ephemeral",void 0,i),r.trackHandle(c)}function z(r,e$1){r.assertOpen();let t=e(e$1.roomId),i=e(e$1.serviceId),o=f(e$1.deviceId);if(!Number.isSafeInteger(e$1.generation)||e$1.generation<1)throw new Error("[OpenRTC] Authority service generation is invalid.");let a=[...e$1.shardIds].map(e).sort();if(a.length<1||a.length>64||new Set(a).size!==a.length)throw new Error("[OpenRTC] Authority service shards are invalid.");if(!/^[A-Za-z0-9_-]{43}$/.test(e$1.devicePublicKeyX))throw new Error("[OpenRTC] Authority service device public key is invalid.");if(!/^[A-Za-z0-9_-]{43}$/.test(e$1.assignmentPublicKeyX))throw new Error("[OpenRTC] Authority assignment public key is invalid.");if(e$1.maxPeers!==void 0&&(!Number.isSafeInteger(e$1.maxPeers)||e$1.maxPeers<1||e$1.maxPeers>50))throw new Error("[OpenRTC] Authority service maxPeers must be within 1..50.");return r.activateOnce(`room:${t}`,JSON.stringify({architecture:"authority",serviceId:i,generation:e$1.generation,shardIds:a,deviceId:o,maxPeers:e$1.maxPeers??null,irohRelay:e$1.irohRelay,devicePublicKeyX:e$1.devicePublicKeyX,assignmentPublicKeyX:e$1.assignmentPublicKeyX,deviceSignerId:r.authorityCallableId(e$1.deviceSign),grantProviderId:r.authorityCallableId(e$1.grantProvider)}),void 0,async()=>{let n={type:"capability",token:"",avenue:{kind:"room",id:t},expiresAtMs:Number.MAX_SAFE_INTEGER,irohRelay:e$1.irohRelay,managedTurn:false},d=await r.activate({kind:"room",id:t,source:n,principalId:i,deviceId:o,maxPeers:e$1.maxPeers,autoConnect:true,architecture:"authority",defaultDelivery:"reliable",authority:{serviceId:i,generation:e$1.generation,shardIds:a,deviceId:o,irohRelay:e$1.irohRelay,devicePublicKeyX:e$1.devicePublicKeyX,assignmentPublicKeyX:e$1.assignmentPublicKeyX,deviceSign:e$1.deviceSign,grantProvider:e$1.grantProvider}}),s;return s=new y(t,d,()=>{r.channels.detach(d),r.onClosed(s);},"ephemeral",void 0,"authority"),r.trackHandle(s)})}function E(r){return Object.freeze({...r,priorityDeviceIds:Object.freeze([...r.priorityDeviceIds]),relevantEntityIds:Object.freeze([...r.relevantEntityIds])})}function M(r){return r?{...r,priorityDeviceIds:[...r.priorityDeviceIds],relevantEntityIds:[...r.relevantEntityIds]}:null}function Q(r){return {requested:r,effective:r==="sparse"?"sparse":"mesh",epoch:0,phase:r==="mesh"||r==="sparse"?"settled":"preparing",reason:r==="auto"?"size":"manual"}}export{y as RoomHandle,j as joinRoom,z as openAuthorityRoom,D as resolveRoomJoinOptions};
@@ -1 +1 @@
1
- import {b}from'../chunk-5LO6PLWZ.js';import'../chunk-AYHD4X2R.js';import {a}from'../chunk-CQHLD52E.js';import'../chunk-LCJQ7RSR.js';import'../chunk-FPJAUAEU.js';import'../chunk-L4HWDDXL.js';import'../chunk-FNCEVW7G.js';import'../chunk-LB27VQRL.js';import'../chunk-OWKAJPOI.js';import'../chunk-TPF643LU.js';import'../chunk-L2ZZXECX.js';import'../chunk-CCCYE3XN.js';import'../chunk-JPBW67B3.js';import'../chunk-ZA44REGI.js';import'../chunk-L7N4T2PX.js';import'../chunk-72MN7BNQ.js';import'../chunk-2GX6GB6L.js';var n=class extends a{constructor(e){super(new b(e));}setWasmClient(e){this.unwrap().setWasmClient(e);}};export{n as WasmRuntimeAdapter};
1
+ import {b}from'../chunk-PA4WT4QM.js';import'../chunk-AYHD4X2R.js';import {a}from'../chunk-CQHLD52E.js';import'../chunk-LCJQ7RSR.js';import'../chunk-FPJAUAEU.js';import'../chunk-WTOA6B2A.js';import'../chunk-FNCEVW7G.js';import'../chunk-LB27VQRL.js';import'../chunk-OWKAJPOI.js';import'../chunk-TPF643LU.js';import'../chunk-L2ZZXECX.js';import'../chunk-CCCYE3XN.js';import'../chunk-JPBW67B3.js';import'../chunk-ZA44REGI.js';import'../chunk-L7N4T2PX.js';import'../chunk-72MN7BNQ.js';import'../chunk-2GX6GB6L.js';var n=class extends a{constructor(e){super(new b(e));}setWasmClient(e){this.unwrap().setWasmClient(e);}};export{n as WasmRuntimeAdapter};
@@ -1 +1 @@
1
- import {a as a$2}from'../chunk-VARKDQGM.js';import {t}from'../chunk-SADNIMUO.js';import'../chunk-IXQ4KWGP.js';import'../chunk-CQHLD52E.js';import'../chunk-LCJQ7RSR.js';import'../chunk-FPJAUAEU.js';import {a as a$1}from'../chunk-L4HWDDXL.js';import'../chunk-2AAZFBRZ.js';import'../chunk-FNCEVW7G.js';import'../chunk-LB27VQRL.js';import'../chunk-OWKAJPOI.js';import {a}from'../chunk-XXZEDZUU.js';import'../chunk-TPF643LU.js';import'../chunk-72NEEJQG.js';import'../chunk-L2ZZXECX.js';import'../chunk-IUU6JCLK.js';import'../chunk-CCCYE3XN.js';import'../chunk-JPBW67B3.js';import'../chunk-ZA44REGI.js';import'../chunk-L7N4T2PX.js';import'../chunk-72MN7BNQ.js';import'../chunk-2GX6GB6L.js';async function l(e){let t=a$1(e),{WasmBridge:o}=await import('../WasmBridge-CJNESUGJ.js');return a$2(t,new o(t))}function y(e,t$1,o=new a){let m=a$1(e);return a$2(m,new t({...m,bridge:t$1,projectionBroker:o}))}export{y as createIpcClient,l as createWasmClient};
1
+ import {a as a$2}from'../chunk-TSMMRR5V.js';import {t}from'../chunk-M4KL5XZU.js';import'../chunk-IXQ4KWGP.js';import'../chunk-CQHLD52E.js';import'../chunk-LCJQ7RSR.js';import'../chunk-FPJAUAEU.js';import {a as a$1}from'../chunk-WTOA6B2A.js';import'../chunk-2AAZFBRZ.js';import'../chunk-FNCEVW7G.js';import'../chunk-LB27VQRL.js';import'../chunk-OWKAJPOI.js';import {a}from'../chunk-XXZEDZUU.js';import'../chunk-TPF643LU.js';import'../chunk-72NEEJQG.js';import'../chunk-L2ZZXECX.js';import'../chunk-IUU6JCLK.js';import'../chunk-CCCYE3XN.js';import'../chunk-JPBW67B3.js';import'../chunk-ZA44REGI.js';import'../chunk-L7N4T2PX.js';import'../chunk-72MN7BNQ.js';import'../chunk-2GX6GB6L.js';async function l(e){let t=a$1(e),{WasmBridge:o}=await import('../WasmBridge-3HYLCY5Y.js');return a$2(t,new o(t))}function y(e,t$1,o=new a){let m=a$1(e);return a$2(m,new t({...m,bridge:t$1,projectionBroker:o}))}export{y as createIpcClient,l as createWasmClient};
@@ -1 +1 @@
1
- export{a as isDeviceActive,c as isDeviceConnectable,b as isDeviceRoutable}from'../chunk-CK6WQV7J.js';export{h as ConnectionActor,e as ConnectionActorError,i as ConnectionActors,a as ConnectionController,k as DEFAULT_MAX_FRAME_BYTES,t as IpcRuntimeAdapter,s as RuntimeClient,d as clog,q as concatRuntimeBytes,f as connectionActorKey,g as connectionActorKeyString,p as createJsonDecoder,l as createU32Decoder,n as decodeJsonPayload,o as encodeJsonFrame,m as encodeJsonPayload,j as encodeU32Frame,c as grantCorrelation,r as readRuntimeU32BE,b as renderCorrelation}from'../chunk-SADNIMUO.js';import'../chunk-IXQ4KWGP.js';import'../chunk-CQHLD52E.js';export{u as BROWSER_CAPABILITIES,v as NATIVE_CAPABILITIES,s as RUNTIME_POLICY,x as browserCapabilities,z as capabilityProfile,w as cloneCapabilities,t as getRuntimePolicy,l as logTeardownTrace,h as openRtcDebug,g as openRtcDebugEnabled,i as openRtcDebugInfo,j as openRtcDebugLog,y as statusCapabilities}from'../chunk-LCJQ7RSR.js';import'../chunk-FPJAUAEU.js';import'../chunk-L4HWDDXL.js';import'../chunk-2AAZFBRZ.js';import'../chunk-FNCEVW7G.js';import'../chunk-LB27VQRL.js';import'../chunk-OWKAJPOI.js';import'../chunk-TPF643LU.js';export{a as classifyIpcFailure,b as isIpcUnavailable}from'../chunk-72NEEJQG.js';import'../chunk-L2ZZXECX.js';export{c as runtimeFromCapability}from'../chunk-5LNRJE6L.js';import'../chunk-FKAQDDUM.js';import'../chunk-RLPWFHOY.js';import'../chunk-IUU6JCLK.js';import'../chunk-CCCYE3XN.js';import'../chunk-JPBW67B3.js';import'../chunk-ZA44REGI.js';import'../chunk-L7N4T2PX.js';import'../chunk-72MN7BNQ.js';import'../chunk-2GX6GB6L.js';
1
+ export{a as isDeviceActive,c as isDeviceConnectable,b as isDeviceRoutable}from'../chunk-CK6WQV7J.js';export{h as ConnectionActor,e as ConnectionActorError,i as ConnectionActors,a as ConnectionController,k as DEFAULT_MAX_FRAME_BYTES,t as IpcRuntimeAdapter,s as RuntimeClient,d as clog,q as concatRuntimeBytes,f as connectionActorKey,g as connectionActorKeyString,p as createJsonDecoder,l as createU32Decoder,n as decodeJsonPayload,o as encodeJsonFrame,m as encodeJsonPayload,j as encodeU32Frame,c as grantCorrelation,r as readRuntimeU32BE,b as renderCorrelation}from'../chunk-M4KL5XZU.js';import'../chunk-IXQ4KWGP.js';import'../chunk-CQHLD52E.js';export{u as BROWSER_CAPABILITIES,v as NATIVE_CAPABILITIES,s as RUNTIME_POLICY,x as browserCapabilities,z as capabilityProfile,w as cloneCapabilities,t as getRuntimePolicy,l as logTeardownTrace,h as openRtcDebug,g as openRtcDebugEnabled,i as openRtcDebugInfo,j as openRtcDebugLog,y as statusCapabilities}from'../chunk-LCJQ7RSR.js';import'../chunk-FPJAUAEU.js';import'../chunk-WTOA6B2A.js';import'../chunk-2AAZFBRZ.js';import'../chunk-FNCEVW7G.js';import'../chunk-LB27VQRL.js';import'../chunk-OWKAJPOI.js';import'../chunk-TPF643LU.js';export{a as classifyIpcFailure,b as isIpcUnavailable}from'../chunk-72NEEJQG.js';import'../chunk-L2ZZXECX.js';export{c as runtimeFromCapability}from'../chunk-KN7DF3NH.js';import'../chunk-FKAQDDUM.js';import'../chunk-IVNXIG7J.js';import'../chunk-IUU6JCLK.js';import'../chunk-CCCYE3XN.js';import'../chunk-JPBW67B3.js';import'../chunk-ZA44REGI.js';import'../chunk-L7N4T2PX.js';import'../chunk-72MN7BNQ.js';import'../chunk-2GX6GB6L.js';
package/dist/server.js CHANGED
@@ -1,2 +1,2 @@
1
- import {a}from'./chunk-LVLU4YQY.js';import'./chunk-5LNRJE6L.js';import'./chunk-FKAQDDUM.js';import'./chunk-RLPWFHOY.js';import'./chunk-IUU6JCLK.js';import'./chunk-CCCYE3XN.js';import'./chunk-JPBW67B3.js';import'./chunk-ZA44REGI.js';import'./chunk-L7N4T2PX.js';import'./chunk-72MN7BNQ.js';import'./chunk-2GX6GB6L.js';function y(n){let e=new URL(n??"https://api.openrtc.app"),t=e.protocol==="http:"&&["127.0.0.1","localhost","::1"].includes(e.hostname.toLowerCase());if(e.protocol!=="https:"&&!t||e.username||e.password||e.search||e.hash)throw new TypeError("[OpenRTC] authority control-plane endpoint is invalid.");return e.toString().replace(/\/$/,"")}function h(){if(typeof document<"u"||typeof window<"u")throw new Error("[OpenRTC] openrtc/server is unavailable in browsers; use openrtc/service-node with a delegated grant.")}var c=class{constructor(e){h();let t=e.secretKey?.trim()??"";if(!/^sk_(?:live|test)_[A-Za-z0-9_-]+$/.test(t))throw new TypeError("[OpenRTC] secretKey is invalid.");let i=e.fetch??globalThis.fetch;if(typeof i!="function")throw new TypeError("[OpenRTC] a Fetch-compatible implementation is required.");let u=y(e.endpoint);this.authority=new a({apiKey:e.apiKey,serviceId:e.serviceId,generation:e.generation,shardIds:e.shardIds,deviceId:e.deviceId,deviceSigner:e.deviceSigner,assignmentSigner:e.assignmentSigner,grantIssuer:async s=>{let r=await i(`${u}/v2/developer/authority/grants`,{method:"POST",headers:{authorization:`Bearer ${t}`,"content-type":"application/json","x-openrtc-idempotency-key":s.idempotencyKey},body:JSON.stringify(s.body)});if(!r.ok){let o=await r.json().catch(()=>null),d=typeof o?.error=="string"?o.error.slice(0,256):`HTTP ${r.status}`;throw new Error(`[OpenRTC] authority service grant failed: ${d}`)}return r.json()}});}requestGrant(e){return this.authority.requestGrant(e)}signAssignment(e){return this.authority.signAssignment(e)}devicePublicKey(){return this.authority.devicePublicKey()}signDeviceBytes(e){return this.authority.signDeviceBytes(e)}grantIssuer(){return async e=>{let t=e.body;return this.requestGrant({roomId:String(t.avenue?.id??""),runtimeInstanceId:String(t.runtimeInstanceId??""),ticketFingerprint:String(t.ticketFingerprint??""),maxPeers:typeof t.maxPeers=="number"?t.maxPeers:void 0,refreshGrant:typeof t.refreshGrant=="string"?t.refreshGrant:void 0,features:typeof t.features=="object"&&t.features?t.features:void 0})}}};
1
+ import {a}from'./chunk-AZ74VBU2.js';import'./chunk-KN7DF3NH.js';import'./chunk-FKAQDDUM.js';import'./chunk-IVNXIG7J.js';import'./chunk-IUU6JCLK.js';import'./chunk-CCCYE3XN.js';import'./chunk-JPBW67B3.js';import'./chunk-ZA44REGI.js';import'./chunk-L7N4T2PX.js';import'./chunk-72MN7BNQ.js';import'./chunk-2GX6GB6L.js';function y(n){let e=new URL(n??"https://api.openrtc.app"),t=e.protocol==="http:"&&["127.0.0.1","localhost","::1"].includes(e.hostname.toLowerCase());if(e.protocol!=="https:"&&!t||e.username||e.password||e.search||e.hash)throw new TypeError("[OpenRTC] authority control-plane endpoint is invalid.");return e.toString().replace(/\/$/,"")}function h(){if(typeof document<"u"||typeof window<"u")throw new Error("[OpenRTC] openrtc/server is unavailable in browsers; use openrtc/service-node with a delegated grant.")}var c=class{constructor(e){h();let t=e.secretKey?.trim()??"";if(!/^sk_(?:live|test)_[A-Za-z0-9_-]+$/.test(t))throw new TypeError("[OpenRTC] secretKey is invalid.");let i=e.fetch??globalThis.fetch;if(typeof i!="function")throw new TypeError("[OpenRTC] a Fetch-compatible implementation is required.");let u=y(e.endpoint);this.authority=new a({apiKey:e.apiKey,serviceId:e.serviceId,generation:e.generation,shardIds:e.shardIds,deviceId:e.deviceId,deviceSigner:e.deviceSigner,assignmentSigner:e.assignmentSigner,grantIssuer:async s=>{let r=await i(`${u}/v2/developer/authority/grants`,{method:"POST",headers:{authorization:`Bearer ${t}`,"content-type":"application/json","x-openrtc-idempotency-key":s.idempotencyKey},body:JSON.stringify(s.body)});if(!r.ok){let o=await r.json().catch(()=>null),d=typeof o?.error=="string"?o.error.slice(0,256):`HTTP ${r.status}`;throw new Error(`[OpenRTC] authority service grant failed: ${d}`)}return r.json()}});}requestGrant(e){return this.authority.requestGrant(e)}signAssignment(e){return this.authority.signAssignment(e)}devicePublicKey(){return this.authority.devicePublicKey()}signDeviceBytes(e){return this.authority.signDeviceBytes(e)}grantIssuer(){return async e=>{let t=e.body;return this.requestGrant({roomId:String(t.avenue?.id??""),runtimeInstanceId:String(t.runtimeInstanceId??""),ticketFingerprint:String(t.ticketFingerprint??""),maxPeers:typeof t.maxPeers=="number"?t.maxPeers:void 0,refreshGrant:typeof t.refreshGrant=="string"?t.refreshGrant:void 0,features:typeof t.features=="object"&&t.features?t.features:void 0})}}};
2
2
  export{c as AuthorityServiceControlPlane};
@@ -1 +1 @@
1
- export{a as DelegatedAuthorityService,b as ServiceNode}from'./chunk-LVLU4YQY.js';import'./chunk-5LNRJE6L.js';import'./chunk-FKAQDDUM.js';import'./chunk-RLPWFHOY.js';import'./chunk-IUU6JCLK.js';import'./chunk-CCCYE3XN.js';import'./chunk-JPBW67B3.js';import'./chunk-ZA44REGI.js';import'./chunk-L7N4T2PX.js';import'./chunk-72MN7BNQ.js';import'./chunk-2GX6GB6L.js';
1
+ export{a as DelegatedAuthorityService,b as ServiceNode}from'./chunk-AZ74VBU2.js';import'./chunk-KN7DF3NH.js';import'./chunk-FKAQDDUM.js';import'./chunk-IVNXIG7J.js';import'./chunk-IUU6JCLK.js';import'./chunk-CCCYE3XN.js';import'./chunk-JPBW67B3.js';import'./chunk-ZA44REGI.js';import'./chunk-L7N4T2PX.js';import'./chunk-72MN7BNQ.js';import'./chunk-2GX6GB6L.js';
@@ -1 +1 @@
1
- import {a}from'../chunk-XXZEDZUU.js';import'../chunk-TPF643LU.js';import {a as a$1}from'../chunk-NS32P65Z.js';import'../chunk-GMPEZXPD.js';import {i}from'../chunk-5LNRJE6L.js';import'../chunk-FKAQDDUM.js';import'../chunk-RLPWFHOY.js';import'../chunk-IUU6JCLK.js';import'../chunk-CCCYE3XN.js';import'../chunk-JPBW67B3.js';import'../chunk-ZA44REGI.js';import'../chunk-L7N4T2PX.js';import'../chunk-72MN7BNQ.js';import'../chunk-2GX6GB6L.js';function v(c,p,e){let o=new a;return i(c,{endpoints:p,testingAllowInsecureLoopback:true,platform:"native",close:()=>o.close(),deviceKeyProvider:a$1(e),deviceIdProvider:async()=>{let t=await e.invoke("get_rtc_local_device_info");return String(t?.deviceId??"")},runtimeFactory:async t=>{let{createIpcClient:a}=await import('../ipcFactory-F75IXEIE.js');return a(t,e,o)}})}export{v as OpenRTC};
1
+ import {a}from'../chunk-XXZEDZUU.js';import'../chunk-TPF643LU.js';import {a as a$1}from'../chunk-NS32P65Z.js';import'../chunk-GMPEZXPD.js';import {i}from'../chunk-KN7DF3NH.js';import'../chunk-FKAQDDUM.js';import'../chunk-IVNXIG7J.js';import'../chunk-IUU6JCLK.js';import'../chunk-CCCYE3XN.js';import'../chunk-JPBW67B3.js';import'../chunk-ZA44REGI.js';import'../chunk-L7N4T2PX.js';import'../chunk-72MN7BNQ.js';import'../chunk-2GX6GB6L.js';function v(c,p,e){let o=new a;return i(c,{endpoints:p,testingAllowInsecureLoopback:true,platform:"native",close:()=>o.close(),deviceKeyProvider:a$1(e),deviceIdProvider:async()=>{let t=await e.invoke("get_rtc_local_device_info");return String(t?.deviceId??"")},runtimeFactory:async t=>{let{createIpcClient:a}=await import('../ipcFactory-6XD3J2UU.js');return a(t,e,o)}})}export{v as OpenRTC};
package/dist/testing.js CHANGED
@@ -1 +1 @@
1
- import {a}from'./chunk-2Q75GXGE.js';import {a as a$1}from'./chunk-IAYQJZQQ.js';import {a as a$2,d,c}from'./chunk-L2ZZXECX.js';import'./chunk-GMPEZXPD.js';import {i}from'./chunk-5LNRJE6L.js';import'./chunk-FKAQDDUM.js';import'./chunk-RLPWFHOY.js';import'./chunk-IUU6JCLK.js';import'./chunk-CCCYE3XN.js';import'./chunk-JPBW67B3.js';import'./chunk-ZA44REGI.js';import'./chunk-L7N4T2PX.js';import'./chunk-72MN7BNQ.js';import'./chunk-2GX6GB6L.js';function v(i,o,e){let n=s=>{let t=new URL(s);return t.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(t.hostname)&&Number(t.port)>0&&t.pathname==="/"&&!t.username&&!t.password&&!t.search&&!t.hash};if(i.apiKey!=="pk_test_0000000000000000000000000000000000000000"||!n(o.controlPlane)||!n(o.gateway)||!/^[A-Za-z0-9_-]{1,64}$/.test(e.keyNamespace))throw new Error("Local broadcast testing requires the disposable loopback service lane")}function b(i){let o=i.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(i.length/4)*4,"=");return Uint8Array.from(atob(o),e=>e.charCodeAt(0))}function A(i,o,e){return new a(i,o,a$1(e))}function R(i$1,o,e={}){if(e.localBroadcast&&v(i$1,o,e.localBroadcast),e.initialTicketLifetimeMs!==void 0){let t=(p,c)=>{let a=new URL(p);return a.protocol===c&&["127.0.0.1","[::1]"].includes(a.hostname)&&Number(a.port)>0&&a.pathname==="/"&&!a.username&&!a.password&&!a.search&&!a.hash};if(e.initialTicketLifetimeMs!==9e4||i$1.apiKey!=="pk_test_0000000000000000000000000000000000000000"||!t(o.controlPlane,"http:")||!t(o.gateway,"http:")||!e.irohTestRelayUrl||!t(e.irohTestRelayUrl,"https:"))throw new Error("Short initial tickets require the disposable local service lane")}let n=e.localBroadcast,s=n?a$1(n.keyNamespace):void 0;return i(i$1,{endpoints:o,testingAllowInsecureLoopback:true,platform:"web",...s?{deviceKeyProvider:s}:{},...n&&s?{broadcastHostFactory:async t=>{let[{BrowserManagedBroadcastHost:p},{loadBrowserWasmRuntimeModule:c}]=await Promise.all([import('./BrowserManagedBroadcastHost-6VGHQQMF.js'),import('./WasmBridge-CJNESUGJ.js')]),a=c().then(async r=>(await r.initWasm(),r.start(),new r.WasmClient(t.apiKey))),y=await s.getOrCreate(`app_${t.apiKey.slice(-16)}`);return new p({resolve:async(r,l)=>({token:r,...await n.resolve(r,l),signBindingChallenge:async m=>b(await y.sign(m))}),loadWasm:()=>a})}}:{},...e.deviceId?{deviceIdProvider:async()=>e.deviceId}:{},...e.irohTestRelayUrl?{irohTestRelayUrl:e.irohTestRelayUrl}:{},runtimeFactory:async t=>{let{createWasmClient:p}=await import('./runtime/factories.js'),c$1=await p(t);if(e.initialTicketLifetimeMs!==void 0){let a=c$1.runtime,y=a.getTicketWithToken.bind(a);a.getTicketWithToken=async(r,l=0)=>{if(a.getTicketWithToken=y,!r.startsWith("v2:room:"))throw new Error("Short initial ticket requires room scope");let{irohTicket:m,tokenSuffix:u}=a$2(await y(r,l)),d$1=u&&d(m,u);if(!d$1||!d$1.t||d$1.s!==r||d$1.m!==l)throw new Error("Invalid initial service ticket");let f=Date.now()+9e4;return await a.registerToken({token:d$1.t,scope:r,maxConnections:l,expiresAtMs:f}),c(m,d$1.t,r,l,f)};}return c$1}})}export{R as OpenRTC,A as controlPlane};
1
+ import {a}from'./chunk-2Q75GXGE.js';import {a as a$1}from'./chunk-IAYQJZQQ.js';import {a as a$2,d,c}from'./chunk-L2ZZXECX.js';import'./chunk-GMPEZXPD.js';import {i}from'./chunk-KN7DF3NH.js';import'./chunk-FKAQDDUM.js';import'./chunk-IVNXIG7J.js';import'./chunk-IUU6JCLK.js';import'./chunk-CCCYE3XN.js';import'./chunk-JPBW67B3.js';import'./chunk-ZA44REGI.js';import'./chunk-L7N4T2PX.js';import'./chunk-72MN7BNQ.js';import'./chunk-2GX6GB6L.js';function v(i,o,e){let n=s=>{let t=new URL(s);return t.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(t.hostname)&&Number(t.port)>0&&t.pathname==="/"&&!t.username&&!t.password&&!t.search&&!t.hash};if(i.apiKey!=="pk_test_0000000000000000000000000000000000000000"||!n(o.controlPlane)||!n(o.gateway)||!/^[A-Za-z0-9_-]{1,64}$/.test(e.keyNamespace))throw new Error("Local broadcast testing requires the disposable loopback service lane")}function b(i){let o=i.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(i.length/4)*4,"=");return Uint8Array.from(atob(o),e=>e.charCodeAt(0))}function A(i,o,e){return new a(i,o,a$1(e))}function R(i$1,o,e={}){if(e.localBroadcast&&v(i$1,o,e.localBroadcast),e.initialTicketLifetimeMs!==void 0){let t=(p,c)=>{let a=new URL(p);return a.protocol===c&&["127.0.0.1","[::1]"].includes(a.hostname)&&Number(a.port)>0&&a.pathname==="/"&&!a.username&&!a.password&&!a.search&&!a.hash};if(e.initialTicketLifetimeMs!==9e4||i$1.apiKey!=="pk_test_0000000000000000000000000000000000000000"||!t(o.controlPlane,"http:")||!t(o.gateway,"http:")||!e.irohTestRelayUrl||!t(e.irohTestRelayUrl,"https:"))throw new Error("Short initial tickets require the disposable local service lane")}let n=e.localBroadcast,s=n?a$1(n.keyNamespace):void 0;return i(i$1,{endpoints:o,testingAllowInsecureLoopback:true,platform:"web",...s?{deviceKeyProvider:s}:{},...n&&s?{broadcastHostFactory:async t=>{let[{BrowserManagedBroadcastHost:p},{loadBrowserWasmRuntimeModule:c}]=await Promise.all([import('./BrowserManagedBroadcastHost-6VGHQQMF.js'),import('./WasmBridge-3HYLCY5Y.js')]),a=c().then(async r=>(await r.initWasm(),r.start(),new r.WasmClient(t.apiKey))),y=await s.getOrCreate(`app_${t.apiKey.slice(-16)}`);return new p({resolve:async(r,l)=>({token:r,...await n.resolve(r,l),signBindingChallenge:async m=>b(await y.sign(m))}),loadWasm:()=>a})}}:{},...e.deviceId?{deviceIdProvider:async()=>e.deviceId}:{},...e.irohTestRelayUrl?{irohTestRelayUrl:e.irohTestRelayUrl}:{},runtimeFactory:async t=>{let{createWasmClient:p}=await import('./runtime/factories.js'),c$1=await p(t);if(e.initialTicketLifetimeMs!==void 0){let a=c$1.runtime,y=a.getTicketWithToken.bind(a);a.getTicketWithToken=async(r,l=0)=>{if(a.getTicketWithToken=y,!r.startsWith("v2:room:"))throw new Error("Short initial ticket requires room scope");let{irohTicket:m,tokenSuffix:u}=a$2(await y(r,l)),d$1=u&&d(m,u);if(!d$1||!d$1.t||d$1.s!==r||d$1.m!==l)throw new Error("Invalid initial service ticket");let f=Date.now()+9e4;return await a.registerToken({token:d$1.t,scope:r,maxConnections:l,expiresAtMs:f}),c(m,d$1.t,r,l,f)};}return c$1}})}export{R as OpenRTC,A as controlPlane};
@@ -4,9 +4,9 @@
4
4
  "platform": "darwin",
5
5
  "arch": "arm64",
6
6
  "rustTarget": "aarch64-apple-darwin",
7
- "sourceCommit": "a42eb60b973b88d09047fa9db8bb9d9f1ff29e80",
8
- "sourceDigest": "2a289da0f6e7006211566a8ad9a6e794803785c599a323df04944972bc7e3517",
9
- "binarySha256": "257acbe1b74c8801ebbb9301d31e2099f5b871ebbc11273c26a563aa3a617b32",
7
+ "sourceCommit": "4908b09f7bf68edb3341dff227d7993878632e1e",
8
+ "sourceDigest": "9daaf331c203465bff23959aeea112835165f7a16c42e42a11e2e50666fe63c9",
9
+ "binarySha256": "f648254d6b8fc472d50660a4266e2a4a1a0b4f4000c0556327b3ee5b921769ae",
10
10
  "protocol": {
11
11
  "lifecycleOwner": "rust-peer-session",
12
12
  "maxApplicationPayloadBytes": 65536,
@@ -16,5 +16,5 @@
16
16
  },
17
17
  "signingKeySha256": "0391c617f3df12611b419e129cace36fa792e73da03271649cbed9e9f9f155ef",
18
18
  "signatureAlgorithm": "ed25519",
19
- "signature": "RcxuYiXYql3LBp2xciQr6I5HOrR3rii573zUi+uaiWBGaoALX+IvUEOEXSGE2bdBiTvur8Itqq4b7JKns299Bw=="
19
+ "signature": "wAYLGUHsARsY8ms2QXTMnCPHhcpHkgUiS9EBsXPuXa+W6qpAI1li53JMPVf59iC7t6Xa1mOYjUca4m/o7RwgAw=="
20
20
  }
Binary file
@@ -4,9 +4,9 @@
4
4
  "platform": "darwin",
5
5
  "arch": "x64",
6
6
  "rustTarget": "x86_64-apple-darwin",
7
- "sourceCommit": "a42eb60b973b88d09047fa9db8bb9d9f1ff29e80",
8
- "sourceDigest": "2a289da0f6e7006211566a8ad9a6e794803785c599a323df04944972bc7e3517",
9
- "binarySha256": "d266b862aab35e3cbaacc61695f9c6d5d6a6226eb5d28c3de616bc69f5e7deea",
7
+ "sourceCommit": "4908b09f7bf68edb3341dff227d7993878632e1e",
8
+ "sourceDigest": "9daaf331c203465bff23959aeea112835165f7a16c42e42a11e2e50666fe63c9",
9
+ "binarySha256": "3bc6c6d00b633bca939cf19153ec82fc99e1501a68e03cb178c9927b9afa9e64",
10
10
  "protocol": {
11
11
  "lifecycleOwner": "rust-peer-session",
12
12
  "maxApplicationPayloadBytes": 65536,
@@ -16,5 +16,5 @@
16
16
  },
17
17
  "signingKeySha256": "0391c617f3df12611b419e129cace36fa792e73da03271649cbed9e9f9f155ef",
18
18
  "signatureAlgorithm": "ed25519",
19
- "signature": "dPA0+L/NYYwKqoJ9it+M7+PF09NeulyhnOoxM7GfDsHfc+pGFU8s1lNy/3iVBsG/8xCWhyRolcD97fPkswV3DQ=="
19
+ "signature": "WN+ohVgmH8GO1KHk9dFb4Rn0o6FqX2kd5uOUxm2uVvYoWVMJ0cYb1sl1Cs5yIWdMTBbSZREOyB83uCTonswqDA=="
20
20
  }
Binary file
@@ -4,9 +4,9 @@
4
4
  "platform": "linux",
5
5
  "arch": "x64",
6
6
  "rustTarget": "x86_64-unknown-linux-gnu",
7
- "sourceCommit": "f10adfa753e025c1470bee60b361599820e0e46f",
8
- "sourceDigest": "2a289da0f6e7006211566a8ad9a6e794803785c599a323df04944972bc7e3517",
9
- "binarySha256": "54f777ba94fd78ee57182eca0d7164601ee58d96f66c5ea4c676f32da8f515cd",
7
+ "sourceCommit": "4908b09f7bf68edb3341dff227d7993878632e1e",
8
+ "sourceDigest": "9daaf331c203465bff23959aeea112835165f7a16c42e42a11e2e50666fe63c9",
9
+ "binarySha256": "3aa5e75e4dbb239c429b137b8c54176ed1c69eb7f0ccd1996180f9803fad011b",
10
10
  "protocol": {
11
11
  "lifecycleOwner": "rust-peer-session",
12
12
  "maxApplicationPayloadBytes": 65536,
@@ -16,5 +16,5 @@
16
16
  },
17
17
  "signingKeySha256": "0391c617f3df12611b419e129cace36fa792e73da03271649cbed9e9f9f155ef",
18
18
  "signatureAlgorithm": "ed25519",
19
- "signature": "JAEy6pMmQKzCKy1qtKVsxFQZbk/VPh+KaHugSz96p+vNQriLcLXgkJ5S9Sepci2zR+2g3ceA7AdsvQnTgRQeCQ=="
19
+ "signature": "rYuRHa7yRqMf+DOG273DiYeeymwlGKrYfoKmWDn1UF9f7kh5XJ25tSm85a/kXvBAUscvCHXcbw46wz3Wqx9JCQ=="
20
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openrtc",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -1,2 +0,0 @@
1
- import {d}from'./chunk-OWKAJPOI.js';import {a as a$1,d as d$1,c}from'./chunk-2GX6GB6L.js';var P=new Set;function p(e,t){P.has(e)||(P.add(e),console.warn(t));}function T(e){return /^pk_(live|test)_[0-9a-f]{40}$/.test(e)}async function F(e,t){let r=`${e}:${t}`,o=new TextEncoder().encode(r),s=await crypto.subtle.digest("SHA-256",o);return Array.from(new Uint8Array(s)).map(R=>R.toString(16).padStart(2,"0")).join("")}function u(e){let t=typeof e.apiKey=="string"?e.apiKey.trim():"";if(t)return T(t)||p(`invalid-api-key:${t.slice(0,10)}`,"[pluto-rtc] The provided `apiKey` does not match the expected format (pk_live_... or pk_test_...). Create an app at https://api.openrtc.app/developer."),`app_${t.slice(-16)}`;throw new Error("[openrtc] `apiKey` is required. Create an app at https://api.openrtc.app/developer.")}function a(e){return e.authMode?e.authMode:("apiKey"in e&&typeof e.apiKey=="string"&&e.apiKey.trim().length>0&&typeof(e.spaceKey??e.space)=="string"&&(e.spaceKey??e.space).trim().length>0||p("default-auth-mode","[pluto-rtc] `authMode` is not set; defaulting to `anonymous` for compatibility."),"anonymous")}function K(e){let t=typeof e.projectId=="string"?e.projectId.trim():"";return t||(p("default-project-id","[pluto-rtc] `projectId` is not set; defaulting to the built-in PlutoRTC Firebase project."),i)}function v(e){return e.trim().replace(/[^a-zA-Z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function j(e){let t="storagePrefix"in e&&typeof e.storagePrefix=="string"?v(e.storagePrefix):"";return t||v(u(e))||"default"}var x={devicesPerUser:100,maxRooms:1e4,maxMembersPerRoom:50,maxPersonalDevices:25e3},G=x;var M=[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun.cloudflare.com:3478"}],f={iceServers:M};var A=/^[A-Za-z0-9._-]+$/,D="[redacted]";function I(e){let t;try{t=new URL(e);}catch{throw new Error("[OpenRTC] transports.moq.relayUrl must be a valid HTTPS URL.")}if(t.protocol!=="https:")throw new Error("[OpenRTC] transports.moq.relayUrl must use HTTPS/WebTransport.");if(t.hash)throw new Error("[OpenRTC] transports.moq.relayUrl must not contain a fragment.");if(t.searchParams.has("jwt"))throw new Error("[OpenRTC] transports.moq.relayUrl must not contain a jwt query parameter; use transports.moq.accessToken.");return t}function m(e){return I(e.trim()).toString()}function Q(e,t){let r=I(e.trim());if(t!==void 0){let n=t.trim();if(!n)throw new Error("[OpenRTC] transports.moq.accessToken must not be empty when provided.");if(new TextEncoder().encode(n).byteLength>16384)throw new Error("[OpenRTC] transports.moq.accessToken exceeds the maximum supported size.");if(!A.test(n))throw new Error("[OpenRTC] transports.moq.accessToken must be a URL-safe JWT.");r.searchParams.append("jwt",n);}return r.toString()}function z(e,t){let r=e instanceof Error?`${e.name}: ${e.message}`:String(e),n=t?.trim();return n?r.split(n).join(D):r}var h=[...d];function g(e){let t=e.spaceKey??e.space;return {...e,...t!==void 0?{spaceKey:t}:{}}}function S(e){return {...e,iceServers:e.iceServers?e.iceServers.map(t=>({...t})):e.iceServers}}function O(e){return {...e}}function w(e){return {...e}}function k(e){if(e)return {iroh:typeof e.iroh=="object"?w(e.iroh):e.iroh,webrtc:typeof e.webrtc=="object"?S(e.webrtc):e.webrtc,ble:typeof e.ble=="object"?{...e.ble}:e.ble,moq:typeof e.moq=="object"?O(e.moq):e.moq,privacy:e.privacy,optimizeFor:e.optimizeFor,priority:a$1(e.priority)}}function N(e){if(e.strictMode&&!e.transports&&(e.transports={iroh:{relayOnly:true}}),!!e.transports){if(e.transports.webrtc===true?e.transports.webrtc=S(f):e.transports.webrtc===false&&(e.transports.webrtc=void 0),e.transports.moq===true)throw new Error("[OpenRTC] transports.moq=true is ambiguous because no anonymous MoQ relay is available; provide transports.moq.relayUrl explicitly.");if(e.transports.moq===false)e.transports.moq=void 0;else if(e.transports.moq&&typeof e.transports.moq=="object"){let t=e.transports.moq,r=t.relayUrl?.trim(),n=t.accessToken;if(n!==void 0&&!n.trim())throw new Error("[OpenRTC] transports.moq.accessToken must not be empty when provided.");e.transports.moq={...t,...r?{relayUrl:m(r)}:{},...n!==void 0?{accessToken:n.trim()}:{}};}if(e.transports.iroh===true?e.transports.iroh={}:e.transports.iroh===false&&(e.transports.iroh=void 0),e.transports.privacy==="relay-only"){let t=e.transports.iroh&&typeof e.transports.iroh=="object"?e.transports.iroh:{};e.transports.iroh={...t,relayOnly:true,localDiscovery:false,localDiscoveryMode:void 0},e.transports.ble=void 0;let r=e.transports.webrtc;r&&typeof r=="object"&&(e.transports.webrtc={...r,privacyMode:true,lanMode:false,iceServers:c(r.iceServers)??[],iceTransportPolicy:"relay"}),e.transports.priority=d$1(e.transports.priority,!!e.transports.webrtc);}}}function E(e){if(!e.strictMode||!e.transports)return;let t=e.transports.iroh&&typeof e.transports.iroh=="object"?e.transports.iroh:{};e.transports.iroh={...t,relayOnly:true,relayTransportPolicy:t.relayTransportPolicy??"websocketRequired",localDiscovery:false,localDiscoveryMode:void 0},e.transports.privacy="relay-only",e.transports.ble=void 0;let r=e.transports.webrtc;r&&typeof r=="object"&&(e.transports.webrtc={...r,privacyMode:true,lanMode:false,iceServers:c(r.iceServers)??[],iceTransportPolicy:"relay"});let n=e.transports.moq;if(n&&typeof n=="object"){let o=n.relayUrl?.trim();if(!o)throw new Error("[OpenRTC] strictMode requires an explicit transports.moq.relayUrl.");e.transports.moq={...n,relayUrl:m(o)};}}function Z(e){let t=g(e),r=u(t),n=a(t),o={strictMode:false,disableIrohFallback:false,transportPriority:[...h],...t,authMode:n,transports:k(t.transports)};N(o),E(o),o.transportPriority=a$1(t.transportPriority??o.transports?.priority)??[...h],(o.strictMode||o.transports?.privacy==="relay-only")&&(o.transportPriority=d$1(t.transportPriority??o.transports?.priority,!!o.transports?.webrtc));let s=C(o),y=(o.discoveryMode??"space")==="space"?"client-open":"client-auth";return {appTag:r,authMode:n,configuredPersistenceMode:s,options:o,roomCreationMode:y}}function C(e){let t=e.transports?.iroh;return e.endpointIdPersistence??e.nodeIdPersistence??(typeof t=="object"?t.persistenceMode:void 0)??"ephemeral"}function ee(e){return "options"in e&&"configuredPersistenceMode"in e?{apiKey:e.options.apiKey,authMode:a(e.options),projectId:e.options.projectId,storagePrefix:e.options.storagePrefix,nodeIdPersistence:e.configuredPersistenceMode}:{apiKey:e.apiKey,authMode:a(e),projectId:e.projectId,storagePrefix:e.storagePrefix,nodeIdPersistence:C(e)}}function te(e,t){t&&(e.transports={...e.transports||{},...t});}var i="pluto-rtc-prod",U="https://api.openrtc.app",_="https://gateway.openrtc.app";function oe(e){let t=g(e),n=(typeof t.projectId=="string"&&t.projectId.trim()?t.projectId.trim():void 0)??i,o=n===i;return {...t,projectId:n,coordinationGateway:t.coordinationGateway??(o?{endpoint:_,controlPlaneEndpoint:U,environment:"production"}:void 0)}}
2
- export{oe as a,F as b,u as c,a as d,K as e,j as f,G as g,M as h,f as i,Q as j,z as k,g as l,Z as m,ee as n,te as o};