freertc 0.1.31 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -216,7 +216,7 @@ Quick checks:
216
216
  Expected `/health` response includes JSON like:
217
217
 
218
218
  ```json
219
- {"ok":true,"version":"0.1.31","protocol_version":"1.0","peers":0}
219
+ {"ok":true,"version":"0.1.33","protocol_version":"1.0","peers":0}
220
220
  ```
221
221
 
222
222
  ## Auto WebRTC two-tab test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freertc",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
4
4
  "description": "Cloudflare Worker signaling relay for WebRTC peers with D1 storage.",
5
5
  "keywords": [
6
6
  "webrtc",
package/public/app.js CHANGED
@@ -117,9 +117,20 @@ function deriveNetworkFromSession(sessionIdValue) {
117
117
  if (!session || !isSpecToken(session)) {
118
118
  return "";
119
119
  }
120
+ if (session.startsWith("sess:")) {
121
+ return session.slice(5);
122
+ }
120
123
  return `room:${session}`;
121
124
  }
122
125
 
126
+ function deriveSessionFromNetwork(networkValue) {
127
+ const network = normalizeText(networkValue);
128
+ if (!network || !isSpecToken(network)) {
129
+ return "room:test";
130
+ }
131
+ return `sess:${network}`;
132
+ }
133
+
123
134
  createApp({
124
135
  setup() {
125
136
  const host = window.location.host;
@@ -152,6 +163,7 @@ createApp({
152
163
  const appliedFromPeer = ref(fromPeer.value);
153
164
  const toPeer = ref("");
154
165
  const sessionId = ref("");
166
+ let sessionIdExplicit = false;
155
167
  const instanceId = ref("");
156
168
 
157
169
  const activeView = ref("webrtc");
@@ -701,12 +713,12 @@ createApp({
701
713
  pushLog("network:error", "Ignoring invalid URL network");
702
714
  }
703
715
 
704
- sessionId.value = hasValidUrlSession ? sessionParam : `sess-${Math.random().toString(36).slice(2, 10)}`;
716
+ sessionIdExplicit = hasValidUrlSession;
705
717
  instanceId.value = hasValidUrlInstance ? instanceParam : `inst-${Math.random().toString(36).slice(2, 10)}`;
706
718
 
707
719
  // Cross-domain links should land in the same room even when each origin has
708
720
  // different sessionStorage UI state. URL network wins; otherwise derive from session_id.
709
- const derivedNetwork = deriveNetworkFromSession(sessionId.value);
721
+ const derivedNetwork = hasValidUrlSession ? deriveNetworkFromSession(sessionParam) : "";
710
722
  const nextNetwork = hasValidUrlNetwork ? networkParam : (derivedNetwork || normalizedNetworkValue());
711
723
  if (nextNetwork && nextNetwork !== network.value) {
712
724
  network.value = nextNetwork;
@@ -715,6 +727,8 @@ createApp({
715
727
  appliedNetwork.value = nextNetwork;
716
728
  }
717
729
 
730
+ sessionId.value = hasValidUrlSession ? sessionParam : deriveSessionFromNetwork(nextNetwork || normalizedNetworkValue());
731
+
718
732
  persistSharedIds();
719
733
  }
720
734
 
@@ -806,12 +820,18 @@ createApp({
806
820
  }
807
821
 
808
822
  function regenerateSharedIds() {
823
+ sessionIdExplicit = true;
809
824
  sessionId.value = `sess-${Math.random().toString(36).slice(2, 10)}`;
810
825
  instanceId.value = `inst-${Math.random().toString(36).slice(2, 10)}`;
811
826
  persistSharedIds();
812
827
  pushLog("ids", "Generated new shared session_id and instance_id");
813
828
  }
814
829
 
830
+ function applySessionIdChange() {
831
+ sessionIdExplicit = true;
832
+ persistSharedIds();
833
+ }
834
+
815
835
  function regeneratePeerId() {
816
836
  fromPeer.value = randomHex();
817
837
  appliedFromPeer.value = fromPeer.value;
@@ -835,6 +855,11 @@ createApp({
835
855
  }
836
856
  appliedNetwork.value = next;
837
857
 
858
+ if (!sessionIdExplicit) {
859
+ sessionId.value = deriveSessionFromNetwork(next);
860
+ persistSharedIds();
861
+ }
862
+
838
863
  reconnectLockedByBye = false;
839
864
  byeCooldowns.clear();
840
865
  failedPeerCooldowns.clear();
@@ -2683,7 +2708,7 @@ createApp({
2683
2708
  <div class="field-grid">
2684
2709
  <label>
2685
2710
  Session ID
2686
- <input v-model="sessionId" @change="persistSharedIds">
2711
+ <input v-model="sessionId" @change="applySessionIdChange">
2687
2712
  </label>
2688
2713
  <label>
2689
2714
  Instance ID
@@ -7,7 +7,7 @@ import { fileURLToPath } from 'node:url';
7
7
  import { WebSocketServer } from 'ws';
8
8
 
9
9
  const PSP_VERSION = '1.0';
10
- const WORKER_VERSION = '0.1.31';
10
+ const WORKER_VERSION = '0.1.33';
11
11
  const DEFAULT_TTL_MS = 30_000;
12
12
  const MAX_TTL_MS = 120_000;
13
13
  const MAX_MESSAGE_SIZE = 64 * 1024;
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const PSP_VERSION = "1.0";
2
- const WORKER_VERSION = "0.1.31";
2
+ const WORKER_VERSION = "0.1.33";
3
3
 
4
4
  const DISCOVERY_TYPES = new Set(["announce", "withdraw", "discover", "peer_list", "redirect"]);
5
5
  const NEGOTIATION_TYPES = new Set(["connect_request", "connect_accept", "connect_reject", "offer", "answer", "ice_candidate", "ice_end", "renegotiate"]);