@yrzhao/aves-core 0.2.0 → 1.0.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 +67 -135
- package/dist/core/AvesClient.d.ts +31 -4
- package/dist/core/AvesClient.js +52 -7
- 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 +23 -7
- package/dist/core/SignalingClient.js +113 -71
- package/dist/core/WebRTCManager.d.ts +77 -33
- package/dist/core/WebRTCManager.js +201 -478
- 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 +31 -4
- package/dist/esm/core/AvesClient.js +55 -10
- 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 +23 -7
- package/dist/esm/core/SignalingClient.js +114 -72
- package/dist/esm/core/WebRTCManager.d.ts +77 -33
- package/dist/esm/core/WebRTCManager.js +199 -476
- 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 +26 -5
- 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 +26 -5
- package/package.json +4 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AvesError } from "./AvesError";
|
|
2
|
+
import { AvesMessage, AvesVideoConstraints, FileTransferInfo, FileTransferOptions, FileTransferProgress, FileTransferResult, LocalAudioState, LocalVideoState, ScreenShareState } from "../types/types";
|
|
2
3
|
/**
|
|
3
4
|
* WebRTCManager - Manages WebRTC PeerConnections, DataChannels, and media tracks
|
|
4
5
|
*/
|
|
@@ -6,27 +7,28 @@ export declare class WebRTCManager {
|
|
|
6
7
|
private peerConnections;
|
|
7
8
|
private dataChannels;
|
|
8
9
|
private iceServers;
|
|
9
|
-
private
|
|
10
|
+
private fileTransfers;
|
|
10
11
|
private messageCallbacks;
|
|
11
12
|
private connectionStateCallbacks;
|
|
12
13
|
private dataChannelStateCallbacks;
|
|
13
14
|
private iceCandidateCallbacks;
|
|
15
|
+
private outgoingTransfers;
|
|
16
|
+
private incomingTransfers;
|
|
17
|
+
private readyResolvers;
|
|
18
|
+
private completionResolvers;
|
|
14
19
|
private fileTransferStartedCallbacks;
|
|
15
20
|
private fileTransferProgressCallbacks;
|
|
16
21
|
private fileTransferCompletedCallbacks;
|
|
17
22
|
private fileTransferFailedCallbacks;
|
|
23
|
+
private mediaTracks;
|
|
24
|
+
private videoSenders;
|
|
18
25
|
private remoteAudioTrackCallbacks;
|
|
19
26
|
private localAudioStateCallbacks;
|
|
20
|
-
private
|
|
21
|
-
private
|
|
22
|
-
private
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
private remoteAudioStreams;
|
|
26
|
-
private localAudioStream;
|
|
27
|
-
private localAudioTrack;
|
|
28
|
-
private isMuted;
|
|
29
|
-
constructor(iceServers: RTCIceServer[], fileChunkSize?: number);
|
|
27
|
+
private remoteVideoTrackCallbacks;
|
|
28
|
+
private localVideoStateCallbacks;
|
|
29
|
+
private screenShareStateCallbacks;
|
|
30
|
+
private errorCallbacks;
|
|
31
|
+
constructor(iceServers: RTCIceServer[], fileChunkSize?: number, videoConstraints?: AvesVideoConstraints);
|
|
30
32
|
/**
|
|
31
33
|
* Create a new PeerConnection for the specified peer.
|
|
32
34
|
* If a connection already exists, returns the existing connection.
|
|
@@ -52,12 +54,14 @@ export declare class WebRTCManager {
|
|
|
52
54
|
addIceCandidate(peerId: string, candidate: RTCIceCandidateInit): Promise<void>;
|
|
53
55
|
/**
|
|
54
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.
|
|
55
59
|
*/
|
|
56
|
-
sendMessage(message:
|
|
60
|
+
sendMessage(message: AvesMessage): void;
|
|
57
61
|
/**
|
|
58
62
|
* Send a JSON message to a specific peer.
|
|
59
63
|
*/
|
|
60
|
-
sendMessageToPeer(peerId: string, message:
|
|
64
|
+
sendMessageToPeer(peerId: string, message: AvesMessage): void;
|
|
61
65
|
/**
|
|
62
66
|
* Send a file to one peer or broadcast to every connected peer.
|
|
63
67
|
*/
|
|
@@ -82,6 +86,59 @@ export declare class WebRTCManager {
|
|
|
82
86
|
* Read current remote audio stream for a peer.
|
|
83
87
|
*/
|
|
84
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;
|
|
110
|
+
/**
|
|
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.
|
|
114
|
+
*/
|
|
115
|
+
startScreenShare(): Promise<MediaStream>;
|
|
116
|
+
/**
|
|
117
|
+
* Stop screen sharing and restore the camera video track (if it was active).
|
|
118
|
+
*/
|
|
119
|
+
stopScreenShare(): void;
|
|
120
|
+
/**
|
|
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;
|
|
85
142
|
/**
|
|
86
143
|
* Register a callback for ICE candidates from the specified peer.
|
|
87
144
|
*/
|
|
@@ -97,11 +154,11 @@ export declare class WebRTCManager {
|
|
|
97
154
|
/**
|
|
98
155
|
* Register a callback for incoming user messages.
|
|
99
156
|
*/
|
|
100
|
-
onMessage(callback: (peerId: string, message:
|
|
157
|
+
onMessage(callback: (peerId: string, message: AvesMessage) => void): void;
|
|
101
158
|
onFileTransferStarted(callback: (peerId: string, info: FileTransferInfo) => void): void;
|
|
102
159
|
onFileTransferProgress(callback: (peerId: string, progress: FileTransferProgress) => void): void;
|
|
103
160
|
onFileTransferCompleted(callback: (peerId: string, result: FileTransferResult) => void): void;
|
|
104
|
-
onFileTransferFailed(callback: (peerId: string, info: FileTransferInfo | null, error:
|
|
161
|
+
onFileTransferFailed(callback: (peerId: string, info: FileTransferInfo | null, error: AvesError) => void): void;
|
|
105
162
|
onRemoteAudioTrack(callback: (peerId: string, stream: MediaStream, track: MediaStreamTrack) => void): void;
|
|
106
163
|
onLocalAudioStateChange(callback: (state: LocalAudioState) => void): void;
|
|
107
164
|
/**
|
|
@@ -121,6 +178,10 @@ export declare class WebRTCManager {
|
|
|
121
178
|
* Check if connected to a specific peer.
|
|
122
179
|
*/
|
|
123
180
|
isConnected(peerId: string): boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Get the actual RTCPeerConnectionState for a peer.
|
|
183
|
+
*/
|
|
184
|
+
getConnectionState(peerId: string): RTCPeerConnectionState;
|
|
124
185
|
/**
|
|
125
186
|
* Check if the main DataChannel is ready for a specific peer.
|
|
126
187
|
*/
|
|
@@ -130,33 +191,16 @@ export declare class WebRTCManager {
|
|
|
130
191
|
*/
|
|
131
192
|
isFileChannelReady(peerId: string): boolean;
|
|
132
193
|
private setupPeerConnection;
|
|
133
|
-
private createAudioSender;
|
|
134
|
-
private syncLocalAudioTrack;
|
|
135
194
|
private ensureDataChannel;
|
|
136
195
|
private setupDataChannel;
|
|
137
196
|
private handleMessageChannelMessage;
|
|
138
|
-
private sendFileToPeer;
|
|
139
197
|
private handleFileControlMessage;
|
|
140
198
|
private handleFileChunk;
|
|
141
|
-
private emitFileTransferStarted;
|
|
142
|
-
private emitFileTransferProgress;
|
|
143
199
|
private emitFileTransferFailed;
|
|
144
|
-
private emitLocalAudioState;
|
|
145
|
-
private sendFileControl;
|
|
146
|
-
private awaitTransferReady;
|
|
147
200
|
private clearReadyResolver;
|
|
148
|
-
private awaitTransferCompletion;
|
|
149
201
|
private clearCompletionResolver;
|
|
150
202
|
private getPeerConnection;
|
|
151
203
|
private getMessageChannel;
|
|
152
204
|
private getFileChannel;
|
|
153
|
-
private isFileControlMessage;
|
|
154
|
-
private getChunkSize;
|
|
155
|
-
private getBlobName;
|
|
156
|
-
private getBlobLastModified;
|
|
157
|
-
private generateTransferId;
|
|
158
|
-
private validateChunkSize;
|
|
159
205
|
private failActiveTransfers;
|
|
160
|
-
private normalizePeerChannels;
|
|
161
|
-
private isPeerChannels;
|
|
162
206
|
}
|