@yrzhao/aves-core 0.1.0 → 0.3.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 +157 -343
- package/dist/core/AvesClient.d.ts +45 -64
- package/dist/core/AvesClient.js +190 -142
- package/dist/core/AvesError.d.ts +39 -0
- package/dist/core/AvesError.js +42 -0
- package/dist/core/EventEmitter.d.ts +26 -24
- package/dist/core/EventEmitter.js +12 -23
- package/dist/core/SignalingClient.d.ts +30 -7
- package/dist/core/SignalingClient.js +177 -41
- package/dist/core/WebRTCManager.d.ts +152 -39
- package/dist/core/WebRTCManager.js +409 -196
- package/dist/core/webrtc/channels.d.ts +10 -0
- package/dist/core/webrtc/channels.js +25 -0
- package/dist/core/webrtc/fileTransfer.d.ts +84 -0
- package/dist/core/webrtc/fileTransfer.js +399 -0
- package/dist/core/webrtc/mediaTracks.d.ts +53 -0
- package/dist/core/webrtc/mediaTracks.js +385 -0
- package/dist/core/webrtc/messages.d.ts +4 -0
- package/dist/core/webrtc/messages.js +53 -0
- package/dist/esm/core/AvesClient.d.ts +45 -64
- package/dist/esm/core/AvesClient.js +193 -145
- package/dist/esm/core/AvesError.d.ts +39 -0
- package/dist/esm/core/AvesError.js +38 -0
- package/dist/esm/core/EventEmitter.d.ts +26 -24
- package/dist/esm/core/EventEmitter.js +12 -23
- package/dist/esm/core/SignalingClient.d.ts +30 -7
- package/dist/esm/core/SignalingClient.js +178 -42
- package/dist/esm/core/WebRTCManager.d.ts +152 -39
- package/dist/esm/core/WebRTCManager.js +409 -196
- package/dist/esm/core/webrtc/channels.d.ts +10 -0
- package/dist/esm/core/webrtc/channels.js +19 -0
- package/dist/esm/core/webrtc/fileTransfer.d.ts +84 -0
- package/dist/esm/core/webrtc/fileTransfer.js +393 -0
- package/dist/esm/core/webrtc/mediaTracks.d.ts +53 -0
- package/dist/esm/core/webrtc/mediaTracks.js +381 -0
- package/dist/esm/core/webrtc/messages.d.ts +4 -0
- package/dist/esm/core/webrtc/messages.js +48 -0
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js +5 -4
- package/dist/esm/package.json +3 -0
- package/dist/esm/types/types.d.ts +84 -4
- package/dist/index.cjs +3 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/types/types.d.ts +84 -4
- package/package.json +4 -3
|
@@ -1,93 +1,206 @@
|
|
|
1
|
+
import { AvesError } from "./AvesError";
|
|
2
|
+
import { AvesMessage, AvesVideoConstraints, FileTransferInfo, FileTransferOptions, FileTransferProgress, FileTransferResult, LocalAudioState, LocalVideoState, ScreenShareState } from "../types/types";
|
|
1
3
|
/**
|
|
2
|
-
* WebRTCManager - Manages WebRTC PeerConnections and
|
|
3
|
-
*
|
|
4
|
-
* This class handles the low-level WebRTC connection management including:
|
|
5
|
-
* - Creating and managing RTCPeerConnection instances
|
|
6
|
-
* - Creating and managing RTCDataChannel instances
|
|
7
|
-
* - Handling ICE candidate exchange
|
|
8
|
-
* - Serializing and deserializing messages
|
|
9
|
-
* - Managing connection lifecycle and cleanup
|
|
4
|
+
* WebRTCManager - Manages WebRTC PeerConnections, DataChannels, and media tracks
|
|
10
5
|
*/
|
|
11
6
|
export declare class WebRTCManager {
|
|
12
7
|
private peerConnections;
|
|
13
8
|
private dataChannels;
|
|
14
9
|
private iceServers;
|
|
10
|
+
private fileTransfers;
|
|
15
11
|
private messageCallbacks;
|
|
16
12
|
private connectionStateCallbacks;
|
|
17
13
|
private dataChannelStateCallbacks;
|
|
18
14
|
private iceCandidateCallbacks;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
private outgoingTransfers;
|
|
16
|
+
private incomingTransfers;
|
|
17
|
+
private readyResolvers;
|
|
18
|
+
private completionResolvers;
|
|
19
|
+
private fileTransferStartedCallbacks;
|
|
20
|
+
private fileTransferProgressCallbacks;
|
|
21
|
+
private fileTransferCompletedCallbacks;
|
|
22
|
+
private fileTransferFailedCallbacks;
|
|
23
|
+
private mediaTracks;
|
|
24
|
+
private videoSenders;
|
|
25
|
+
private remoteAudioTrackCallbacks;
|
|
26
|
+
private localAudioStateCallbacks;
|
|
27
|
+
private remoteVideoTrackCallbacks;
|
|
28
|
+
private localVideoStateCallbacks;
|
|
29
|
+
private screenShareStateCallbacks;
|
|
30
|
+
private errorCallbacks;
|
|
31
|
+
constructor(iceServers: RTCIceServer[], fileChunkSize?: number, videoConstraints?: AvesVideoConstraints);
|
|
32
|
+
/**
|
|
33
|
+
* Create a new PeerConnection for the specified peer.
|
|
34
|
+
* If a connection already exists, returns the existing connection.
|
|
23
35
|
*/
|
|
24
36
|
createPeerConnection(peerId: string): RTCPeerConnection;
|
|
25
37
|
/**
|
|
26
|
-
* Create an offer for the specified peer
|
|
27
|
-
*
|
|
38
|
+
* Create an offer for the specified peer.
|
|
39
|
+
* The offer side creates both the message and file channels.
|
|
28
40
|
*/
|
|
29
41
|
createOffer(peerId: string): Promise<RTCSessionDescriptionInit>;
|
|
30
42
|
/**
|
|
31
|
-
* Create an answer for the specified peer
|
|
32
|
-
*
|
|
43
|
+
* Create an answer for the specified peer.
|
|
44
|
+
* The answer side receives data channels from the remote offer.
|
|
33
45
|
*/
|
|
34
46
|
createAnswer(peerId: string, offer: RTCSessionDescriptionInit): Promise<RTCSessionDescriptionInit>;
|
|
35
47
|
/**
|
|
36
|
-
* Set the remote answer for the specified peer
|
|
48
|
+
* Set the remote answer for the specified peer.
|
|
37
49
|
*/
|
|
38
50
|
setRemoteAnswer(peerId: string, answer: RTCSessionDescriptionInit): Promise<void>;
|
|
39
51
|
/**
|
|
40
|
-
* Add an ICE candidate for the specified peer
|
|
52
|
+
* Add an ICE candidate for the specified peer.
|
|
41
53
|
*/
|
|
42
54
|
addIceCandidate(peerId: string, candidate: RTCIceCandidateInit): Promise<void>;
|
|
43
55
|
/**
|
|
44
|
-
*
|
|
56
|
+
* Send a JSON message to all connected peers.
|
|
57
|
+
* Peers with unavailable channels are skipped gracefully;
|
|
58
|
+
* the message is delivered to every ready peer.
|
|
45
59
|
*/
|
|
46
|
-
|
|
60
|
+
sendMessage(message: AvesMessage): void;
|
|
47
61
|
/**
|
|
48
|
-
*
|
|
62
|
+
* Send a JSON message to a specific peer.
|
|
49
63
|
*/
|
|
50
|
-
|
|
64
|
+
sendMessageToPeer(peerId: string, message: AvesMessage): void;
|
|
51
65
|
/**
|
|
52
|
-
*
|
|
66
|
+
* Send a file to one peer or broadcast to every connected peer.
|
|
53
67
|
*/
|
|
54
|
-
|
|
68
|
+
sendFile(blob: Blob, options?: FileTransferOptions): Promise<FileTransferInfo[]>;
|
|
55
69
|
/**
|
|
56
|
-
*
|
|
70
|
+
* Start capturing local audio and bind it to current peer connections.
|
|
57
71
|
*/
|
|
58
|
-
|
|
72
|
+
startVoice(): Promise<MediaStream>;
|
|
59
73
|
/**
|
|
60
|
-
*
|
|
74
|
+
* Stop local audio capture and detach it from active peers.
|
|
61
75
|
*/
|
|
62
|
-
|
|
76
|
+
stopVoice(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Toggle local mute state.
|
|
79
|
+
*/
|
|
80
|
+
setMuted(muted: boolean): void;
|
|
81
|
+
/**
|
|
82
|
+
* Read current local audio state.
|
|
83
|
+
*/
|
|
84
|
+
getLocalAudioState(): LocalAudioState;
|
|
85
|
+
/**
|
|
86
|
+
* Read current remote audio stream for a peer.
|
|
87
|
+
*/
|
|
88
|
+
getRemoteAudioStream(peerId: string): MediaStream | null;
|
|
89
|
+
/**
|
|
90
|
+
* Start capturing local camera video and bind it to current peer connections.
|
|
91
|
+
* Idempotent: returns the existing stream if already active.
|
|
92
|
+
*/
|
|
93
|
+
startVideo(constraints?: AvesVideoConstraints): Promise<MediaStream>;
|
|
94
|
+
/**
|
|
95
|
+
* Stop local camera capture and detach it from active peers.
|
|
96
|
+
*/
|
|
97
|
+
stopVideo(): void;
|
|
98
|
+
/**
|
|
99
|
+
* Toggle local video mute state (camera on/off).
|
|
100
|
+
*/
|
|
101
|
+
setVideoMuted(muted: boolean): void;
|
|
102
|
+
/**
|
|
103
|
+
* Read current local video state.
|
|
104
|
+
*/
|
|
105
|
+
getLocalVideoState(): LocalVideoState;
|
|
106
|
+
/**
|
|
107
|
+
* Read current remote video stream for a peer.
|
|
108
|
+
*/
|
|
109
|
+
getRemoteVideoStream(peerId: string): MediaStream | null;
|
|
63
110
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
111
|
+
* Start screen sharing. Replaces the camera video track with the display track
|
|
112
|
+
* on all active peer connections. The camera track is saved and restored when
|
|
113
|
+
* screen sharing stops.
|
|
66
114
|
*/
|
|
67
|
-
|
|
115
|
+
startScreenShare(): Promise<MediaStream>;
|
|
68
116
|
/**
|
|
69
|
-
*
|
|
70
|
-
* Throws error if DataChannel is not ready
|
|
117
|
+
* Stop screen sharing and restore the camera video track (if it was active).
|
|
71
118
|
*/
|
|
72
|
-
|
|
119
|
+
stopScreenShare(): void;
|
|
73
120
|
/**
|
|
74
|
-
*
|
|
121
|
+
* Read current screen share state.
|
|
122
|
+
*/
|
|
123
|
+
getScreenShareState(): ScreenShareState;
|
|
124
|
+
/**
|
|
125
|
+
* Register a callback for remote video tracks.
|
|
126
|
+
*/
|
|
127
|
+
onRemoteVideoTrack(callback: (peerId: string, stream: MediaStream, track: MediaStreamTrack) => void): void;
|
|
128
|
+
/**
|
|
129
|
+
* Register a callback for local video state changes.
|
|
130
|
+
*/
|
|
131
|
+
onLocalVideoStateChange(callback: (state: LocalVideoState) => void): void;
|
|
132
|
+
/**
|
|
133
|
+
* Register a callback for screen share state changes.
|
|
134
|
+
*/
|
|
135
|
+
onScreenShareStateChange(callback: (state: ScreenShareState) => void): void;
|
|
136
|
+
/**
|
|
137
|
+
* Register a callback for WebRTCManager-level errors
|
|
138
|
+
* (e.g. DataChannel failures, message parse errors).
|
|
139
|
+
*/
|
|
140
|
+
onError(callback: (error: AvesError) => void): void;
|
|
141
|
+
private emitError;
|
|
142
|
+
/**
|
|
143
|
+
* Register a callback for ICE candidates from the specified peer.
|
|
144
|
+
*/
|
|
145
|
+
onIceCandidate(peerId: string, callback: (candidate: RTCIceCandidateInit) => void): void;
|
|
146
|
+
/**
|
|
147
|
+
* Register a callback for connection state changes.
|
|
148
|
+
*/
|
|
149
|
+
onConnectionStateChange(peerId: string, callback: (state: RTCPeerConnectionState) => void): void;
|
|
150
|
+
/**
|
|
151
|
+
* Register a callback for main DataChannel state changes.
|
|
152
|
+
*/
|
|
153
|
+
onDataChannelStateChange(peerId: string, callback: (state: RTCDataChannelState) => void): void;
|
|
154
|
+
/**
|
|
155
|
+
* Register a callback for incoming user messages.
|
|
156
|
+
*/
|
|
157
|
+
onMessage(callback: (peerId: string, message: AvesMessage) => void): void;
|
|
158
|
+
onFileTransferStarted(callback: (peerId: string, info: FileTransferInfo) => void): void;
|
|
159
|
+
onFileTransferProgress(callback: (peerId: string, progress: FileTransferProgress) => void): void;
|
|
160
|
+
onFileTransferCompleted(callback: (peerId: string, result: FileTransferResult) => void): void;
|
|
161
|
+
onFileTransferFailed(callback: (peerId: string, info: FileTransferInfo | null, error: AvesError) => void): void;
|
|
162
|
+
onRemoteAudioTrack(callback: (peerId: string, stream: MediaStream, track: MediaStreamTrack) => void): void;
|
|
163
|
+
onLocalAudioStateChange(callback: (state: LocalAudioState) => void): void;
|
|
164
|
+
/**
|
|
165
|
+
* Close the connection with a specific peer.
|
|
75
166
|
*/
|
|
76
167
|
closePeerConnection(peerId: string): void;
|
|
77
168
|
/**
|
|
78
|
-
* Close all connections and clean up resources
|
|
169
|
+
* Close all connections and clean up resources.
|
|
79
170
|
*/
|
|
80
171
|
closeAll(): void;
|
|
172
|
+
destroy(): void;
|
|
81
173
|
/**
|
|
82
|
-
* Get all active peer IDs
|
|
174
|
+
* Get all active peer IDs.
|
|
83
175
|
*/
|
|
84
176
|
getActivePeers(): string[];
|
|
85
177
|
/**
|
|
86
|
-
* Check if connected to a specific peer
|
|
178
|
+
* Check if connected to a specific peer.
|
|
87
179
|
*/
|
|
88
180
|
isConnected(peerId: string): boolean;
|
|
89
181
|
/**
|
|
90
|
-
*
|
|
182
|
+
* Get the actual RTCPeerConnectionState for a peer.
|
|
183
|
+
*/
|
|
184
|
+
getConnectionState(peerId: string): RTCPeerConnectionState;
|
|
185
|
+
/**
|
|
186
|
+
* Check if the main DataChannel is ready for a specific peer.
|
|
91
187
|
*/
|
|
92
188
|
isDataChannelReady(peerId: string): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Check if the file channel is ready for a specific peer.
|
|
191
|
+
*/
|
|
192
|
+
isFileChannelReady(peerId: string): boolean;
|
|
193
|
+
private setupPeerConnection;
|
|
194
|
+
private ensureDataChannel;
|
|
195
|
+
private setupDataChannel;
|
|
196
|
+
private handleMessageChannelMessage;
|
|
197
|
+
private handleFileControlMessage;
|
|
198
|
+
private handleFileChunk;
|
|
199
|
+
private emitFileTransferFailed;
|
|
200
|
+
private clearReadyResolver;
|
|
201
|
+
private clearCompletionResolver;
|
|
202
|
+
private getPeerConnection;
|
|
203
|
+
private getMessageChannel;
|
|
204
|
+
private getFileChannel;
|
|
205
|
+
private failActiveTransfers;
|
|
93
206
|
}
|