@telperion/messenger 8.3.1 → 8.4.2
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/.build-manifest.json +416 -0
- package/README.md +35 -4
- package/broadcast/default-channel-name.cjs +6 -4
- package/broadcast/default-channel-name.cjs.map +1 -0
- package/broadcast/default-channel-name.d.cts +3 -0
- package/broadcast/default-channel-name.d.ts +3 -1
- package/broadcast/default-channel-name.js +2 -1
- package/broadcast/default-channel-name.js.map +1 -1
- package/broadcast/index.cjs +16 -13
- package/broadcast/index.cjs.map +1 -0
- package/broadcast/index.d.cts +11 -0
- package/broadcast/index.d.ts +11 -5
- package/broadcast/index.js +5 -6
- package/broadcast/index.js.map +1 -1
- package/broadcast/message-client.cjs +15 -13
- package/broadcast/message-client.cjs.map +1 -0
- package/broadcast/message-client.d.cts +15 -0
- package/broadcast/message-client.d.ts +9 -6
- package/broadcast/message-client.js +7 -5
- package/broadcast/message-client.js.map +1 -1
- package/broadcast/message-host.cjs +14 -12
- package/broadcast/message-host.cjs.map +1 -0
- package/broadcast/message-host.d.cts +14 -0
- package/broadcast/message-host.d.ts +9 -4
- package/broadcast/message-host.js +7 -5
- package/broadcast/message-host.js.map +1 -1
- package/broadcast/message-service.cjs +11 -9
- package/broadcast/message-service.cjs.map +1 -0
- package/broadcast/message-service.d.cts +15 -0
- package/broadcast/message-service.d.ts +10 -3
- package/broadcast/message-service.js +7 -5
- package/broadcast/message-service.js.map +1 -1
- package/chrome/default-connection-name.cjs +6 -4
- package/chrome/default-connection-name.cjs.map +1 -0
- package/chrome/default-connection-name.d.cts +3 -0
- package/chrome/default-connection-name.d.ts +3 -1
- package/chrome/default-connection-name.js +2 -1
- package/chrome/default-connection-name.js.map +1 -1
- package/chrome/index.cjs +14 -11
- package/chrome/index.cjs.map +1 -0
- package/chrome/index.d.cts +10 -0
- package/chrome/index.d.ts +10 -4
- package/chrome/index.js +4 -5
- package/chrome/index.js.map +1 -1
- package/chrome/message-client.cjs +18 -16
- package/chrome/message-client.cjs.map +1 -0
- package/chrome/message-client.d.cts +17 -0
- package/chrome/message-client.d.ts +8 -6
- package/chrome/message-client.js +6 -4
- package/chrome/message-client.js.map +1 -1
- package/chrome/message-host.cjs +15 -13
- package/chrome/message-host.cjs.map +1 -0
- package/chrome/message-host.d.cts +14 -0
- package/chrome/message-host.d.ts +9 -4
- package/chrome/message-host.js +6 -4
- package/chrome/message-host.js.map +1 -1
- package/fesm/messenger.mjs +114 -0
- package/fesm/messenger.mjs.map +1 -0
- package/iframe/channel-path-splitter.cjs +6 -4
- package/iframe/channel-path-splitter.cjs.map +1 -0
- package/iframe/channel-path-splitter.d.cts +3 -0
- package/iframe/channel-path-splitter.d.ts +3 -1
- package/iframe/channel-path-splitter.js +2 -1
- package/iframe/channel-path-splitter.js.map +1 -1
- package/iframe/default-channel-name.cjs +6 -4
- package/iframe/default-channel-name.cjs.map +1 -0
- package/iframe/default-channel-name.d.cts +3 -0
- package/iframe/default-channel-name.d.ts +3 -1
- package/iframe/default-channel-name.js +2 -1
- package/iframe/default-channel-name.js.map +1 -1
- package/iframe/iframe.type.cjs +3 -2
- package/iframe/iframe.type.cjs.map +1 -0
- package/iframe/iframe.type.d.cts +6 -0
- package/iframe/iframe.type.d.ts +6 -4
- package/iframe/iframe.type.js +0 -1
- package/iframe/iframe.type.js.map +1 -1
- package/iframe/index.cjs +16 -13
- package/iframe/index.cjs.map +1 -0
- package/iframe/index.d.cts +13 -0
- package/iframe/index.d.ts +13 -6
- package/iframe/index.js +5 -6
- package/iframe/index.js.map +1 -1
- package/iframe/message-client.cjs +26 -24
- package/iframe/message-client.cjs.map +1 -0
- package/iframe/message-client.d.cts +19 -0
- package/iframe/message-client.d.ts +9 -7
- package/iframe/message-client.js +7 -5
- package/iframe/message-client.js.map +1 -1
- package/iframe/message-host.cjs +30 -28
- package/iframe/message-host.cjs.map +1 -0
- package/iframe/message-host.d.cts +23 -0
- package/iframe/message-host.d.ts +10 -6
- package/iframe/message-host.js +8 -6
- package/iframe/message-host.js.map +1 -1
- package/iframe/message-service.cjs +13 -11
- package/iframe/message-service.cjs.map +1 -0
- package/iframe/message-service.d.cts +18 -0
- package/iframe/message-service.d.ts +11 -4
- package/iframe/message-service.js +7 -5
- package/iframe/message-service.js.map +1 -1
- package/iframe/source-id-splitter.cjs +6 -4
- package/iframe/source-id-splitter.cjs.map +1 -0
- package/iframe/source-id-splitter.d.cts +3 -0
- package/iframe/source-id-splitter.d.ts +3 -1
- package/iframe/source-id-splitter.js +2 -1
- package/iframe/source-id-splitter.js.map +1 -1
- package/iframe/upcoming-message.cjs +3 -2
- package/iframe/upcoming-message.cjs.map +1 -0
- package/iframe/upcoming-message.d.cts +6 -0
- package/iframe/upcoming-message.d.ts +3 -1
- package/iframe/upcoming-message.js +0 -1
- package/iframe/upcoming-message.js.map +1 -1
- package/index.cjs +22 -13
- package/index.cjs.map +1 -0
- package/index.d.cts +8 -0
- package/index.d.ts +8 -7
- package/index.js +5 -6
- package/index.js.map +1 -1
- package/listen.decorator.cjs +11 -8
- package/listen.decorator.cjs.map +1 -0
- package/listen.decorator.d.cts +8 -0
- package/listen.decorator.d.ts +3 -1
- package/listen.decorator.js +4 -2
- package/listen.decorator.js.map +1 -1
- package/listener-storage.type.cjs +3 -2
- package/listener-storage.type.cjs.map +1 -0
- package/listener-storage.type.d.cts +5 -0
- package/listener-storage.type.d.ts +4 -1
- package/listener-storage.type.js +0 -1
- package/listener-storage.type.js.map +1 -1
- package/message-client.cjs +4 -4
- package/message-client.cjs.map +1 -0
- package/message-client.d.cts +26 -0
- package/message-client.d.ts +8 -5
- package/message-client.js +2 -2
- package/message-client.js.map +1 -1
- package/message-host.cjs +20 -18
- package/message-host.cjs.map +1 -0
- package/message-host.d.cts +29 -0
- package/message-host.d.ts +8 -5
- package/message-host.js +5 -3
- package/message-host.js.map +1 -1
- package/message-response.type.cjs +3 -2
- package/message-response.type.cjs.map +1 -0
- package/message-response.type.d.cts +18 -0
- package/message-response.type.d.ts +8 -6
- package/message-response.type.js +0 -1
- package/message-response.type.js.map +1 -1
- package/message.interface.cjs +3 -2
- package/message.interface.cjs.map +1 -0
- package/message.interface.d.cts +8 -0
- package/message.interface.d.ts +3 -1
- package/message.interface.js +0 -1
- package/message.interface.js.map +1 -1
- package/package.json +387 -75
- package/request.decorator.cjs +16 -9
- package/request.decorator.cjs.map +1 -0
- package/request.decorator.d.cts +3 -0
- package/request.decorator.d.ts +3 -1
- package/request.decorator.js +10 -4
- package/request.decorator.js.map +1 -1
- package/rtc/channel-controller.cjs +13 -7
- package/rtc/channel-controller.cjs.map +1 -0
- package/rtc/channel-controller.d.cts +8 -0
- package/rtc/channel-controller.d.ts +4 -3
- package/rtc/channel-controller.js +9 -4
- package/rtc/channel-controller.js.map +1 -1
- package/rtc/default-channel-name.cjs +6 -4
- package/rtc/default-channel-name.cjs.map +1 -0
- package/rtc/default-channel-name.d.cts +4 -0
- package/rtc/default-channel-name.d.ts +3 -1
- package/rtc/default-channel-name.js +2 -1
- package/rtc/default-channel-name.js.map +1 -1
- package/rtc/index.cjs +16 -13
- package/rtc/index.cjs.map +1 -0
- package/rtc/index.d.cts +12 -0
- package/rtc/index.d.ts +12 -5
- package/rtc/index.js +5 -6
- package/rtc/index.js.map +1 -1
- package/rtc/initializer.cjs +52 -0
- package/rtc/initializer.cjs.map +1 -0
- package/rtc/initializer.d.cts +20 -0
- package/rtc/initializer.d.ts +20 -0
- package/rtc/initializer.js +50 -0
- package/rtc/initializer.js.map +1 -0
- package/rtc/message-client.cjs +97 -72
- package/rtc/message-client.cjs.map +1 -0
- package/rtc/message-client.d.cts +75 -0
- package/rtc/message-client.d.ts +42 -19
- package/rtc/message-client.js +82 -59
- package/rtc/message-client.js.map +1 -1
- package/rtc/message-host.cjs +77 -70
- package/rtc/message-host.cjs.map +1 -0
- package/rtc/message-host.d.cts +70 -0
- package/rtc/message-host.d.ts +37 -17
- package/rtc/message-host.js +64 -59
- package/rtc/message-host.js.map +1 -1
- package/rtc/message-service.cjs +28 -16
- package/rtc/message-service.cjs.map +1 -0
- package/rtc/message-service.d.cts +46 -0
- package/rtc/message-service.d.ts +18 -9
- package/rtc/message-service.js +25 -13
- package/rtc/message-service.js.map +1 -1
- package/rtc/rtc.type.cjs +3 -2
- package/rtc/rtc.type.cjs.map +1 -0
- package/rtc/rtc.type.d.cts +14 -0
- package/rtc/rtc.type.d.ts +6 -4
- package/rtc/rtc.type.js +0 -1
- package/rtc/rtc.type.js.map +1 -1
- package/selectors.cjs +18 -10
- package/selectors.cjs.map +1 -0
- package/selectors.d.cts +9 -0
- package/selectors.d.ts +9 -7
- package/selectors.js +8 -7
- package/selectors.js.map +1 -1
- package/worker/index.cjs +16 -13
- package/worker/index.cjs.map +1 -0
- package/worker/index.d.cts +12 -0
- package/worker/index.d.ts +12 -5
- package/worker/index.js +5 -6
- package/worker/index.js.map +1 -1
- package/worker/initializer.cjs +11 -8
- package/worker/initializer.cjs.map +1 -0
- package/worker/initializer.d.cts +15 -0
- package/worker/initializer.d.ts +8 -5
- package/worker/initializer.js +5 -3
- package/worker/initializer.js.map +1 -1
- package/worker/message-client.cjs +19 -17
- package/worker/message-client.cjs.map +1 -0
- package/worker/message-client.d.cts +133 -0
- package/worker/message-client.d.ts +10 -8
- package/worker/message-client.js +9 -7
- package/worker/message-client.js.map +1 -1
- package/worker/message-host.cjs +17 -15
- package/worker/message-host.cjs.map +1 -0
- package/worker/message-host.d.cts +135 -0
- package/worker/message-host.d.ts +10 -6
- package/worker/message-host.js +8 -6
- package/worker/message-host.js.map +1 -1
- package/worker/message-service.cjs +11 -9
- package/worker/message-service.cjs.map +1 -0
- package/worker/message-service.d.cts +124 -0
- package/worker/message-service.d.ts +11 -4
- package/worker/message-service.js +6 -4
- package/worker/message-service.js.map +1 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Subject } from 'rxjs';
|
|
2
|
+
import { MessageClient } from '../message-client.cjs';
|
|
3
|
+
import { MessageResponse } from '../message-response.type.cjs';
|
|
4
|
+
import { Message } from '../message.interface.cjs';
|
|
5
|
+
import { RESPONSES$, SEND, GET_NEW_ID } from '../selectors.cjs';
|
|
6
|
+
import { RTCConnectionArg } from './rtc.type.cjs';
|
|
7
|
+
|
|
8
|
+
declare const CHANNEL_NAME: unique symbol;
|
|
9
|
+
declare const CHANNEL: unique symbol;
|
|
10
|
+
declare const CHANNEL_OPEN: unique symbol;
|
|
11
|
+
declare const DEINITIALIZE: unique symbol;
|
|
12
|
+
declare const PENDING: unique symbol;
|
|
13
|
+
declare const FAIL_PENDING: unique symbol;
|
|
14
|
+
declare const READY: unique symbol;
|
|
15
|
+
declare const CREATED: unique symbol;
|
|
16
|
+
/**
|
|
17
|
+
* WebRTC DataChannel message client that sends request messages and receives
|
|
18
|
+
* responses over a negotiated channel.
|
|
19
|
+
*
|
|
20
|
+
* Both peers must create the channel with an identical name and negotiated ID.
|
|
21
|
+
* The ID is derived automatically from the channel name via an FNV-1a hash
|
|
22
|
+
* unless an explicit `channelId` is supplied.
|
|
23
|
+
*
|
|
24
|
+
* Use `@Request` decorators to define outgoing RPC methods. The client can be
|
|
25
|
+
* constructed without a connection and initialized later via {@link initialize}.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* class GameClient extends RTCMessageClient {
|
|
30
|
+
* @Request('move')
|
|
31
|
+
* sendMove(position: [number, number]): Observable<boolean> {
|
|
32
|
+
* return null!;
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* const client = new GameClient(peerConnection, 'game-events');
|
|
37
|
+
* client.sendMove([3, 4]).subscribe(ok => console.log('Accepted:', ok));
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare class RTCMessageClient extends MessageClient {
|
|
41
|
+
[RESPONSES$]: Subject<MessageResponse>;
|
|
42
|
+
private [CHANNEL_NAME];
|
|
43
|
+
private [CHANNEL];
|
|
44
|
+
private [CHANNEL_OPEN];
|
|
45
|
+
private [DEINITIALIZE];
|
|
46
|
+
/** IDs of requests sent (or waiting to send) that have not completed yet. */
|
|
47
|
+
private [PENDING];
|
|
48
|
+
private get [CREATED]();
|
|
49
|
+
/** Resolves with the `RTCDataChannel` once it has been created (may not yet be open). */
|
|
50
|
+
get created(): Promise<RTCDataChannel>;
|
|
51
|
+
private get [READY]();
|
|
52
|
+
/** Resolves with the `RTCDataChannel` once it is open and ready to transmit. */
|
|
53
|
+
get ready(): Promise<RTCDataChannel>;
|
|
54
|
+
/**
|
|
55
|
+
* @param connection - RTCPeerConnection instance, promise, or factory function. Omit to initialize later via {@link initialize}.
|
|
56
|
+
* @param channelName - Name for the negotiated data channel. Determines the channel ID via FNV-1a hash.
|
|
57
|
+
* @param channelId - Explicit negotiated channel ID. Overrides the hash-derived default.
|
|
58
|
+
*/
|
|
59
|
+
constructor(connection?: RTCConnectionArg, channelName?: string, channelId?: number);
|
|
60
|
+
/**
|
|
61
|
+
* (Re)initializes the data channel with a new connection.
|
|
62
|
+
* Waits for the previous channel to be cleaned up (with a 5 s timeout)
|
|
63
|
+
* before establishing the new one.
|
|
64
|
+
*
|
|
65
|
+
* @param connection - RTCPeerConnection instance, promise, or factory function.
|
|
66
|
+
* @param channelId - Optional negotiated channel ID. Defaults to the hash-derived ID.
|
|
67
|
+
*/
|
|
68
|
+
initialize(connection?: RTCConnectionArg, channelId?: number): void;
|
|
69
|
+
[SEND]<T>(message: Message<T>): Promise<void>;
|
|
70
|
+
/** Errors every in-flight request, since no response can arrive on a closed channel. */
|
|
71
|
+
private [FAIL_PENDING];
|
|
72
|
+
protected [GET_NEW_ID](): string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { CREATED, READY, RTCMessageClient };
|
package/rtc/message-client.d.ts
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
import { Subject } from 'rxjs';
|
|
2
|
-
import { MessageClient } from '../message-client';
|
|
3
|
-
import { MessageResponse } from '../message-response.type';
|
|
4
|
-
import { Message } from '../message.interface';
|
|
5
|
-
import {
|
|
6
|
-
import { RTCConnectionArg } from './rtc.type';
|
|
7
|
-
|
|
2
|
+
import { MessageClient } from '../message-client.js';
|
|
3
|
+
import { MessageResponse } from '../message-response.type.js';
|
|
4
|
+
import { Message } from '../message.interface.js';
|
|
5
|
+
import { RESPONSES$, SEND, GET_NEW_ID } from '../selectors.js';
|
|
6
|
+
import { RTCConnectionArg } from './rtc.type.js';
|
|
7
|
+
|
|
8
8
|
declare const CHANNEL_NAME: unique symbol;
|
|
9
|
-
|
|
9
|
+
declare const CHANNEL: unique symbol;
|
|
10
|
+
declare const CHANNEL_OPEN: unique symbol;
|
|
11
|
+
declare const DEINITIALIZE: unique symbol;
|
|
12
|
+
declare const PENDING: unique symbol;
|
|
13
|
+
declare const FAIL_PENDING: unique symbol;
|
|
14
|
+
declare const READY: unique symbol;
|
|
15
|
+
declare const CREATED: unique symbol;
|
|
10
16
|
/**
|
|
11
|
-
*
|
|
17
|
+
* WebRTC DataChannel message client that sends request messages and receives
|
|
18
|
+
* responses over a negotiated channel.
|
|
12
19
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
20
|
+
* Both peers must create the channel with an identical name and negotiated ID.
|
|
21
|
+
* The ID is derived automatically from the channel name via an FNV-1a hash
|
|
22
|
+
* unless an explicit `channelId` is supplied.
|
|
23
|
+
*
|
|
24
|
+
* Use `@Request` decorators to define outgoing RPC methods. The client can be
|
|
25
|
+
* constructed without a connection and initialized later via {@link initialize}.
|
|
16
26
|
*
|
|
17
27
|
* @example
|
|
18
28
|
* ```typescript
|
|
@@ -27,26 +37,39 @@ export declare const READY: unique symbol;
|
|
|
27
37
|
* client.sendMove([3, 4]).subscribe(ok => console.log('Accepted:', ok));
|
|
28
38
|
* ```
|
|
29
39
|
*/
|
|
30
|
-
|
|
40
|
+
declare class RTCMessageClient extends MessageClient {
|
|
31
41
|
[RESPONSES$]: Subject<MessageResponse>;
|
|
32
|
-
private [CONNECTION];
|
|
33
42
|
private [CHANNEL_NAME];
|
|
43
|
+
private [CHANNEL];
|
|
44
|
+
private [CHANNEL_OPEN];
|
|
45
|
+
private [DEINITIALIZE];
|
|
46
|
+
/** IDs of requests sent (or waiting to send) that have not completed yet. */
|
|
47
|
+
private [PENDING];
|
|
48
|
+
private get [CREATED]();
|
|
49
|
+
/** Resolves with the `RTCDataChannel` once it has been created (may not yet be open). */
|
|
50
|
+
get created(): Promise<RTCDataChannel>;
|
|
34
51
|
private get [READY]();
|
|
52
|
+
/** Resolves with the `RTCDataChannel` once it is open and ready to transmit. */
|
|
35
53
|
get ready(): Promise<RTCDataChannel>;
|
|
36
54
|
/**
|
|
37
|
-
* @param connection
|
|
55
|
+
* @param connection - RTCPeerConnection instance, promise, or factory function. Omit to initialize later via {@link initialize}.
|
|
38
56
|
* @param channelName - Name for the negotiated data channel. Determines the channel ID via FNV-1a hash.
|
|
57
|
+
* @param channelId - Explicit negotiated channel ID. Overrides the hash-derived default.
|
|
39
58
|
*/
|
|
40
|
-
constructor(connection?: RTCConnectionArg, channelName?: string);
|
|
59
|
+
constructor(connection?: RTCConnectionArg, channelName?: string, channelId?: number);
|
|
41
60
|
/**
|
|
42
61
|
* (Re)initializes the data channel with a new connection.
|
|
43
|
-
*
|
|
62
|
+
* Waits for the previous channel to be cleaned up (with a 5 s timeout)
|
|
63
|
+
* before establishing the new one.
|
|
44
64
|
*
|
|
45
65
|
* @param connection - RTCPeerConnection instance, promise, or factory function.
|
|
46
|
-
* @param
|
|
66
|
+
* @param channelId - Optional negotiated channel ID. Defaults to the hash-derived ID.
|
|
47
67
|
*/
|
|
48
|
-
initialize(connection?: RTCConnectionArg): void;
|
|
68
|
+
initialize(connection?: RTCConnectionArg, channelId?: number): void;
|
|
49
69
|
[SEND]<T>(message: Message<T>): Promise<void>;
|
|
70
|
+
/** Errors every in-flight request, since no response can arrive on a closed channel. */
|
|
71
|
+
private [FAIL_PENDING];
|
|
50
72
|
protected [GET_NEW_ID](): string;
|
|
51
73
|
}
|
|
52
|
-
|
|
74
|
+
|
|
75
|
+
export { CREATED, READY, RTCMessageClient };
|
package/rtc/message-client.js
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
import { uniqueId } from '@telperion/js-utils/unique-id';
|
|
2
2
|
import { noop } from '@telperion/js-utils/function/noop';
|
|
3
|
-
import { promisify } from '@telperion/js-utils/promise/promisify';
|
|
4
|
-
import { timeout } from '@telperion/js-utils/promise/timeout';
|
|
5
3
|
import { NEVER } from '@telperion/js-utils/promise/never';
|
|
6
4
|
import { Subject } from 'rxjs';
|
|
7
|
-
import { MessageClient } from '../message-client';
|
|
8
|
-
import {
|
|
9
|
-
import { DEFAULT_CHANNEL_NAME } from './default-channel-name';
|
|
10
|
-
import {
|
|
11
|
-
|
|
5
|
+
import { MessageClient } from '../message-client.js';
|
|
6
|
+
import { RESPONSES$, SEND, GET_NEW_ID } from '../selectors.js';
|
|
7
|
+
import { DEFAULT_CHANNEL_NAME } from './default-channel-name.js';
|
|
8
|
+
import { initialize } from './initializer.js';
|
|
9
|
+
|
|
12
10
|
const CHANNEL_NAME = Symbol('RTCMessageClient Channel Name');
|
|
13
|
-
|
|
11
|
+
const CHANNEL = Symbol('RTCMessageClient Channel');
|
|
12
|
+
const CHANNEL_OPEN = Symbol('RTCMessageClient Channel Open');
|
|
13
|
+
const DEINITIALIZE = Symbol('RTCMessageClient Deinitialize');
|
|
14
|
+
const PENDING = Symbol('RTCMessageClient Pending Requests');
|
|
15
|
+
const FAIL_PENDING = Symbol('RTCMessageClient Fail Pending Requests');
|
|
16
|
+
const READY = Symbol('RTCMessageClient Ready');
|
|
17
|
+
const CREATED = Symbol('RTCMessageClient Created');
|
|
14
18
|
/**
|
|
15
|
-
*
|
|
19
|
+
* WebRTC DataChannel message client that sends request messages and receives
|
|
20
|
+
* responses over a negotiated channel.
|
|
21
|
+
*
|
|
22
|
+
* Both peers must create the channel with an identical name and negotiated ID.
|
|
23
|
+
* The ID is derived automatically from the channel name via an FNV-1a hash
|
|
24
|
+
* unless an explicit `channelId` is supplied.
|
|
16
25
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* name and negotiated ID (handled automatically via {@link channelId}).
|
|
26
|
+
* Use `@Request` decorators to define outgoing RPC methods. The client can be
|
|
27
|
+
* constructed without a connection and initialized later via {@link initialize}.
|
|
20
28
|
*
|
|
21
29
|
* @example
|
|
22
30
|
* ```typescript
|
|
@@ -31,78 +39,93 @@ export const READY = Symbol('RTCMessageClient Ready');
|
|
|
31
39
|
* client.sendMove([3, 4]).subscribe(ok => console.log('Accepted:', ok));
|
|
32
40
|
* ```
|
|
33
41
|
*/
|
|
34
|
-
|
|
42
|
+
class RTCMessageClient extends MessageClient {
|
|
35
43
|
[RESPONSES$] = new Subject();
|
|
36
|
-
[CONNECTION] = Promise.resolve([undefined, noop]);
|
|
37
44
|
[CHANNEL_NAME];
|
|
45
|
+
[CHANNEL] = NEVER;
|
|
46
|
+
[CHANNEL_OPEN] = NEVER;
|
|
47
|
+
[DEINITIALIZE] = Promise.resolve(noop);
|
|
48
|
+
/** IDs of requests sent (or waiting to send) that have not completed yet. */
|
|
49
|
+
[PENDING] = new Set();
|
|
50
|
+
get [CREATED]() {
|
|
51
|
+
return this[CHANNEL];
|
|
52
|
+
}
|
|
53
|
+
/** Resolves with the `RTCDataChannel` once it has been created (may not yet be open). */
|
|
54
|
+
get created() {
|
|
55
|
+
return this[CREATED];
|
|
56
|
+
}
|
|
38
57
|
get [READY]() {
|
|
39
|
-
return this[
|
|
58
|
+
return this[CHANNEL_OPEN];
|
|
40
59
|
}
|
|
60
|
+
/** Resolves with the `RTCDataChannel` once it is open and ready to transmit. */
|
|
41
61
|
get ready() {
|
|
42
62
|
return this[READY];
|
|
43
63
|
}
|
|
44
64
|
/**
|
|
45
|
-
* @param connection
|
|
65
|
+
* @param connection - RTCPeerConnection instance, promise, or factory function. Omit to initialize later via {@link initialize}.
|
|
46
66
|
* @param channelName - Name for the negotiated data channel. Determines the channel ID via FNV-1a hash.
|
|
67
|
+
* @param channelId - Explicit negotiated channel ID. Overrides the hash-derived default.
|
|
47
68
|
*/
|
|
48
|
-
constructor(connection, channelName = DEFAULT_CHANNEL_NAME) {
|
|
69
|
+
constructor(connection, channelName = DEFAULT_CHANNEL_NAME, channelId) {
|
|
49
70
|
super();
|
|
50
71
|
this[CHANNEL_NAME] = channelName;
|
|
51
|
-
|
|
72
|
+
this[RESPONSES$].subscribe(({ id, completed }) => {
|
|
73
|
+
if (completed)
|
|
74
|
+
this[PENDING].delete(id);
|
|
75
|
+
});
|
|
76
|
+
RTCMessageClient.prototype.initialize.call(this, connection, channelId);
|
|
52
77
|
}
|
|
53
78
|
/**
|
|
54
79
|
* (Re)initializes the data channel with a new connection.
|
|
55
|
-
*
|
|
80
|
+
* Waits for the previous channel to be cleaned up (with a 5 s timeout)
|
|
81
|
+
* before establishing the new one.
|
|
56
82
|
*
|
|
57
83
|
* @param connection - RTCPeerConnection instance, promise, or factory function.
|
|
58
|
-
* @param
|
|
84
|
+
* @param channelId - Optional negotiated channel ID. Defaults to the hash-derived ID.
|
|
59
85
|
*/
|
|
60
|
-
initialize(connection) {
|
|
61
|
-
|
|
62
|
-
this
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const dataChannel = CHANNEL_CONTROLLER.getChannel(conn, this[CHANNEL_NAME]);
|
|
75
|
-
if (dataChannel.readyState === 'open')
|
|
76
|
-
return dataChannel;
|
|
77
|
-
return new Promise((resolve) => {
|
|
78
|
-
dataChannel.addEventListener('open', () => resolve(dataChannel), { once: true });
|
|
79
|
-
});
|
|
80
|
-
})
|
|
81
|
-
.then(dataChannel => {
|
|
82
|
-
if (!dataChannel)
|
|
83
|
-
return [undefined, noop];
|
|
84
|
-
const listener = (event) => {
|
|
85
|
-
const data = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
|
|
86
|
-
if (data.type !== 'response')
|
|
87
|
-
return;
|
|
88
|
-
this[RESPONSES$].next(data);
|
|
89
|
-
};
|
|
90
|
-
dataChannel.addEventListener('message', listener);
|
|
91
|
-
return [dataChannel, () => {
|
|
92
|
-
dataChannel.removeEventListener('message', listener);
|
|
93
|
-
CHANNEL_CONTROLLER.close(dataChannel);
|
|
94
|
-
}];
|
|
86
|
+
initialize(connection, channelId) {
|
|
87
|
+
initialize({
|
|
88
|
+
context: this,
|
|
89
|
+
selectors: {
|
|
90
|
+
channel: CHANNEL,
|
|
91
|
+
channelOpen: CHANNEL_OPEN,
|
|
92
|
+
deinit: DEINITIALIZE,
|
|
93
|
+
emitter: RESPONSES$
|
|
94
|
+
},
|
|
95
|
+
connection,
|
|
96
|
+
channelName: this[CHANNEL_NAME],
|
|
97
|
+
channelId,
|
|
98
|
+
messageFilterType: 'response',
|
|
99
|
+
onClose: () => this[FAIL_PENDING]()
|
|
95
100
|
});
|
|
96
101
|
}
|
|
97
102
|
async [SEND](message) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
this[PENDING].add(message.id);
|
|
104
|
+
try {
|
|
105
|
+
const dataChannel = await this[CHANNEL_OPEN];
|
|
106
|
+
if (dataChannel.readyState !== 'open') {
|
|
107
|
+
throw new Error(`RTCMessageClient: data channel is ${dataChannel.readyState}`);
|
|
108
|
+
}
|
|
109
|
+
dataChannel.send(JSON.stringify({ ...message, type: 'request' }));
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
this[PENDING].delete(message.id);
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** Errors every in-flight request, since no response can arrive on a closed channel. */
|
|
117
|
+
[FAIL_PENDING]() {
|
|
118
|
+
const error = new Error('RTCMessageClient: data channel closed');
|
|
119
|
+
const ids = [...this[PENDING]];
|
|
120
|
+
this[PENDING].clear();
|
|
121
|
+
for (const id of ids) {
|
|
122
|
+
this[RESPONSES$].next({ id, completed: true, error });
|
|
123
|
+
}
|
|
102
124
|
}
|
|
103
125
|
[GET_NEW_ID]() {
|
|
104
126
|
return uniqueId('messenger-rtc-message');
|
|
105
127
|
}
|
|
106
128
|
}
|
|
107
129
|
|
|
130
|
+
export { CREATED, READY, RTCMessageClient };
|
|
108
131
|
//# sourceMappingURL=message-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"file":"message-client.js","sources":["../../../../libs/messenger/src/rtc/message-client.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAaA,MAAM,YAAY,GAAG,MAAM,CAAC,+BAA+B,CAAC;AAC5D,MAAM,OAAO,GAAG,MAAM,CAAC,0BAA0B,CAAC;AAClD,MAAM,YAAY,GAAG,MAAM,CAAC,+BAA+B,CAAC;AAC5D,MAAM,YAAY,GAAG,MAAM,CAAC,+BAA+B,CAAC;AAC5D,MAAM,OAAO,GAAG,MAAM,CAAC,mCAAmC,CAAC;AAC3D,MAAM,YAAY,GAAG,MAAM,CAAC,wCAAwC,CAAC;MACxD,KAAK,GAAG,MAAM,CAAC,wBAAwB;MACvC,OAAO,GAAG,MAAM,CAAC,0BAA0B;AAExD;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACG,MAAO,gBAAiB,SAAQ,aAAa,CAAA;AAC1C,IAAA,CAAC,UAAU,IAAI,IAAI,OAAO,EAAmB;IAC5C,CAAC,YAAY;AACb,IAAA,CAAC,OAAO,IAA6B,KAAK;AAC1C,IAAA,CAAC,YAAY,IAA6B,KAAK;IAC/C,CAAC,YAAY,IAAyB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;;AAE3D,IAAA,CAAC,OAAO,IAAI,IAAI,GAAG,EAAU;IAErC,KAAa,OAAO,CAAC,GAAA;AACnB,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB;;AAG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controller");
|
|
13
|
-
const CONNECTION = Symbol('RTCMessageHost Connection');
|
|
14
|
-
const REQUESTS = Symbol('RTCMessageHost Requests');
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var noop = require('@telperion/js-utils/function/noop');
|
|
4
|
+
var call = require('@telperion/js-utils/function/call');
|
|
5
|
+
var never = require('@telperion/js-utils/promise/never');
|
|
6
|
+
var rxjs = require('rxjs');
|
|
7
|
+
var messageHost = require('../message-host.cjs');
|
|
8
|
+
var selectors = require('../selectors.cjs');
|
|
9
|
+
var rtc_defaultChannelName = require('./default-channel-name.cjs');
|
|
10
|
+
var rtc_initializer = require('./initializer.cjs');
|
|
11
|
+
|
|
15
12
|
const CHANNEL_NAME = Symbol('RTCMessageHost Channel Name');
|
|
16
|
-
|
|
13
|
+
const CHANNEL = Symbol('RTCMessageHost Channel');
|
|
14
|
+
const CHANNEL_OPEN = Symbol('RTCMessageHost Channel Open');
|
|
15
|
+
const DEINITIALIZE = Symbol('RTCMessageHost Deinitialize');
|
|
16
|
+
const REQUESTS = Symbol('RTCMessageHost Requests');
|
|
17
|
+
const READY = Symbol('RTCMessageHost Ready');
|
|
18
|
+
const CREATED = Symbol('RTCMessageHost Created');
|
|
17
19
|
/**
|
|
18
|
-
*
|
|
20
|
+
* WebRTC DataChannel message host that listens for incoming request messages
|
|
21
|
+
* and dispatches responses over the same negotiated channel.
|
|
22
|
+
*
|
|
23
|
+
* Both peers must create the channel with an identical name and negotiated ID.
|
|
24
|
+
* The ID is derived automatically from the channel name via an FNV-1a hash
|
|
25
|
+
* unless an explicit `channelId` is supplied.
|
|
19
26
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
27
|
+
* Use `@Listen` decorators to register request handlers. The host begins
|
|
28
|
+
* listening as soon as it is constructed; pass a connection later via
|
|
29
|
+
* {@link initialize} if one is not available at construction time.
|
|
23
30
|
*
|
|
24
31
|
* @example
|
|
25
32
|
* ```typescript
|
|
@@ -33,78 +40,78 @@ exports.READY = Symbol('RTCMessageHost Ready');
|
|
|
33
40
|
* const host = new GameHost(peerConnection, 'game-events');
|
|
34
41
|
* ```
|
|
35
42
|
*/
|
|
36
|
-
class RTCMessageHost extends
|
|
37
|
-
[REQUESTS] = new
|
|
38
|
-
[CONNECTION] = Promise.resolve([undefined, noop_1.noop]);
|
|
43
|
+
class RTCMessageHost extends messageHost.MessageHost {
|
|
44
|
+
[REQUESTS] = new rxjs.Subject();
|
|
39
45
|
[CHANNEL_NAME];
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
[CHANNEL] = never.NEVER;
|
|
47
|
+
[CHANNEL_OPEN] = never.NEVER;
|
|
48
|
+
[DEINITIALIZE] = Promise.resolve(noop.noop);
|
|
49
|
+
get [CREATED]() {
|
|
50
|
+
return this[CHANNEL];
|
|
51
|
+
}
|
|
52
|
+
/** Resolves with the `RTCDataChannel` once it has been created (may not yet be open). */
|
|
53
|
+
get created() {
|
|
54
|
+
return this[CREATED];
|
|
55
|
+
}
|
|
56
|
+
get [READY]() {
|
|
57
|
+
return this[CHANNEL_OPEN];
|
|
42
58
|
}
|
|
59
|
+
/** Resolves with the `RTCDataChannel` once it is open and ready to transmit. */
|
|
43
60
|
get ready() {
|
|
44
|
-
return this[
|
|
61
|
+
return this[READY];
|
|
45
62
|
}
|
|
46
63
|
/**
|
|
47
|
-
* @param connection
|
|
64
|
+
* @param connection - RTCPeerConnection instance, promise, or factory function. Omit to initialize later via {@link initialize}.
|
|
48
65
|
* @param channelName - Name for the negotiated data channel. Determines the channel ID via FNV-1a hash.
|
|
66
|
+
* @param channelId - Explicit negotiated channel ID. Overrides the hash-derived default.
|
|
49
67
|
*/
|
|
50
|
-
constructor(connection, channelName =
|
|
68
|
+
constructor(connection, channelName = rtc_defaultChannelName.DEFAULT_CHANNEL_NAME, channelId) {
|
|
51
69
|
super();
|
|
52
70
|
this[CHANNEL_NAME] = channelName;
|
|
53
|
-
RTCMessageHost.prototype.initialize.call(this, connection);
|
|
54
|
-
this[
|
|
71
|
+
RTCMessageHost.prototype.initialize.call(this, connection, channelId);
|
|
72
|
+
this[selectors.LISTEN](this[REQUESTS]);
|
|
55
73
|
}
|
|
56
74
|
/**
|
|
57
75
|
* (Re)initializes the data channel with a new connection.
|
|
58
76
|
* Cleans up the previous channel before establishing a new one.
|
|
59
77
|
*
|
|
60
78
|
* @param connection - RTCPeerConnection instance, promise, or factory function.
|
|
79
|
+
* @param channelId - Optional new channel ID. Defaults to the current channel ID.
|
|
61
80
|
*/
|
|
62
|
-
initialize(connection) {
|
|
63
|
-
|
|
64
|
-
this
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return;
|
|
76
|
-
const dataChannel = channel_controller_1.CHANNEL_CONTROLLER.getChannel(conn, this[CHANNEL_NAME]);
|
|
77
|
-
if (dataChannel.readyState === 'open')
|
|
78
|
-
return dataChannel;
|
|
79
|
-
return new Promise((resolve) => {
|
|
80
|
-
dataChannel.addEventListener('open', () => resolve(dataChannel), { once: true });
|
|
81
|
-
});
|
|
82
|
-
})
|
|
83
|
-
.then(dataChannel => {
|
|
84
|
-
if (!dataChannel)
|
|
85
|
-
return [undefined, noop_1.noop];
|
|
86
|
-
const handler = (event) => {
|
|
87
|
-
const data = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
|
|
88
|
-
if (data.type !== 'request')
|
|
89
|
-
return;
|
|
90
|
-
this[REQUESTS].next(data);
|
|
91
|
-
};
|
|
92
|
-
dataChannel.addEventListener('message', handler);
|
|
93
|
-
return [dataChannel, () => {
|
|
94
|
-
dataChannel.removeEventListener('message', handler);
|
|
95
|
-
channel_controller_1.CHANNEL_CONTROLLER.close(dataChannel);
|
|
96
|
-
}];
|
|
81
|
+
initialize(connection, channelId) {
|
|
82
|
+
rtc_initializer.initialize({
|
|
83
|
+
context: this,
|
|
84
|
+
selectors: {
|
|
85
|
+
channel: CHANNEL,
|
|
86
|
+
channelOpen: CHANNEL_OPEN,
|
|
87
|
+
deinit: DEINITIALIZE,
|
|
88
|
+
emitter: REQUESTS
|
|
89
|
+
},
|
|
90
|
+
connection,
|
|
91
|
+
channelName: this[CHANNEL_NAME],
|
|
92
|
+
channelId,
|
|
93
|
+
messageFilterType: 'request'
|
|
97
94
|
});
|
|
98
95
|
}
|
|
99
96
|
/** Closes the data channel and removes event listeners. */
|
|
100
97
|
terminate() {
|
|
101
|
-
this[
|
|
102
|
-
.then(([_, deinitialize]) => deinitialize())
|
|
103
|
-
.catch(noop_1.noop);
|
|
98
|
+
this[DEINITIALIZE].then(call.call);
|
|
104
99
|
}
|
|
105
|
-
async [
|
|
106
|
-
const
|
|
107
|
-
|
|
100
|
+
async [selectors.RESPONSE](message) {
|
|
101
|
+
const dataChannel = await this[CHANNEL_OPEN];
|
|
102
|
+
// If the channel closed, the requester is gone, so the response is dropped.
|
|
103
|
+
if (dataChannel.readyState !== 'open')
|
|
104
|
+
return;
|
|
105
|
+
try {
|
|
106
|
+
dataChannel.send(JSON.stringify({ ...message, type: 'response' }));
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// The channel closed while sending. The requester is gone, so drop it.
|
|
110
|
+
}
|
|
108
111
|
}
|
|
109
112
|
}
|
|
113
|
+
|
|
114
|
+
exports.CREATED = CREATED;
|
|
115
|
+
exports.READY = READY;
|
|
110
116
|
exports.RTCMessageHost = RTCMessageHost;
|
|
117
|
+
//# sourceMappingURL=message-host.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-host.cjs","sources":["../../../../libs/messenger/src/rtc/message-host.ts"],"sourcesContent":[null],"names":["MessageHost","Subject","NEVER","noop","DEFAULT_CHANNEL_NAME","LISTEN","initialize","call","RESPONSE"],"mappings":";;;;;;;;;;;AAaA,MAAM,YAAY,GAAG,MAAM,CAAC,6BAA6B,CAAC;AAC1D,MAAM,OAAO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,CAAC,UAA6B,EAAE,SAAkB,EAAA;AAC1D,QAAAC,0BAAU,CAAC;AACT,YAAA,OAAO,EAAE,IAAI;AACb,YAAA,SAAS,EAAE;AACT,gBAAA,OAAO,EAAE,OAAO;AAChB,gBAAA,WAAW,EAAE,YAAY;AACzB,gBAAA,MAAM,EAAE,YAAY;AACpB,gBAAA,OAAO,EAAE;AACV,aAAA;YACD,UAAU;AACV,YAAA,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC;YAC/B,SAAS;AACT,YAAA,iBAAiB,EAAE;AACpB,SAAA,CAAC;IACJ;;IAGO,SAAS,GAAA;QACd,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAACC,SAAI,CAAC;IAC/B;AAEU,IAAA,OAAOC,kBAAQ,CAAC,CAAC,OAAwB,EAAA;AACjD,QAAA,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC;;AAG5C,QAAA,IAAI,WAAW,CAAC,UAAU,KAAK,MAAM;YAAE;AAEvC,QAAA,IAAI;AACF,YAAA,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAC,GAAG,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;QACnE;AAAE,QAAA,MAAM;;QAER;IACF;AACD;;;;;;"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { MessageHost } from '../message-host.cjs';
|
|
2
|
+
import { MessageResponse } from '../message-response.type.cjs';
|
|
3
|
+
import { RESPONSE } from '../selectors.cjs';
|
|
4
|
+
import { RTCConnectionArg } from './rtc.type.cjs';
|
|
5
|
+
import 'rxjs';
|
|
6
|
+
import '../message.interface.cjs';
|
|
7
|
+
|
|
8
|
+
declare const CHANNEL_NAME: unique symbol;
|
|
9
|
+
declare const CHANNEL: unique symbol;
|
|
10
|
+
declare const CHANNEL_OPEN: unique symbol;
|
|
11
|
+
declare const DEINITIALIZE: unique symbol;
|
|
12
|
+
declare const REQUESTS: unique symbol;
|
|
13
|
+
declare const READY: unique symbol;
|
|
14
|
+
declare const CREATED: unique symbol;
|
|
15
|
+
/**
|
|
16
|
+
* WebRTC DataChannel message host that listens for incoming request messages
|
|
17
|
+
* and dispatches responses over the same negotiated channel.
|
|
18
|
+
*
|
|
19
|
+
* Both peers must create the channel with an identical name and negotiated ID.
|
|
20
|
+
* The ID is derived automatically from the channel name via an FNV-1a hash
|
|
21
|
+
* unless an explicit `channelId` is supplied.
|
|
22
|
+
*
|
|
23
|
+
* Use `@Listen` decorators to register request handlers. The host begins
|
|
24
|
+
* listening as soon as it is constructed; pass a connection later via
|
|
25
|
+
* {@link initialize} if one is not available at construction time.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* class GameHost extends RTCMessageHost {
|
|
30
|
+
* @Listen('move')
|
|
31
|
+
* handleMove({ data }: { data: [number, number] }): Observable<boolean> {
|
|
32
|
+
* return of(applyMove(data));
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* const host = new GameHost(peerConnection, 'game-events');
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare class RTCMessageHost extends MessageHost {
|
|
40
|
+
private [REQUESTS];
|
|
41
|
+
private [CHANNEL_NAME];
|
|
42
|
+
private [CHANNEL];
|
|
43
|
+
private [CHANNEL_OPEN];
|
|
44
|
+
private [DEINITIALIZE];
|
|
45
|
+
private get [CREATED]();
|
|
46
|
+
/** Resolves with the `RTCDataChannel` once it has been created (may not yet be open). */
|
|
47
|
+
get created(): Promise<RTCDataChannel>;
|
|
48
|
+
private get [READY]();
|
|
49
|
+
/** Resolves with the `RTCDataChannel` once it is open and ready to transmit. */
|
|
50
|
+
get ready(): Promise<RTCDataChannel>;
|
|
51
|
+
/**
|
|
52
|
+
* @param connection - RTCPeerConnection instance, promise, or factory function. Omit to initialize later via {@link initialize}.
|
|
53
|
+
* @param channelName - Name for the negotiated data channel. Determines the channel ID via FNV-1a hash.
|
|
54
|
+
* @param channelId - Explicit negotiated channel ID. Overrides the hash-derived default.
|
|
55
|
+
*/
|
|
56
|
+
constructor(connection?: RTCConnectionArg, channelName?: string, channelId?: number);
|
|
57
|
+
/**
|
|
58
|
+
* (Re)initializes the data channel with a new connection.
|
|
59
|
+
* Cleans up the previous channel before establishing a new one.
|
|
60
|
+
*
|
|
61
|
+
* @param connection - RTCPeerConnection instance, promise, or factory function.
|
|
62
|
+
* @param channelId - Optional new channel ID. Defaults to the current channel ID.
|
|
63
|
+
*/
|
|
64
|
+
initialize(connection?: RTCConnectionArg, channelId?: number): void;
|
|
65
|
+
/** Closes the data channel and removes event listeners. */
|
|
66
|
+
terminate(): void;
|
|
67
|
+
protected [RESPONSE](message: MessageResponse): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { CREATED, READY, RTCMessageHost };
|