rtc.io-server 1.1.0 → 1.2.0

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
@@ -21,12 +21,9 @@ server.on("connection", (socket) => {
21
21
  socket.to(roomId).emit("#rtcio:init-offer", { source: socket.id });
22
22
  });
23
23
 
24
- socket.on("disconnecting", () => {
25
- socket.rooms.forEach((roomId) => {
26
- if (roomId === socket.id) return;
27
- socket.to(roomId).emit("user-disconnected", { id: socket.id });
28
- });
29
- });
24
+ // No `disconnecting` handler needed for peer cleanup — the rtc.io-server
25
+ // core emits `#rtcio:peer-left` automatically. Add one only if you have
26
+ // app-level cleanup (presence rosters, room password registries, etc.).
30
27
  });
31
28
 
32
29
  server.listen(3001);
@@ -34,7 +31,12 @@ server.listen(3001);
34
31
 
35
32
  ## What this server does
36
33
 
37
- The rtc.io client multiplexes all WebRTC signaling (offers, answers, ICE candidates, stream metadata) into a single `#rtcio:message` event. This server registers a default handler for that event and relays it to the addressed peer (`socket.to(target).emit(...)`). Everything else — room management, app-level events, presence — is **your** code.
34
+ The rtc.io client multiplexes all WebRTC signaling (offers, answers, ICE candidates, stream metadata) into a single `#rtcio:message` event. This server registers default handlers that:
35
+
36
+ 1. Relay `#rtcio:message` envelopes to the addressed peer (`socket.to(target).emit(...)`).
37
+ 2. Emit a `#rtcio:peer-left` notification to a leaving socket's rooms on `disconnecting`, so existing peers can short-circuit ICE consent-freshness (~30 s) when a tab closes. The client treats this as a hint that's cross-checked against the local WebRTC state; it never tears down a healthy P2P call on the basis of a signaling-only event. See the [signaling protocol](https://docs.rtcio.dev/docs/server/protocol#rtciopeer-left) for the full contract.
38
+
39
+ Everything else — room management, app-level events, presence — is **your** code.
38
40
 
39
41
  ### What you implement
40
42
 
@@ -7,6 +7,19 @@ const events_1 = require("./events");
7
7
  function rtcMessageHandler(socket, data) {
8
8
  socket.to(data.target).emit(events_1.RtcioEvents.MESSAGE, data);
9
9
  }
10
+ // Fast-path "this socket is leaving" notification. Without it, peers have to
11
+ // wait on ICE consent freshness (~30 s, RFC 7675) to declare a vanished peer
12
+ // dead. With it, peers can confirm against their own WebRTC layer and tear
13
+ // down the matching RTCPeerConnection in a couple of seconds.
14
+ function rtcDisconnectingHandler(socket) {
15
+ const ownId = socket.id;
16
+ socket.rooms.forEach((roomId) => {
17
+ if (roomId === ownId)
18
+ return;
19
+ socket.to(roomId).emit(events_1.RtcioEvents.PEER_LEFT, { id: ownId });
20
+ });
21
+ }
10
22
  function addDefaultListeners(socket) {
11
23
  socket.on(events_1.RtcioEvents.MESSAGE, (data) => rtcMessageHandler(socket, data));
24
+ socket.on("disconnecting", () => rtcDisconnectingHandler(socket));
12
25
  }
@@ -5,4 +5,5 @@ export declare const RtcioEvents: {
5
5
  readonly MESSAGE: "#rtcio:message";
6
6
  readonly STREAM_META: "#rtcio:stream-meta";
7
7
  readonly INIT_OFFER: "#rtcio:init-offer";
8
+ readonly PEER_LEFT: "#rtcio:peer-left";
8
9
  };
@@ -8,4 +8,8 @@ exports.RtcioEvents = {
8
8
  MESSAGE: "#rtcio:message",
9
9
  STREAM_META: "#rtcio:stream-meta",
10
10
  INIT_OFFER: "#rtcio:init-offer",
11
+ // Server → client. Fan out to a leaving socket's rooms so existing peers
12
+ // can tear down their RTCPeerConnection immediately instead of waiting
13
+ // on ICE consent-freshness (~30 s) to declare the peer dead.
14
+ PEER_LEFT: "#rtcio:peer-left",
11
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rtc.io-server",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Signaling server for the rtc.io WebRTC client. Built on socket.io.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",