@telperion/messenger 8.0.0 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -649,7 +649,7 @@ constructor(connection?: RTCConnectionArg, channelName?: string)
649
649
  - `Promise<RTCPeerConnection>`: Async connection
650
650
  - `() => RTCPeerConnection | Promise<RTCPeerConnection>`: Factory function
651
651
  - Omit to initialize later via `initialize()`
652
- - **`channelName`** (optional): Name for the negotiated data channel. Default: `'MessengerRTCChannelDefault'`. A deterministic 16-bit channel ID is derived from this name via FNV-1a hash.
652
+ - **`channelName`** (optional): Name for the negotiated data channel. Default: `'MessengerRTCChannelDefault'`. A deterministic channel ID in [0, 1023] is derived from this name via FNV-1a hash.
653
653
 
654
654
  **Examples:**
655
655
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telperion/messenger",
3
- "version": "8.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "Javascript messaging library",
5
5
  "keywords": [
6
6
  "javascript",
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.channelId = channelId;
4
4
  /**
5
- * Generates a deterministic 16-bit unsigned integer (0–65534) from a channel name string.
5
+ * Generates a deterministic integer in [0, 1023] from a channel name string.
6
6
  * Used as the negotiated data channel ID for RTCDataChannel.
7
7
  *
8
- * Uses FNV-1a hash algorithm truncated to 16 bits.
8
+ * Uses FNV-1a hash algorithm truncated to 10 bits.
9
9
  *
10
10
  * @param name - The channel name to hash
11
- * @returns A deterministic channel ID in [0, 65534]
11
+ * @returns A deterministic channel ID in [0, 1023]
12
12
  */
13
13
  function channelId(name) {
14
14
  let hash = 0x811c9dc5; // FNV offset basis (32-bit)
@@ -16,6 +16,6 @@ function channelId(name) {
16
16
  hash ^= name.charCodeAt(i);
17
17
  hash = (hash * 0x01000193) >>> 0; // FNV prime, keep as unsigned 32-bit
18
18
  }
19
- // Truncate to 16-bit range [0, 65534] (65535 is reserved)
20
- return hash % 65535;
19
+ // Truncate to 10-bit range [0, 1023]
20
+ return hash % 1024;
21
21
  }
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Generates a deterministic 16-bit unsigned integer (0–65534) from a channel name string.
2
+ * Generates a deterministic integer in [0, 1023] from a channel name string.
3
3
  * Used as the negotiated data channel ID for RTCDataChannel.
4
4
  *
5
- * Uses FNV-1a hash algorithm truncated to 16 bits.
5
+ * Uses FNV-1a hash algorithm truncated to 10 bits.
6
6
  *
7
7
  * @param name - The channel name to hash
8
- * @returns A deterministic channel ID in [0, 65534]
8
+ * @returns A deterministic channel ID in [0, 1023]
9
9
  */
10
10
  export declare function channelId(name: string): number;
package/rtc/channel-id.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Generates a deterministic 16-bit unsigned integer (0–65534) from a channel name string.
2
+ * Generates a deterministic integer in [0, 1023] from a channel name string.
3
3
  * Used as the negotiated data channel ID for RTCDataChannel.
4
4
  *
5
- * Uses FNV-1a hash algorithm truncated to 16 bits.
5
+ * Uses FNV-1a hash algorithm truncated to 10 bits.
6
6
  *
7
7
  * @param name - The channel name to hash
8
- * @returns A deterministic channel ID in [0, 65534]
8
+ * @returns A deterministic channel ID in [0, 1023]
9
9
  */
10
10
  export function channelId(name) {
11
11
  let hash = 0x811c9dc5; // FNV offset basis (32-bit)
@@ -13,8 +13,8 @@ export function channelId(name) {
13
13
  hash ^= name.charCodeAt(i);
14
14
  hash = (hash * 0x01000193) >>> 0; // FNV prime, keep as unsigned 32-bit
15
15
  }
16
- // Truncate to 16-bit range [0, 65534] (65535 is reserved)
17
- return hash % 65535;
16
+ // Truncate to 10-bit range [0, 1023]
17
+ return hash % 1024;
18
18
  }
19
19
 
20
20
  //# sourceMappingURL=channel-id.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/messenger/src/rtc/channel-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,IAAI,IAAI,GAAG,UAAU,CAAC,CAAC,4BAA4B;IAEnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,GAAG,CAAC,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,qCAAqC;IACzE,CAAC;IAED,0DAA0D;IAC1D,OAAO,IAAI,GAAG,KAAK,CAAC;AACtB,CAAC","file":"channel-id.js","sourcesContent":["/**\r\n * Generates a deterministic 16-bit unsigned integer (0–65534) from a channel name string.\r\n * Used as the negotiated data channel ID for RTCDataChannel.\r\n *\r\n * Uses FNV-1a hash algorithm truncated to 16 bits.\r\n *\r\n * @param name - The channel name to hash\r\n * @returns A deterministic channel ID in [0, 65534]\r\n */\r\nexport function channelId(name: string): number {\r\n let hash = 0x811c9dc5; // FNV offset basis (32-bit)\r\n\r\n for (let i = 0; i < name.length; i++) {\r\n hash ^= name.charCodeAt(i);\r\n hash = (hash * 0x01000193) >>> 0; // FNV prime, keep as unsigned 32-bit\r\n }\r\n\r\n // Truncate to 16-bit range [0, 65534] (65535 is reserved)\r\n return hash % 65535;\r\n}\r\n"]}
1
+ {"version":3,"sources":["../../../../../libs/messenger/src/rtc/channel-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,IAAI,IAAI,GAAG,UAAU,CAAC,CAAC,4BAA4B;IAEnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,GAAG,CAAC,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,qCAAqC;IACzE,CAAC;IAED,qCAAqC;IACrC,OAAO,IAAI,GAAG,IAAI,CAAC;AACrB,CAAC","file":"channel-id.js","sourcesContent":["/**\r\n * Generates a deterministic integer in [0, 1023] from a channel name string.\r\n * Used as the negotiated data channel ID for RTCDataChannel.\r\n *\r\n * Uses FNV-1a hash algorithm truncated to 10 bits.\r\n *\r\n * @param name - The channel name to hash\r\n * @returns A deterministic channel ID in [0, 1023]\r\n */\r\nexport function channelId(name: string): number {\r\n let hash = 0x811c9dc5; // FNV offset basis (32-bit)\r\n\r\n for (let i = 0; i < name.length; i++) {\r\n hash ^= name.charCodeAt(i);\r\n hash = (hash * 0x01000193) >>> 0; // FNV prime, keep as unsigned 32-bit\r\n }\r\n\r\n // Truncate to 10-bit range [0, 1023]\r\n return hash % 1024;\r\n}\r\n"]}
@@ -32,7 +32,7 @@ class RTCMessageService extends (0, mixin_1.mixin)(message_host_1.RTCMessageHost
32
32
  * @param channelName - Name for the negotiated data channel.
33
33
  */
34
34
  constructor(connection, channelName = default_channel_name_1.DEFAULT_CHANNEL_NAME) {
35
- super([connection, channelName], [connection, channelName]);
35
+ super([connection, `${channelName}H`], [connection, `${channelName}C`]);
36
36
  }
37
37
  initialize = (connection, channelName) => {
38
38
  message_host_1.RTCMessageHost.prototype.initialize.call(this, connection, channelName);
@@ -29,7 +29,7 @@ export class RTCMessageService extends mixin(RTCMessageHost, RTCMessageClient) {
29
29
  * @param channelName - Name for the negotiated data channel.
30
30
  */
31
31
  constructor(connection, channelName = DEFAULT_CHANNEL_NAME) {
32
- super([connection, channelName], [connection, channelName]);
32
+ super([connection, `${channelName}H`], [connection, `${channelName}C`]);
33
33
  }
34
34
  initialize = (connection, channelName) => {
35
35
  RTCMessageHost.prototype.initialize.call(this, connection, channelName);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/messenger/src/rtc/message-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK,CAAC,cAAc,EAAE,gBAAgB,CAAC;IAC5E;;;OAGG;IACH,YAAY,UAA6B,EAAE,WAAW,GAAG,oBAAoB;QAC3E,KAAK,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IAC9D,CAAC;IAEe,UAAU,GAAG,CAAC,UAA4B,EAAE,WAAoB,EAAQ,EAAE;QACxF,cAAc,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QACxE,gBAAgB,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;IAC5E,CAAC,CAAC;CACH","file":"message-service.js","sourcesContent":["import { mixin } from \"@telperion/js-utils/class/mixin\";\r\nimport { RTCMessageClient } from \"./message-client\";\r\nimport { RTCMessageHost } from \"./message-host\";\r\nimport { RTCConnectionArg } from \"./rtc.type\";\r\nimport { DEFAULT_CHANNEL_NAME } from \"./default-channel-name\";\r\n\r\n/**\r\n * Bidirectional message service for WebRTC DataChannel communication.\r\n *\r\n * Combines {@link RTCMessageHost} and {@link RTCMessageClient} via mixin,\r\n * enabling both `@Listen` and `@Request` decorators on the same class.\r\n *\r\n * @example\r\n * ```typescript\r\n * class GamePeer extends RTCMessageService {\r\n * @Request('move')\r\n * sendMove(pos: [number, number]): Observable<boolean> { return null!; }\r\n *\r\n * @Listen('move')\r\n * handleMove({ data }: { data: [number, number] }): Observable<boolean> {\r\n * return of(applyMove(data));\r\n * }\r\n * }\r\n *\r\n * const peer = new GamePeer(peerConnection, 'game-events');\r\n * ```\r\n */\r\nexport class RTCMessageService extends mixin(RTCMessageHost, RTCMessageClient) {\r\n /**\r\n * @param connection - RTCPeerConnection instance, promise, or factory function.\r\n * @param channelName - Name for the negotiated data channel.\r\n */\r\n constructor(connection?: RTCConnectionArg, channelName = DEFAULT_CHANNEL_NAME) {\r\n super([connection, channelName], [connection, channelName]);\r\n }\r\n\r\n public override initialize = (connection: RTCConnectionArg, channelName?: string): void => {\r\n RTCMessageHost.prototype.initialize.call(this, connection, channelName);\r\n RTCMessageClient.prototype.initialize.call(this, connection, channelName);\r\n };\r\n}\r\n"]}
1
+ {"version":3,"sources":["../../../../../libs/messenger/src/rtc/message-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK,CAAC,cAAc,EAAE,gBAAgB,CAAC;IAC5E;;;OAGG;IACH,YAAY,UAA6B,EAAE,WAAW,GAAG,oBAAoB;QAC3E,KAAK,CAAC,CAAC,UAAU,EAAE,GAAG,WAAW,GAAG,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC;IAC1E,CAAC;IAEe,UAAU,GAAG,CAAC,UAA4B,EAAE,WAAoB,EAAQ,EAAE;QACxF,cAAc,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QACxE,gBAAgB,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;IAC5E,CAAC,CAAC;CACH","file":"message-service.js","sourcesContent":["import { mixin } from \"@telperion/js-utils/class/mixin\";\r\nimport { RTCMessageClient } from \"./message-client\";\r\nimport { RTCMessageHost } from \"./message-host\";\r\nimport { RTCConnectionArg } from \"./rtc.type\";\r\nimport { DEFAULT_CHANNEL_NAME } from \"./default-channel-name\";\r\n\r\n/**\r\n * Bidirectional message service for WebRTC DataChannel communication.\r\n *\r\n * Combines {@link RTCMessageHost} and {@link RTCMessageClient} via mixin,\r\n * enabling both `@Listen` and `@Request` decorators on the same class.\r\n *\r\n * @example\r\n * ```typescript\r\n * class GamePeer extends RTCMessageService {\r\n * @Request('move')\r\n * sendMove(pos: [number, number]): Observable<boolean> { return null!; }\r\n *\r\n * @Listen('move')\r\n * handleMove({ data }: { data: [number, number] }): Observable<boolean> {\r\n * return of(applyMove(data));\r\n * }\r\n * }\r\n *\r\n * const peer = new GamePeer(peerConnection, 'game-events');\r\n * ```\r\n */\r\nexport class RTCMessageService extends mixin(RTCMessageHost, RTCMessageClient) {\r\n /**\r\n * @param connection - RTCPeerConnection instance, promise, or factory function.\r\n * @param channelName - Name for the negotiated data channel.\r\n */\r\n constructor(connection?: RTCConnectionArg, channelName = DEFAULT_CHANNEL_NAME) {\r\n super([connection, `${channelName}H`], [connection, `${channelName}C`]);\r\n }\r\n\r\n public override initialize = (connection: RTCConnectionArg, channelName?: string): void => {\r\n RTCMessageHost.prototype.initialize.call(this, connection, channelName);\r\n RTCMessageClient.prototype.initialize.call(this, connection, channelName);\r\n };\r\n}\r\n"]}