@marianmeres/webrtc 1.3.1 → 1.4.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/AGENTS.md +16 -17
- package/API.md +39 -43
- package/README.md +23 -24
- package/dist/types.d.ts +8 -10
- package/dist/types.js +20 -20
- package/dist/webrtc-manager.d.ts +11 -11
- package/dist/webrtc-manager.js +157 -188
- package/package.json +2 -2
package/dist/types.js
CHANGED
|
@@ -2,41 +2,41 @@
|
|
|
2
2
|
* Possible states of the WebRTC connection lifecycle.
|
|
3
3
|
* The manager transitions between these states based on connection events.
|
|
4
4
|
*/
|
|
5
|
-
export var
|
|
6
|
-
(function (
|
|
5
|
+
export var WebRTCState;
|
|
6
|
+
(function (WebRTCState) {
|
|
7
7
|
/** Initial state, no resources allocated. */
|
|
8
|
-
|
|
8
|
+
WebRTCState["IDLE"] = "IDLE";
|
|
9
9
|
/** Creating peer connection and setting up media tracks. */
|
|
10
|
-
|
|
10
|
+
WebRTCState["INITIALIZING"] = "INITIALIZING";
|
|
11
11
|
/** Performing SDP offer/answer exchange. */
|
|
12
|
-
|
|
12
|
+
WebRTCState["CONNECTING"] = "CONNECTING";
|
|
13
13
|
/** Connection established, communication active. */
|
|
14
|
-
|
|
14
|
+
WebRTCState["CONNECTED"] = "CONNECTED";
|
|
15
15
|
/** Automatic reconnection in progress. */
|
|
16
|
-
|
|
16
|
+
WebRTCState["RECONNECTING"] = "RECONNECTING";
|
|
17
17
|
/** Connection closed, can be restarted. */
|
|
18
|
-
|
|
18
|
+
WebRTCState["DISCONNECTED"] = "DISCONNECTED";
|
|
19
19
|
/** Error state, requires reset() to recover. */
|
|
20
|
-
|
|
21
|
-
})(
|
|
20
|
+
WebRTCState["ERROR"] = "ERROR";
|
|
21
|
+
})(WebRTCState || (WebRTCState = {}));
|
|
22
22
|
/**
|
|
23
23
|
* Internal FSM events that trigger state transitions.
|
|
24
24
|
* These events are dispatched internally by the manager methods.
|
|
25
25
|
*/
|
|
26
|
-
export var
|
|
27
|
-
(function (
|
|
26
|
+
export var WebRTCFsmEvent;
|
|
27
|
+
(function (WebRTCFsmEvent) {
|
|
28
28
|
/** Triggers transition from IDLE to INITIALIZING. */
|
|
29
|
-
|
|
29
|
+
WebRTCFsmEvent["INIT"] = "initialize";
|
|
30
30
|
/** Triggers transition to CONNECTING state. */
|
|
31
|
-
|
|
31
|
+
WebRTCFsmEvent["CONNECT"] = "connect";
|
|
32
32
|
/** Signals successful connection establishment. */
|
|
33
|
-
|
|
33
|
+
WebRTCFsmEvent["CONNECTED"] = "connected";
|
|
34
34
|
/** Triggers transition to RECONNECTING state. */
|
|
35
|
-
|
|
35
|
+
WebRTCFsmEvent["RECONNECTING"] = "reconnecting";
|
|
36
36
|
/** Triggers transition to DISCONNECTED state. */
|
|
37
|
-
|
|
37
|
+
WebRTCFsmEvent["DISCONNECT"] = "disconnect";
|
|
38
38
|
/** Triggers transition to ERROR state. */
|
|
39
|
-
|
|
39
|
+
WebRTCFsmEvent["ERROR"] = "error";
|
|
40
40
|
/** Resets the manager to IDLE state. */
|
|
41
|
-
|
|
42
|
-
})(
|
|
41
|
+
WebRTCFsmEvent["RESET"] = "reset";
|
|
42
|
+
})(WebRTCFsmEvent || (WebRTCFsmEvent = {}));
|
package/dist/webrtc-manager.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type WebRTCFactory, type WebRTCManagerConfig, WebRTCState, type WebRTCEvents, type GatherIceCandidatesOptions } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* WebRTC connection manager with FSM-based lifecycle and event-driven architecture.
|
|
4
4
|
*
|
|
@@ -14,7 +14,7 @@ import { type WebRtcFactory, type WebRtcManagerConfig, WebRtcState, type WebRtcE
|
|
|
14
14
|
* enumerateDevices: () => navigator.mediaDevices.enumerateDevices(),
|
|
15
15
|
* };
|
|
16
16
|
*
|
|
17
|
-
* const manager = new
|
|
17
|
+
* const manager = new WebRTCManager(factory, {
|
|
18
18
|
* peerConfig: { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] },
|
|
19
19
|
* enableMicrophone: true,
|
|
20
20
|
* });
|
|
@@ -25,9 +25,9 @@ import { type WebRtcFactory, type WebRtcManagerConfig, WebRtcState, type WebRtcE
|
|
|
25
25
|
* await manager.setLocalDescription(offer);
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export declare class
|
|
28
|
+
export declare class WebRTCManager<TContext = unknown> {
|
|
29
29
|
#private;
|
|
30
|
-
/** Event emitted when connection state changes. Payload: {@link
|
|
30
|
+
/** Event emitted when connection state changes. Payload: {@link WebRTCState} */
|
|
31
31
|
static readonly EVENT_STATE_CHANGE = "state_change";
|
|
32
32
|
/** Event emitted when local media stream changes. Payload: `MediaStream | null` */
|
|
33
33
|
static readonly EVENT_LOCAL_STREAM = "local_stream";
|
|
@@ -59,24 +59,24 @@ export declare class WebRtcManager<TContext = unknown> {
|
|
|
59
59
|
* @example
|
|
60
60
|
* ```typescript
|
|
61
61
|
* // With type parameter for full type safety:
|
|
62
|
-
* const manager = new
|
|
62
|
+
* const manager = new WebRTCManager<{ audioStream: MediaStream; sessionId: string }>(factory);
|
|
63
63
|
* manager.context = { audioStream: myStream, sessionId: '123' };
|
|
64
64
|
* manager.context.audioStream; // typed as MediaStream
|
|
65
65
|
*
|
|
66
66
|
* // Without type parameter (backwards compatible):
|
|
67
|
-
* const manager = new
|
|
67
|
+
* const manager = new WebRTCManager(factory);
|
|
68
68
|
* manager.context = { anything: 'goes' };
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
71
|
context: TContext | null;
|
|
72
72
|
/**
|
|
73
|
-
* Creates a new
|
|
73
|
+
* Creates a new WebRTCManager instance.
|
|
74
74
|
* @param factory - Factory object providing WebRTC primitives (peer connection, media, devices).
|
|
75
75
|
* @param config - Optional configuration for the manager.
|
|
76
76
|
*/
|
|
77
|
-
constructor(factory:
|
|
77
|
+
constructor(factory: WebRTCFactory, config?: WebRTCManagerConfig);
|
|
78
78
|
/** Returns the current state of the WebRTC connection. */
|
|
79
|
-
get state():
|
|
79
|
+
get state(): WebRTCState;
|
|
80
80
|
/** Returns a readonly map of all active data channels indexed by label. */
|
|
81
81
|
get dataChannels(): ReadonlyMap<string, RTCDataChannel>;
|
|
82
82
|
/** Returns the local media stream, or null if not initialized. */
|
|
@@ -93,7 +93,7 @@ export declare class WebRtcManager<TContext = unknown> {
|
|
|
93
93
|
* @param handler - Callback function that receives the event data.
|
|
94
94
|
* @returns Unsubscribe function to remove the event listener.
|
|
95
95
|
*/
|
|
96
|
-
on(event: keyof
|
|
96
|
+
on(event: keyof WebRTCEvents, handler: (data: any) => void): () => void;
|
|
97
97
|
/**
|
|
98
98
|
* Subscribe to the overall state of the WebRTC manager.
|
|
99
99
|
* Compatible with Svelte stores - immediately calls handler with current state,
|
|
@@ -102,7 +102,7 @@ export declare class WebRtcManager<TContext = unknown> {
|
|
|
102
102
|
* @returns Unsubscribe function to remove the event listener.
|
|
103
103
|
*/
|
|
104
104
|
subscribe(handler: (state: {
|
|
105
|
-
state:
|
|
105
|
+
state: WebRTCState;
|
|
106
106
|
localStream: MediaStream | null;
|
|
107
107
|
remoteStream: MediaStream | null;
|
|
108
108
|
dataChannels: ReadonlyMap<string, RTCDataChannel>;
|