@dobuki/hello-worker 1.0.79 → 1.0.80
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/enter-world.js +2 -2
- package/dist/enter-world.js.map +3 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/dist/webrtc-peer-collector.d.ts.map +1 -1
- package/dist/webrtc-peer-collector.js +2 -2
- package/dist/webrtc-peer-collector.js.map +3 -3
- package/package.json +1 -1
package/dist/enter-world.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class k{sendToServerFunctions=[];icePromiseResolve;icePromise;receiveIce(T,H){this.icePromiseResolve?.({url:T,expiration:H}),this.icePromiseResolve=void 0,this.icePromise=void 0}addRequester(T){return this.sendToServerFunctions.push(T),()=>{this.removeRequester(T)}}removeRequester(T){this.sendToServerFunctions.splice(this.sendToServerFunctions.indexOf(T),1)}sendToServer(T){this.sendToServerFunctions[Math.floor(this.sendToServerFunctions.length*Math.random())](T)}async requestIce(){if(!this.icePromise)this.icePromise=new Promise((T)=>{this.icePromiseResolve=T,this.sendToServer("request-ice")});return await this.icePromise}}function L(T){let{userId:H,worldId:Q,room:S,host:J,autoRejoin:V=!0,logLine:Z}=T,P=!1,x=0,G,Y,E=!0,$=new Map,K=`wss://${J}/room/${Q}/${S}?userId=${encodeURIComponent(H)}`,X=[],N=0;function W(b,h,B){if(!G)return Z?.("\uD83D\uDC64 ➡️ ❌","no ws available"),!1;let F={type:b,to:h,payload:B};if(X.push(F),Z?.("\uD83D\uDC64 ➡️ \uD83D\uDDA5️",F),clearTimeout(N),P||G.readyState!==WebSocket.OPEN)return Z?.("\uD83D\uDC64 ➡️ ❌","Not in opened state: "+G.readyState),!1;return N=setTimeout(()=>{G.send(JSON.stringify(X)),X.length=0}),!0}function O(){if(P)return;G=new WebSocket(K),G.onopen=()=>{if(E)T.onOpen?.(),E=!1;x=0},G.onmessage=(b)=>{try{let h=JSON.parse(b.data);(Array.isArray(h)?h:[h]).forEach((F)=>{if(Z?.("\uD83D\uDDA5️ ➡️ \uD83D\uDC64",F),F.type==="peer-joined"||F.type==="peer-left")M(F.users,F);else if(F.type==="ice-server")T.onIceUrl?.(F.url,F.expiration);else if(F.userId)T.onMessage(F.type,F.payload,{userId:F.userId,receive:(z,A)=>W(z,F.userId,A)})})}catch{Z?.("⚠️ ERROR",{error:"invalid-json"})}},G.onclose=(b)=>{let B=[1001,1006,1011,1012,1013].includes(b.code);if(V&&!P&&B){let F=Math.min(Math.pow(2,x)*1000,30000),z=Math.random()*1000,A=F+z;Z?.("\uD83D\uDD04 RECONNECTING",{attempt:x+1,delayMs:Math.round(A)}),x++,Y=setTimeout(O,A)}else T.onClose?.({code:b.code,reason:b.reason,wasClean:b.wasClean})},G.onerror=(b)=>{console.error("WS Error",b),T.onError?.()}}function M(b,h){let B=[],F=[],z=new Set;b.forEach(({userId:A})=>{if(A===H)return;if(!$.has(A)||h.type==="peer-joined"&&A===h.userId){let c={userId:A,receive:(v,w)=>W(v,A,w)};$.set(A,c),B.push(c)}z.add(A)});for(let A of $.keys())if(!z.has(A)||h.type==="peer-left"&&A===h.userId)$.delete(A),F.push({userId:A});if(B.length)T.onPeerJoined(B);if(F.length)T.onPeerLeft(F)}return O(),{sendToServer(b,h){W(b,"server",h)},exitRoom:()=>{P=!0,clearTimeout(Y),G.close()}}}function j({userId:T,worldId:H,room:Q,host:S,autoRejoin:J=!0,onOpen:V,onClose:Z,onError:P,onPeerJoined:x,onPeerLeft:G,onIceUrl:Y,onMessage:E,logLine:$,workerUrl:K}){if(!K)return console.warn("Warning: enterRoom called without workerUrl; this may cause issues in some environments. You should pass workerUrl explicitly. Use:","https://cdn.jsdelivr.net/npm/@dobuki/hello-worker/dist/signal-room.worker.min.js"),L({userId:T,worldId:H,room:Q,host:S,autoRejoin:J,onOpen:V,onClose:Z,onError:P,onPeerJoined:x,onPeerLeft:G,onIceUrl:Y,onMessage:E});let X=new Worker(K,{type:"module"}),N=!1;function W({userId:M}){return{userId:M,receive:(b,h)=>{if(N)return!1;return X.postMessage({cmd:"send",toUserId:M,host:S,room:Q,type:b,payload:h}),!0}}}let O=(M)=>{let b=M.data;if(b.kind==="open")V?.();else if(b.kind==="close")X.terminate(),Z?.(b.ev);else if(b.kind==="error")P?.();else if(b.kind==="peer-joined")x(b.users.map((h)=>W({userId:h.userId})));else if(b.kind==="peer-left")G(b.users);else if(b.kind==="ice-server")Y?.(b.url,b.expiration);else if(b.kind==="message")E(b.type,b.payload,W({userId:b.fromUserId}));else if(b.kind==="log")$?.(b.direction,b.obj)};return X.addEventListener("message",O),X.postMessage({cmd:"enter",userId:T,worldId:H,room:Q,host:S,autoRejoin:J}),{exitRoom:()=>{N=!0,X.removeEventListener("message",O),X.postMessage({cmd:"exit"})},sendToServer:(M,b)=>{X.postMessage({cmd:"send",toUserId:"server",host:S,room:Q,type:M,payload:b})}}}var U={iceServers:[{urls:"stun:stun.l.google.com:19302"}]};class n{iceUrlProvider;constructor(T){this.iceUrlProvider=T}rtcConfig={...U,timestamp:Date.now()};rtcConfigPromise;async getRtcConfig(){if(Date.now()-(this.rtcConfig?.timestamp??0)<1e4)return this.rtcConfig;if(!this.rtcConfigPromise)this.rtcConfigPromise=new Promise(async(H)=>{let Q=3;for(let S=0;S<Q;S++)try{let J=(await this.iceUrlProvider.requestIce()).url,V=await fetch(J);if(!V.ok)throw Error(`ICE endpoint failed: ${V.status}`);let Z=await V.json();H(Z);return}catch(J){console.warn("Failed fetching iceUrl")}}),this.rtcConfig=await this.rtcConfigPromise,this.rtcConfigPromise=void 0;return this.rtcConfig}}var m=j;function g({userId:T,worldId:H,receivePeerConnection:Q,peerlessUserExpiration:S=5000,enterRoomFunction:J=m,logLine:V,onLeaveUser:Z,workerUrl:P,onRoomReady:x,onRoomClose:G,onBroadcastMessage:Y}){let E=T??`user-${crypto.randomUUID()}`,$=new Map,K=new Map;function X(h){Z?.(h);let B=$.get(h);if(!B)return;$.delete(h);try{B.close()}catch{}}async function N(h){if(!h.connection?.pc?.remoteDescription)return;let B=h.connection.pendingRemoteIce;h.connection.pendingRemoteIce=[];for(let F of B)try{await h.connection.pc.addIceCandidate(F)}catch(z){V?.("⚠️ ERROR",{error:"add-ice-failed",userId:h.peer.userId,detail:String(z)})}}let W=new k,O=new n(W);function M({room:h,host:B}){let F=`${B}/room/${h}`,z=K.get(F);if(z)z.exitRoom(),K.delete(F)}function b({room:h,host:B}){return new Promise(async(F,z)=>{async function A(i){if(i.connectionPromise)return i.connectionPromise;return i.connectionPromise=new Promise(async(q)=>{i.connection={id:`conn-${crypto.randomUUID()}`,pc:new RTCPeerConnection(await O.getRtcConfig()),pendingRemoteIce:[]},i.connection.pc.onicecandidate=(f)=>{if(!f.candidate)return;i.peer.receive("ice",{connectionId:i.connection?.id,ice:f.candidate.toJSON()})},i.connection.pc.onconnectionstatechange=async()=>{if(V?.("\uD83D\uDCAC",{event:"pc-state",userId:i.peer.userId,state:i.connection?.pc?.connectionState}),i.connection?.pc?.connectionState==="failed"){i.close();let f=await c(i.peer,!0);if(f.connection?.pc)Q({pc:f.connection?.pc,userId:f.peer.userId,restart:()=>f.close()});else V?.("\uD83D\uDC64ℹ️","no pc: "+f.peer.userId);return}},q(i.connection)})}async function c(i,q){let f=$.get(i.userId);if(!f||q){let D={peer:i,close(){if(this.connection)this.connection.pc.close(),this.connection=void 0;$.delete(i.userId)},async reset(){D.close(),setTimeout(async()=>{let R=await c(i,!0);if(!R.connection?.pc){V?.("⚠️","no pc");return}Q({pc:R.connection?.pc,userId:R.peer.userId,restart:()=>R.close()}),await v(R.peer)},500)}};f=D,await A(D),$.set(f.peer.userId,f)}else if(f){if(clearTimeout(f.expirationTimeout),f.expirationTimeout=0,!f.connection?.pc||f.connection?.pc.signalingState==="closed")await A(f)}return f.peer=i,f}async function v(i){let q=await c(i),f=q.connection?.pc,D=await f?.createOffer();await f?.setLocalDescription(D),i.receive("offer",{connectionId:q.connection?.id,offer:f.localDescription.toJSON()})}let{exitRoom:w,sendToServer:C}=J({userId:E,worldId:H,room:h,host:B,logLine:V,workerUrl:P,autoRejoin:!0,onOpen(){x?.({room:h,host:B}),F()},onError(){console.error("onError"),z()},onClose(i){G?.({room:h,host:B,ev:i})},onPeerJoined(i){i.forEach(async(q)=>{let f=await c(q,!0),D=f.connection?.pc;if(!D){V?.("\uD83D\uDC64ℹ️","no pc: "+q.userId);return}Q({pc:D,userId:q.userId,restart:()=>f.close()}),await v(q)})},onPeerLeft(i){i.forEach(({userId:q})=>{let f=$.get(q);if(!f)return;f.expirationTimeout=setTimeout(()=>X(q),S??0)})},onIceUrl(i,q){W.receiveIce(i,q)},async onMessage(i,q,f){if(i==="offer"&&q.offer){let D=await c(f,!1),R=!D.connection||D.connection.pc.signalingState==="stable"?await A(D):D.connection;V?.("\uD83D\uDCAC",{type:i,signalingState:R.pc.signalingState}),R.peerConnectionId=q.connectionId,Q({pc:R.pc,userId:f.userId,restart:()=>D.close()}),await R.pc.setRemoteDescription(q.offer);let _=await R.pc.createAnswer();await R.pc.setLocalDescription(_),f.receive("answer",{connectionId:R.id,answer:R.pc.localDescription?.toJSON()}),await N(D);return}if(i==="answer"&&q.answer){let D=await c(f,!1),R=D.connection&&D.connection.pc.signalingState!=="closed"?D.connection:await A(D);V?.("\uD83D\uDCAC",{type:i,signalingState:R.pc.signalingState}),await R.pc.setRemoteDescription(q.answer),R.peerConnectionId=q.connectionId,await N(D);return}if(i==="ice"&&q.ice){let D=await c(f,!1),R=D.connection??await D.connectionPromise;if(!R){V?.("⚠️","No connection");return}if(V?.("\uD83D\uDCAC",{type:i,signalingState:R.pc.signalingState}),R.peerConnectionId&&q.connectionId!==R.peerConnectionId){V?.("⚠️","Mismatch peerConnectionID"+q.connectionId+"vs"+R.peerConnectionId);return}if(!R.pc.remoteDescription||!R.peerConnectionId){R.peerConnectionId=q.connectionId,R.pendingRemoteIce.push(q.ice);return}try{await R.pc.addIceCandidate(q.ice)}catch(_){V?.("⚠️ ERROR",{error:"add-ice-failed",userId:D.peer.userId,detail:String(_)})}return}if(i==="broadcast")Y?.(q,f.userId)}});W.addRequester(C),K.set(`${B}/room/${h}`,{exitRoom:()=>{w(),W.removeRequester(C)},room:h,host:B,broadcast:(i)=>C("broadcast",i)})})}return{userId:E,enterRoom:b,exitRoom:M,leaveUser:X,async reset(h){$.get(h)?.reset()},broadcast(h){K.forEach((B)=>B.broadcast(h))},end(){K.forEach(({exitRoom:h})=>h()),K.clear(),$.forEach(({peer:h})=>X(h.userId)),$.clear()}}}function Ci({userId:T,worldId:H,logLine:Q,enterRoomFunction:S=j,peerlessUserExpiration:J,workerUrl:V,onRoomReady:Z,onRoomClose:P,dataChannelOptions:x}){let G=new Set,Y=new Map,E=new Set,$=new Set;function K(C,i,q){function f(R){let _=R.channel;N(i,_,q),Y.set(i,_)}C.addEventListener("datachannel",f);let D=C.createDataChannel("data",x);return N(i,D,q),Y.set(i,D),()=>{C.removeEventListener("datachannel",f)}}function X(C,i){$.forEach((q)=>q(C,i))}function N(C,i,q){i.onopen=()=>{Q?.("\uD83D\uDCAC",{event:"dc-open",userId:C}),G.add(C),E.forEach((D)=>D(C,"join",[...G]))};let f=({data:D})=>{X(D,C)};i.addEventListener("message",f),i.onclose=()=>{Q?.("\uD83D\uDCAC",{event:"dc-close",userId:C}),G.delete(C),E.forEach((D)=>D(C,"leave",[...G])),i.removeEventListener("message",f),i.onopen=null,i.onclose=null,i.onerror=null,i.close(),q?.()},i.onerror=()=>Q?.("⚠️ ERROR",{error:"dc-error",userId:C})}let{userId:W,enterRoom:O,exitRoom:M,leaveUser:b,broadcast:h,end:B,reset:F}=g({userId:T,worldId:H,enterRoomFunction:S,logLine:Q,workerUrl:V,peerlessUserExpiration:J,onRoomReady:Z,onRoomClose:P,onLeaveUser(C){let i=Y.get(C);try{i?.close()}catch{}Y.delete(C)},receivePeerConnection({pc:C,userId:i,restart:q}){K(C,i,q)},onBroadcastMessage(C,i){X(C,i),Q?.("\uD83D\uDCE2",{event:"broadcast",userId:W,data:C})}});function z(C,i){Y.forEach((q,f)=>{if(i&&f!==i)return;if(q.readyState==="open")q.send(C)})}function A(C){$.delete(C)}function c(C){return $.add(C),()=>{A(C)}}function v(C){E.delete(C)}function w(C){return E.add(C),()=>{v(C)}}return{userId:W,send:z,broadcast:h,enterRoom:O,exitRoom:M,leaveUser:b,getUsers:()=>[...G],addMessageListener:c,removeMessageListener:A,addUserListener:w,removeUserListener:v,reset(){G.forEach((C)=>{Y.get(C)?.close(),Y.delete(C),F(C)})},end(){Y.forEach((C)=>{try{C.close()}catch{}}),Y.clear(),B(),E.clear(),G.clear()}}}export{Ci as enterWorld};
|
|
1
|
+
class k{sendToServerFunctions=[];icePromiseResolve;icePromise;receiveIce(T,H){this.icePromiseResolve?.({url:T,expiration:H}),this.icePromiseResolve=void 0,this.icePromise=void 0}addRequester(T){return this.sendToServerFunctions.push(T),()=>{this.removeRequester(T)}}removeRequester(T){this.sendToServerFunctions.splice(this.sendToServerFunctions.indexOf(T),1)}sendToServer(T){this.sendToServerFunctions[Math.floor(this.sendToServerFunctions.length*Math.random())](T)}async requestIce(){if(!this.icePromise)this.icePromise=new Promise((T)=>{this.icePromiseResolve=T,this.sendToServer("request-ice")});return await this.icePromise}}function L(T){let{userId:H,worldId:Q,room:S,host:J,autoRejoin:V=!0,logLine:Z}=T,P=!1,x=0,G,Y,E=!0,$=new Map,K=`wss://${J}/room/${Q}/${S}?userId=${encodeURIComponent(H)}`,X=[],N=0;function W(b,f,B){if(!G)return Z?.("\uD83D\uDC64 ➡️ ❌","no ws available"),!1;let F={type:b,to:f,payload:B};if(X.push(F),Z?.("\uD83D\uDC64 ➡️ \uD83D\uDDA5️",F),clearTimeout(N),P||G.readyState!==WebSocket.OPEN)return Z?.("\uD83D\uDC64 ➡️ ❌","Not in opened state: "+G.readyState),!1;return N=setTimeout(()=>{G.send(JSON.stringify(X)),X.length=0}),!0}function O(){if(P)return;G=new WebSocket(K),G.onopen=()=>{if(E)T.onOpen?.(),E=!1;x=0},G.onmessage=(b)=>{try{let f=JSON.parse(b.data);(Array.isArray(f)?f:[f]).forEach((F)=>{if(Z?.("\uD83D\uDDA5️ ➡️ \uD83D\uDC64",F),F.type==="peer-joined"||F.type==="peer-left")M(F.users,F);else if(F.type==="ice-server")T.onIceUrl?.(F.url,F.expiration);else if(F.userId)T.onMessage(F.type,F.payload,{userId:F.userId,receive:(z,A)=>W(z,F.userId,A)})})}catch{Z?.("⚠️ ERROR",{error:"invalid-json"})}},G.onclose=(b)=>{let B=[1001,1006,1011,1012,1013].includes(b.code);if(V&&!P&&B){let F=Math.min(Math.pow(2,x)*1000,30000),z=Math.random()*1000,A=F+z;Z?.("\uD83D\uDD04 RECONNECTING",{attempt:x+1,delayMs:Math.round(A)}),x++,Y=setTimeout(O,A)}else T.onClose?.({code:b.code,reason:b.reason,wasClean:b.wasClean})},G.onerror=(b)=>{console.error("WS Error",b),T.onError?.()}}function M(b,f){let B=[],F=[],z=new Set;b.forEach(({userId:A})=>{if(A===H)return;if(!$.has(A)||f.type==="peer-joined"&&A===f.userId){let c={userId:A,receive:(v,w)=>W(v,A,w)};$.set(A,c),B.push(c)}z.add(A)});for(let A of $.keys())if(!z.has(A)||f.type==="peer-left"&&A===f.userId)$.delete(A),F.push({userId:A});if(B.length)T.onPeerJoined(B);if(F.length)T.onPeerLeft(F)}return O(),{sendToServer(b,f){W(b,"server",f)},exitRoom:()=>{P=!0,clearTimeout(Y),G.close()}}}function j({userId:T,worldId:H,room:Q,host:S,autoRejoin:J=!0,onOpen:V,onClose:Z,onError:P,onPeerJoined:x,onPeerLeft:G,onIceUrl:Y,onMessage:E,logLine:$,workerUrl:K}){if(!K)return console.warn("Warning: enterRoom called without workerUrl; this may cause issues in some environments. You should pass workerUrl explicitly. Use:","https://cdn.jsdelivr.net/npm/@dobuki/hello-worker/dist/signal-room.worker.min.js"),L({userId:T,worldId:H,room:Q,host:S,autoRejoin:J,onOpen:V,onClose:Z,onError:P,onPeerJoined:x,onPeerLeft:G,onIceUrl:Y,onMessage:E});let X=new Worker(K,{type:"module"}),N=!1;function W({userId:M}){return{userId:M,receive:(b,f)=>{if(N)return!1;return X.postMessage({cmd:"send",toUserId:M,host:S,room:Q,type:b,payload:f}),!0}}}let O=(M)=>{let b=M.data;if(b.kind==="open")V?.();else if(b.kind==="close")X.terminate(),Z?.(b.ev);else if(b.kind==="error")P?.();else if(b.kind==="peer-joined")x(b.users.map((f)=>W({userId:f.userId})));else if(b.kind==="peer-left")G(b.users);else if(b.kind==="ice-server")Y?.(b.url,b.expiration);else if(b.kind==="message")E(b.type,b.payload,W({userId:b.fromUserId}));else if(b.kind==="log")$?.(b.direction,b.obj)};return X.addEventListener("message",O),X.postMessage({cmd:"enter",userId:T,worldId:H,room:Q,host:S,autoRejoin:J}),{exitRoom:()=>{N=!0,X.removeEventListener("message",O),X.postMessage({cmd:"exit"})},sendToServer:(M,b)=>{X.postMessage({cmd:"send",toUserId:"server",host:S,room:Q,type:M,payload:b})}}}var U={iceServers:[{urls:"stun:stun.l.google.com:19302"}]};class n{iceUrlProvider;constructor(T){this.iceUrlProvider=T}rtcConfig={...U,timestamp:Date.now()};rtcConfigPromise;async getRtcConfig(){if(Date.now()-(this.rtcConfig?.timestamp??0)<1e4)return this.rtcConfig;if(!this.rtcConfigPromise)this.rtcConfigPromise=new Promise(async(H)=>{let Q=3;for(let S=0;S<Q;S++)try{let J=(await this.iceUrlProvider.requestIce()).url,V=await fetch(J);if(!V.ok)throw Error(`ICE endpoint failed: ${V.status}`);let Z=await V.json();H(Z);return}catch(J){console.warn("Failed fetching iceUrl")}}),this.rtcConfig=await this.rtcConfigPromise,this.rtcConfigPromise=void 0;return this.rtcConfig}}var u=j;function g({userId:T,worldId:H,receivePeerConnection:Q,peerlessUserExpiration:S=5000,enterRoomFunction:J=u,logLine:V,onLeaveUser:Z,workerUrl:P,onRoomReady:x,onRoomClose:G,onBroadcastMessage:Y}){let E=T??`user-${crypto.randomUUID()}`,$=new Map,K=new Map;function X(f){Z?.(f);let B=$.get(f);if(!B)return;$.delete(f);try{B.close()}catch{}}async function N(f){if(!f.connection?.pc?.remoteDescription)return;let B=f.connection.pendingRemoteIce;f.connection.pendingRemoteIce=[];for(let F of B)try{await f.connection.pc.addIceCandidate(F)}catch(z){V?.("⚠️ ERROR",{error:"add-ice-failed",userId:f.peer.userId,detail:String(z)})}}let W=new k,O=new n(W);function M({room:f,host:B}){let F=`${B}/room/${f}`,z=K.get(F);if(z)z.exitRoom(),K.delete(F)}function b({room:f,host:B}){return new Promise(async(F,z)=>{async function A(i){if(i.connectionPromise)return i.connectionPromise;let C=new Promise(async(D)=>{i.connection={id:`conn-${crypto.randomUUID()}`,pc:new RTCPeerConnection(await O.getRtcConfig()),pendingRemoteIce:[]},i.connection.pc.onicecandidate=(q)=>{if(!q.candidate)return;i.peer.receive("ice",{connectionId:i.connection?.id,ice:q.candidate.toJSON()})},i.connection.pc.onconnectionstatechange=async()=>{if(V?.("\uD83D\uDCAC",{event:"pc-state",userId:i.peer.userId,state:i.connection?.pc?.connectionState}),i.connection?.pc?.connectionState==="failed"){i.close();let q=await c(i.peer,!0);if(q.connection?.pc)Q({pc:q.connection?.pc,userId:q.peer.userId,restart:()=>q.close()});else V?.("\uD83D\uDC64ℹ️","no pc: "+q.peer.userId);return}},D(i.connection)});return i.connectionPromise=C,await C,i.connectionPromise=void 0,C}async function c(i,C){let D=$.get(i.userId);if(!D||C){let q={peer:i,close(){if(this.connection)this.connection.pc.close(),this.connection=void 0;$.delete(i.userId)},async reset(){q.close(),setTimeout(async()=>{let R=await c(i,!0);if(!R.connection?.pc){V?.("⚠️","no pc");return}Q({pc:R.connection?.pc,userId:R.peer.userId,restart:()=>R.close()}),await v(R.peer)},500)}};D=q,await A(q),$.set(D.peer.userId,D)}else if(D){if(clearTimeout(D.expirationTimeout),D.expirationTimeout=0,!D.connection?.pc||D.connection?.pc.signalingState==="closed")await A(D)}return D.peer=i,D}async function v(i){let C=await c(i),D=C.connection?.pc,q=await D?.createOffer();await D?.setLocalDescription(q),i.receive("offer",{connectionId:C.connection?.id,offer:D.localDescription.toJSON()})}let{exitRoom:w,sendToServer:h}=J({userId:E,worldId:H,room:f,host:B,logLine:V,workerUrl:P,autoRejoin:!0,onOpen(){x?.({room:f,host:B}),F()},onError(){console.error("onError"),z()},onClose(i){G?.({room:f,host:B,ev:i})},onPeerJoined(i){i.forEach(async(C)=>{let D=await c(C,!0),q=D.connection?.pc;if(!q){V?.("\uD83D\uDC64ℹ️","no pc: "+C.userId);return}Q({pc:q,userId:C.userId,restart:()=>D.close()}),await v(C)})},onPeerLeft(i){i.forEach(({userId:C})=>{let D=$.get(C);if(!D)return;D.expirationTimeout=setTimeout(()=>X(C),S??0)})},onIceUrl(i,C){W.receiveIce(i,C)},async onMessage(i,C,D){if(i==="offer"&&C.offer){let q=await c(D,!1),R=!q.connection||q.connection.pc.signalingState==="stable"?await A(q):q.connection;V?.("\uD83D\uDCAC",{type:i,signalingState:R.pc.signalingState}),R.peerConnectionId=C.connectionId,Q({pc:R.pc,userId:D.userId,restart:()=>q.close()}),await R.pc.setRemoteDescription(C.offer);let _=await R.pc.createAnswer();await R.pc.setLocalDescription(_),D.receive("answer",{connectionId:R.id,answer:R.pc.localDescription?.toJSON()}),await N(q);return}if(i==="answer"&&C.answer){let q=await c(D,!1),R=q.connection&&q.connection.pc.signalingState!=="closed"?q.connection:await A(q);V?.("\uD83D\uDCAC",{type:i,signalingState:R.pc.signalingState}),await R.pc.setRemoteDescription(C.answer),R.peerConnectionId=C.connectionId,await N(q);return}if(i==="ice"&&C.ice){let q=await c(D,!1),R=q.connection??await q.connectionPromise;if(!R){V?.("⚠️","No connection");return}if(V?.("\uD83D\uDCAC",{type:i,signalingState:R.pc.signalingState}),R.peerConnectionId&&C.connectionId!==R.peerConnectionId){V?.("⚠️","Mismatch peerConnectionID"+C.connectionId+"vs"+R.peerConnectionId);return}if(!R.pc.remoteDescription||!R.peerConnectionId){R.peerConnectionId=C.connectionId,R.pendingRemoteIce.push(C.ice);return}try{await R.pc.addIceCandidate(C.ice)}catch(_){V?.("⚠️ ERROR",{error:"add-ice-failed",userId:q.peer.userId,detail:String(_)})}return}if(i==="broadcast")Y?.(C,D.userId)}});W.addRequester(h),K.set(`${B}/room/${f}`,{exitRoom:()=>{w(),W.removeRequester(h)},room:f,host:B,broadcast:(i)=>h("broadcast",i)})})}return{userId:E,enterRoom:b,exitRoom:M,leaveUser:X,async reset(f){$.get(f)?.reset()},broadcast(f){K.forEach((B)=>B.broadcast(f))},end(){K.forEach(({exitRoom:f})=>f()),K.clear(),$.forEach(({peer:f})=>X(f.userId)),$.clear()}}}function Ci({userId:T,worldId:H,logLine:Q,enterRoomFunction:S=j,peerlessUserExpiration:J,workerUrl:V,onRoomReady:Z,onRoomClose:P,dataChannelOptions:x}){let G=new Set,Y=new Map,E=new Set,$=new Set;function K(h,i,C){function D(R){let _=R.channel;N(i,_,C),Y.set(i,_)}h.addEventListener("datachannel",D);let q=h.createDataChannel("data",x);return N(i,q,C),Y.set(i,q),()=>{h.removeEventListener("datachannel",D)}}function X(h,i){$.forEach((C)=>C(h,i))}function N(h,i,C){i.onopen=()=>{Q?.("\uD83D\uDCAC",{event:"dc-open",userId:h}),G.add(h),E.forEach((q)=>q(h,"join",[...G]))};let D=({data:q})=>{X(q,h)};i.addEventListener("message",D),i.onclose=()=>{Q?.("\uD83D\uDCAC",{event:"dc-close",userId:h}),G.delete(h),E.forEach((q)=>q(h,"leave",[...G])),i.removeEventListener("message",D),i.onopen=null,i.onclose=null,i.onerror=null,i.close(),C?.()},i.onerror=()=>Q?.("⚠️ ERROR",{error:"dc-error",userId:h})}let{userId:W,enterRoom:O,exitRoom:M,leaveUser:b,broadcast:f,end:B,reset:F}=g({userId:T,worldId:H,enterRoomFunction:S,logLine:Q,workerUrl:V,peerlessUserExpiration:J,onRoomReady:Z,onRoomClose:P,onLeaveUser(h){let i=Y.get(h);try{i?.close()}catch{}Y.delete(h)},receivePeerConnection({pc:h,userId:i,restart:C}){K(h,i,C)},onBroadcastMessage(h,i){X(h,i),Q?.("\uD83D\uDCE2",{event:"broadcast",userId:W,data:h})}});function z(h,i){Y.forEach((C,D)=>{if(i&&D!==i)return;if(C.readyState==="open")C.send(h)})}function A(h){$.delete(h)}function c(h){return $.add(h),()=>{A(h)}}function v(h){E.delete(h)}function w(h){return E.add(h),()=>{v(h)}}return{userId:W,send:z,broadcast:f,enterRoom:O,exitRoom:M,leaveUser:b,getUsers:()=>[...G],addMessageListener:c,removeMessageListener:A,addUserListener:w,removeUserListener:v,reset(){G.forEach((h)=>{Y.get(h)?.close(),Y.delete(h),F(h)})},end(){Y.forEach((h)=>{try{h.close()}catch{}}),Y.clear(),B(),E.clear(),G.clear()}}}export{Ci as enterWorld};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=F76F84CB423911CF64756E2164756E21
|
|
4
4
|
//# sourceMappingURL=enter-world.js.map
|
package/dist/enter-world.js.map
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
"export interface IPeer<T extends string = string, P = any> {\n userId: string;\n receive(type: T, payload: P): boolean;\n}\n\ntype OutMessage = { type: string; to: string; payload: any };\n\n/**\n * enterRoom connects to the signaling room via WebSocket.\n */\nexport function enterRoom<T extends string, P = any>(params: {\n userId: string;\n worldId: string;\n room: string;\n host: string;\n onOpen?: () => void;\n onClose?: (ev: Pick<CloseEvent, \"code\" | \"reason\" | \"wasClean\">) => void;\n onError?: () => void;\n logLine?: (direction: string, obj?: any) => void;\n onPeerJoined(users: IPeer<T, P>[]): void;\n onPeerLeft(users: { userId: string }[]): void;\n onIceUrl?(url: string, expiration: number): void;\n onMessage(type: T, payload: P, from: IPeer<T, P>): void;\n autoRejoin?: boolean;\n}): {\n exitRoom: () => void;\n sendToServer: <P extends any>(type: T, payload?: P) => void;\n} {\n type Message = {\n type: \"peer-joined\" | \"peer-left\" | \"ice-server\" | T;\n userId: string;\n users: { userId: string }[];\n payload: P;\n url: string;\n expiration: number;\n };\n\n const { userId, worldId, room, host, autoRejoin = true, logLine } = params;\n\n let exited = false;\n let retryCount = 0;\n let ws: WebSocket;\n let timeoutId: ReturnType<typeof setTimeout>;\n let initialConnection = true;\n\n const peers = new Map<string, IPeer<T, P>>();\n const wsUrl = `wss://${host}/room/${worldId}/${room}?userId=${encodeURIComponent(\n userId,\n )}`;\n\n // Helper for sending (uses the current ws instance)\n const accumulatedMessages: OutMessage[] = [];\n let timeout: ReturnType<typeof setTimeout> = 0;\n function send(type: string, to: \"server\" | string, payload?: any) {\n if (!ws) {\n logLine?.(\"👤 ➡️ ❌\", \"no ws available\");\n return false;\n }\n const obj: OutMessage = { type, to, payload };\n accumulatedMessages.push(obj);\n logLine?.(\"👤 ➡️ 🖥️\", obj);\n clearTimeout(timeout);\n if (exited || ws.readyState !== WebSocket.OPEN) {\n logLine?.(\"👤 ➡️ ❌\", \"Not in opened state: \" + ws.readyState);\n return false;\n }\n timeout = setTimeout(() => {\n ws.send(JSON.stringify(accumulatedMessages));\n accumulatedMessages.length = 0;\n });\n return true;\n }\n\n function connect() {\n if (exited) return;\n\n ws = new WebSocket(wsUrl);\n\n ws.onopen = () => {\n if (initialConnection) {\n params.onOpen?.();\n initialConnection = false;\n }\n retryCount = 0; // Reset backoff on successful connection\n };\n\n ws.onmessage = (e: MessageEvent) => {\n try {\n const result = JSON.parse(e.data);\n const msgs: Message[] = Array.isArray(result) ? result : [result];\n msgs.forEach((msg) => {\n logLine?.(\"🖥️ ➡️ 👤\", msg);\n if (msg.type === \"peer-joined\" || msg.type === \"peer-left\") {\n updatePeers(msg.users, msg);\n } else if (msg.type === \"ice-server\") {\n params.onIceUrl?.(msg.url, msg.expiration);\n } else if (msg.userId) {\n params.onMessage(msg.type, msg.payload, {\n userId: msg.userId,\n receive: (type: T, payload: P) => send(type, msg.userId, payload),\n });\n }\n });\n } catch {\n logLine?.(\"⚠️ ERROR\", { error: \"invalid-json\" });\n }\n };\n\n ws.onclose = (ev: CloseEvent) => {\n // 1. Check if we should even try to reconnect\n const recoverableCodes = [1001, 1006, 1011, 1012, 1013];\n const isRecoverable = recoverableCodes.includes(ev.code);\n\n if (autoRejoin && !exited && isRecoverable) {\n // 2. Exponential Backoff: 1s, 2s, 4s, 8s... capped at 30s\n const backoff = Math.min(Math.pow(2, retryCount) * 1000, 30000);\n // 3. Add Jitter: +/- 1000ms randomness\n const jitter = Math.random() * 1000;\n const delay = backoff + jitter;\n\n logLine?.(\"🔄 RECONNECTING\", {\n attempt: retryCount + 1,\n delayMs: Math.round(delay),\n });\n\n retryCount++;\n timeoutId = setTimeout(connect, delay);\n } else {\n params.onClose?.({\n code: ev.code,\n reason: ev.reason,\n wasClean: ev.wasClean,\n });\n }\n };\n\n ws.onerror = (ev) => {\n console.error(\"WS Error\", ev);\n params.onError?.();\n };\n }\n\n // Helper for peer tracking (logic from your original code)\n function updatePeers(updatedUsers: { userId: string }[], msg: Message) {\n const joined: IPeer<T, P>[] = [];\n const left: { userId: string }[] = [];\n const updatedPeerSet = new Set<string>();\n\n updatedUsers.forEach(({ userId: pUserId }) => {\n if (pUserId === userId) return;\n if (\n !peers.has(pUserId) ||\n (msg.type === \"peer-joined\" && pUserId === msg.userId)\n ) {\n const newPeer = {\n userId: pUserId,\n receive: (t: T, p: P) => send(t, pUserId, p),\n };\n peers.set(pUserId, newPeer);\n joined.push(newPeer);\n }\n updatedPeerSet.add(pUserId);\n });\n\n for (const pUserId of peers.keys()) {\n if (\n !updatedPeerSet.has(pUserId) ||\n (msg.type === \"peer-left\" && pUserId === msg.userId)\n ) {\n peers.delete(pUserId);\n left.push({ userId: pUserId });\n }\n }\n\n // Notify peer joined first then peer left. (avoid disconnect in case the peer leaving / joining is on the same user).\n if (joined.length) params.onPeerJoined(joined);\n if (left.length) params.onPeerLeft(left);\n }\n\n // Start initial connection\n connect();\n\n return {\n sendToServer(type, payload) {\n send(type, \"server\", payload);\n },\n exitRoom: () => {\n exited = true;\n clearTimeout(timeoutId);\n ws.close();\n },\n };\n}\n",
|
|
7
7
|
"import type { IPeer } from \"./impl/signal-room.js\";\nimport { enterRoom as baseEnterRoom } from \"./impl/signal-room.js\";\nimport { RoomEvent, WorkerCommand } from \"./signal-room.worker.js\";\n\nexport function enterRoom<T extends string, P = any>({\n userId,\n worldId,\n room,\n host,\n autoRejoin = true,\n onOpen,\n onClose,\n onError,\n onPeerJoined,\n onPeerLeft,\n onIceUrl,\n onMessage,\n logLine,\n workerUrl,\n}: {\n userId: string;\n worldId: string;\n room: string;\n host: string;\n autoRejoin?: boolean;\n onOpen?: () => void;\n onClose?: (ev: Pick<CloseEvent, \"code\" | \"reason\" | \"wasClean\">) => void;\n onError?: () => void;\n onPeerJoined: (users: IPeer<T, P>[]) => void;\n onPeerLeft: (users: { userId: string }[]) => void;\n onIceUrl?(url: string, expiration: number): void;\n onMessage: (type: T, payload: P, from: IPeer<T, P>) => void;\n logLine?: (direction: string, obj?: any) => void;\n\n // Pass the URL to your worker file (bundler will handle it)\n workerUrl?: URL;\n}): {\n exitRoom: () => void;\n sendToServer: <P extends any>(type: T, payload?: P) => void;\n} {\n if (!workerUrl) {\n const CDN_WORKER_URL = `https://cdn.jsdelivr.net/npm/@dobuki/hello-worker/dist/signal-room.worker.min.js`;\n\n console.warn(\n \"Warning: enterRoom called without workerUrl; this may cause issues in some environments. You should pass workerUrl explicitly. Use:\",\n CDN_WORKER_URL,\n );\n return baseEnterRoom<T, P>({\n userId,\n worldId,\n room,\n host,\n autoRejoin,\n onOpen,\n onClose,\n onError,\n onPeerJoined,\n onPeerLeft,\n onIceUrl,\n onMessage,\n });\n }\n const worker = new Worker(workerUrl, { type: \"module\" });\n let exited = false;\n\n function makeUser({ userId }: { userId: string }): IPeer<T, P> {\n return {\n userId,\n receive: (type: T, payload: P) => {\n if (exited) return false;\n worker.postMessage({\n cmd: \"send\",\n toUserId: userId,\n host,\n room,\n type,\n payload,\n } as WorkerCommand);\n return true;\n },\n };\n }\n\n const onWorkerMessage = (e: MessageEvent<RoomEvent<T, P>>) => {\n const ev = e.data;\n\n if (ev.kind === \"open\") onOpen?.();\n else if (ev.kind === \"close\") {\n worker.terminate();\n onClose?.(ev.ev);\n } else if (ev.kind === \"error\") onError?.();\n else if (ev.kind === \"peer-joined\")\n onPeerJoined(ev.users.map((ev) => makeUser({ userId: ev.userId })));\n else if (ev.kind === \"peer-left\") onPeerLeft(ev.users);\n else if (ev.kind === \"ice-server\") onIceUrl?.(ev.url, ev.expiration);\n else if (ev.kind === \"message\")\n onMessage(ev.type, ev.payload, makeUser({ userId: ev.fromUserId }));\n else if (ev.kind === \"log\") logLine?.(ev.direction, ev.obj);\n };\n\n worker.addEventListener(\"message\", onWorkerMessage);\n\n worker.postMessage({\n cmd: \"enter\",\n userId,\n worldId,\n room,\n host,\n autoRejoin,\n } as WorkerCommand);\n\n return {\n exitRoom: () => {\n exited = true;\n worker.removeEventListener(\"message\", onWorkerMessage);\n worker.postMessage({ cmd: \"exit\" } as WorkerCommand);\n },\n sendToServer: <P extends any>(type: T, payload?: P) => {\n worker.postMessage({\n cmd: \"send\",\n toUserId: \"server\",\n host,\n room,\n type,\n payload,\n } as WorkerCommand);\n },\n };\n}\n\nexport type EnterRoom<T extends string, P> = typeof enterRoom<T, P>;\n",
|
|
8
8
|
"import { IceUrlProvider } from \"./ice-url-provider\";\n\nconst FALLBACK_RTC_CONFIG = {\n iceServers: [{ urls: \"stun:stun.l.google.com:19302\" }],\n};\n\nexport class RTCConfigProvider {\n constructor(private iceUrlProvider: IceUrlProvider) {}\n\n private rtcConfig: RTCConfiguration & { timestamp: number } = {\n ...FALLBACK_RTC_CONFIG,\n timestamp: Date.now(),\n };\n private rtcConfigPromise?: Promise<RTCConfiguration & { timestamp: number }>;\n\n async getRtcConfig(): Promise<RTCConfiguration & { timestamp: number }> {\n const now = Date.now();\n if (now - (this.rtcConfig?.timestamp ?? 0) < 10000) {\n return this.rtcConfig;\n }\n\n if (!this.rtcConfigPromise) {\n this.rtcConfigPromise = new Promise<\n RTCConfiguration & { timestamp: number }\n >(async (resolve) => {\n let retries = 3;\n for (let r = 0; r < retries; r++) {\n try {\n const iceUrl = (await this.iceUrlProvider.requestIce()).url;\n const r = await fetch(iceUrl);\n if (!r.ok) throw new Error(`ICE endpoint failed: ${r.status}`);\n const rtcConfig = (await r.json()) as RTCConfiguration & {\n timestamp: number;\n };\n resolve(rtcConfig);\n return;\n } catch (e) {\n console.warn(\"Failed fetching iceUrl\");\n }\n }\n });\n this.rtcConfig = await this.rtcConfigPromise;\n this.rtcConfigPromise = undefined;\n }\n return this.rtcConfig;\n }\n}\n",
|
|
9
|
-
"import { IceUrlProvider } from \"./utils/ice-url-provider\";\nimport { IPeer } from \"./signal/impl/signal-room\";\nimport { EnterRoom, enterRoom } from \"./signal/signal-room\";\nimport { RTCConfigProvider } from \"./utils/rtc-config\";\n\nexport type SigType = \"offer\" | \"answer\" | \"ice\" | \"request-ice\" | \"broadcast\";\nexport type SigPayload = {\n connectionId?: string;\n offer?: RTCSessionDescriptionInit;\n answer?: RTCSessionDescriptionInit;\n ice?: RTCIceCandidateInit;\n} & Record<string, any>;\n\ninterface Connection {\n id: string;\n peerConnectionId?: string;\n pc: RTCPeerConnection;\n // ICE that arrived before we had remoteDescription\n pendingRemoteIce: RTCIceCandidateInit[];\n}\n\ntype UserState = {\n connection?: Connection;\n\n // the signaling \"user\" handle so we can send messages\n peer: IPeer<SigType, SigPayload>;\n\n expirationTimeout?: number;\n close(): void;\n reset(): void;\n connectionPromise?: Promise<Connection>;\n};\n\nconst DEFAULT_ENTER_ROOM = enterRoom;\n\n/**\n * Collect peers\n */\nexport function collectPeerConnections({\n userId: passedUserId,\n worldId,\n receivePeerConnection,\n peerlessUserExpiration = 5000,\n enterRoomFunction: enterRoom = DEFAULT_ENTER_ROOM,\n logLine,\n onLeaveUser,\n workerUrl,\n onRoomReady,\n onRoomClose,\n onBroadcastMessage,\n}: {\n userId?: string;\n worldId: string;\n enterRoomFunction?: EnterRoom<SigType, SigPayload>;\n onLeaveUser?: (userId: string) => void;\n logLine?: (direction: string, obj?: any) => void;\n workerUrl?: URL;\n peerlessUserExpiration?: number;\n receivePeerConnection(connection: {\n pc: RTCPeerConnection;\n userId: string;\n restart?: () => void;\n }): void;\n onRoomReady?(info: { host: string; room: string }): void;\n onRoomClose?(info: {\n host: string;\n room: string;\n ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">;\n }): void;\n onBroadcastMessage?<P extends any>(payload: P, from: string): void;\n}) {\n const userId = passedUserId ?? `user-${crypto.randomUUID()}`;\n const users: Map<string, UserState> = new Map();\n\n const roomsEntered = new Map<\n string,\n {\n room: string;\n host: string;\n exitRoom: () => void;\n broadcast: <P extends any>(payload: P) => void;\n }\n >();\n\n function leaveUser(userId: string) {\n onLeaveUser?.(userId);\n const p = users.get(userId);\n if (!p) return;\n users.delete(userId);\n try {\n p.close();\n } catch {}\n }\n\n async function flushRemoteIce(state: UserState) {\n if (!state.connection?.pc?.remoteDescription) return;\n\n const queued = state.connection.pendingRemoteIce;\n state.connection.pendingRemoteIce = [];\n\n for (const ice of queued) {\n try {\n await state.connection.pc.addIceCandidate(ice);\n } catch (e) {\n logLine?.(\"⚠️ ERROR\", {\n error: \"add-ice-failed\",\n userId: state.peer.userId,\n detail: String(e),\n });\n }\n }\n }\n\n const iceUrlProvider = new IceUrlProvider();\n const rtcConfigProvider = new RTCConfigProvider(iceUrlProvider);\n\n function exit({ room, host }: { room: string; host: string }) {\n const key = `${host}/room/${room}`;\n const session = roomsEntered.get(key);\n if (session) {\n session.exitRoom();\n roomsEntered.delete(key);\n }\n }\n\n function enter({ room, host }: { room: string; host: string }) {\n return new Promise<void>(async (resolve, reject) => {\n async function setupConnection(state: UserState) {\n if (state.connectionPromise) {\n return state.connectionPromise;\n }\n return (state.connectionPromise = new Promise<Connection>(\n async (resolve) => {\n state.connection = {\n id: `conn-${crypto.randomUUID()}`,\n pc: new RTCPeerConnection(await rtcConfigProvider.getRtcConfig()),\n pendingRemoteIce: [],\n };\n\n // Send local ICE candidates to this peer\n state.connection.pc.onicecandidate = (ev) => {\n if (!ev.candidate) return;\n state.peer.receive(\"ice\", {\n connectionId: state.connection?.id,\n ice: ev.candidate.toJSON(),\n });\n };\n\n state.connection.pc.onconnectionstatechange = async () => {\n logLine?.(\"💬\", {\n event: \"pc-state\",\n userId: state.peer.userId,\n state: state.connection?.pc?.connectionState,\n });\n if (state.connection?.pc?.connectionState === \"failed\") {\n // reset the connection\n state.close();\n const userState = await getPeer(state.peer, true);\n if (userState.connection?.pc) {\n receivePeerConnection({\n pc: userState.connection?.pc,\n userId: userState.peer.userId,\n restart: () => userState.close(),\n });\n } else {\n logLine?.(\"👤ℹ️\", \"no pc: \" + userState.peer.userId);\n }\n return;\n }\n };\n\n resolve(state.connection);\n },\n ));\n }\n\n async function getPeer(\n peer: IPeer<SigType, SigPayload>,\n forceReset?: boolean,\n ): Promise<UserState> {\n let state = users.get(peer.userId);\n if (!state || forceReset) {\n const newState: UserState = {\n peer,\n close() {\n if (this.connection) {\n this.connection.pc.close();\n this.connection = undefined;\n }\n users.delete(peer.userId);\n },\n async reset() {\n newState.close();\n\n setTimeout(async () => {\n const userState = await getPeer(peer, true);\n if (!userState.connection?.pc) {\n logLine?.(\"⚠️\", \"no pc\");\n return;\n }\n receivePeerConnection({\n pc: userState.connection?.pc,\n userId: userState.peer.userId,\n restart: () => userState.close(),\n });\n await makeOffer(userState.peer);\n }, 500);\n },\n };\n state = newState;\n\n await setupConnection(newState);\n\n // New user\n users.set(state.peer.userId, state);\n } else if (state) {\n clearTimeout(state.expirationTimeout);\n state.expirationTimeout = 0;\n if (\n !state.connection?.pc ||\n state.connection?.pc.signalingState === \"closed\"\n ) {\n await setupConnection(state);\n }\n }\n state.peer = peer;\n return state;\n }\n\n async function makeOffer(user: IPeer<SigType, SigPayload>) {\n // Offer flow: createOffer -> setLocalDescription -> send localDescription\n const state = await getPeer(user);\n const pc = state.connection?.pc;\n const offer = await pc?.createOffer();\n await pc?.setLocalDescription(offer);\n user.receive(\"offer\", {\n connectionId: state.connection?.id,\n offer: pc!.localDescription!.toJSON(),\n });\n }\n\n const { exitRoom, sendToServer } = enterRoom({\n userId,\n worldId,\n room,\n host,\n logLine,\n workerUrl,\n autoRejoin: true,\n\n onOpen() {\n onRoomReady?.({ room, host });\n resolve();\n },\n onError() {\n console.error(\"onError\");\n reject();\n },\n onClose(ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">) {\n onRoomClose?.({ room, host, ev });\n },\n\n // Existing peers initiate to the newcomer\n onPeerJoined(joiningUsers: IPeer<SigType, SigPayload>[]) {\n joiningUsers.forEach(async (user) => {\n const state = await getPeer(user, true);\n const pc = state.connection?.pc;\n if (!pc) {\n logLine?.(\"👤ℹ️\", \"no pc: \" + user.userId);\n return;\n }\n\n receivePeerConnection({\n pc,\n userId: user.userId,\n restart: () => state.close(),\n });\n await makeOffer(user);\n });\n },\n\n onPeerLeft(leavingUsers: { userId: string }[]) {\n leavingUsers.forEach(({ userId }) => {\n const state = users.get(userId);\n if (!state) return;\n state.expirationTimeout = setTimeout(\n () => leaveUser(userId),\n peerlessUserExpiration ?? 0,\n );\n });\n },\n\n onIceUrl(url: string, expiration: number) {\n iceUrlProvider.receiveIce(url, expiration);\n },\n\n async onMessage(type, payload, from: IPeer<SigType, SigPayload>) {\n if (type === \"offer\" && payload.offer) {\n // Grab state and connection\n const state = await getPeer(from, false);\n const connection =\n !state.connection ||\n state.connection.pc.signalingState === \"stable\"\n ? await setupConnection(state)\n : state.connection; // reset\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n connection.peerConnectionId = payload.connectionId;\n receivePeerConnection({\n pc: connection.pc,\n userId: from.userId,\n restart: () => state.close(),\n });\n // Responder: set remote offer\n await connection.pc.setRemoteDescription(payload.offer);\n\n // Create and send answer\n const answer = await connection.pc.createAnswer();\n await connection.pc.setLocalDescription(answer);\n\n from.receive(\"answer\", {\n connectionId: connection.id,\n answer: connection.pc.localDescription?.toJSON(),\n });\n\n // Now safe to apply any queued ICE from this peer\n await flushRemoteIce(state);\n return;\n }\n\n if (type === \"answer\" && payload.answer) {\n const state = await getPeer(from, false);\n const connection =\n state.connection &&\n state.connection.pc.signalingState !== \"closed\"\n ? state.connection\n : await setupConnection(state);\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n // Initiator: set remote answer\n await connection.pc.setRemoteDescription(payload.answer);\n connection.peerConnectionId = payload.connectionId;\n await flushRemoteIce(state);\n return;\n }\n\n if (type === \"ice\" && payload.ice) {\n // Grab state and connection\n const state = await getPeer(from, false);\n const connection =\n state.connection ?? (await state.connectionPromise);\n if (!connection) {\n logLine?.(\"⚠️\", \"No connection\");\n return;\n }\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n if (\n connection.peerConnectionId &&\n payload.connectionId !== connection.peerConnectionId\n ) {\n logLine?.(\n \"⚠️\",\n \"Mismatch peerConnectionID\" +\n payload.connectionId +\n \"vs\" +\n connection.peerConnectionId,\n );\n return;\n }\n\n // If we don't have remoteDescription yet (or if connectionId doesn't match), queue it\n if (\n !connection.pc.remoteDescription ||\n !connection.peerConnectionId\n ) {\n connection.peerConnectionId = payload.connectionId;\n connection.pendingRemoteIce.push(payload.ice);\n return;\n }\n\n try {\n await connection.pc.addIceCandidate(payload.ice);\n } catch (e) {\n logLine?.(\"⚠️ ERROR\", {\n error: \"add-ice-failed\",\n userId: state.peer.userId,\n detail: String(e),\n });\n }\n return;\n }\n\n if (type === \"broadcast\") {\n onBroadcastMessage?.(payload, from.userId);\n }\n },\n });\n\n iceUrlProvider.addRequester(sendToServer);\n\n roomsEntered.set(`${host}/room/${room}`, {\n exitRoom: () => {\n exitRoom();\n iceUrlProvider.removeRequester(sendToServer);\n },\n room,\n host,\n broadcast: (payload) => sendToServer(\"broadcast\", payload),\n });\n });\n }\n\n return {\n userId,\n enterRoom: enter,\n exitRoom: exit,\n leaveUser,\n async reset(userId: string) {\n const userState = users.get(userId);\n userState?.reset();\n },\n broadcast<P extends any>(payload: P) {\n roomsEntered.forEach((room) => room.broadcast(payload));\n },\n end() {\n roomsEntered.forEach(({ exitRoom }) => exitRoom());\n roomsEntered.clear();\n users.forEach(({ peer }) => leaveUser(peer.userId));\n users.clear();\n },\n };\n}\n\n/*\nTurn Token ID\n<CF_TURN_TOKEN_ID>\n\nAPI Token\n<CF_RTC_API_TOKEN>\n\nCURL\ncurl \\\n\t-H \"Authorization: Bearer <CF_RTC_API_TOKEN>\" \\\n\t-H \"Content-Type: application/json\" -d '{\"ttl\": 86400}' \\\n\thttps://rtc.live.cloudflare.com/v1/turn/keys/<CF_TURN_TOKEN_ID>/credentials/generate-ice-servers\n\nJSON\n{\n\t\"iceServers\": [\n {\n \"urls\": [\n \"stun:stun.cloudflare.com:3478\",\n \"turn:turn.cloudflare.com:3478?transport=udp\",\n \"turn:turn.cloudflare.com:3478?transport=tcp\",\n \"turns:turn.cloudflare.com:5349?transport=tcp\"\n ],\n \"username\": \"xxxx\",\n \"credential\": \"yyyy\",\n }\n ]\n}\n\n*/\n",
|
|
9
|
+
"import { IceUrlProvider } from \"./utils/ice-url-provider\";\nimport { IPeer } from \"./signal/impl/signal-room\";\nimport { EnterRoom, enterRoom } from \"./signal/signal-room\";\nimport { RTCConfigProvider } from \"./utils/rtc-config\";\n\nexport type SigType = \"offer\" | \"answer\" | \"ice\" | \"request-ice\" | \"broadcast\";\nexport type SigPayload = {\n connectionId?: string;\n offer?: RTCSessionDescriptionInit;\n answer?: RTCSessionDescriptionInit;\n ice?: RTCIceCandidateInit;\n} & Record<string, any>;\n\ninterface Connection {\n id: string;\n peerConnectionId?: string;\n pc: RTCPeerConnection;\n // ICE that arrived before we had remoteDescription\n pendingRemoteIce: RTCIceCandidateInit[];\n}\n\ntype UserState = {\n connection?: Connection;\n\n // the signaling \"user\" handle so we can send messages\n peer: IPeer<SigType, SigPayload>;\n\n expirationTimeout?: number;\n close(): void;\n reset(): void;\n connectionPromise?: Promise<Connection>;\n};\n\nconst DEFAULT_ENTER_ROOM = enterRoom;\n\n/**\n * Collect peers\n */\nexport function collectPeerConnections({\n userId: passedUserId,\n worldId,\n receivePeerConnection,\n peerlessUserExpiration = 5000,\n enterRoomFunction: enterRoom = DEFAULT_ENTER_ROOM,\n logLine,\n onLeaveUser,\n workerUrl,\n onRoomReady,\n onRoomClose,\n onBroadcastMessage,\n}: {\n userId?: string;\n worldId: string;\n enterRoomFunction?: EnterRoom<SigType, SigPayload>;\n onLeaveUser?: (userId: string) => void;\n logLine?: (direction: string, obj?: any) => void;\n workerUrl?: URL;\n peerlessUserExpiration?: number;\n receivePeerConnection(connection: {\n pc: RTCPeerConnection;\n userId: string;\n restart?: () => void;\n }): void;\n onRoomReady?(info: { host: string; room: string }): void;\n onRoomClose?(info: {\n host: string;\n room: string;\n ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">;\n }): void;\n onBroadcastMessage?<P extends any>(payload: P, from: string): void;\n}) {\n const userId = passedUserId ?? `user-${crypto.randomUUID()}`;\n const users: Map<string, UserState> = new Map();\n\n const roomsEntered = new Map<\n string,\n {\n room: string;\n host: string;\n exitRoom: () => void;\n broadcast: <P extends any>(payload: P) => void;\n }\n >();\n\n function leaveUser(userId: string) {\n onLeaveUser?.(userId);\n const p = users.get(userId);\n if (!p) return;\n users.delete(userId);\n try {\n p.close();\n } catch {}\n }\n\n async function flushRemoteIce(state: UserState) {\n if (!state.connection?.pc?.remoteDescription) return;\n\n const queued = state.connection.pendingRemoteIce;\n state.connection.pendingRemoteIce = [];\n\n for (const ice of queued) {\n try {\n await state.connection.pc.addIceCandidate(ice);\n } catch (e) {\n logLine?.(\"⚠️ ERROR\", {\n error: \"add-ice-failed\",\n userId: state.peer.userId,\n detail: String(e),\n });\n }\n }\n }\n\n const iceUrlProvider = new IceUrlProvider();\n const rtcConfigProvider = new RTCConfigProvider(iceUrlProvider);\n\n function exit({ room, host }: { room: string; host: string }) {\n const key = `${host}/room/${room}`;\n const session = roomsEntered.get(key);\n if (session) {\n session.exitRoom();\n roomsEntered.delete(key);\n }\n }\n\n function enter({ room, host }: { room: string; host: string }) {\n return new Promise<void>(async (resolve, reject) => {\n async function setupConnection(state: UserState) {\n if (state.connectionPromise) {\n return state.connectionPromise;\n }\n const promise = new Promise<Connection>(async (resolve) => {\n state.connection = {\n id: `conn-${crypto.randomUUID()}`,\n pc: new RTCPeerConnection(await rtcConfigProvider.getRtcConfig()),\n pendingRemoteIce: [],\n };\n\n // Send local ICE candidates to this peer\n state.connection.pc.onicecandidate = (ev) => {\n if (!ev.candidate) return;\n state.peer.receive(\"ice\", {\n connectionId: state.connection?.id,\n ice: ev.candidate.toJSON(),\n });\n };\n\n state.connection.pc.onconnectionstatechange = async () => {\n logLine?.(\"💬\", {\n event: \"pc-state\",\n userId: state.peer.userId,\n state: state.connection?.pc?.connectionState,\n });\n if (state.connection?.pc?.connectionState === \"failed\") {\n // reset the connection\n state.close();\n const userState = await getPeer(state.peer, true);\n if (userState.connection?.pc) {\n receivePeerConnection({\n pc: userState.connection?.pc,\n userId: userState.peer.userId,\n restart: () => userState.close(),\n });\n } else {\n logLine?.(\"👤ℹ️\", \"no pc: \" + userState.peer.userId);\n }\n return;\n }\n };\n\n resolve(state.connection);\n });\n state.connectionPromise = promise;\n await promise;\n state.connectionPromise = undefined;\n return promise;\n }\n\n async function getPeer(\n peer: IPeer<SigType, SigPayload>,\n forceReset?: boolean,\n ): Promise<UserState> {\n let state = users.get(peer.userId);\n if (!state || forceReset) {\n const newState: UserState = {\n peer,\n close() {\n if (this.connection) {\n this.connection.pc.close();\n this.connection = undefined;\n }\n users.delete(peer.userId);\n },\n async reset() {\n newState.close();\n\n setTimeout(async () => {\n const userState = await getPeer(peer, true);\n if (!userState.connection?.pc) {\n logLine?.(\"⚠️\", \"no pc\");\n return;\n }\n receivePeerConnection({\n pc: userState.connection?.pc,\n userId: userState.peer.userId,\n restart: () => userState.close(),\n });\n await makeOffer(userState.peer);\n }, 500);\n },\n };\n state = newState;\n\n await setupConnection(newState);\n\n // New user\n users.set(state.peer.userId, state);\n } else if (state) {\n clearTimeout(state.expirationTimeout);\n state.expirationTimeout = 0;\n if (\n !state.connection?.pc ||\n state.connection?.pc.signalingState === \"closed\"\n ) {\n await setupConnection(state);\n }\n }\n state.peer = peer;\n return state;\n }\n\n async function makeOffer(user: IPeer<SigType, SigPayload>) {\n // Offer flow: createOffer -> setLocalDescription -> send localDescription\n const state = await getPeer(user);\n const pc = state.connection?.pc;\n const offer = await pc?.createOffer();\n await pc?.setLocalDescription(offer);\n user.receive(\"offer\", {\n connectionId: state.connection?.id,\n offer: pc!.localDescription!.toJSON(),\n });\n }\n\n const { exitRoom, sendToServer } = enterRoom({\n userId,\n worldId,\n room,\n host,\n logLine,\n workerUrl,\n autoRejoin: true,\n\n onOpen() {\n onRoomReady?.({ room, host });\n resolve();\n },\n onError() {\n console.error(\"onError\");\n reject();\n },\n onClose(ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">) {\n onRoomClose?.({ room, host, ev });\n },\n\n // Existing peers initiate to the newcomer\n onPeerJoined(joiningUsers: IPeer<SigType, SigPayload>[]) {\n joiningUsers.forEach(async (user) => {\n const state = await getPeer(user, true);\n const pc = state.connection?.pc;\n if (!pc) {\n logLine?.(\"👤ℹ️\", \"no pc: \" + user.userId);\n return;\n }\n\n receivePeerConnection({\n pc,\n userId: user.userId,\n restart: () => state.close(),\n });\n await makeOffer(user);\n });\n },\n\n onPeerLeft(leavingUsers: { userId: string }[]) {\n leavingUsers.forEach(({ userId }) => {\n const state = users.get(userId);\n if (!state) return;\n state.expirationTimeout = setTimeout(\n () => leaveUser(userId),\n peerlessUserExpiration ?? 0,\n );\n });\n },\n\n onIceUrl(url: string, expiration: number) {\n iceUrlProvider.receiveIce(url, expiration);\n },\n\n async onMessage(type, payload, from: IPeer<SigType, SigPayload>) {\n if (type === \"offer\" && payload.offer) {\n // Grab state and connection\n const state = await getPeer(from, false);\n const connection =\n !state.connection ||\n state.connection.pc.signalingState === \"stable\"\n ? await setupConnection(state)\n : state.connection; // reset\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n connection.peerConnectionId = payload.connectionId;\n receivePeerConnection({\n pc: connection.pc,\n userId: from.userId,\n restart: () => state.close(),\n });\n // Responder: set remote offer\n await connection.pc.setRemoteDescription(payload.offer);\n\n // Create and send answer\n const answer = await connection.pc.createAnswer();\n await connection.pc.setLocalDescription(answer);\n\n from.receive(\"answer\", {\n connectionId: connection.id,\n answer: connection.pc.localDescription?.toJSON(),\n });\n\n // Now safe to apply any queued ICE from this peer\n await flushRemoteIce(state);\n return;\n }\n\n if (type === \"answer\" && payload.answer) {\n const state = await getPeer(from, false);\n const connection =\n state.connection &&\n state.connection.pc.signalingState !== \"closed\"\n ? state.connection\n : await setupConnection(state);\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n // Initiator: set remote answer\n await connection.pc.setRemoteDescription(payload.answer);\n connection.peerConnectionId = payload.connectionId;\n await flushRemoteIce(state);\n return;\n }\n\n if (type === \"ice\" && payload.ice) {\n // Grab state and connection\n const state = await getPeer(from, false);\n const connection =\n state.connection ?? (await state.connectionPromise);\n if (!connection) {\n logLine?.(\"⚠️\", \"No connection\");\n return;\n }\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n if (\n connection.peerConnectionId &&\n payload.connectionId !== connection.peerConnectionId\n ) {\n logLine?.(\n \"⚠️\",\n \"Mismatch peerConnectionID\" +\n payload.connectionId +\n \"vs\" +\n connection.peerConnectionId,\n );\n return;\n }\n\n // If we don't have remoteDescription yet (or if connectionId doesn't match), queue it\n if (\n !connection.pc.remoteDescription ||\n !connection.peerConnectionId\n ) {\n connection.peerConnectionId = payload.connectionId;\n connection.pendingRemoteIce.push(payload.ice);\n return;\n }\n\n try {\n await connection.pc.addIceCandidate(payload.ice);\n } catch (e) {\n logLine?.(\"⚠️ ERROR\", {\n error: \"add-ice-failed\",\n userId: state.peer.userId,\n detail: String(e),\n });\n }\n return;\n }\n\n if (type === \"broadcast\") {\n onBroadcastMessage?.(payload, from.userId);\n }\n },\n });\n\n iceUrlProvider.addRequester(sendToServer);\n\n roomsEntered.set(`${host}/room/${room}`, {\n exitRoom: () => {\n exitRoom();\n iceUrlProvider.removeRequester(sendToServer);\n },\n room,\n host,\n broadcast: (payload) => sendToServer(\"broadcast\", payload),\n });\n });\n }\n\n return {\n userId,\n enterRoom: enter,\n exitRoom: exit,\n leaveUser,\n async reset(userId: string) {\n const userState = users.get(userId);\n userState?.reset();\n },\n broadcast<P extends any>(payload: P) {\n roomsEntered.forEach((room) => room.broadcast(payload));\n },\n end() {\n roomsEntered.forEach(({ exitRoom }) => exitRoom());\n roomsEntered.clear();\n users.forEach(({ peer }) => leaveUser(peer.userId));\n users.clear();\n },\n };\n}\n\n/*\nTurn Token ID\n<CF_TURN_TOKEN_ID>\n\nAPI Token\n<CF_RTC_API_TOKEN>\n\nCURL\ncurl \\\n\t-H \"Authorization: Bearer <CF_RTC_API_TOKEN>\" \\\n\t-H \"Content-Type: application/json\" -d '{\"ttl\": 86400}' \\\n\thttps://rtc.live.cloudflare.com/v1/turn/keys/<CF_TURN_TOKEN_ID>/credentials/generate-ice-servers\n\nJSON\n{\n\t\"iceServers\": [\n {\n \"urls\": [\n \"stun:stun.cloudflare.com:3478\",\n \"turn:turn.cloudflare.com:3478?transport=udp\",\n \"turn:turn.cloudflare.com:3478?transport=tcp\",\n \"turns:turn.cloudflare.com:5349?transport=tcp\"\n ],\n \"username\": \"xxxx\",\n \"credential\": \"yyyy\",\n }\n ]\n}\n\n*/\n",
|
|
10
10
|
"import { EnterRoom, enterRoom } from \"./signal/signal-room\";\nimport {\n SigType,\n SigPayload,\n collectPeerConnections,\n} from \"./webrtc-peer-collector\";\n\ntype UserListener = (\n user: string,\n action: \"join\" | \"leave\",\n users: string[],\n) => void;\n\nexport function enterWorld<\n S extends string | ArrayBufferView = string | ArrayBufferView,\n R extends string | ArrayBufferLike = string | ArrayBufferLike,\n>({\n userId: passedUserId,\n worldId,\n logLine,\n enterRoomFunction = enterRoom,\n peerlessUserExpiration,\n workerUrl,\n onRoomReady,\n onRoomClose,\n dataChannelOptions,\n}: {\n userId?: string;\n worldId: string;\n logLine?: (...obj: any[]) => void;\n enterRoomFunction?: EnterRoom<SigType, SigPayload>;\n peerlessUserExpiration?: number;\n workerUrl?: URL;\n onRoomReady?(info: { host: string; room: string }): void;\n onRoomClose?(info: {\n host: string;\n room: string;\n ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">;\n }): void;\n dataChannelOptions?: RTCDataChannelInit;\n}) {\n const userIds = new Set<string>();\n const dataChannels = new Map<string, RTCDataChannel>();\n const userListeners = new Set<UserListener>();\n const messagesListeners = new Set<(data: R, from: string) => void>();\n\n function createDataChannel(\n pc: RTCPeerConnection,\n peerUserId: string,\n restart?: () => void,\n ) {\n function listener(ev: RTCDataChannelEvent) {\n const dc = ev.channel;\n wireDataChannel(peerUserId, dc, restart);\n dataChannels.set(peerUserId, dc);\n }\n pc.addEventListener(\"datachannel\", listener);\n const dc = pc.createDataChannel(\"data\", dataChannelOptions);\n wireDataChannel(peerUserId, dc, restart);\n dataChannels.set(peerUserId, dc);\n return () => {\n pc.removeEventListener(\"datachannel\", listener);\n };\n }\n\n function conveyMessage(data: any, userId: string) {\n messagesListeners.forEach((listener) => listener(data, userId));\n }\n\n function wireDataChannel(\n userId: string,\n dc: RTCDataChannel,\n restart?: () => void,\n ) {\n dc.onopen = () => {\n logLine?.(\"💬\", { event: \"dc-open\", userId });\n userIds.add(userId);\n userListeners.forEach((listener) =>\n listener(userId, \"join\", [...userIds]),\n );\n };\n const onmessage = ({ data }: MessageEvent) => {\n conveyMessage(data, userId);\n };\n dc.addEventListener(\"message\", onmessage);\n dc.onclose = () => {\n logLine?.(\"💬\", { event: \"dc-close\", userId });\n userIds.delete(userId);\n userListeners.forEach((listener) =>\n listener(userId, \"leave\", [...userIds]),\n );\n dc.removeEventListener(\"message\", onmessage);\n dc.onopen = null;\n dc.onclose = null;\n dc.onerror = null;\n dc.close();\n restart?.();\n };\n dc.onerror = () => logLine?.(\"⚠️ ERROR\", { error: \"dc-error\", userId });\n }\n\n const {\n userId,\n enterRoom,\n exitRoom,\n leaveUser,\n broadcast,\n end: endPeerCollection,\n reset: resetPeerCollection,\n } = collectPeerConnections({\n userId: passedUserId,\n worldId,\n enterRoomFunction,\n logLine,\n workerUrl,\n peerlessUserExpiration,\n onRoomReady,\n onRoomClose,\n onLeaveUser(userId: string) {\n const dc = dataChannels.get(userId);\n try {\n dc?.close();\n } catch {}\n dataChannels.delete(userId);\n },\n receivePeerConnection({ pc, userId, restart }) {\n createDataChannel(pc, userId, restart);\n },\n onBroadcastMessage(payload, from) {\n conveyMessage(payload, from);\n logLine?.(\"📢\", { event: \"broadcast\", userId, data: payload });\n },\n });\n\n function send(data: S, userId?: string) {\n dataChannels.forEach((dataChannel, pUserId) => {\n if (userId && pUserId !== userId) return;\n if (dataChannel.readyState === \"open\") {\n dataChannel.send(data as any);\n }\n });\n }\n\n function removeMessageListener(listener: (data: R, from: string) => void) {\n messagesListeners.delete(listener);\n }\n\n function addMessageListener(listener: (data: R, from: string) => void) {\n messagesListeners.add(listener);\n return () => {\n removeMessageListener(listener);\n };\n }\n\n function removeUserListener(listener: UserListener) {\n userListeners.delete(listener);\n }\n\n function addUserListener(listener: UserListener) {\n userListeners.add(listener);\n return () => {\n removeUserListener(listener);\n };\n }\n\n return {\n userId,\n send,\n broadcast,\n enterRoom,\n exitRoom,\n leaveUser,\n getUsers: () => [...userIds],\n addMessageListener,\n removeMessageListener,\n addUserListener,\n removeUserListener,\n reset() {\n userIds.forEach((userId) => {\n dataChannels.get(userId)?.close();\n dataChannels.delete(userId);\n resetPeerCollection(userId);\n });\n },\n end() {\n dataChannels.forEach((dataChannel) => {\n try {\n dataChannel.close();\n } catch {}\n });\n dataChannels.clear();\n endPeerCollection();\n userListeners.clear();\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ACF,EAAY,MAAM,EAClB,KAAM,GACT,EACD,EAAa,MAAM,EACnB,EAAkB,EAClB,EAAc,MAAM,EACpB,EAAQ,MAAM,EAElB",
|
|
13
|
+
"debugId": "F76F84CB423911CF64756E2164756E21",
|
|
14
14
|
"names": []
|
|
15
15
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class j{sendToServerFunctions=[];icePromiseResolve;icePromise;receiveIce(T,E){this.icePromiseResolve?.({url:T,expiration:E}),this.icePromiseResolve=void 0,this.icePromise=void 0}addRequester(T){return this.sendToServerFunctions.push(T),()=>{this.removeRequester(T)}}removeRequester(T){this.sendToServerFunctions.splice(this.sendToServerFunctions.indexOf(T),1)}sendToServer(T){this.sendToServerFunctions[Math.floor(this.sendToServerFunctions.length*Math.random())](T)}async requestIce(){if(!this.icePromise)this.icePromise=new Promise((T)=>{this.icePromiseResolve=T,this.sendToServer("request-ice")});return await this.icePromise}}function k(T){let{userId:E,worldId:c,room:H,host:M,autoRejoin:V=!0,logLine:X}=T,J=!1,P=0,G,W,Z=!0,$=new Map,S=`wss://${M}/room/${c}/${H}?userId=${encodeURIComponent(E)}`,Q=[],N=0;function z(q,h,B){if(!G)return X?.("\uD83D\uDC64 ➡️ ❌","no ws available"),!1;let D={type:q,to:h,payload:B};if(Q.push(D),X?.("\uD83D\uDC64 ➡️ \uD83D\uDDA5️",D),clearTimeout(N),J||G.readyState!==WebSocket.OPEN)return X?.("\uD83D\uDC64 ➡️ ❌","Not in opened state: "+G.readyState),!1;return N=setTimeout(()=>{G.send(JSON.stringify(Q)),Q.length=0}),!0}function O(){if(J)return;G=new WebSocket(S),G.onopen=()=>{if(Z)T.onOpen?.(),Z=!1;P=0},G.onmessage=(q)=>{try{let h=JSON.parse(q.data);(Array.isArray(h)?h:[h]).forEach((D)=>{if(X?.("\uD83D\uDDA5️ ➡️ \uD83D\uDC64",D),D.type==="peer-joined"||D.type==="peer-left")K(D.users,D);else if(D.type==="ice-server")T.onIceUrl?.(D.url,D.expiration);else if(D.userId)T.onMessage(D.type,D.payload,{userId:D.userId,receive:(Y,A)=>z(Y,D.userId,A)})})}catch{X?.("⚠️ ERROR",{error:"invalid-json"})}},G.onclose=(q)=>{let B=[1001,1006,1011,1012,1013].includes(q.code);if(V&&!J&&B){let D=Math.min(Math.pow(2,P)*1000,30000),Y=Math.random()*1000,A=D+Y;X?.("\uD83D\uDD04 RECONNECTING",{attempt:P+1,delayMs:Math.round(A)}),P++,W=setTimeout(O,A)}else T.onClose?.({code:q.code,reason:q.reason,wasClean:q.wasClean})},G.onerror=(q)=>{console.error("WS Error",q),T.onError?.()}}function K(q,h){let B=[],D=[],Y=new Set;q.forEach(({userId:A})=>{if(A===E)return;if(!$.has(A)||h.type==="peer-joined"&&A===h.userId){let x={userId:A,receive:(v,n)=>z(v,A,n)};$.set(A,x),B.push(x)}Y.add(A)});for(let A of $.keys())if(!Y.has(A)||h.type==="peer-left"&&A===h.userId)$.delete(A),D.push({userId:A});if(B.length)T.onPeerJoined(B);if(D.length)T.onPeerLeft(D)}return O(),{sendToServer(q,h){z(q,"server",h)},exitRoom:()=>{J=!0,clearTimeout(W),G.close()}}}function w({userId:T,worldId:E,room:c,host:H,autoRejoin:M=!0,onOpen:V,onClose:X,onError:J,onPeerJoined:P,onPeerLeft:G,onIceUrl:W,onMessage:Z,logLine:$,workerUrl:S}){if(!S)return console.warn("Warning: enterRoom called without workerUrl; this may cause issues in some environments. You should pass workerUrl explicitly. Use:","https://cdn.jsdelivr.net/npm/@dobuki/hello-worker/dist/signal-room.worker.min.js"),k({userId:T,worldId:E,room:c,host:H,autoRejoin:M,onOpen:V,onClose:X,onError:J,onPeerJoined:P,onPeerLeft:G,onIceUrl:W,onMessage:Z});let Q=new Worker(S,{type:"module"}),N=!1;function z({userId:K}){return{userId:K,receive:(q,h)=>{if(N)return!1;return Q.postMessage({cmd:"send",toUserId:K,host:H,room:c,type:q,payload:h}),!0}}}let O=(K)=>{let q=K.data;if(q.kind==="open")V?.();else if(q.kind==="close")Q.terminate(),X?.(q.ev);else if(q.kind==="error")J?.();else if(q.kind==="peer-joined")P(q.users.map((h)=>z({userId:h.userId})));else if(q.kind==="peer-left")G(q.users);else if(q.kind==="ice-server")W?.(q.url,q.expiration);else if(q.kind==="message")Z(q.type,q.payload,z({userId:q.fromUserId}));else if(q.kind==="log")$?.(q.direction,q.obj)};return Q.addEventListener("message",O),Q.postMessage({cmd:"enter",userId:T,worldId:E,room:c,host:H,autoRejoin:M}),{exitRoom:()=>{N=!0,Q.removeEventListener("message",O),Q.postMessage({cmd:"exit"})},sendToServer:(K,q)=>{Q.postMessage({cmd:"send",toUserId:"server",host:H,room:c,type:K,payload:q})}}}var U={iceServers:[{urls:"stun:stun.l.google.com:19302"}]};class L{iceUrlProvider;constructor(T){this.iceUrlProvider=T}rtcConfig={...U,timestamp:Date.now()};rtcConfigPromise;async getRtcConfig(){if(Date.now()-(this.rtcConfig?.timestamp??0)<1e4)return this.rtcConfig;if(!this.rtcConfigPromise)this.rtcConfigPromise=new Promise(async(E)=>{let c=3;for(let H=0;H<c;H++)try{let M=(await this.iceUrlProvider.requestIce()).url,V=await fetch(M);if(!V.ok)throw Error(`ICE endpoint failed: ${V.status}`);let X=await V.json();E(X);return}catch(M){console.warn("Failed fetching iceUrl")}}),this.rtcConfig=await this.rtcConfigPromise,this.rtcConfigPromise=void 0;return this.rtcConfig}}var m=w;function g({userId:T,worldId:E,receivePeerConnection:c,peerlessUserExpiration:H=5000,enterRoomFunction:M=m,logLine:V,onLeaveUser:X,workerUrl:J,onRoomReady:P,onRoomClose:G,onBroadcastMessage:W}){let Z=T??`user-${crypto.randomUUID()}`,$=new Map,S=new Map;function Q(h){X?.(h);let B=$.get(h);if(!B)return;$.delete(h);try{B.close()}catch{}}async function N(h){if(!h.connection?.pc?.remoteDescription)return;let B=h.connection.pendingRemoteIce;h.connection.pendingRemoteIce=[];for(let D of B)try{await h.connection.pc.addIceCandidate(D)}catch(Y){V?.("⚠️ ERROR",{error:"add-ice-failed",userId:h.peer.userId,detail:String(Y)})}}let z=new j,O=new L(z);function K({room:h,host:B}){let D=`${B}/room/${h}`,Y=S.get(D);if(Y)Y.exitRoom(),S.delete(D)}function q({room:h,host:B}){return new Promise(async(D,Y)=>{async function A(i){if(i.connectionPromise)return i.connectionPromise;return i.connectionPromise=new Promise(async(b)=>{i.connection={id:`conn-${crypto.randomUUID()}`,pc:new RTCPeerConnection(await O.getRtcConfig()),pendingRemoteIce:[]},i.connection.pc.onicecandidate=(f)=>{if(!f.candidate)return;i.peer.receive("ice",{connectionId:i.connection?.id,ice:f.candidate.toJSON()})},i.connection.pc.onconnectionstatechange=async()=>{if(V?.("\uD83D\uDCAC",{event:"pc-state",userId:i.peer.userId,state:i.connection?.pc?.connectionState}),i.connection?.pc?.connectionState==="failed"){i.close();let f=await x(i.peer,!0);if(f.connection?.pc)c({pc:f.connection?.pc,userId:f.peer.userId,restart:()=>f.close()});else V?.("\uD83D\uDC64ℹ️","no pc: "+f.peer.userId);return}},b(i.connection)})}async function x(i,b){let f=$.get(i.userId);if(!f||b){let R={peer:i,close(){if(this.connection)this.connection.pc.close(),this.connection=void 0;$.delete(i.userId)},async reset(){R.close(),setTimeout(async()=>{let F=await x(i,!0);if(!F.connection?.pc){V?.("⚠️","no pc");return}c({pc:F.connection?.pc,userId:F.peer.userId,restart:()=>F.close()}),await v(F.peer)},500)}};f=R,await A(R),$.set(f.peer.userId,f)}else if(f){if(clearTimeout(f.expirationTimeout),f.expirationTimeout=0,!f.connection?.pc||f.connection?.pc.signalingState==="closed")await A(f)}return f.peer=i,f}async function v(i){let b=await x(i),f=b.connection?.pc,R=await f?.createOffer();await f?.setLocalDescription(R),i.receive("offer",{connectionId:b.connection?.id,offer:f.localDescription.toJSON()})}let{exitRoom:n,sendToServer:C}=M({userId:Z,worldId:E,room:h,host:B,logLine:V,workerUrl:J,autoRejoin:!0,onOpen(){P?.({room:h,host:B}),D()},onError(){console.error("onError"),Y()},onClose(i){G?.({room:h,host:B,ev:i})},onPeerJoined(i){i.forEach(async(b)=>{let f=await x(b,!0),R=f.connection?.pc;if(!R){V?.("\uD83D\uDC64ℹ️","no pc: "+b.userId);return}c({pc:R,userId:b.userId,restart:()=>f.close()}),await v(b)})},onPeerLeft(i){i.forEach(({userId:b})=>{let f=$.get(b);if(!f)return;f.expirationTimeout=setTimeout(()=>Q(b),H??0)})},onIceUrl(i,b){z.receiveIce(i,b)},async onMessage(i,b,f){if(i==="offer"&&b.offer){let R=await x(f,!1),F=!R.connection||R.connection.pc.signalingState==="stable"?await A(R):R.connection;V?.("\uD83D\uDCAC",{type:i,signalingState:F.pc.signalingState}),F.peerConnectionId=b.connectionId,c({pc:F.pc,userId:f.userId,restart:()=>R.close()}),await F.pc.setRemoteDescription(b.offer);let _=await F.pc.createAnswer();await F.pc.setLocalDescription(_),f.receive("answer",{connectionId:F.id,answer:F.pc.localDescription?.toJSON()}),await N(R);return}if(i==="answer"&&b.answer){let R=await x(f,!1),F=R.connection&&R.connection.pc.signalingState!=="closed"?R.connection:await A(R);V?.("\uD83D\uDCAC",{type:i,signalingState:F.pc.signalingState}),await F.pc.setRemoteDescription(b.answer),F.peerConnectionId=b.connectionId,await N(R);return}if(i==="ice"&&b.ice){let R=await x(f,!1),F=R.connection??await R.connectionPromise;if(!F){V?.("⚠️","No connection");return}if(V?.("\uD83D\uDCAC",{type:i,signalingState:F.pc.signalingState}),F.peerConnectionId&&b.connectionId!==F.peerConnectionId){V?.("⚠️","Mismatch peerConnectionID"+b.connectionId+"vs"+F.peerConnectionId);return}if(!F.pc.remoteDescription||!F.peerConnectionId){F.peerConnectionId=b.connectionId,F.pendingRemoteIce.push(b.ice);return}try{await F.pc.addIceCandidate(b.ice)}catch(_){V?.("⚠️ ERROR",{error:"add-ice-failed",userId:R.peer.userId,detail:String(_)})}return}if(i==="broadcast")W?.(b,f.userId)}});z.addRequester(C),S.set(`${B}/room/${h}`,{exitRoom:()=>{n(),z.removeRequester(C)},room:h,host:B,broadcast:(i)=>C("broadcast",i)})})}return{userId:Z,enterRoom:q,exitRoom:K,leaveUser:Q,async reset(h){$.get(h)?.reset()},broadcast(h){S.forEach((B)=>B.broadcast(h))},end(){S.forEach(({exitRoom:h})=>h()),S.clear(),$.forEach(({peer:h})=>Q(h.userId)),$.clear()}}}function u({userId:T,worldId:E,logLine:c,enterRoomFunction:H=w,peerlessUserExpiration:M,workerUrl:V,onRoomReady:X,onRoomClose:J,dataChannelOptions:P}){let G=new Set,W=new Map,Z=new Set,$=new Set;function S(C,i,b){function f(F){let _=F.channel;N(i,_,b),W.set(i,_)}C.addEventListener("datachannel",f);let R=C.createDataChannel("data",P);return N(i,R,b),W.set(i,R),()=>{C.removeEventListener("datachannel",f)}}function Q(C,i){$.forEach((b)=>b(C,i))}function N(C,i,b){i.onopen=()=>{c?.("\uD83D\uDCAC",{event:"dc-open",userId:C}),G.add(C),Z.forEach((R)=>R(C,"join",[...G]))};let f=({data:R})=>{Q(R,C)};i.addEventListener("message",f),i.onclose=()=>{c?.("\uD83D\uDCAC",{event:"dc-close",userId:C}),G.delete(C),Z.forEach((R)=>R(C,"leave",[...G])),i.removeEventListener("message",f),i.onopen=null,i.onclose=null,i.onerror=null,i.close(),b?.()},i.onerror=()=>c?.("⚠️ ERROR",{error:"dc-error",userId:C})}let{userId:z,enterRoom:O,exitRoom:K,leaveUser:q,broadcast:h,end:B,reset:D}=g({userId:T,worldId:E,enterRoomFunction:H,logLine:c,workerUrl:V,peerlessUserExpiration:M,onRoomReady:X,onRoomClose:J,onLeaveUser(C){let i=W.get(C);try{i?.close()}catch{}W.delete(C)},receivePeerConnection({pc:C,userId:i,restart:b}){S(C,i,b)},onBroadcastMessage(C,i){Q(C,i),c?.("\uD83D\uDCE2",{event:"broadcast",userId:z,data:C})}});function Y(C,i){W.forEach((b,f)=>{if(i&&f!==i)return;if(b.readyState==="open")b.send(C)})}function A(C){$.delete(C)}function x(C){return $.add(C),()=>{A(C)}}function v(C){Z.delete(C)}function n(C){return Z.add(C),()=>{v(C)}}return{userId:z,send:Y,broadcast:h,enterRoom:O,exitRoom:K,leaveUser:q,getUsers:()=>[...G],addMessageListener:x,removeMessageListener:A,addUserListener:n,removeUserListener:v,reset(){G.forEach((C)=>{W.get(C)?.close(),W.delete(C),D(C)})},end(){W.forEach((C)=>{try{C.close()}catch{}}),W.clear(),B(),Z.clear(),G.clear()}}}export{u as enterWorld,k as enterRoom,g as collectPeerConnections};
|
|
1
|
+
class j{sendToServerFunctions=[];icePromiseResolve;icePromise;receiveIce(T,E){this.icePromiseResolve?.({url:T,expiration:E}),this.icePromiseResolve=void 0,this.icePromise=void 0}addRequester(T){return this.sendToServerFunctions.push(T),()=>{this.removeRequester(T)}}removeRequester(T){this.sendToServerFunctions.splice(this.sendToServerFunctions.indexOf(T),1)}sendToServer(T){this.sendToServerFunctions[Math.floor(this.sendToServerFunctions.length*Math.random())](T)}async requestIce(){if(!this.icePromise)this.icePromise=new Promise((T)=>{this.icePromiseResolve=T,this.sendToServer("request-ice")});return await this.icePromise}}function k(T){let{userId:E,worldId:c,room:H,host:M,autoRejoin:V=!0,logLine:X}=T,J=!1,P=0,G,W,Z=!0,$=new Map,S=`wss://${M}/room/${c}/${H}?userId=${encodeURIComponent(E)}`,Q=[],N=0;function z(q,f,B){if(!G)return X?.("\uD83D\uDC64 ➡️ ❌","no ws available"),!1;let D={type:q,to:f,payload:B};if(Q.push(D),X?.("\uD83D\uDC64 ➡️ \uD83D\uDDA5️",D),clearTimeout(N),J||G.readyState!==WebSocket.OPEN)return X?.("\uD83D\uDC64 ➡️ ❌","Not in opened state: "+G.readyState),!1;return N=setTimeout(()=>{G.send(JSON.stringify(Q)),Q.length=0}),!0}function O(){if(J)return;G=new WebSocket(S),G.onopen=()=>{if(Z)T.onOpen?.(),Z=!1;P=0},G.onmessage=(q)=>{try{let f=JSON.parse(q.data);(Array.isArray(f)?f:[f]).forEach((D)=>{if(X?.("\uD83D\uDDA5️ ➡️ \uD83D\uDC64",D),D.type==="peer-joined"||D.type==="peer-left")K(D.users,D);else if(D.type==="ice-server")T.onIceUrl?.(D.url,D.expiration);else if(D.userId)T.onMessage(D.type,D.payload,{userId:D.userId,receive:(Y,A)=>z(Y,D.userId,A)})})}catch{X?.("⚠️ ERROR",{error:"invalid-json"})}},G.onclose=(q)=>{let B=[1001,1006,1011,1012,1013].includes(q.code);if(V&&!J&&B){let D=Math.min(Math.pow(2,P)*1000,30000),Y=Math.random()*1000,A=D+Y;X?.("\uD83D\uDD04 RECONNECTING",{attempt:P+1,delayMs:Math.round(A)}),P++,W=setTimeout(O,A)}else T.onClose?.({code:q.code,reason:q.reason,wasClean:q.wasClean})},G.onerror=(q)=>{console.error("WS Error",q),T.onError?.()}}function K(q,f){let B=[],D=[],Y=new Set;q.forEach(({userId:A})=>{if(A===E)return;if(!$.has(A)||f.type==="peer-joined"&&A===f.userId){let x={userId:A,receive:(v,n)=>z(v,A,n)};$.set(A,x),B.push(x)}Y.add(A)});for(let A of $.keys())if(!Y.has(A)||f.type==="peer-left"&&A===f.userId)$.delete(A),D.push({userId:A});if(B.length)T.onPeerJoined(B);if(D.length)T.onPeerLeft(D)}return O(),{sendToServer(q,f){z(q,"server",f)},exitRoom:()=>{J=!0,clearTimeout(W),G.close()}}}function w({userId:T,worldId:E,room:c,host:H,autoRejoin:M=!0,onOpen:V,onClose:X,onError:J,onPeerJoined:P,onPeerLeft:G,onIceUrl:W,onMessage:Z,logLine:$,workerUrl:S}){if(!S)return console.warn("Warning: enterRoom called without workerUrl; this may cause issues in some environments. You should pass workerUrl explicitly. Use:","https://cdn.jsdelivr.net/npm/@dobuki/hello-worker/dist/signal-room.worker.min.js"),k({userId:T,worldId:E,room:c,host:H,autoRejoin:M,onOpen:V,onClose:X,onError:J,onPeerJoined:P,onPeerLeft:G,onIceUrl:W,onMessage:Z});let Q=new Worker(S,{type:"module"}),N=!1;function z({userId:K}){return{userId:K,receive:(q,f)=>{if(N)return!1;return Q.postMessage({cmd:"send",toUserId:K,host:H,room:c,type:q,payload:f}),!0}}}let O=(K)=>{let q=K.data;if(q.kind==="open")V?.();else if(q.kind==="close")Q.terminate(),X?.(q.ev);else if(q.kind==="error")J?.();else if(q.kind==="peer-joined")P(q.users.map((f)=>z({userId:f.userId})));else if(q.kind==="peer-left")G(q.users);else if(q.kind==="ice-server")W?.(q.url,q.expiration);else if(q.kind==="message")Z(q.type,q.payload,z({userId:q.fromUserId}));else if(q.kind==="log")$?.(q.direction,q.obj)};return Q.addEventListener("message",O),Q.postMessage({cmd:"enter",userId:T,worldId:E,room:c,host:H,autoRejoin:M}),{exitRoom:()=>{N=!0,Q.removeEventListener("message",O),Q.postMessage({cmd:"exit"})},sendToServer:(K,q)=>{Q.postMessage({cmd:"send",toUserId:"server",host:H,room:c,type:K,payload:q})}}}var U={iceServers:[{urls:"stun:stun.l.google.com:19302"}]};class L{iceUrlProvider;constructor(T){this.iceUrlProvider=T}rtcConfig={...U,timestamp:Date.now()};rtcConfigPromise;async getRtcConfig(){if(Date.now()-(this.rtcConfig?.timestamp??0)<1e4)return this.rtcConfig;if(!this.rtcConfigPromise)this.rtcConfigPromise=new Promise(async(E)=>{let c=3;for(let H=0;H<c;H++)try{let M=(await this.iceUrlProvider.requestIce()).url,V=await fetch(M);if(!V.ok)throw Error(`ICE endpoint failed: ${V.status}`);let X=await V.json();E(X);return}catch(M){console.warn("Failed fetching iceUrl")}}),this.rtcConfig=await this.rtcConfigPromise,this.rtcConfigPromise=void 0;return this.rtcConfig}}var m=w;function g({userId:T,worldId:E,receivePeerConnection:c,peerlessUserExpiration:H=5000,enterRoomFunction:M=m,logLine:V,onLeaveUser:X,workerUrl:J,onRoomReady:P,onRoomClose:G,onBroadcastMessage:W}){let Z=T??`user-${crypto.randomUUID()}`,$=new Map,S=new Map;function Q(f){X?.(f);let B=$.get(f);if(!B)return;$.delete(f);try{B.close()}catch{}}async function N(f){if(!f.connection?.pc?.remoteDescription)return;let B=f.connection.pendingRemoteIce;f.connection.pendingRemoteIce=[];for(let D of B)try{await f.connection.pc.addIceCandidate(D)}catch(Y){V?.("⚠️ ERROR",{error:"add-ice-failed",userId:f.peer.userId,detail:String(Y)})}}let z=new j,O=new L(z);function K({room:f,host:B}){let D=`${B}/room/${f}`,Y=S.get(D);if(Y)Y.exitRoom(),S.delete(D)}function q({room:f,host:B}){return new Promise(async(D,Y)=>{async function A(i){if(i.connectionPromise)return i.connectionPromise;let C=new Promise(async(R)=>{i.connection={id:`conn-${crypto.randomUUID()}`,pc:new RTCPeerConnection(await O.getRtcConfig()),pendingRemoteIce:[]},i.connection.pc.onicecandidate=(b)=>{if(!b.candidate)return;i.peer.receive("ice",{connectionId:i.connection?.id,ice:b.candidate.toJSON()})},i.connection.pc.onconnectionstatechange=async()=>{if(V?.("\uD83D\uDCAC",{event:"pc-state",userId:i.peer.userId,state:i.connection?.pc?.connectionState}),i.connection?.pc?.connectionState==="failed"){i.close();let b=await x(i.peer,!0);if(b.connection?.pc)c({pc:b.connection?.pc,userId:b.peer.userId,restart:()=>b.close()});else V?.("\uD83D\uDC64ℹ️","no pc: "+b.peer.userId);return}},R(i.connection)});return i.connectionPromise=C,await C,i.connectionPromise=void 0,C}async function x(i,C){let R=$.get(i.userId);if(!R||C){let b={peer:i,close(){if(this.connection)this.connection.pc.close(),this.connection=void 0;$.delete(i.userId)},async reset(){b.close(),setTimeout(async()=>{let F=await x(i,!0);if(!F.connection?.pc){V?.("⚠️","no pc");return}c({pc:F.connection?.pc,userId:F.peer.userId,restart:()=>F.close()}),await v(F.peer)},500)}};R=b,await A(b),$.set(R.peer.userId,R)}else if(R){if(clearTimeout(R.expirationTimeout),R.expirationTimeout=0,!R.connection?.pc||R.connection?.pc.signalingState==="closed")await A(R)}return R.peer=i,R}async function v(i){let C=await x(i),R=C.connection?.pc,b=await R?.createOffer();await R?.setLocalDescription(b),i.receive("offer",{connectionId:C.connection?.id,offer:R.localDescription.toJSON()})}let{exitRoom:n,sendToServer:h}=M({userId:Z,worldId:E,room:f,host:B,logLine:V,workerUrl:J,autoRejoin:!0,onOpen(){P?.({room:f,host:B}),D()},onError(){console.error("onError"),Y()},onClose(i){G?.({room:f,host:B,ev:i})},onPeerJoined(i){i.forEach(async(C)=>{let R=await x(C,!0),b=R.connection?.pc;if(!b){V?.("\uD83D\uDC64ℹ️","no pc: "+C.userId);return}c({pc:b,userId:C.userId,restart:()=>R.close()}),await v(C)})},onPeerLeft(i){i.forEach(({userId:C})=>{let R=$.get(C);if(!R)return;R.expirationTimeout=setTimeout(()=>Q(C),H??0)})},onIceUrl(i,C){z.receiveIce(i,C)},async onMessage(i,C,R){if(i==="offer"&&C.offer){let b=await x(R,!1),F=!b.connection||b.connection.pc.signalingState==="stable"?await A(b):b.connection;V?.("\uD83D\uDCAC",{type:i,signalingState:F.pc.signalingState}),F.peerConnectionId=C.connectionId,c({pc:F.pc,userId:R.userId,restart:()=>b.close()}),await F.pc.setRemoteDescription(C.offer);let _=await F.pc.createAnswer();await F.pc.setLocalDescription(_),R.receive("answer",{connectionId:F.id,answer:F.pc.localDescription?.toJSON()}),await N(b);return}if(i==="answer"&&C.answer){let b=await x(R,!1),F=b.connection&&b.connection.pc.signalingState!=="closed"?b.connection:await A(b);V?.("\uD83D\uDCAC",{type:i,signalingState:F.pc.signalingState}),await F.pc.setRemoteDescription(C.answer),F.peerConnectionId=C.connectionId,await N(b);return}if(i==="ice"&&C.ice){let b=await x(R,!1),F=b.connection??await b.connectionPromise;if(!F){V?.("⚠️","No connection");return}if(V?.("\uD83D\uDCAC",{type:i,signalingState:F.pc.signalingState}),F.peerConnectionId&&C.connectionId!==F.peerConnectionId){V?.("⚠️","Mismatch peerConnectionID"+C.connectionId+"vs"+F.peerConnectionId);return}if(!F.pc.remoteDescription||!F.peerConnectionId){F.peerConnectionId=C.connectionId,F.pendingRemoteIce.push(C.ice);return}try{await F.pc.addIceCandidate(C.ice)}catch(_){V?.("⚠️ ERROR",{error:"add-ice-failed",userId:b.peer.userId,detail:String(_)})}return}if(i==="broadcast")W?.(C,R.userId)}});z.addRequester(h),S.set(`${B}/room/${f}`,{exitRoom:()=>{n(),z.removeRequester(h)},room:f,host:B,broadcast:(i)=>h("broadcast",i)})})}return{userId:Z,enterRoom:q,exitRoom:K,leaveUser:Q,async reset(f){$.get(f)?.reset()},broadcast(f){S.forEach((B)=>B.broadcast(f))},end(){S.forEach(({exitRoom:f})=>f()),S.clear(),$.forEach(({peer:f})=>Q(f.userId)),$.clear()}}}function u({userId:T,worldId:E,logLine:c,enterRoomFunction:H=w,peerlessUserExpiration:M,workerUrl:V,onRoomReady:X,onRoomClose:J,dataChannelOptions:P}){let G=new Set,W=new Map,Z=new Set,$=new Set;function S(h,i,C){function R(F){let _=F.channel;N(i,_,C),W.set(i,_)}h.addEventListener("datachannel",R);let b=h.createDataChannel("data",P);return N(i,b,C),W.set(i,b),()=>{h.removeEventListener("datachannel",R)}}function Q(h,i){$.forEach((C)=>C(h,i))}function N(h,i,C){i.onopen=()=>{c?.("\uD83D\uDCAC",{event:"dc-open",userId:h}),G.add(h),Z.forEach((b)=>b(h,"join",[...G]))};let R=({data:b})=>{Q(b,h)};i.addEventListener("message",R),i.onclose=()=>{c?.("\uD83D\uDCAC",{event:"dc-close",userId:h}),G.delete(h),Z.forEach((b)=>b(h,"leave",[...G])),i.removeEventListener("message",R),i.onopen=null,i.onclose=null,i.onerror=null,i.close(),C?.()},i.onerror=()=>c?.("⚠️ ERROR",{error:"dc-error",userId:h})}let{userId:z,enterRoom:O,exitRoom:K,leaveUser:q,broadcast:f,end:B,reset:D}=g({userId:T,worldId:E,enterRoomFunction:H,logLine:c,workerUrl:V,peerlessUserExpiration:M,onRoomReady:X,onRoomClose:J,onLeaveUser(h){let i=W.get(h);try{i?.close()}catch{}W.delete(h)},receivePeerConnection({pc:h,userId:i,restart:C}){S(h,i,C)},onBroadcastMessage(h,i){Q(h,i),c?.("\uD83D\uDCE2",{event:"broadcast",userId:z,data:h})}});function Y(h,i){W.forEach((C,R)=>{if(i&&R!==i)return;if(C.readyState==="open")C.send(h)})}function A(h){$.delete(h)}function x(h){return $.add(h),()=>{A(h)}}function v(h){Z.delete(h)}function n(h){return Z.add(h),()=>{v(h)}}return{userId:z,send:Y,broadcast:f,enterRoom:O,exitRoom:K,leaveUser:q,getUsers:()=>[...G],addMessageListener:x,removeMessageListener:A,addUserListener:n,removeUserListener:v,reset(){G.forEach((h)=>{W.get(h)?.close(),W.delete(h),D(h)})},end(){W.forEach((h)=>{try{h.close()}catch{}}),W.clear(),B(),Z.clear(),G.clear()}}}export{u as enterWorld,k as enterRoom,g as collectPeerConnections};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=AADEA038C84812ED64756E2164756E21
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
"export interface IPeer<T extends string = string, P = any> {\n userId: string;\n receive(type: T, payload: P): boolean;\n}\n\ntype OutMessage = { type: string; to: string; payload: any };\n\n/**\n * enterRoom connects to the signaling room via WebSocket.\n */\nexport function enterRoom<T extends string, P = any>(params: {\n userId: string;\n worldId: string;\n room: string;\n host: string;\n onOpen?: () => void;\n onClose?: (ev: Pick<CloseEvent, \"code\" | \"reason\" | \"wasClean\">) => void;\n onError?: () => void;\n logLine?: (direction: string, obj?: any) => void;\n onPeerJoined(users: IPeer<T, P>[]): void;\n onPeerLeft(users: { userId: string }[]): void;\n onIceUrl?(url: string, expiration: number): void;\n onMessage(type: T, payload: P, from: IPeer<T, P>): void;\n autoRejoin?: boolean;\n}): {\n exitRoom: () => void;\n sendToServer: <P extends any>(type: T, payload?: P) => void;\n} {\n type Message = {\n type: \"peer-joined\" | \"peer-left\" | \"ice-server\" | T;\n userId: string;\n users: { userId: string }[];\n payload: P;\n url: string;\n expiration: number;\n };\n\n const { userId, worldId, room, host, autoRejoin = true, logLine } = params;\n\n let exited = false;\n let retryCount = 0;\n let ws: WebSocket;\n let timeoutId: ReturnType<typeof setTimeout>;\n let initialConnection = true;\n\n const peers = new Map<string, IPeer<T, P>>();\n const wsUrl = `wss://${host}/room/${worldId}/${room}?userId=${encodeURIComponent(\n userId,\n )}`;\n\n // Helper for sending (uses the current ws instance)\n const accumulatedMessages: OutMessage[] = [];\n let timeout: ReturnType<typeof setTimeout> = 0;\n function send(type: string, to: \"server\" | string, payload?: any) {\n if (!ws) {\n logLine?.(\"👤 ➡️ ❌\", \"no ws available\");\n return false;\n }\n const obj: OutMessage = { type, to, payload };\n accumulatedMessages.push(obj);\n logLine?.(\"👤 ➡️ 🖥️\", obj);\n clearTimeout(timeout);\n if (exited || ws.readyState !== WebSocket.OPEN) {\n logLine?.(\"👤 ➡️ ❌\", \"Not in opened state: \" + ws.readyState);\n return false;\n }\n timeout = setTimeout(() => {\n ws.send(JSON.stringify(accumulatedMessages));\n accumulatedMessages.length = 0;\n });\n return true;\n }\n\n function connect() {\n if (exited) return;\n\n ws = new WebSocket(wsUrl);\n\n ws.onopen = () => {\n if (initialConnection) {\n params.onOpen?.();\n initialConnection = false;\n }\n retryCount = 0; // Reset backoff on successful connection\n };\n\n ws.onmessage = (e: MessageEvent) => {\n try {\n const result = JSON.parse(e.data);\n const msgs: Message[] = Array.isArray(result) ? result : [result];\n msgs.forEach((msg) => {\n logLine?.(\"🖥️ ➡️ 👤\", msg);\n if (msg.type === \"peer-joined\" || msg.type === \"peer-left\") {\n updatePeers(msg.users, msg);\n } else if (msg.type === \"ice-server\") {\n params.onIceUrl?.(msg.url, msg.expiration);\n } else if (msg.userId) {\n params.onMessage(msg.type, msg.payload, {\n userId: msg.userId,\n receive: (type: T, payload: P) => send(type, msg.userId, payload),\n });\n }\n });\n } catch {\n logLine?.(\"⚠️ ERROR\", { error: \"invalid-json\" });\n }\n };\n\n ws.onclose = (ev: CloseEvent) => {\n // 1. Check if we should even try to reconnect\n const recoverableCodes = [1001, 1006, 1011, 1012, 1013];\n const isRecoverable = recoverableCodes.includes(ev.code);\n\n if (autoRejoin && !exited && isRecoverable) {\n // 2. Exponential Backoff: 1s, 2s, 4s, 8s... capped at 30s\n const backoff = Math.min(Math.pow(2, retryCount) * 1000, 30000);\n // 3. Add Jitter: +/- 1000ms randomness\n const jitter = Math.random() * 1000;\n const delay = backoff + jitter;\n\n logLine?.(\"🔄 RECONNECTING\", {\n attempt: retryCount + 1,\n delayMs: Math.round(delay),\n });\n\n retryCount++;\n timeoutId = setTimeout(connect, delay);\n } else {\n params.onClose?.({\n code: ev.code,\n reason: ev.reason,\n wasClean: ev.wasClean,\n });\n }\n };\n\n ws.onerror = (ev) => {\n console.error(\"WS Error\", ev);\n params.onError?.();\n };\n }\n\n // Helper for peer tracking (logic from your original code)\n function updatePeers(updatedUsers: { userId: string }[], msg: Message) {\n const joined: IPeer<T, P>[] = [];\n const left: { userId: string }[] = [];\n const updatedPeerSet = new Set<string>();\n\n updatedUsers.forEach(({ userId: pUserId }) => {\n if (pUserId === userId) return;\n if (\n !peers.has(pUserId) ||\n (msg.type === \"peer-joined\" && pUserId === msg.userId)\n ) {\n const newPeer = {\n userId: pUserId,\n receive: (t: T, p: P) => send(t, pUserId, p),\n };\n peers.set(pUserId, newPeer);\n joined.push(newPeer);\n }\n updatedPeerSet.add(pUserId);\n });\n\n for (const pUserId of peers.keys()) {\n if (\n !updatedPeerSet.has(pUserId) ||\n (msg.type === \"peer-left\" && pUserId === msg.userId)\n ) {\n peers.delete(pUserId);\n left.push({ userId: pUserId });\n }\n }\n\n // Notify peer joined first then peer left. (avoid disconnect in case the peer leaving / joining is on the same user).\n if (joined.length) params.onPeerJoined(joined);\n if (left.length) params.onPeerLeft(left);\n }\n\n // Start initial connection\n connect();\n\n return {\n sendToServer(type, payload) {\n send(type, \"server\", payload);\n },\n exitRoom: () => {\n exited = true;\n clearTimeout(timeoutId);\n ws.close();\n },\n };\n}\n",
|
|
7
7
|
"import type { IPeer } from \"./impl/signal-room.js\";\nimport { enterRoom as baseEnterRoom } from \"./impl/signal-room.js\";\nimport { RoomEvent, WorkerCommand } from \"./signal-room.worker.js\";\n\nexport function enterRoom<T extends string, P = any>({\n userId,\n worldId,\n room,\n host,\n autoRejoin = true,\n onOpen,\n onClose,\n onError,\n onPeerJoined,\n onPeerLeft,\n onIceUrl,\n onMessage,\n logLine,\n workerUrl,\n}: {\n userId: string;\n worldId: string;\n room: string;\n host: string;\n autoRejoin?: boolean;\n onOpen?: () => void;\n onClose?: (ev: Pick<CloseEvent, \"code\" | \"reason\" | \"wasClean\">) => void;\n onError?: () => void;\n onPeerJoined: (users: IPeer<T, P>[]) => void;\n onPeerLeft: (users: { userId: string }[]) => void;\n onIceUrl?(url: string, expiration: number): void;\n onMessage: (type: T, payload: P, from: IPeer<T, P>) => void;\n logLine?: (direction: string, obj?: any) => void;\n\n // Pass the URL to your worker file (bundler will handle it)\n workerUrl?: URL;\n}): {\n exitRoom: () => void;\n sendToServer: <P extends any>(type: T, payload?: P) => void;\n} {\n if (!workerUrl) {\n const CDN_WORKER_URL = `https://cdn.jsdelivr.net/npm/@dobuki/hello-worker/dist/signal-room.worker.min.js`;\n\n console.warn(\n \"Warning: enterRoom called without workerUrl; this may cause issues in some environments. You should pass workerUrl explicitly. Use:\",\n CDN_WORKER_URL,\n );\n return baseEnterRoom<T, P>({\n userId,\n worldId,\n room,\n host,\n autoRejoin,\n onOpen,\n onClose,\n onError,\n onPeerJoined,\n onPeerLeft,\n onIceUrl,\n onMessage,\n });\n }\n const worker = new Worker(workerUrl, { type: \"module\" });\n let exited = false;\n\n function makeUser({ userId }: { userId: string }): IPeer<T, P> {\n return {\n userId,\n receive: (type: T, payload: P) => {\n if (exited) return false;\n worker.postMessage({\n cmd: \"send\",\n toUserId: userId,\n host,\n room,\n type,\n payload,\n } as WorkerCommand);\n return true;\n },\n };\n }\n\n const onWorkerMessage = (e: MessageEvent<RoomEvent<T, P>>) => {\n const ev = e.data;\n\n if (ev.kind === \"open\") onOpen?.();\n else if (ev.kind === \"close\") {\n worker.terminate();\n onClose?.(ev.ev);\n } else if (ev.kind === \"error\") onError?.();\n else if (ev.kind === \"peer-joined\")\n onPeerJoined(ev.users.map((ev) => makeUser({ userId: ev.userId })));\n else if (ev.kind === \"peer-left\") onPeerLeft(ev.users);\n else if (ev.kind === \"ice-server\") onIceUrl?.(ev.url, ev.expiration);\n else if (ev.kind === \"message\")\n onMessage(ev.type, ev.payload, makeUser({ userId: ev.fromUserId }));\n else if (ev.kind === \"log\") logLine?.(ev.direction, ev.obj);\n };\n\n worker.addEventListener(\"message\", onWorkerMessage);\n\n worker.postMessage({\n cmd: \"enter\",\n userId,\n worldId,\n room,\n host,\n autoRejoin,\n } as WorkerCommand);\n\n return {\n exitRoom: () => {\n exited = true;\n worker.removeEventListener(\"message\", onWorkerMessage);\n worker.postMessage({ cmd: \"exit\" } as WorkerCommand);\n },\n sendToServer: <P extends any>(type: T, payload?: P) => {\n worker.postMessage({\n cmd: \"send\",\n toUserId: \"server\",\n host,\n room,\n type,\n payload,\n } as WorkerCommand);\n },\n };\n}\n\nexport type EnterRoom<T extends string, P> = typeof enterRoom<T, P>;\n",
|
|
8
8
|
"import { IceUrlProvider } from \"./ice-url-provider\";\n\nconst FALLBACK_RTC_CONFIG = {\n iceServers: [{ urls: \"stun:stun.l.google.com:19302\" }],\n};\n\nexport class RTCConfigProvider {\n constructor(private iceUrlProvider: IceUrlProvider) {}\n\n private rtcConfig: RTCConfiguration & { timestamp: number } = {\n ...FALLBACK_RTC_CONFIG,\n timestamp: Date.now(),\n };\n private rtcConfigPromise?: Promise<RTCConfiguration & { timestamp: number }>;\n\n async getRtcConfig(): Promise<RTCConfiguration & { timestamp: number }> {\n const now = Date.now();\n if (now - (this.rtcConfig?.timestamp ?? 0) < 10000) {\n return this.rtcConfig;\n }\n\n if (!this.rtcConfigPromise) {\n this.rtcConfigPromise = new Promise<\n RTCConfiguration & { timestamp: number }\n >(async (resolve) => {\n let retries = 3;\n for (let r = 0; r < retries; r++) {\n try {\n const iceUrl = (await this.iceUrlProvider.requestIce()).url;\n const r = await fetch(iceUrl);\n if (!r.ok) throw new Error(`ICE endpoint failed: ${r.status}`);\n const rtcConfig = (await r.json()) as RTCConfiguration & {\n timestamp: number;\n };\n resolve(rtcConfig);\n return;\n } catch (e) {\n console.warn(\"Failed fetching iceUrl\");\n }\n }\n });\n this.rtcConfig = await this.rtcConfigPromise;\n this.rtcConfigPromise = undefined;\n }\n return this.rtcConfig;\n }\n}\n",
|
|
9
|
-
"import { IceUrlProvider } from \"./utils/ice-url-provider\";\nimport { IPeer } from \"./signal/impl/signal-room\";\nimport { EnterRoom, enterRoom } from \"./signal/signal-room\";\nimport { RTCConfigProvider } from \"./utils/rtc-config\";\n\nexport type SigType = \"offer\" | \"answer\" | \"ice\" | \"request-ice\" | \"broadcast\";\nexport type SigPayload = {\n connectionId?: string;\n offer?: RTCSessionDescriptionInit;\n answer?: RTCSessionDescriptionInit;\n ice?: RTCIceCandidateInit;\n} & Record<string, any>;\n\ninterface Connection {\n id: string;\n peerConnectionId?: string;\n pc: RTCPeerConnection;\n // ICE that arrived before we had remoteDescription\n pendingRemoteIce: RTCIceCandidateInit[];\n}\n\ntype UserState = {\n connection?: Connection;\n\n // the signaling \"user\" handle so we can send messages\n peer: IPeer<SigType, SigPayload>;\n\n expirationTimeout?: number;\n close(): void;\n reset(): void;\n connectionPromise?: Promise<Connection>;\n};\n\nconst DEFAULT_ENTER_ROOM = enterRoom;\n\n/**\n * Collect peers\n */\nexport function collectPeerConnections({\n userId: passedUserId,\n worldId,\n receivePeerConnection,\n peerlessUserExpiration = 5000,\n enterRoomFunction: enterRoom = DEFAULT_ENTER_ROOM,\n logLine,\n onLeaveUser,\n workerUrl,\n onRoomReady,\n onRoomClose,\n onBroadcastMessage,\n}: {\n userId?: string;\n worldId: string;\n enterRoomFunction?: EnterRoom<SigType, SigPayload>;\n onLeaveUser?: (userId: string) => void;\n logLine?: (direction: string, obj?: any) => void;\n workerUrl?: URL;\n peerlessUserExpiration?: number;\n receivePeerConnection(connection: {\n pc: RTCPeerConnection;\n userId: string;\n restart?: () => void;\n }): void;\n onRoomReady?(info: { host: string; room: string }): void;\n onRoomClose?(info: {\n host: string;\n room: string;\n ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">;\n }): void;\n onBroadcastMessage?<P extends any>(payload: P, from: string): void;\n}) {\n const userId = passedUserId ?? `user-${crypto.randomUUID()}`;\n const users: Map<string, UserState> = new Map();\n\n const roomsEntered = new Map<\n string,\n {\n room: string;\n host: string;\n exitRoom: () => void;\n broadcast: <P extends any>(payload: P) => void;\n }\n >();\n\n function leaveUser(userId: string) {\n onLeaveUser?.(userId);\n const p = users.get(userId);\n if (!p) return;\n users.delete(userId);\n try {\n p.close();\n } catch {}\n }\n\n async function flushRemoteIce(state: UserState) {\n if (!state.connection?.pc?.remoteDescription) return;\n\n const queued = state.connection.pendingRemoteIce;\n state.connection.pendingRemoteIce = [];\n\n for (const ice of queued) {\n try {\n await state.connection.pc.addIceCandidate(ice);\n } catch (e) {\n logLine?.(\"⚠️ ERROR\", {\n error: \"add-ice-failed\",\n userId: state.peer.userId,\n detail: String(e),\n });\n }\n }\n }\n\n const iceUrlProvider = new IceUrlProvider();\n const rtcConfigProvider = new RTCConfigProvider(iceUrlProvider);\n\n function exit({ room, host }: { room: string; host: string }) {\n const key = `${host}/room/${room}`;\n const session = roomsEntered.get(key);\n if (session) {\n session.exitRoom();\n roomsEntered.delete(key);\n }\n }\n\n function enter({ room, host }: { room: string; host: string }) {\n return new Promise<void>(async (resolve, reject) => {\n async function setupConnection(state: UserState) {\n if (state.connectionPromise) {\n return state.connectionPromise;\n }\n return (state.connectionPromise = new Promise<Connection>(\n async (resolve) => {\n state.connection = {\n id: `conn-${crypto.randomUUID()}`,\n pc: new RTCPeerConnection(await rtcConfigProvider.getRtcConfig()),\n pendingRemoteIce: [],\n };\n\n // Send local ICE candidates to this peer\n state.connection.pc.onicecandidate = (ev) => {\n if (!ev.candidate) return;\n state.peer.receive(\"ice\", {\n connectionId: state.connection?.id,\n ice: ev.candidate.toJSON(),\n });\n };\n\n state.connection.pc.onconnectionstatechange = async () => {\n logLine?.(\"💬\", {\n event: \"pc-state\",\n userId: state.peer.userId,\n state: state.connection?.pc?.connectionState,\n });\n if (state.connection?.pc?.connectionState === \"failed\") {\n // reset the connection\n state.close();\n const userState = await getPeer(state.peer, true);\n if (userState.connection?.pc) {\n receivePeerConnection({\n pc: userState.connection?.pc,\n userId: userState.peer.userId,\n restart: () => userState.close(),\n });\n } else {\n logLine?.(\"👤ℹ️\", \"no pc: \" + userState.peer.userId);\n }\n return;\n }\n };\n\n resolve(state.connection);\n },\n ));\n }\n\n async function getPeer(\n peer: IPeer<SigType, SigPayload>,\n forceReset?: boolean,\n ): Promise<UserState> {\n let state = users.get(peer.userId);\n if (!state || forceReset) {\n const newState: UserState = {\n peer,\n close() {\n if (this.connection) {\n this.connection.pc.close();\n this.connection = undefined;\n }\n users.delete(peer.userId);\n },\n async reset() {\n newState.close();\n\n setTimeout(async () => {\n const userState = await getPeer(peer, true);\n if (!userState.connection?.pc) {\n logLine?.(\"⚠️\", \"no pc\");\n return;\n }\n receivePeerConnection({\n pc: userState.connection?.pc,\n userId: userState.peer.userId,\n restart: () => userState.close(),\n });\n await makeOffer(userState.peer);\n }, 500);\n },\n };\n state = newState;\n\n await setupConnection(newState);\n\n // New user\n users.set(state.peer.userId, state);\n } else if (state) {\n clearTimeout(state.expirationTimeout);\n state.expirationTimeout = 0;\n if (\n !state.connection?.pc ||\n state.connection?.pc.signalingState === \"closed\"\n ) {\n await setupConnection(state);\n }\n }\n state.peer = peer;\n return state;\n }\n\n async function makeOffer(user: IPeer<SigType, SigPayload>) {\n // Offer flow: createOffer -> setLocalDescription -> send localDescription\n const state = await getPeer(user);\n const pc = state.connection?.pc;\n const offer = await pc?.createOffer();\n await pc?.setLocalDescription(offer);\n user.receive(\"offer\", {\n connectionId: state.connection?.id,\n offer: pc!.localDescription!.toJSON(),\n });\n }\n\n const { exitRoom, sendToServer } = enterRoom({\n userId,\n worldId,\n room,\n host,\n logLine,\n workerUrl,\n autoRejoin: true,\n\n onOpen() {\n onRoomReady?.({ room, host });\n resolve();\n },\n onError() {\n console.error(\"onError\");\n reject();\n },\n onClose(ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">) {\n onRoomClose?.({ room, host, ev });\n },\n\n // Existing peers initiate to the newcomer\n onPeerJoined(joiningUsers: IPeer<SigType, SigPayload>[]) {\n joiningUsers.forEach(async (user) => {\n const state = await getPeer(user, true);\n const pc = state.connection?.pc;\n if (!pc) {\n logLine?.(\"👤ℹ️\", \"no pc: \" + user.userId);\n return;\n }\n\n receivePeerConnection({\n pc,\n userId: user.userId,\n restart: () => state.close(),\n });\n await makeOffer(user);\n });\n },\n\n onPeerLeft(leavingUsers: { userId: string }[]) {\n leavingUsers.forEach(({ userId }) => {\n const state = users.get(userId);\n if (!state) return;\n state.expirationTimeout = setTimeout(\n () => leaveUser(userId),\n peerlessUserExpiration ?? 0,\n );\n });\n },\n\n onIceUrl(url: string, expiration: number) {\n iceUrlProvider.receiveIce(url, expiration);\n },\n\n async onMessage(type, payload, from: IPeer<SigType, SigPayload>) {\n if (type === \"offer\" && payload.offer) {\n // Grab state and connection\n const state = await getPeer(from, false);\n const connection =\n !state.connection ||\n state.connection.pc.signalingState === \"stable\"\n ? await setupConnection(state)\n : state.connection; // reset\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n connection.peerConnectionId = payload.connectionId;\n receivePeerConnection({\n pc: connection.pc,\n userId: from.userId,\n restart: () => state.close(),\n });\n // Responder: set remote offer\n await connection.pc.setRemoteDescription(payload.offer);\n\n // Create and send answer\n const answer = await connection.pc.createAnswer();\n await connection.pc.setLocalDescription(answer);\n\n from.receive(\"answer\", {\n connectionId: connection.id,\n answer: connection.pc.localDescription?.toJSON(),\n });\n\n // Now safe to apply any queued ICE from this peer\n await flushRemoteIce(state);\n return;\n }\n\n if (type === \"answer\" && payload.answer) {\n const state = await getPeer(from, false);\n const connection =\n state.connection &&\n state.connection.pc.signalingState !== \"closed\"\n ? state.connection\n : await setupConnection(state);\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n // Initiator: set remote answer\n await connection.pc.setRemoteDescription(payload.answer);\n connection.peerConnectionId = payload.connectionId;\n await flushRemoteIce(state);\n return;\n }\n\n if (type === \"ice\" && payload.ice) {\n // Grab state and connection\n const state = await getPeer(from, false);\n const connection =\n state.connection ?? (await state.connectionPromise);\n if (!connection) {\n logLine?.(\"⚠️\", \"No connection\");\n return;\n }\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n if (\n connection.peerConnectionId &&\n payload.connectionId !== connection.peerConnectionId\n ) {\n logLine?.(\n \"⚠️\",\n \"Mismatch peerConnectionID\" +\n payload.connectionId +\n \"vs\" +\n connection.peerConnectionId,\n );\n return;\n }\n\n // If we don't have remoteDescription yet (or if connectionId doesn't match), queue it\n if (\n !connection.pc.remoteDescription ||\n !connection.peerConnectionId\n ) {\n connection.peerConnectionId = payload.connectionId;\n connection.pendingRemoteIce.push(payload.ice);\n return;\n }\n\n try {\n await connection.pc.addIceCandidate(payload.ice);\n } catch (e) {\n logLine?.(\"⚠️ ERROR\", {\n error: \"add-ice-failed\",\n userId: state.peer.userId,\n detail: String(e),\n });\n }\n return;\n }\n\n if (type === \"broadcast\") {\n onBroadcastMessage?.(payload, from.userId);\n }\n },\n });\n\n iceUrlProvider.addRequester(sendToServer);\n\n roomsEntered.set(`${host}/room/${room}`, {\n exitRoom: () => {\n exitRoom();\n iceUrlProvider.removeRequester(sendToServer);\n },\n room,\n host,\n broadcast: (payload) => sendToServer(\"broadcast\", payload),\n });\n });\n }\n\n return {\n userId,\n enterRoom: enter,\n exitRoom: exit,\n leaveUser,\n async reset(userId: string) {\n const userState = users.get(userId);\n userState?.reset();\n },\n broadcast<P extends any>(payload: P) {\n roomsEntered.forEach((room) => room.broadcast(payload));\n },\n end() {\n roomsEntered.forEach(({ exitRoom }) => exitRoom());\n roomsEntered.clear();\n users.forEach(({ peer }) => leaveUser(peer.userId));\n users.clear();\n },\n };\n}\n\n/*\nTurn Token ID\n<CF_TURN_TOKEN_ID>\n\nAPI Token\n<CF_RTC_API_TOKEN>\n\nCURL\ncurl \\\n\t-H \"Authorization: Bearer <CF_RTC_API_TOKEN>\" \\\n\t-H \"Content-Type: application/json\" -d '{\"ttl\": 86400}' \\\n\thttps://rtc.live.cloudflare.com/v1/turn/keys/<CF_TURN_TOKEN_ID>/credentials/generate-ice-servers\n\nJSON\n{\n\t\"iceServers\": [\n {\n \"urls\": [\n \"stun:stun.cloudflare.com:3478\",\n \"turn:turn.cloudflare.com:3478?transport=udp\",\n \"turn:turn.cloudflare.com:3478?transport=tcp\",\n \"turns:turn.cloudflare.com:5349?transport=tcp\"\n ],\n \"username\": \"xxxx\",\n \"credential\": \"yyyy\",\n }\n ]\n}\n\n*/\n",
|
|
9
|
+
"import { IceUrlProvider } from \"./utils/ice-url-provider\";\nimport { IPeer } from \"./signal/impl/signal-room\";\nimport { EnterRoom, enterRoom } from \"./signal/signal-room\";\nimport { RTCConfigProvider } from \"./utils/rtc-config\";\n\nexport type SigType = \"offer\" | \"answer\" | \"ice\" | \"request-ice\" | \"broadcast\";\nexport type SigPayload = {\n connectionId?: string;\n offer?: RTCSessionDescriptionInit;\n answer?: RTCSessionDescriptionInit;\n ice?: RTCIceCandidateInit;\n} & Record<string, any>;\n\ninterface Connection {\n id: string;\n peerConnectionId?: string;\n pc: RTCPeerConnection;\n // ICE that arrived before we had remoteDescription\n pendingRemoteIce: RTCIceCandidateInit[];\n}\n\ntype UserState = {\n connection?: Connection;\n\n // the signaling \"user\" handle so we can send messages\n peer: IPeer<SigType, SigPayload>;\n\n expirationTimeout?: number;\n close(): void;\n reset(): void;\n connectionPromise?: Promise<Connection>;\n};\n\nconst DEFAULT_ENTER_ROOM = enterRoom;\n\n/**\n * Collect peers\n */\nexport function collectPeerConnections({\n userId: passedUserId,\n worldId,\n receivePeerConnection,\n peerlessUserExpiration = 5000,\n enterRoomFunction: enterRoom = DEFAULT_ENTER_ROOM,\n logLine,\n onLeaveUser,\n workerUrl,\n onRoomReady,\n onRoomClose,\n onBroadcastMessage,\n}: {\n userId?: string;\n worldId: string;\n enterRoomFunction?: EnterRoom<SigType, SigPayload>;\n onLeaveUser?: (userId: string) => void;\n logLine?: (direction: string, obj?: any) => void;\n workerUrl?: URL;\n peerlessUserExpiration?: number;\n receivePeerConnection(connection: {\n pc: RTCPeerConnection;\n userId: string;\n restart?: () => void;\n }): void;\n onRoomReady?(info: { host: string; room: string }): void;\n onRoomClose?(info: {\n host: string;\n room: string;\n ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">;\n }): void;\n onBroadcastMessage?<P extends any>(payload: P, from: string): void;\n}) {\n const userId = passedUserId ?? `user-${crypto.randomUUID()}`;\n const users: Map<string, UserState> = new Map();\n\n const roomsEntered = new Map<\n string,\n {\n room: string;\n host: string;\n exitRoom: () => void;\n broadcast: <P extends any>(payload: P) => void;\n }\n >();\n\n function leaveUser(userId: string) {\n onLeaveUser?.(userId);\n const p = users.get(userId);\n if (!p) return;\n users.delete(userId);\n try {\n p.close();\n } catch {}\n }\n\n async function flushRemoteIce(state: UserState) {\n if (!state.connection?.pc?.remoteDescription) return;\n\n const queued = state.connection.pendingRemoteIce;\n state.connection.pendingRemoteIce = [];\n\n for (const ice of queued) {\n try {\n await state.connection.pc.addIceCandidate(ice);\n } catch (e) {\n logLine?.(\"⚠️ ERROR\", {\n error: \"add-ice-failed\",\n userId: state.peer.userId,\n detail: String(e),\n });\n }\n }\n }\n\n const iceUrlProvider = new IceUrlProvider();\n const rtcConfigProvider = new RTCConfigProvider(iceUrlProvider);\n\n function exit({ room, host }: { room: string; host: string }) {\n const key = `${host}/room/${room}`;\n const session = roomsEntered.get(key);\n if (session) {\n session.exitRoom();\n roomsEntered.delete(key);\n }\n }\n\n function enter({ room, host }: { room: string; host: string }) {\n return new Promise<void>(async (resolve, reject) => {\n async function setupConnection(state: UserState) {\n if (state.connectionPromise) {\n return state.connectionPromise;\n }\n const promise = new Promise<Connection>(async (resolve) => {\n state.connection = {\n id: `conn-${crypto.randomUUID()}`,\n pc: new RTCPeerConnection(await rtcConfigProvider.getRtcConfig()),\n pendingRemoteIce: [],\n };\n\n // Send local ICE candidates to this peer\n state.connection.pc.onicecandidate = (ev) => {\n if (!ev.candidate) return;\n state.peer.receive(\"ice\", {\n connectionId: state.connection?.id,\n ice: ev.candidate.toJSON(),\n });\n };\n\n state.connection.pc.onconnectionstatechange = async () => {\n logLine?.(\"💬\", {\n event: \"pc-state\",\n userId: state.peer.userId,\n state: state.connection?.pc?.connectionState,\n });\n if (state.connection?.pc?.connectionState === \"failed\") {\n // reset the connection\n state.close();\n const userState = await getPeer(state.peer, true);\n if (userState.connection?.pc) {\n receivePeerConnection({\n pc: userState.connection?.pc,\n userId: userState.peer.userId,\n restart: () => userState.close(),\n });\n } else {\n logLine?.(\"👤ℹ️\", \"no pc: \" + userState.peer.userId);\n }\n return;\n }\n };\n\n resolve(state.connection);\n });\n state.connectionPromise = promise;\n await promise;\n state.connectionPromise = undefined;\n return promise;\n }\n\n async function getPeer(\n peer: IPeer<SigType, SigPayload>,\n forceReset?: boolean,\n ): Promise<UserState> {\n let state = users.get(peer.userId);\n if (!state || forceReset) {\n const newState: UserState = {\n peer,\n close() {\n if (this.connection) {\n this.connection.pc.close();\n this.connection = undefined;\n }\n users.delete(peer.userId);\n },\n async reset() {\n newState.close();\n\n setTimeout(async () => {\n const userState = await getPeer(peer, true);\n if (!userState.connection?.pc) {\n logLine?.(\"⚠️\", \"no pc\");\n return;\n }\n receivePeerConnection({\n pc: userState.connection?.pc,\n userId: userState.peer.userId,\n restart: () => userState.close(),\n });\n await makeOffer(userState.peer);\n }, 500);\n },\n };\n state = newState;\n\n await setupConnection(newState);\n\n // New user\n users.set(state.peer.userId, state);\n } else if (state) {\n clearTimeout(state.expirationTimeout);\n state.expirationTimeout = 0;\n if (\n !state.connection?.pc ||\n state.connection?.pc.signalingState === \"closed\"\n ) {\n await setupConnection(state);\n }\n }\n state.peer = peer;\n return state;\n }\n\n async function makeOffer(user: IPeer<SigType, SigPayload>) {\n // Offer flow: createOffer -> setLocalDescription -> send localDescription\n const state = await getPeer(user);\n const pc = state.connection?.pc;\n const offer = await pc?.createOffer();\n await pc?.setLocalDescription(offer);\n user.receive(\"offer\", {\n connectionId: state.connection?.id,\n offer: pc!.localDescription!.toJSON(),\n });\n }\n\n const { exitRoom, sendToServer } = enterRoom({\n userId,\n worldId,\n room,\n host,\n logLine,\n workerUrl,\n autoRejoin: true,\n\n onOpen() {\n onRoomReady?.({ room, host });\n resolve();\n },\n onError() {\n console.error(\"onError\");\n reject();\n },\n onClose(ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">) {\n onRoomClose?.({ room, host, ev });\n },\n\n // Existing peers initiate to the newcomer\n onPeerJoined(joiningUsers: IPeer<SigType, SigPayload>[]) {\n joiningUsers.forEach(async (user) => {\n const state = await getPeer(user, true);\n const pc = state.connection?.pc;\n if (!pc) {\n logLine?.(\"👤ℹ️\", \"no pc: \" + user.userId);\n return;\n }\n\n receivePeerConnection({\n pc,\n userId: user.userId,\n restart: () => state.close(),\n });\n await makeOffer(user);\n });\n },\n\n onPeerLeft(leavingUsers: { userId: string }[]) {\n leavingUsers.forEach(({ userId }) => {\n const state = users.get(userId);\n if (!state) return;\n state.expirationTimeout = setTimeout(\n () => leaveUser(userId),\n peerlessUserExpiration ?? 0,\n );\n });\n },\n\n onIceUrl(url: string, expiration: number) {\n iceUrlProvider.receiveIce(url, expiration);\n },\n\n async onMessage(type, payload, from: IPeer<SigType, SigPayload>) {\n if (type === \"offer\" && payload.offer) {\n // Grab state and connection\n const state = await getPeer(from, false);\n const connection =\n !state.connection ||\n state.connection.pc.signalingState === \"stable\"\n ? await setupConnection(state)\n : state.connection; // reset\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n connection.peerConnectionId = payload.connectionId;\n receivePeerConnection({\n pc: connection.pc,\n userId: from.userId,\n restart: () => state.close(),\n });\n // Responder: set remote offer\n await connection.pc.setRemoteDescription(payload.offer);\n\n // Create and send answer\n const answer = await connection.pc.createAnswer();\n await connection.pc.setLocalDescription(answer);\n\n from.receive(\"answer\", {\n connectionId: connection.id,\n answer: connection.pc.localDescription?.toJSON(),\n });\n\n // Now safe to apply any queued ICE from this peer\n await flushRemoteIce(state);\n return;\n }\n\n if (type === \"answer\" && payload.answer) {\n const state = await getPeer(from, false);\n const connection =\n state.connection &&\n state.connection.pc.signalingState !== \"closed\"\n ? state.connection\n : await setupConnection(state);\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n // Initiator: set remote answer\n await connection.pc.setRemoteDescription(payload.answer);\n connection.peerConnectionId = payload.connectionId;\n await flushRemoteIce(state);\n return;\n }\n\n if (type === \"ice\" && payload.ice) {\n // Grab state and connection\n const state = await getPeer(from, false);\n const connection =\n state.connection ?? (await state.connectionPromise);\n if (!connection) {\n logLine?.(\"⚠️\", \"No connection\");\n return;\n }\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n if (\n connection.peerConnectionId &&\n payload.connectionId !== connection.peerConnectionId\n ) {\n logLine?.(\n \"⚠️\",\n \"Mismatch peerConnectionID\" +\n payload.connectionId +\n \"vs\" +\n connection.peerConnectionId,\n );\n return;\n }\n\n // If we don't have remoteDescription yet (or if connectionId doesn't match), queue it\n if (\n !connection.pc.remoteDescription ||\n !connection.peerConnectionId\n ) {\n connection.peerConnectionId = payload.connectionId;\n connection.pendingRemoteIce.push(payload.ice);\n return;\n }\n\n try {\n await connection.pc.addIceCandidate(payload.ice);\n } catch (e) {\n logLine?.(\"⚠️ ERROR\", {\n error: \"add-ice-failed\",\n userId: state.peer.userId,\n detail: String(e),\n });\n }\n return;\n }\n\n if (type === \"broadcast\") {\n onBroadcastMessage?.(payload, from.userId);\n }\n },\n });\n\n iceUrlProvider.addRequester(sendToServer);\n\n roomsEntered.set(`${host}/room/${room}`, {\n exitRoom: () => {\n exitRoom();\n iceUrlProvider.removeRequester(sendToServer);\n },\n room,\n host,\n broadcast: (payload) => sendToServer(\"broadcast\", payload),\n });\n });\n }\n\n return {\n userId,\n enterRoom: enter,\n exitRoom: exit,\n leaveUser,\n async reset(userId: string) {\n const userState = users.get(userId);\n userState?.reset();\n },\n broadcast<P extends any>(payload: P) {\n roomsEntered.forEach((room) => room.broadcast(payload));\n },\n end() {\n roomsEntered.forEach(({ exitRoom }) => exitRoom());\n roomsEntered.clear();\n users.forEach(({ peer }) => leaveUser(peer.userId));\n users.clear();\n },\n };\n}\n\n/*\nTurn Token ID\n<CF_TURN_TOKEN_ID>\n\nAPI Token\n<CF_RTC_API_TOKEN>\n\nCURL\ncurl \\\n\t-H \"Authorization: Bearer <CF_RTC_API_TOKEN>\" \\\n\t-H \"Content-Type: application/json\" -d '{\"ttl\": 86400}' \\\n\thttps://rtc.live.cloudflare.com/v1/turn/keys/<CF_TURN_TOKEN_ID>/credentials/generate-ice-servers\n\nJSON\n{\n\t\"iceServers\": [\n {\n \"urls\": [\n \"stun:stun.cloudflare.com:3478\",\n \"turn:turn.cloudflare.com:3478?transport=udp\",\n \"turn:turn.cloudflare.com:3478?transport=tcp\",\n \"turns:turn.cloudflare.com:5349?transport=tcp\"\n ],\n \"username\": \"xxxx\",\n \"credential\": \"yyyy\",\n }\n ]\n}\n\n*/\n",
|
|
10
10
|
"import { EnterRoom, enterRoom } from \"./signal/signal-room\";\nimport {\n SigType,\n SigPayload,\n collectPeerConnections,\n} from \"./webrtc-peer-collector\";\n\ntype UserListener = (\n user: string,\n action: \"join\" | \"leave\",\n users: string[],\n) => void;\n\nexport function enterWorld<\n S extends string | ArrayBufferView = string | ArrayBufferView,\n R extends string | ArrayBufferLike = string | ArrayBufferLike,\n>({\n userId: passedUserId,\n worldId,\n logLine,\n enterRoomFunction = enterRoom,\n peerlessUserExpiration,\n workerUrl,\n onRoomReady,\n onRoomClose,\n dataChannelOptions,\n}: {\n userId?: string;\n worldId: string;\n logLine?: (...obj: any[]) => void;\n enterRoomFunction?: EnterRoom<SigType, SigPayload>;\n peerlessUserExpiration?: number;\n workerUrl?: URL;\n onRoomReady?(info: { host: string; room: string }): void;\n onRoomClose?(info: {\n host: string;\n room: string;\n ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">;\n }): void;\n dataChannelOptions?: RTCDataChannelInit;\n}) {\n const userIds = new Set<string>();\n const dataChannels = new Map<string, RTCDataChannel>();\n const userListeners = new Set<UserListener>();\n const messagesListeners = new Set<(data: R, from: string) => void>();\n\n function createDataChannel(\n pc: RTCPeerConnection,\n peerUserId: string,\n restart?: () => void,\n ) {\n function listener(ev: RTCDataChannelEvent) {\n const dc = ev.channel;\n wireDataChannel(peerUserId, dc, restart);\n dataChannels.set(peerUserId, dc);\n }\n pc.addEventListener(\"datachannel\", listener);\n const dc = pc.createDataChannel(\"data\", dataChannelOptions);\n wireDataChannel(peerUserId, dc, restart);\n dataChannels.set(peerUserId, dc);\n return () => {\n pc.removeEventListener(\"datachannel\", listener);\n };\n }\n\n function conveyMessage(data: any, userId: string) {\n messagesListeners.forEach((listener) => listener(data, userId));\n }\n\n function wireDataChannel(\n userId: string,\n dc: RTCDataChannel,\n restart?: () => void,\n ) {\n dc.onopen = () => {\n logLine?.(\"💬\", { event: \"dc-open\", userId });\n userIds.add(userId);\n userListeners.forEach((listener) =>\n listener(userId, \"join\", [...userIds]),\n );\n };\n const onmessage = ({ data }: MessageEvent) => {\n conveyMessage(data, userId);\n };\n dc.addEventListener(\"message\", onmessage);\n dc.onclose = () => {\n logLine?.(\"💬\", { event: \"dc-close\", userId });\n userIds.delete(userId);\n userListeners.forEach((listener) =>\n listener(userId, \"leave\", [...userIds]),\n );\n dc.removeEventListener(\"message\", onmessage);\n dc.onopen = null;\n dc.onclose = null;\n dc.onerror = null;\n dc.close();\n restart?.();\n };\n dc.onerror = () => logLine?.(\"⚠️ ERROR\", { error: \"dc-error\", userId });\n }\n\n const {\n userId,\n enterRoom,\n exitRoom,\n leaveUser,\n broadcast,\n end: endPeerCollection,\n reset: resetPeerCollection,\n } = collectPeerConnections({\n userId: passedUserId,\n worldId,\n enterRoomFunction,\n logLine,\n workerUrl,\n peerlessUserExpiration,\n onRoomReady,\n onRoomClose,\n onLeaveUser(userId: string) {\n const dc = dataChannels.get(userId);\n try {\n dc?.close();\n } catch {}\n dataChannels.delete(userId);\n },\n receivePeerConnection({ pc, userId, restart }) {\n createDataChannel(pc, userId, restart);\n },\n onBroadcastMessage(payload, from) {\n conveyMessage(payload, from);\n logLine?.(\"📢\", { event: \"broadcast\", userId, data: payload });\n },\n });\n\n function send(data: S, userId?: string) {\n dataChannels.forEach((dataChannel, pUserId) => {\n if (userId && pUserId !== userId) return;\n if (dataChannel.readyState === \"open\") {\n dataChannel.send(data as any);\n }\n });\n }\n\n function removeMessageListener(listener: (data: R, from: string) => void) {\n messagesListeners.delete(listener);\n }\n\n function addMessageListener(listener: (data: R, from: string) => void) {\n messagesListeners.add(listener);\n return () => {\n removeMessageListener(listener);\n };\n }\n\n function removeUserListener(listener: UserListener) {\n userListeners.delete(listener);\n }\n\n function addUserListener(listener: UserListener) {\n userListeners.add(listener);\n return () => {\n removeUserListener(listener);\n };\n }\n\n return {\n userId,\n send,\n broadcast,\n enterRoom,\n exitRoom,\n leaveUser,\n getUsers: () => [...userIds],\n addMessageListener,\n removeMessageListener,\n addUserListener,\n removeUserListener,\n reset() {\n userIds.forEach((userId) => {\n dataChannels.get(userId)?.close();\n dataChannels.delete(userId);\n resetPeerCollection(userId);\n });\n },\n end() {\n dataChannels.forEach((dataChannel) => {\n try {\n dataChannel.close();\n } catch {}\n });\n dataChannels.clear();\n endPeerCollection();\n userListeners.clear();\n userIds.clear();\n },\n };\n}\n"
|
|
11
11
|
],
|
|
12
|
-
"mappings": "AAAO,MAAM,CAAe,CAClB,sBAAwB,GACxB,kBAIA,WA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|
|
13
|
+
"debugId": "AADEA038C84812ED64756E2164756E21",
|
|
14
14
|
"names": []
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webrtc-peer-collector.d.ts","sourceRoot":"","sources":["../src/browser/webrtc-peer-collector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAa,MAAM,sBAAsB,CAAC;AAG5D,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,aAAa,GAAG,WAAW,CAAC;AAC/E,MAAM,MAAM,UAAU,GAAG;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,yBAAyB,CAAC;IAClC,MAAM,CAAC,EAAE,yBAAyB,CAAC;IACnC,GAAG,CAAC,EAAE,mBAAmB,CAAC;CAC3B,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAwBxB;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,MAAM,EAAE,YAAY,EACpB,OAAO,EACP,qBAAqB,EACrB,sBAA6B,EAC7B,iBAAiB,EAAE,SAA8B,EACjD,OAAO,EACP,WAAW,EACX,SAAS,EACT,WAAW,EACX,WAAW,EACX,kBAAkB,GACnB,EAAE;IACD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACnD,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IACjD,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,qBAAqB,CAAC,UAAU,EAAE;QAChC,EAAE,EAAE,iBAAiB,CAAC;QACt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,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;wBAhCjC,MAAM;kBAyVX,MAAM;cAIhB,CAAC,2BAAuB,CAAC;;EAUtC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class L{sendToServerFunctions=[];icePromiseResolve;icePromise;receiveIce(
|
|
1
|
+
class L{sendToServerFunctions=[];icePromiseResolve;icePromise;receiveIce(X,T){this.icePromiseResolve?.({url:X,expiration:T}),this.icePromiseResolve=void 0,this.icePromise=void 0}addRequester(X){return this.sendToServerFunctions.push(X),()=>{this.removeRequester(X)}}removeRequester(X){this.sendToServerFunctions.splice(this.sendToServerFunctions.indexOf(X),1)}sendToServer(X){this.sendToServerFunctions[Math.floor(this.sendToServerFunctions.length*Math.random())](X)}async requestIce(){if(!this.icePromise)this.icePromise=new Promise((X)=>{this.icePromiseResolve=X,this.sendToServer("request-ice")});return await this.icePromise}}function U(X){let{userId:T,worldId:H,room:J,host:O,autoRejoin:z=!0,logLine:W}=X,x=!1,S=0,B,R,_=!0,A=new Map,C=`wss://${O}/room/${H}/${J}?userId=${encodeURIComponent(T)}`,D=[],P=0;function N(b,q,Y){if(!B)return W?.("\uD83D\uDC64 ➡️ ❌","no ws available"),!1;let Q={type:b,to:q,payload:Y};if(D.push(Q),W?.("\uD83D\uDC64 ➡️ \uD83D\uDDA5️",Q),clearTimeout(P),x||B.readyState!==WebSocket.OPEN)return W?.("\uD83D\uDC64 ➡️ ❌","Not in opened state: "+B.readyState),!1;return P=setTimeout(()=>{B.send(JSON.stringify(D)),D.length=0}),!0}function E(){if(x)return;B=new WebSocket(C),B.onopen=()=>{if(_)X.onOpen?.(),_=!1;S=0},B.onmessage=(b)=>{try{let q=JSON.parse(b.data);(Array.isArray(q)?q:[q]).forEach((Q)=>{if(W?.("\uD83D\uDDA5️ ➡️ \uD83D\uDC64",Q),Q.type==="peer-joined"||Q.type==="peer-left")M(Q.users,Q);else if(Q.type==="ice-server")X.onIceUrl?.(Q.url,Q.expiration);else if(Q.userId)X.onMessage(Q.type,Q.payload,{userId:Q.userId,receive:(K,Z)=>N(K,Q.userId,Z)})})}catch{W?.("⚠️ ERROR",{error:"invalid-json"})}},B.onclose=(b)=>{let Y=[1001,1006,1011,1012,1013].includes(b.code);if(z&&!x&&Y){let Q=Math.min(Math.pow(2,S)*1000,30000),K=Math.random()*1000,Z=Q+K;W?.("\uD83D\uDD04 RECONNECTING",{attempt:S+1,delayMs:Math.round(Z)}),S++,R=setTimeout(E,Z)}else X.onClose?.({code:b.code,reason:b.reason,wasClean:b.wasClean})},B.onerror=(b)=>{console.error("WS Error",b),X.onError?.()}}function M(b,q){let Y=[],Q=[],K=new Set;b.forEach(({userId:Z})=>{if(Z===T)return;if(!A.has(Z)||q.type==="peer-joined"&&Z===q.userId){let f={userId:Z,receive:(j,w)=>N(j,Z,w)};A.set(Z,f),Y.push(f)}K.add(Z)});for(let Z of A.keys())if(!K.has(Z)||q.type==="peer-left"&&Z===q.userId)A.delete(Z),Q.push({userId:Z});if(Y.length)X.onPeerJoined(Y);if(Q.length)X.onPeerLeft(Q)}return E(),{sendToServer(b,q){N(b,"server",q)},exitRoom:()=>{x=!0,clearTimeout(R),B.close()}}}function I({userId:X,worldId:T,room:H,host:J,autoRejoin:O=!0,onOpen:z,onClose:W,onError:x,onPeerJoined:S,onPeerLeft:B,onIceUrl:R,onMessage:_,logLine:A,workerUrl:C}){if(!C)return console.warn("Warning: enterRoom called without workerUrl; this may cause issues in some environments. You should pass workerUrl explicitly. Use:","https://cdn.jsdelivr.net/npm/@dobuki/hello-worker/dist/signal-room.worker.min.js"),U({userId:X,worldId:T,room:H,host:J,autoRejoin:O,onOpen:z,onClose:W,onError:x,onPeerJoined:S,onPeerLeft:B,onIceUrl:R,onMessage:_});let D=new Worker(C,{type:"module"}),P=!1;function N({userId:M}){return{userId:M,receive:(b,q)=>{if(P)return!1;return D.postMessage({cmd:"send",toUserId:M,host:J,room:H,type:b,payload:q}),!0}}}let E=(M)=>{let b=M.data;if(b.kind==="open")z?.();else if(b.kind==="close")D.terminate(),W?.(b.ev);else if(b.kind==="error")x?.();else if(b.kind==="peer-joined")S(b.users.map((q)=>N({userId:q.userId})));else if(b.kind==="peer-left")B(b.users);else if(b.kind==="ice-server")R?.(b.url,b.expiration);else if(b.kind==="message")_(b.type,b.payload,N({userId:b.fromUserId}));else if(b.kind==="log")A?.(b.direction,b.obj)};return D.addEventListener("message",E),D.postMessage({cmd:"enter",userId:X,worldId:T,room:H,host:J,autoRejoin:O}),{exitRoom:()=>{P=!0,D.removeEventListener("message",E),D.postMessage({cmd:"exit"})},sendToServer:(M,b)=>{D.postMessage({cmd:"send",toUserId:"server",host:J,room:H,type:M,payload:b})}}}var c={iceServers:[{urls:"stun:stun.l.google.com:19302"}]};class v{iceUrlProvider;constructor(X){this.iceUrlProvider=X}rtcConfig={...c,timestamp:Date.now()};rtcConfigPromise;async getRtcConfig(){if(Date.now()-(this.rtcConfig?.timestamp??0)<1e4)return this.rtcConfig;if(!this.rtcConfigPromise)this.rtcConfigPromise=new Promise(async(T)=>{let H=3;for(let J=0;J<H;J++)try{let O=(await this.iceUrlProvider.requestIce()).url,z=await fetch(O);if(!z.ok)throw Error(`ICE endpoint failed: ${z.status}`);let W=await z.json();T(W);return}catch(O){console.warn("Failed fetching iceUrl")}}),this.rtcConfig=await this.rtcConfigPromise,this.rtcConfigPromise=void 0;return this.rtcConfig}}var u=I;function s({userId:X,worldId:T,receivePeerConnection:H,peerlessUserExpiration:J=5000,enterRoomFunction:O=u,logLine:z,onLeaveUser:W,workerUrl:x,onRoomReady:S,onRoomClose:B,onBroadcastMessage:R}){let _=X??`user-${crypto.randomUUID()}`,A=new Map,C=new Map;function D(q){W?.(q);let Y=A.get(q);if(!Y)return;A.delete(q);try{Y.close()}catch{}}async function P(q){if(!q.connection?.pc?.remoteDescription)return;let Y=q.connection.pendingRemoteIce;q.connection.pendingRemoteIce=[];for(let Q of Y)try{await q.connection.pc.addIceCandidate(Q)}catch(K){z?.("⚠️ ERROR",{error:"add-ice-failed",userId:q.peer.userId,detail:String(K)})}}let N=new L,E=new v(N);function M({room:q,host:Y}){let Q=`${Y}/room/${q}`,K=C.get(Q);if(K)K.exitRoom(),C.delete(Q)}function b({room:q,host:Y}){return new Promise(async(Q,K)=>{async function Z(F){if(F.connectionPromise)return F.connectionPromise;let G=new Promise(async($)=>{F.connection={id:`conn-${crypto.randomUUID()}`,pc:new RTCPeerConnection(await E.getRtcConfig()),pendingRemoteIce:[]},F.connection.pc.onicecandidate=(h)=>{if(!h.candidate)return;F.peer.receive("ice",{connectionId:F.connection?.id,ice:h.candidate.toJSON()})},F.connection.pc.onconnectionstatechange=async()=>{if(z?.("\uD83D\uDCAC",{event:"pc-state",userId:F.peer.userId,state:F.connection?.pc?.connectionState}),F.connection?.pc?.connectionState==="failed"){F.close();let h=await f(F.peer,!0);if(h.connection?.pc)H({pc:h.connection?.pc,userId:h.peer.userId,restart:()=>h.close()});else z?.("\uD83D\uDC64ℹ️","no pc: "+h.peer.userId);return}},$(F.connection)});return F.connectionPromise=G,await G,F.connectionPromise=void 0,G}async function f(F,G){let $=A.get(F.userId);if(!$||G){let h={peer:F,close(){if(this.connection)this.connection.pc.close(),this.connection=void 0;A.delete(F.userId)},async reset(){h.close(),setTimeout(async()=>{let V=await f(F,!0);if(!V.connection?.pc){z?.("⚠️","no pc");return}H({pc:V.connection?.pc,userId:V.peer.userId,restart:()=>V.close()}),await j(V.peer)},500)}};$=h,await Z(h),A.set($.peer.userId,$)}else if($){if(clearTimeout($.expirationTimeout),$.expirationTimeout=0,!$.connection?.pc||$.connection?.pc.signalingState==="closed")await Z($)}return $.peer=F,$}async function j(F){let G=await f(F),$=G.connection?.pc,h=await $?.createOffer();await $?.setLocalDescription(h),F.receive("offer",{connectionId:G.connection?.id,offer:$.localDescription.toJSON()})}let{exitRoom:w,sendToServer:k}=O({userId:_,worldId:T,room:q,host:Y,logLine:z,workerUrl:x,autoRejoin:!0,onOpen(){S?.({room:q,host:Y}),Q()},onError(){console.error("onError"),K()},onClose(F){B?.({room:q,host:Y,ev:F})},onPeerJoined(F){F.forEach(async(G)=>{let $=await f(G,!0),h=$.connection?.pc;if(!h){z?.("\uD83D\uDC64ℹ️","no pc: "+G.userId);return}H({pc:h,userId:G.userId,restart:()=>$.close()}),await j(G)})},onPeerLeft(F){F.forEach(({userId:G})=>{let $=A.get(G);if(!$)return;$.expirationTimeout=setTimeout(()=>D(G),J??0)})},onIceUrl(F,G){N.receiveIce(F,G)},async onMessage(F,G,$){if(F==="offer"&&G.offer){let h=await f($,!1),V=!h.connection||h.connection.pc.signalingState==="stable"?await Z(h):h.connection;z?.("\uD83D\uDCAC",{type:F,signalingState:V.pc.signalingState}),V.peerConnectionId=G.connectionId,H({pc:V.pc,userId:$.userId,restart:()=>h.close()}),await V.pc.setRemoteDescription(G.offer);let i=await V.pc.createAnswer();await V.pc.setLocalDescription(i),$.receive("answer",{connectionId:V.id,answer:V.pc.localDescription?.toJSON()}),await P(h);return}if(F==="answer"&&G.answer){let h=await f($,!1),V=h.connection&&h.connection.pc.signalingState!=="closed"?h.connection:await Z(h);z?.("\uD83D\uDCAC",{type:F,signalingState:V.pc.signalingState}),await V.pc.setRemoteDescription(G.answer),V.peerConnectionId=G.connectionId,await P(h);return}if(F==="ice"&&G.ice){let h=await f($,!1),V=h.connection??await h.connectionPromise;if(!V){z?.("⚠️","No connection");return}if(z?.("\uD83D\uDCAC",{type:F,signalingState:V.pc.signalingState}),V.peerConnectionId&&G.connectionId!==V.peerConnectionId){z?.("⚠️","Mismatch peerConnectionID"+G.connectionId+"vs"+V.peerConnectionId);return}if(!V.pc.remoteDescription||!V.peerConnectionId){V.peerConnectionId=G.connectionId,V.pendingRemoteIce.push(G.ice);return}try{await V.pc.addIceCandidate(G.ice)}catch(i){z?.("⚠️ ERROR",{error:"add-ice-failed",userId:h.peer.userId,detail:String(i)})}return}if(F==="broadcast")R?.(G,$.userId)}});N.addRequester(k),C.set(`${Y}/room/${q}`,{exitRoom:()=>{w(),N.removeRequester(k)},room:q,host:Y,broadcast:(F)=>k("broadcast",F)})})}return{userId:_,enterRoom:b,exitRoom:M,leaveUser:D,async reset(q){A.get(q)?.reset()},broadcast(q){C.forEach((Y)=>Y.broadcast(q))},end(){C.forEach(({exitRoom:q})=>q()),C.clear(),A.forEach(({peer:q})=>D(q.userId)),A.clear()}}}export{s as collectPeerConnections};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=8E74421F9D5F8A3A64756E2164756E21
|
|
4
4
|
//# sourceMappingURL=webrtc-peer-collector.js.map
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
"export interface IPeer<T extends string = string, P = any> {\n userId: string;\n receive(type: T, payload: P): boolean;\n}\n\ntype OutMessage = { type: string; to: string; payload: any };\n\n/**\n * enterRoom connects to the signaling room via WebSocket.\n */\nexport function enterRoom<T extends string, P = any>(params: {\n userId: string;\n worldId: string;\n room: string;\n host: string;\n onOpen?: () => void;\n onClose?: (ev: Pick<CloseEvent, \"code\" | \"reason\" | \"wasClean\">) => void;\n onError?: () => void;\n logLine?: (direction: string, obj?: any) => void;\n onPeerJoined(users: IPeer<T, P>[]): void;\n onPeerLeft(users: { userId: string }[]): void;\n onIceUrl?(url: string, expiration: number): void;\n onMessage(type: T, payload: P, from: IPeer<T, P>): void;\n autoRejoin?: boolean;\n}): {\n exitRoom: () => void;\n sendToServer: <P extends any>(type: T, payload?: P) => void;\n} {\n type Message = {\n type: \"peer-joined\" | \"peer-left\" | \"ice-server\" | T;\n userId: string;\n users: { userId: string }[];\n payload: P;\n url: string;\n expiration: number;\n };\n\n const { userId, worldId, room, host, autoRejoin = true, logLine } = params;\n\n let exited = false;\n let retryCount = 0;\n let ws: WebSocket;\n let timeoutId: ReturnType<typeof setTimeout>;\n let initialConnection = true;\n\n const peers = new Map<string, IPeer<T, P>>();\n const wsUrl = `wss://${host}/room/${worldId}/${room}?userId=${encodeURIComponent(\n userId,\n )}`;\n\n // Helper for sending (uses the current ws instance)\n const accumulatedMessages: OutMessage[] = [];\n let timeout: ReturnType<typeof setTimeout> = 0;\n function send(type: string, to: \"server\" | string, payload?: any) {\n if (!ws) {\n logLine?.(\"👤 ➡️ ❌\", \"no ws available\");\n return false;\n }\n const obj: OutMessage = { type, to, payload };\n accumulatedMessages.push(obj);\n logLine?.(\"👤 ➡️ 🖥️\", obj);\n clearTimeout(timeout);\n if (exited || ws.readyState !== WebSocket.OPEN) {\n logLine?.(\"👤 ➡️ ❌\", \"Not in opened state: \" + ws.readyState);\n return false;\n }\n timeout = setTimeout(() => {\n ws.send(JSON.stringify(accumulatedMessages));\n accumulatedMessages.length = 0;\n });\n return true;\n }\n\n function connect() {\n if (exited) return;\n\n ws = new WebSocket(wsUrl);\n\n ws.onopen = () => {\n if (initialConnection) {\n params.onOpen?.();\n initialConnection = false;\n }\n retryCount = 0; // Reset backoff on successful connection\n };\n\n ws.onmessage = (e: MessageEvent) => {\n try {\n const result = JSON.parse(e.data);\n const msgs: Message[] = Array.isArray(result) ? result : [result];\n msgs.forEach((msg) => {\n logLine?.(\"🖥️ ➡️ 👤\", msg);\n if (msg.type === \"peer-joined\" || msg.type === \"peer-left\") {\n updatePeers(msg.users, msg);\n } else if (msg.type === \"ice-server\") {\n params.onIceUrl?.(msg.url, msg.expiration);\n } else if (msg.userId) {\n params.onMessage(msg.type, msg.payload, {\n userId: msg.userId,\n receive: (type: T, payload: P) => send(type, msg.userId, payload),\n });\n }\n });\n } catch {\n logLine?.(\"⚠️ ERROR\", { error: \"invalid-json\" });\n }\n };\n\n ws.onclose = (ev: CloseEvent) => {\n // 1. Check if we should even try to reconnect\n const recoverableCodes = [1001, 1006, 1011, 1012, 1013];\n const isRecoverable = recoverableCodes.includes(ev.code);\n\n if (autoRejoin && !exited && isRecoverable) {\n // 2. Exponential Backoff: 1s, 2s, 4s, 8s... capped at 30s\n const backoff = Math.min(Math.pow(2, retryCount) * 1000, 30000);\n // 3. Add Jitter: +/- 1000ms randomness\n const jitter = Math.random() * 1000;\n const delay = backoff + jitter;\n\n logLine?.(\"🔄 RECONNECTING\", {\n attempt: retryCount + 1,\n delayMs: Math.round(delay),\n });\n\n retryCount++;\n timeoutId = setTimeout(connect, delay);\n } else {\n params.onClose?.({\n code: ev.code,\n reason: ev.reason,\n wasClean: ev.wasClean,\n });\n }\n };\n\n ws.onerror = (ev) => {\n console.error(\"WS Error\", ev);\n params.onError?.();\n };\n }\n\n // Helper for peer tracking (logic from your original code)\n function updatePeers(updatedUsers: { userId: string }[], msg: Message) {\n const joined: IPeer<T, P>[] = [];\n const left: { userId: string }[] = [];\n const updatedPeerSet = new Set<string>();\n\n updatedUsers.forEach(({ userId: pUserId }) => {\n if (pUserId === userId) return;\n if (\n !peers.has(pUserId) ||\n (msg.type === \"peer-joined\" && pUserId === msg.userId)\n ) {\n const newPeer = {\n userId: pUserId,\n receive: (t: T, p: P) => send(t, pUserId, p),\n };\n peers.set(pUserId, newPeer);\n joined.push(newPeer);\n }\n updatedPeerSet.add(pUserId);\n });\n\n for (const pUserId of peers.keys()) {\n if (\n !updatedPeerSet.has(pUserId) ||\n (msg.type === \"peer-left\" && pUserId === msg.userId)\n ) {\n peers.delete(pUserId);\n left.push({ userId: pUserId });\n }\n }\n\n // Notify peer joined first then peer left. (avoid disconnect in case the peer leaving / joining is on the same user).\n if (joined.length) params.onPeerJoined(joined);\n if (left.length) params.onPeerLeft(left);\n }\n\n // Start initial connection\n connect();\n\n return {\n sendToServer(type, payload) {\n send(type, \"server\", payload);\n },\n exitRoom: () => {\n exited = true;\n clearTimeout(timeoutId);\n ws.close();\n },\n };\n}\n",
|
|
7
7
|
"import type { IPeer } from \"./impl/signal-room.js\";\nimport { enterRoom as baseEnterRoom } from \"./impl/signal-room.js\";\nimport { RoomEvent, WorkerCommand } from \"./signal-room.worker.js\";\n\nexport function enterRoom<T extends string, P = any>({\n userId,\n worldId,\n room,\n host,\n autoRejoin = true,\n onOpen,\n onClose,\n onError,\n onPeerJoined,\n onPeerLeft,\n onIceUrl,\n onMessage,\n logLine,\n workerUrl,\n}: {\n userId: string;\n worldId: string;\n room: string;\n host: string;\n autoRejoin?: boolean;\n onOpen?: () => void;\n onClose?: (ev: Pick<CloseEvent, \"code\" | \"reason\" | \"wasClean\">) => void;\n onError?: () => void;\n onPeerJoined: (users: IPeer<T, P>[]) => void;\n onPeerLeft: (users: { userId: string }[]) => void;\n onIceUrl?(url: string, expiration: number): void;\n onMessage: (type: T, payload: P, from: IPeer<T, P>) => void;\n logLine?: (direction: string, obj?: any) => void;\n\n // Pass the URL to your worker file (bundler will handle it)\n workerUrl?: URL;\n}): {\n exitRoom: () => void;\n sendToServer: <P extends any>(type: T, payload?: P) => void;\n} {\n if (!workerUrl) {\n const CDN_WORKER_URL = `https://cdn.jsdelivr.net/npm/@dobuki/hello-worker/dist/signal-room.worker.min.js`;\n\n console.warn(\n \"Warning: enterRoom called without workerUrl; this may cause issues in some environments. You should pass workerUrl explicitly. Use:\",\n CDN_WORKER_URL,\n );\n return baseEnterRoom<T, P>({\n userId,\n worldId,\n room,\n host,\n autoRejoin,\n onOpen,\n onClose,\n onError,\n onPeerJoined,\n onPeerLeft,\n onIceUrl,\n onMessage,\n });\n }\n const worker = new Worker(workerUrl, { type: \"module\" });\n let exited = false;\n\n function makeUser({ userId }: { userId: string }): IPeer<T, P> {\n return {\n userId,\n receive: (type: T, payload: P) => {\n if (exited) return false;\n worker.postMessage({\n cmd: \"send\",\n toUserId: userId,\n host,\n room,\n type,\n payload,\n } as WorkerCommand);\n return true;\n },\n };\n }\n\n const onWorkerMessage = (e: MessageEvent<RoomEvent<T, P>>) => {\n const ev = e.data;\n\n if (ev.kind === \"open\") onOpen?.();\n else if (ev.kind === \"close\") {\n worker.terminate();\n onClose?.(ev.ev);\n } else if (ev.kind === \"error\") onError?.();\n else if (ev.kind === \"peer-joined\")\n onPeerJoined(ev.users.map((ev) => makeUser({ userId: ev.userId })));\n else if (ev.kind === \"peer-left\") onPeerLeft(ev.users);\n else if (ev.kind === \"ice-server\") onIceUrl?.(ev.url, ev.expiration);\n else if (ev.kind === \"message\")\n onMessage(ev.type, ev.payload, makeUser({ userId: ev.fromUserId }));\n else if (ev.kind === \"log\") logLine?.(ev.direction, ev.obj);\n };\n\n worker.addEventListener(\"message\", onWorkerMessage);\n\n worker.postMessage({\n cmd: \"enter\",\n userId,\n worldId,\n room,\n host,\n autoRejoin,\n } as WorkerCommand);\n\n return {\n exitRoom: () => {\n exited = true;\n worker.removeEventListener(\"message\", onWorkerMessage);\n worker.postMessage({ cmd: \"exit\" } as WorkerCommand);\n },\n sendToServer: <P extends any>(type: T, payload?: P) => {\n worker.postMessage({\n cmd: \"send\",\n toUserId: \"server\",\n host,\n room,\n type,\n payload,\n } as WorkerCommand);\n },\n };\n}\n\nexport type EnterRoom<T extends string, P> = typeof enterRoom<T, P>;\n",
|
|
8
8
|
"import { IceUrlProvider } from \"./ice-url-provider\";\n\nconst FALLBACK_RTC_CONFIG = {\n iceServers: [{ urls: \"stun:stun.l.google.com:19302\" }],\n};\n\nexport class RTCConfigProvider {\n constructor(private iceUrlProvider: IceUrlProvider) {}\n\n private rtcConfig: RTCConfiguration & { timestamp: number } = {\n ...FALLBACK_RTC_CONFIG,\n timestamp: Date.now(),\n };\n private rtcConfigPromise?: Promise<RTCConfiguration & { timestamp: number }>;\n\n async getRtcConfig(): Promise<RTCConfiguration & { timestamp: number }> {\n const now = Date.now();\n if (now - (this.rtcConfig?.timestamp ?? 0) < 10000) {\n return this.rtcConfig;\n }\n\n if (!this.rtcConfigPromise) {\n this.rtcConfigPromise = new Promise<\n RTCConfiguration & { timestamp: number }\n >(async (resolve) => {\n let retries = 3;\n for (let r = 0; r < retries; r++) {\n try {\n const iceUrl = (await this.iceUrlProvider.requestIce()).url;\n const r = await fetch(iceUrl);\n if (!r.ok) throw new Error(`ICE endpoint failed: ${r.status}`);\n const rtcConfig = (await r.json()) as RTCConfiguration & {\n timestamp: number;\n };\n resolve(rtcConfig);\n return;\n } catch (e) {\n console.warn(\"Failed fetching iceUrl\");\n }\n }\n });\n this.rtcConfig = await this.rtcConfigPromise;\n this.rtcConfigPromise = undefined;\n }\n return this.rtcConfig;\n }\n}\n",
|
|
9
|
-
"import { IceUrlProvider } from \"./utils/ice-url-provider\";\nimport { IPeer } from \"./signal/impl/signal-room\";\nimport { EnterRoom, enterRoom } from \"./signal/signal-room\";\nimport { RTCConfigProvider } from \"./utils/rtc-config\";\n\nexport type SigType = \"offer\" | \"answer\" | \"ice\" | \"request-ice\" | \"broadcast\";\nexport type SigPayload = {\n connectionId?: string;\n offer?: RTCSessionDescriptionInit;\n answer?: RTCSessionDescriptionInit;\n ice?: RTCIceCandidateInit;\n} & Record<string, any>;\n\ninterface Connection {\n id: string;\n peerConnectionId?: string;\n pc: RTCPeerConnection;\n // ICE that arrived before we had remoteDescription\n pendingRemoteIce: RTCIceCandidateInit[];\n}\n\ntype UserState = {\n connection?: Connection;\n\n // the signaling \"user\" handle so we can send messages\n peer: IPeer<SigType, SigPayload>;\n\n expirationTimeout?: number;\n close(): void;\n reset(): void;\n connectionPromise?: Promise<Connection>;\n};\n\nconst DEFAULT_ENTER_ROOM = enterRoom;\n\n/**\n * Collect peers\n */\nexport function collectPeerConnections({\n userId: passedUserId,\n worldId,\n receivePeerConnection,\n peerlessUserExpiration = 5000,\n enterRoomFunction: enterRoom = DEFAULT_ENTER_ROOM,\n logLine,\n onLeaveUser,\n workerUrl,\n onRoomReady,\n onRoomClose,\n onBroadcastMessage,\n}: {\n userId?: string;\n worldId: string;\n enterRoomFunction?: EnterRoom<SigType, SigPayload>;\n onLeaveUser?: (userId: string) => void;\n logLine?: (direction: string, obj?: any) => void;\n workerUrl?: URL;\n peerlessUserExpiration?: number;\n receivePeerConnection(connection: {\n pc: RTCPeerConnection;\n userId: string;\n restart?: () => void;\n }): void;\n onRoomReady?(info: { host: string; room: string }): void;\n onRoomClose?(info: {\n host: string;\n room: string;\n ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">;\n }): void;\n onBroadcastMessage?<P extends any>(payload: P, from: string): void;\n}) {\n const userId = passedUserId ?? `user-${crypto.randomUUID()}`;\n const users: Map<string, UserState> = new Map();\n\n const roomsEntered = new Map<\n string,\n {\n room: string;\n host: string;\n exitRoom: () => void;\n broadcast: <P extends any>(payload: P) => void;\n }\n >();\n\n function leaveUser(userId: string) {\n onLeaveUser?.(userId);\n const p = users.get(userId);\n if (!p) return;\n users.delete(userId);\n try {\n p.close();\n } catch {}\n }\n\n async function flushRemoteIce(state: UserState) {\n if (!state.connection?.pc?.remoteDescription) return;\n\n const queued = state.connection.pendingRemoteIce;\n state.connection.pendingRemoteIce = [];\n\n for (const ice of queued) {\n try {\n await state.connection.pc.addIceCandidate(ice);\n } catch (e) {\n logLine?.(\"⚠️ ERROR\", {\n error: \"add-ice-failed\",\n userId: state.peer.userId,\n detail: String(e),\n });\n }\n }\n }\n\n const iceUrlProvider = new IceUrlProvider();\n const rtcConfigProvider = new RTCConfigProvider(iceUrlProvider);\n\n function exit({ room, host }: { room: string; host: string }) {\n const key = `${host}/room/${room}`;\n const session = roomsEntered.get(key);\n if (session) {\n session.exitRoom();\n roomsEntered.delete(key);\n }\n }\n\n function enter({ room, host }: { room: string; host: string }) {\n return new Promise<void>(async (resolve, reject) => {\n async function setupConnection(state: UserState) {\n if (state.connectionPromise) {\n return state.connectionPromise;\n }\n return (state.connectionPromise = new Promise<Connection>(\n async (resolve) => {\n state.connection = {\n id: `conn-${crypto.randomUUID()}`,\n pc: new RTCPeerConnection(await rtcConfigProvider.getRtcConfig()),\n pendingRemoteIce: [],\n };\n\n // Send local ICE candidates to this peer\n state.connection.pc.onicecandidate = (ev) => {\n if (!ev.candidate) return;\n state.peer.receive(\"ice\", {\n connectionId: state.connection?.id,\n ice: ev.candidate.toJSON(),\n });\n };\n\n state.connection.pc.onconnectionstatechange = async () => {\n logLine?.(\"💬\", {\n event: \"pc-state\",\n userId: state.peer.userId,\n state: state.connection?.pc?.connectionState,\n });\n if (state.connection?.pc?.connectionState === \"failed\") {\n // reset the connection\n state.close();\n const userState = await getPeer(state.peer, true);\n if (userState.connection?.pc) {\n receivePeerConnection({\n pc: userState.connection?.pc,\n userId: userState.peer.userId,\n restart: () => userState.close(),\n });\n } else {\n logLine?.(\"👤ℹ️\", \"no pc: \" + userState.peer.userId);\n }\n return;\n }\n };\n\n resolve(state.connection);\n },\n ));\n }\n\n async function getPeer(\n peer: IPeer<SigType, SigPayload>,\n forceReset?: boolean,\n ): Promise<UserState> {\n let state = users.get(peer.userId);\n if (!state || forceReset) {\n const newState: UserState = {\n peer,\n close() {\n if (this.connection) {\n this.connection.pc.close();\n this.connection = undefined;\n }\n users.delete(peer.userId);\n },\n async reset() {\n newState.close();\n\n setTimeout(async () => {\n const userState = await getPeer(peer, true);\n if (!userState.connection?.pc) {\n logLine?.(\"⚠️\", \"no pc\");\n return;\n }\n receivePeerConnection({\n pc: userState.connection?.pc,\n userId: userState.peer.userId,\n restart: () => userState.close(),\n });\n await makeOffer(userState.peer);\n }, 500);\n },\n };\n state = newState;\n\n await setupConnection(newState);\n\n // New user\n users.set(state.peer.userId, state);\n } else if (state) {\n clearTimeout(state.expirationTimeout);\n state.expirationTimeout = 0;\n if (\n !state.connection?.pc ||\n state.connection?.pc.signalingState === \"closed\"\n ) {\n await setupConnection(state);\n }\n }\n state.peer = peer;\n return state;\n }\n\n async function makeOffer(user: IPeer<SigType, SigPayload>) {\n // Offer flow: createOffer -> setLocalDescription -> send localDescription\n const state = await getPeer(user);\n const pc = state.connection?.pc;\n const offer = await pc?.createOffer();\n await pc?.setLocalDescription(offer);\n user.receive(\"offer\", {\n connectionId: state.connection?.id,\n offer: pc!.localDescription!.toJSON(),\n });\n }\n\n const { exitRoom, sendToServer } = enterRoom({\n userId,\n worldId,\n room,\n host,\n logLine,\n workerUrl,\n autoRejoin: true,\n\n onOpen() {\n onRoomReady?.({ room, host });\n resolve();\n },\n onError() {\n console.error(\"onError\");\n reject();\n },\n onClose(ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">) {\n onRoomClose?.({ room, host, ev });\n },\n\n // Existing peers initiate to the newcomer\n onPeerJoined(joiningUsers: IPeer<SigType, SigPayload>[]) {\n joiningUsers.forEach(async (user) => {\n const state = await getPeer(user, true);\n const pc = state.connection?.pc;\n if (!pc) {\n logLine?.(\"👤ℹ️\", \"no pc: \" + user.userId);\n return;\n }\n\n receivePeerConnection({\n pc,\n userId: user.userId,\n restart: () => state.close(),\n });\n await makeOffer(user);\n });\n },\n\n onPeerLeft(leavingUsers: { userId: string }[]) {\n leavingUsers.forEach(({ userId }) => {\n const state = users.get(userId);\n if (!state) return;\n state.expirationTimeout = setTimeout(\n () => leaveUser(userId),\n peerlessUserExpiration ?? 0,\n );\n });\n },\n\n onIceUrl(url: string, expiration: number) {\n iceUrlProvider.receiveIce(url, expiration);\n },\n\n async onMessage(type, payload, from: IPeer<SigType, SigPayload>) {\n if (type === \"offer\" && payload.offer) {\n // Grab state and connection\n const state = await getPeer(from, false);\n const connection =\n !state.connection ||\n state.connection.pc.signalingState === \"stable\"\n ? await setupConnection(state)\n : state.connection; // reset\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n connection.peerConnectionId = payload.connectionId;\n receivePeerConnection({\n pc: connection.pc,\n userId: from.userId,\n restart: () => state.close(),\n });\n // Responder: set remote offer\n await connection.pc.setRemoteDescription(payload.offer);\n\n // Create and send answer\n const answer = await connection.pc.createAnswer();\n await connection.pc.setLocalDescription(answer);\n\n from.receive(\"answer\", {\n connectionId: connection.id,\n answer: connection.pc.localDescription?.toJSON(),\n });\n\n // Now safe to apply any queued ICE from this peer\n await flushRemoteIce(state);\n return;\n }\n\n if (type === \"answer\" && payload.answer) {\n const state = await getPeer(from, false);\n const connection =\n state.connection &&\n state.connection.pc.signalingState !== \"closed\"\n ? state.connection\n : await setupConnection(state);\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n // Initiator: set remote answer\n await connection.pc.setRemoteDescription(payload.answer);\n connection.peerConnectionId = payload.connectionId;\n await flushRemoteIce(state);\n return;\n }\n\n if (type === \"ice\" && payload.ice) {\n // Grab state and connection\n const state = await getPeer(from, false);\n const connection =\n state.connection ?? (await state.connectionPromise);\n if (!connection) {\n logLine?.(\"⚠️\", \"No connection\");\n return;\n }\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n if (\n connection.peerConnectionId &&\n payload.connectionId !== connection.peerConnectionId\n ) {\n logLine?.(\n \"⚠️\",\n \"Mismatch peerConnectionID\" +\n payload.connectionId +\n \"vs\" +\n connection.peerConnectionId,\n );\n return;\n }\n\n // If we don't have remoteDescription yet (or if connectionId doesn't match), queue it\n if (\n !connection.pc.remoteDescription ||\n !connection.peerConnectionId\n ) {\n connection.peerConnectionId = payload.connectionId;\n connection.pendingRemoteIce.push(payload.ice);\n return;\n }\n\n try {\n await connection.pc.addIceCandidate(payload.ice);\n } catch (e) {\n logLine?.(\"⚠️ ERROR\", {\n error: \"add-ice-failed\",\n userId: state.peer.userId,\n detail: String(e),\n });\n }\n return;\n }\n\n if (type === \"broadcast\") {\n onBroadcastMessage?.(payload, from.userId);\n }\n },\n });\n\n iceUrlProvider.addRequester(sendToServer);\n\n roomsEntered.set(`${host}/room/${room}`, {\n exitRoom: () => {\n exitRoom();\n iceUrlProvider.removeRequester(sendToServer);\n },\n room,\n host,\n broadcast: (payload) => sendToServer(\"broadcast\", payload),\n });\n });\n }\n\n return {\n userId,\n enterRoom: enter,\n exitRoom: exit,\n leaveUser,\n async reset(userId: string) {\n const userState = users.get(userId);\n userState?.reset();\n },\n broadcast<P extends any>(payload: P) {\n roomsEntered.forEach((room) => room.broadcast(payload));\n },\n end() {\n roomsEntered.forEach(({ exitRoom }) => exitRoom());\n roomsEntered.clear();\n users.forEach(({ peer }) => leaveUser(peer.userId));\n users.clear();\n },\n };\n}\n\n/*\nTurn Token ID\n<CF_TURN_TOKEN_ID>\n\nAPI Token\n<CF_RTC_API_TOKEN>\n\nCURL\ncurl \\\n\t-H \"Authorization: Bearer <CF_RTC_API_TOKEN>\" \\\n\t-H \"Content-Type: application/json\" -d '{\"ttl\": 86400}' \\\n\thttps://rtc.live.cloudflare.com/v1/turn/keys/<CF_TURN_TOKEN_ID>/credentials/generate-ice-servers\n\nJSON\n{\n\t\"iceServers\": [\n {\n \"urls\": [\n \"stun:stun.cloudflare.com:3478\",\n \"turn:turn.cloudflare.com:3478?transport=udp\",\n \"turn:turn.cloudflare.com:3478?transport=tcp\",\n \"turns:turn.cloudflare.com:5349?transport=tcp\"\n ],\n \"username\": \"xxxx\",\n \"credential\": \"yyyy\",\n }\n ]\n}\n\n*/\n"
|
|
9
|
+
"import { IceUrlProvider } from \"./utils/ice-url-provider\";\nimport { IPeer } from \"./signal/impl/signal-room\";\nimport { EnterRoom, enterRoom } from \"./signal/signal-room\";\nimport { RTCConfigProvider } from \"./utils/rtc-config\";\n\nexport type SigType = \"offer\" | \"answer\" | \"ice\" | \"request-ice\" | \"broadcast\";\nexport type SigPayload = {\n connectionId?: string;\n offer?: RTCSessionDescriptionInit;\n answer?: RTCSessionDescriptionInit;\n ice?: RTCIceCandidateInit;\n} & Record<string, any>;\n\ninterface Connection {\n id: string;\n peerConnectionId?: string;\n pc: RTCPeerConnection;\n // ICE that arrived before we had remoteDescription\n pendingRemoteIce: RTCIceCandidateInit[];\n}\n\ntype UserState = {\n connection?: Connection;\n\n // the signaling \"user\" handle so we can send messages\n peer: IPeer<SigType, SigPayload>;\n\n expirationTimeout?: number;\n close(): void;\n reset(): void;\n connectionPromise?: Promise<Connection>;\n};\n\nconst DEFAULT_ENTER_ROOM = enterRoom;\n\n/**\n * Collect peers\n */\nexport function collectPeerConnections({\n userId: passedUserId,\n worldId,\n receivePeerConnection,\n peerlessUserExpiration = 5000,\n enterRoomFunction: enterRoom = DEFAULT_ENTER_ROOM,\n logLine,\n onLeaveUser,\n workerUrl,\n onRoomReady,\n onRoomClose,\n onBroadcastMessage,\n}: {\n userId?: string;\n worldId: string;\n enterRoomFunction?: EnterRoom<SigType, SigPayload>;\n onLeaveUser?: (userId: string) => void;\n logLine?: (direction: string, obj?: any) => void;\n workerUrl?: URL;\n peerlessUserExpiration?: number;\n receivePeerConnection(connection: {\n pc: RTCPeerConnection;\n userId: string;\n restart?: () => void;\n }): void;\n onRoomReady?(info: { host: string; room: string }): void;\n onRoomClose?(info: {\n host: string;\n room: string;\n ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">;\n }): void;\n onBroadcastMessage?<P extends any>(payload: P, from: string): void;\n}) {\n const userId = passedUserId ?? `user-${crypto.randomUUID()}`;\n const users: Map<string, UserState> = new Map();\n\n const roomsEntered = new Map<\n string,\n {\n room: string;\n host: string;\n exitRoom: () => void;\n broadcast: <P extends any>(payload: P) => void;\n }\n >();\n\n function leaveUser(userId: string) {\n onLeaveUser?.(userId);\n const p = users.get(userId);\n if (!p) return;\n users.delete(userId);\n try {\n p.close();\n } catch {}\n }\n\n async function flushRemoteIce(state: UserState) {\n if (!state.connection?.pc?.remoteDescription) return;\n\n const queued = state.connection.pendingRemoteIce;\n state.connection.pendingRemoteIce = [];\n\n for (const ice of queued) {\n try {\n await state.connection.pc.addIceCandidate(ice);\n } catch (e) {\n logLine?.(\"⚠️ ERROR\", {\n error: \"add-ice-failed\",\n userId: state.peer.userId,\n detail: String(e),\n });\n }\n }\n }\n\n const iceUrlProvider = new IceUrlProvider();\n const rtcConfigProvider = new RTCConfigProvider(iceUrlProvider);\n\n function exit({ room, host }: { room: string; host: string }) {\n const key = `${host}/room/${room}`;\n const session = roomsEntered.get(key);\n if (session) {\n session.exitRoom();\n roomsEntered.delete(key);\n }\n }\n\n function enter({ room, host }: { room: string; host: string }) {\n return new Promise<void>(async (resolve, reject) => {\n async function setupConnection(state: UserState) {\n if (state.connectionPromise) {\n return state.connectionPromise;\n }\n const promise = new Promise<Connection>(async (resolve) => {\n state.connection = {\n id: `conn-${crypto.randomUUID()}`,\n pc: new RTCPeerConnection(await rtcConfigProvider.getRtcConfig()),\n pendingRemoteIce: [],\n };\n\n // Send local ICE candidates to this peer\n state.connection.pc.onicecandidate = (ev) => {\n if (!ev.candidate) return;\n state.peer.receive(\"ice\", {\n connectionId: state.connection?.id,\n ice: ev.candidate.toJSON(),\n });\n };\n\n state.connection.pc.onconnectionstatechange = async () => {\n logLine?.(\"💬\", {\n event: \"pc-state\",\n userId: state.peer.userId,\n state: state.connection?.pc?.connectionState,\n });\n if (state.connection?.pc?.connectionState === \"failed\") {\n // reset the connection\n state.close();\n const userState = await getPeer(state.peer, true);\n if (userState.connection?.pc) {\n receivePeerConnection({\n pc: userState.connection?.pc,\n userId: userState.peer.userId,\n restart: () => userState.close(),\n });\n } else {\n logLine?.(\"👤ℹ️\", \"no pc: \" + userState.peer.userId);\n }\n return;\n }\n };\n\n resolve(state.connection);\n });\n state.connectionPromise = promise;\n await promise;\n state.connectionPromise = undefined;\n return promise;\n }\n\n async function getPeer(\n peer: IPeer<SigType, SigPayload>,\n forceReset?: boolean,\n ): Promise<UserState> {\n let state = users.get(peer.userId);\n if (!state || forceReset) {\n const newState: UserState = {\n peer,\n close() {\n if (this.connection) {\n this.connection.pc.close();\n this.connection = undefined;\n }\n users.delete(peer.userId);\n },\n async reset() {\n newState.close();\n\n setTimeout(async () => {\n const userState = await getPeer(peer, true);\n if (!userState.connection?.pc) {\n logLine?.(\"⚠️\", \"no pc\");\n return;\n }\n receivePeerConnection({\n pc: userState.connection?.pc,\n userId: userState.peer.userId,\n restart: () => userState.close(),\n });\n await makeOffer(userState.peer);\n }, 500);\n },\n };\n state = newState;\n\n await setupConnection(newState);\n\n // New user\n users.set(state.peer.userId, state);\n } else if (state) {\n clearTimeout(state.expirationTimeout);\n state.expirationTimeout = 0;\n if (\n !state.connection?.pc ||\n state.connection?.pc.signalingState === \"closed\"\n ) {\n await setupConnection(state);\n }\n }\n state.peer = peer;\n return state;\n }\n\n async function makeOffer(user: IPeer<SigType, SigPayload>) {\n // Offer flow: createOffer -> setLocalDescription -> send localDescription\n const state = await getPeer(user);\n const pc = state.connection?.pc;\n const offer = await pc?.createOffer();\n await pc?.setLocalDescription(offer);\n user.receive(\"offer\", {\n connectionId: state.connection?.id,\n offer: pc!.localDescription!.toJSON(),\n });\n }\n\n const { exitRoom, sendToServer } = enterRoom({\n userId,\n worldId,\n room,\n host,\n logLine,\n workerUrl,\n autoRejoin: true,\n\n onOpen() {\n onRoomReady?.({ room, host });\n resolve();\n },\n onError() {\n console.error(\"onError\");\n reject();\n },\n onClose(ev: Pick<CloseEvent, \"reason\" | \"code\" | \"wasClean\">) {\n onRoomClose?.({ room, host, ev });\n },\n\n // Existing peers initiate to the newcomer\n onPeerJoined(joiningUsers: IPeer<SigType, SigPayload>[]) {\n joiningUsers.forEach(async (user) => {\n const state = await getPeer(user, true);\n const pc = state.connection?.pc;\n if (!pc) {\n logLine?.(\"👤ℹ️\", \"no pc: \" + user.userId);\n return;\n }\n\n receivePeerConnection({\n pc,\n userId: user.userId,\n restart: () => state.close(),\n });\n await makeOffer(user);\n });\n },\n\n onPeerLeft(leavingUsers: { userId: string }[]) {\n leavingUsers.forEach(({ userId }) => {\n const state = users.get(userId);\n if (!state) return;\n state.expirationTimeout = setTimeout(\n () => leaveUser(userId),\n peerlessUserExpiration ?? 0,\n );\n });\n },\n\n onIceUrl(url: string, expiration: number) {\n iceUrlProvider.receiveIce(url, expiration);\n },\n\n async onMessage(type, payload, from: IPeer<SigType, SigPayload>) {\n if (type === \"offer\" && payload.offer) {\n // Grab state and connection\n const state = await getPeer(from, false);\n const connection =\n !state.connection ||\n state.connection.pc.signalingState === \"stable\"\n ? await setupConnection(state)\n : state.connection; // reset\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n connection.peerConnectionId = payload.connectionId;\n receivePeerConnection({\n pc: connection.pc,\n userId: from.userId,\n restart: () => state.close(),\n });\n // Responder: set remote offer\n await connection.pc.setRemoteDescription(payload.offer);\n\n // Create and send answer\n const answer = await connection.pc.createAnswer();\n await connection.pc.setLocalDescription(answer);\n\n from.receive(\"answer\", {\n connectionId: connection.id,\n answer: connection.pc.localDescription?.toJSON(),\n });\n\n // Now safe to apply any queued ICE from this peer\n await flushRemoteIce(state);\n return;\n }\n\n if (type === \"answer\" && payload.answer) {\n const state = await getPeer(from, false);\n const connection =\n state.connection &&\n state.connection.pc.signalingState !== \"closed\"\n ? state.connection\n : await setupConnection(state);\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n // Initiator: set remote answer\n await connection.pc.setRemoteDescription(payload.answer);\n connection.peerConnectionId = payload.connectionId;\n await flushRemoteIce(state);\n return;\n }\n\n if (type === \"ice\" && payload.ice) {\n // Grab state and connection\n const state = await getPeer(from, false);\n const connection =\n state.connection ?? (await state.connectionPromise);\n if (!connection) {\n logLine?.(\"⚠️\", \"No connection\");\n return;\n }\n logLine?.(\"💬\", {\n type,\n signalingState: connection.pc.signalingState,\n });\n\n if (\n connection.peerConnectionId &&\n payload.connectionId !== connection.peerConnectionId\n ) {\n logLine?.(\n \"⚠️\",\n \"Mismatch peerConnectionID\" +\n payload.connectionId +\n \"vs\" +\n connection.peerConnectionId,\n );\n return;\n }\n\n // If we don't have remoteDescription yet (or if connectionId doesn't match), queue it\n if (\n !connection.pc.remoteDescription ||\n !connection.peerConnectionId\n ) {\n connection.peerConnectionId = payload.connectionId;\n connection.pendingRemoteIce.push(payload.ice);\n return;\n }\n\n try {\n await connection.pc.addIceCandidate(payload.ice);\n } catch (e) {\n logLine?.(\"⚠️ ERROR\", {\n error: \"add-ice-failed\",\n userId: state.peer.userId,\n detail: String(e),\n });\n }\n return;\n }\n\n if (type === \"broadcast\") {\n onBroadcastMessage?.(payload, from.userId);\n }\n },\n });\n\n iceUrlProvider.addRequester(sendToServer);\n\n roomsEntered.set(`${host}/room/${room}`, {\n exitRoom: () => {\n exitRoom();\n iceUrlProvider.removeRequester(sendToServer);\n },\n room,\n host,\n broadcast: (payload) => sendToServer(\"broadcast\", payload),\n });\n });\n }\n\n return {\n userId,\n enterRoom: enter,\n exitRoom: exit,\n leaveUser,\n async reset(userId: string) {\n const userState = users.get(userId);\n userState?.reset();\n },\n broadcast<P extends any>(payload: P) {\n roomsEntered.forEach((room) => room.broadcast(payload));\n },\n end() {\n roomsEntered.forEach(({ exitRoom }) => exitRoom());\n roomsEntered.clear();\n users.forEach(({ peer }) => leaveUser(peer.userId));\n users.clear();\n },\n };\n}\n\n/*\nTurn Token ID\n<CF_TURN_TOKEN_ID>\n\nAPI Token\n<CF_RTC_API_TOKEN>\n\nCURL\ncurl \\\n\t-H \"Authorization: Bearer <CF_RTC_API_TOKEN>\" \\\n\t-H \"Content-Type: application/json\" -d '{\"ttl\": 86400}' \\\n\thttps://rtc.live.cloudflare.com/v1/turn/keys/<CF_TURN_TOKEN_ID>/credentials/generate-ice-servers\n\nJSON\n{\n\t\"iceServers\": [\n {\n \"urls\": [\n \"stun:stun.cloudflare.com:3478\",\n \"turn:turn.cloudflare.com:3478?transport=udp\",\n \"turn:turn.cloudflare.com:3478?transport=tcp\",\n \"turns:turn.cloudflare.com:5349?transport=tcp\"\n ],\n \"username\": \"xxxx\",\n \"credential\": \"yyyy\",\n }\n ]\n}\n\n*/\n"
|
|
10
10
|
],
|
|
11
|
-
"mappings": "AAAO,MAAM,CAAe,CAClB,sBAAwB,GACxB,kBAIA,WAER,UAAU,CAAC,EAAa,EAAoB,CAC1C,KAAK,oBAAoB,CAAE,MAAK,YAAW,CAAC,EAC5C,KAAK,kBAAoB,OACzB,KAAK,WAAa,OAGpB,YAAY,CAAC,EAA6C,CAExD,OADA,KAAK,sBAAsB,KAAK,CAAS,EAClC,IAAM,CACX,KAAK,gBAAgB,CAAS,GAIlC,eAAe,CAAC,EAA6C,CAC3D,KAAK,sBAAsB,OACzB,KAAK,sBAAsB,QAAQ,CAAS,EAC5C,CACF,EAGF,YAAY,CAAC,EAAwB,CACnC,KAAK,sBACH,KAAK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