@yrzhao/aves-core 1.0.0 → 1.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/dist/core/AvesClient.js +1 -1
- package/dist/core/WebRTCManager.d.ts +6 -0
- package/dist/core/WebRTCManager.js +19 -2
- package/dist/core/webrtc/mediaTracks.d.ts +2 -0
- package/dist/core/webrtc/mediaTracks.js +24 -6
- package/dist/esm/core/AvesClient.js +1 -1
- package/dist/esm/core/WebRTCManager.d.ts +6 -0
- package/dist/esm/core/WebRTCManager.js +19 -2
- package/dist/esm/core/webrtc/mediaTracks.d.ts +2 -0
- package/dist/esm/core/webrtc/mediaTracks.js +24 -6
- package/package.json +1 -1
package/dist/core/AvesClient.js
CHANGED
|
@@ -141,7 +141,7 @@ class AvesClient extends EventEmitter_1.EventEmitter {
|
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
143
|
try {
|
|
144
|
-
this.webrtcManager.
|
|
144
|
+
this.webrtcManager.closeAllPeerConnections();
|
|
145
145
|
this.participants.clear();
|
|
146
146
|
this.preparedPeers.clear();
|
|
147
147
|
const joinResult = await this.signalingClient.joinRoom(this.currentRoomId, this.currentUserId, this.currentUserName);
|
|
@@ -165,6 +165,11 @@ export declare class WebRTCManager {
|
|
|
165
165
|
* Close the connection with a specific peer.
|
|
166
166
|
*/
|
|
167
167
|
closePeerConnection(peerId: string): void;
|
|
168
|
+
/**
|
|
169
|
+
* Close all peer connections while preserving local media capture.
|
|
170
|
+
* Used during signaling reconnect restore so camera/mic intent survives.
|
|
171
|
+
*/
|
|
172
|
+
closeAllPeerConnections(): void;
|
|
168
173
|
/**
|
|
169
174
|
* Close all connections and clean up resources.
|
|
170
175
|
*/
|
|
@@ -193,6 +198,7 @@ export declare class WebRTCManager {
|
|
|
193
198
|
private setupPeerConnection;
|
|
194
199
|
private ensureDataChannel;
|
|
195
200
|
private setupDataChannel;
|
|
201
|
+
private isCurrentDataChannel;
|
|
196
202
|
private handleMessageChannelMessage;
|
|
197
203
|
private handleFileControlMessage;
|
|
198
204
|
private handleFileChunk;
|
|
@@ -336,12 +336,19 @@ class WebRTCManager {
|
|
|
336
336
|
this.iceCandidateCallbacks.delete(peerId);
|
|
337
337
|
}
|
|
338
338
|
/**
|
|
339
|
-
* Close all connections
|
|
339
|
+
* Close all peer connections while preserving local media capture.
|
|
340
|
+
* Used during signaling reconnect restore so camera/mic intent survives.
|
|
340
341
|
*/
|
|
341
|
-
|
|
342
|
+
closeAllPeerConnections() {
|
|
342
343
|
this.getActivePeers().forEach((peerId) => {
|
|
343
344
|
this.closePeerConnection(peerId);
|
|
344
345
|
});
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Close all connections and clean up resources.
|
|
349
|
+
*/
|
|
350
|
+
closeAll() {
|
|
351
|
+
this.closeAllPeerConnections();
|
|
345
352
|
this.stopVoice();
|
|
346
353
|
this.stopVideo();
|
|
347
354
|
this.stopScreenShare();
|
|
@@ -449,6 +456,9 @@ class WebRTCManager {
|
|
|
449
456
|
}
|
|
450
457
|
};
|
|
451
458
|
dataChannel.onerror = (error) => {
|
|
459
|
+
if (!this.isCurrentDataChannel(peerId, kind, dataChannel)) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
452
462
|
this.emitError(new AvesError_1.AvesError({ message: `DataChannel error with ${peerId}: ${(0, messages_1.errorMessage)(error)}`, code: "WEBRTC_DATACHANNEL_FAILED", stage: "transport", retryable: true, peerId }));
|
|
453
463
|
const transfer = kind === "file"
|
|
454
464
|
? this.outgoingTransfers.get(peerId) ?? this.incomingTransfers.get(peerId) ?? null
|
|
@@ -465,6 +475,13 @@ class WebRTCManager {
|
|
|
465
475
|
this.handleMessageChannelMessage(peerId, event.data);
|
|
466
476
|
};
|
|
467
477
|
}
|
|
478
|
+
isCurrentDataChannel(peerId, kind, dataChannel) {
|
|
479
|
+
if (!this.peerConnections.has(peerId)) {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
const channels = (0, channels_1.normalizePeerChannels)(this.dataChannels.get(peerId));
|
|
483
|
+
return channels[kind] === dataChannel;
|
|
484
|
+
}
|
|
468
485
|
handleMessageChannelMessage(peerId, rawData) {
|
|
469
486
|
try {
|
|
470
487
|
const message = JSON.parse(rawData);
|
|
@@ -47,6 +47,8 @@ export declare class MediaTrackManager {
|
|
|
47
47
|
private createTransceiverSender;
|
|
48
48
|
private syncLocalAudioTrack;
|
|
49
49
|
private syncLocalVideoTrack;
|
|
50
|
+
private getOutgoingVideoTrack;
|
|
51
|
+
private getOutgoingVideoStream;
|
|
50
52
|
private emitLocalAudioState;
|
|
51
53
|
private emitLocalVideoState;
|
|
52
54
|
private emitScreenShareState;
|
|
@@ -52,6 +52,7 @@ class MediaTrackManager {
|
|
|
52
52
|
this.audioSenders.set(peerId, this.createTransceiverSender(pc, "audio"));
|
|
53
53
|
this.videoSenders.set(peerId, this.createTransceiverSender(pc, "video"));
|
|
54
54
|
void this.syncLocalAudioTrack(peerId);
|
|
55
|
+
void this.syncLocalVideoTrack(peerId);
|
|
55
56
|
}
|
|
56
57
|
async startVoice() {
|
|
57
58
|
if (this.localAudioStream && this.localAudioTrack) {
|
|
@@ -351,24 +352,41 @@ class MediaTrackManager {
|
|
|
351
352
|
if (!pc) {
|
|
352
353
|
return;
|
|
353
354
|
}
|
|
355
|
+
const outgoingTrack = this.getOutgoingVideoTrack();
|
|
354
356
|
let sender = this.videoSenders.get(peerId) ?? null;
|
|
355
357
|
if (sender && typeof sender.replaceTrack === "function") {
|
|
356
|
-
await sender.replaceTrack(
|
|
358
|
+
await sender.replaceTrack(outgoingTrack);
|
|
357
359
|
return;
|
|
358
360
|
}
|
|
359
361
|
const addTrackCapable = pc;
|
|
360
|
-
if (
|
|
362
|
+
if (outgoingTrack &&
|
|
361
363
|
typeof addTrackCapable.addTrack === "function") {
|
|
362
|
-
const stream = this.
|
|
364
|
+
const stream = this.getOutgoingVideoStream() ??
|
|
363
365
|
(typeof MediaStream !== "undefined"
|
|
364
|
-
? new MediaStream([
|
|
366
|
+
? new MediaStream([outgoingTrack])
|
|
365
367
|
: undefined);
|
|
366
368
|
sender = stream
|
|
367
|
-
? addTrackCapable.addTrack(
|
|
368
|
-
: addTrackCapable.addTrack(
|
|
369
|
+
? addTrackCapable.addTrack(outgoingTrack, stream)
|
|
370
|
+
: addTrackCapable.addTrack(outgoingTrack);
|
|
369
371
|
this.videoSenders.set(peerId, sender);
|
|
370
372
|
}
|
|
371
373
|
}
|
|
374
|
+
getOutgoingVideoTrack() {
|
|
375
|
+
if (this.screenShareActive &&
|
|
376
|
+
this.screenShareTrack &&
|
|
377
|
+
this.screenShareTrack.readyState === "live") {
|
|
378
|
+
return this.screenShareTrack;
|
|
379
|
+
}
|
|
380
|
+
return this.localVideoTrack;
|
|
381
|
+
}
|
|
382
|
+
getOutgoingVideoStream() {
|
|
383
|
+
if (this.screenShareActive &&
|
|
384
|
+
this.screenShareStream &&
|
|
385
|
+
this.screenShareTrack?.readyState === "live") {
|
|
386
|
+
return this.screenShareStream;
|
|
387
|
+
}
|
|
388
|
+
return this.localVideoStream;
|
|
389
|
+
}
|
|
372
390
|
emitLocalAudioState() {
|
|
373
391
|
const state = this.getLocalAudioState();
|
|
374
392
|
this.localAudioStateCallbacks.forEach((callback) => callback(state));
|
|
@@ -138,7 +138,7 @@ export class AvesClient extends EventEmitter {
|
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
140
|
try {
|
|
141
|
-
this.webrtcManager.
|
|
141
|
+
this.webrtcManager.closeAllPeerConnections();
|
|
142
142
|
this.participants.clear();
|
|
143
143
|
this.preparedPeers.clear();
|
|
144
144
|
const joinResult = await this.signalingClient.joinRoom(this.currentRoomId, this.currentUserId, this.currentUserName);
|
|
@@ -165,6 +165,11 @@ export declare class WebRTCManager {
|
|
|
165
165
|
* Close the connection with a specific peer.
|
|
166
166
|
*/
|
|
167
167
|
closePeerConnection(peerId: string): void;
|
|
168
|
+
/**
|
|
169
|
+
* Close all peer connections while preserving local media capture.
|
|
170
|
+
* Used during signaling reconnect restore so camera/mic intent survives.
|
|
171
|
+
*/
|
|
172
|
+
closeAllPeerConnections(): void;
|
|
168
173
|
/**
|
|
169
174
|
* Close all connections and clean up resources.
|
|
170
175
|
*/
|
|
@@ -193,6 +198,7 @@ export declare class WebRTCManager {
|
|
|
193
198
|
private setupPeerConnection;
|
|
194
199
|
private ensureDataChannel;
|
|
195
200
|
private setupDataChannel;
|
|
201
|
+
private isCurrentDataChannel;
|
|
196
202
|
private handleMessageChannelMessage;
|
|
197
203
|
private handleFileControlMessage;
|
|
198
204
|
private handleFileChunk;
|
|
@@ -333,12 +333,19 @@ export class WebRTCManager {
|
|
|
333
333
|
this.iceCandidateCallbacks.delete(peerId);
|
|
334
334
|
}
|
|
335
335
|
/**
|
|
336
|
-
* Close all connections
|
|
336
|
+
* Close all peer connections while preserving local media capture.
|
|
337
|
+
* Used during signaling reconnect restore so camera/mic intent survives.
|
|
337
338
|
*/
|
|
338
|
-
|
|
339
|
+
closeAllPeerConnections() {
|
|
339
340
|
this.getActivePeers().forEach((peerId) => {
|
|
340
341
|
this.closePeerConnection(peerId);
|
|
341
342
|
});
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Close all connections and clean up resources.
|
|
346
|
+
*/
|
|
347
|
+
closeAll() {
|
|
348
|
+
this.closeAllPeerConnections();
|
|
342
349
|
this.stopVoice();
|
|
343
350
|
this.stopVideo();
|
|
344
351
|
this.stopScreenShare();
|
|
@@ -446,6 +453,9 @@ export class WebRTCManager {
|
|
|
446
453
|
}
|
|
447
454
|
};
|
|
448
455
|
dataChannel.onerror = (error) => {
|
|
456
|
+
if (!this.isCurrentDataChannel(peerId, kind, dataChannel)) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
449
459
|
this.emitError(new AvesError({ message: `DataChannel error with ${peerId}: ${errorMessage(error)}`, code: "WEBRTC_DATACHANNEL_FAILED", stage: "transport", retryable: true, peerId }));
|
|
450
460
|
const transfer = kind === "file"
|
|
451
461
|
? this.outgoingTransfers.get(peerId) ?? this.incomingTransfers.get(peerId) ?? null
|
|
@@ -462,6 +472,13 @@ export class WebRTCManager {
|
|
|
462
472
|
this.handleMessageChannelMessage(peerId, event.data);
|
|
463
473
|
};
|
|
464
474
|
}
|
|
475
|
+
isCurrentDataChannel(peerId, kind, dataChannel) {
|
|
476
|
+
if (!this.peerConnections.has(peerId)) {
|
|
477
|
+
return false;
|
|
478
|
+
}
|
|
479
|
+
const channels = normalizePeerChannels(this.dataChannels.get(peerId));
|
|
480
|
+
return channels[kind] === dataChannel;
|
|
481
|
+
}
|
|
465
482
|
handleMessageChannelMessage(peerId, rawData) {
|
|
466
483
|
try {
|
|
467
484
|
const message = JSON.parse(rawData);
|
|
@@ -47,6 +47,8 @@ export declare class MediaTrackManager {
|
|
|
47
47
|
private createTransceiverSender;
|
|
48
48
|
private syncLocalAudioTrack;
|
|
49
49
|
private syncLocalVideoTrack;
|
|
50
|
+
private getOutgoingVideoTrack;
|
|
51
|
+
private getOutgoingVideoStream;
|
|
50
52
|
private emitLocalAudioState;
|
|
51
53
|
private emitLocalVideoState;
|
|
52
54
|
private emitScreenShareState;
|
|
@@ -49,6 +49,7 @@ export class MediaTrackManager {
|
|
|
49
49
|
this.audioSenders.set(peerId, this.createTransceiverSender(pc, "audio"));
|
|
50
50
|
this.videoSenders.set(peerId, this.createTransceiverSender(pc, "video"));
|
|
51
51
|
void this.syncLocalAudioTrack(peerId);
|
|
52
|
+
void this.syncLocalVideoTrack(peerId);
|
|
52
53
|
}
|
|
53
54
|
async startVoice() {
|
|
54
55
|
if (this.localAudioStream && this.localAudioTrack) {
|
|
@@ -348,24 +349,41 @@ export class MediaTrackManager {
|
|
|
348
349
|
if (!pc) {
|
|
349
350
|
return;
|
|
350
351
|
}
|
|
352
|
+
const outgoingTrack = this.getOutgoingVideoTrack();
|
|
351
353
|
let sender = this.videoSenders.get(peerId) ?? null;
|
|
352
354
|
if (sender && typeof sender.replaceTrack === "function") {
|
|
353
|
-
await sender.replaceTrack(
|
|
355
|
+
await sender.replaceTrack(outgoingTrack);
|
|
354
356
|
return;
|
|
355
357
|
}
|
|
356
358
|
const addTrackCapable = pc;
|
|
357
|
-
if (
|
|
359
|
+
if (outgoingTrack &&
|
|
358
360
|
typeof addTrackCapable.addTrack === "function") {
|
|
359
|
-
const stream = this.
|
|
361
|
+
const stream = this.getOutgoingVideoStream() ??
|
|
360
362
|
(typeof MediaStream !== "undefined"
|
|
361
|
-
? new MediaStream([
|
|
363
|
+
? new MediaStream([outgoingTrack])
|
|
362
364
|
: undefined);
|
|
363
365
|
sender = stream
|
|
364
|
-
? addTrackCapable.addTrack(
|
|
365
|
-
: addTrackCapable.addTrack(
|
|
366
|
+
? addTrackCapable.addTrack(outgoingTrack, stream)
|
|
367
|
+
: addTrackCapable.addTrack(outgoingTrack);
|
|
366
368
|
this.videoSenders.set(peerId, sender);
|
|
367
369
|
}
|
|
368
370
|
}
|
|
371
|
+
getOutgoingVideoTrack() {
|
|
372
|
+
if (this.screenShareActive &&
|
|
373
|
+
this.screenShareTrack &&
|
|
374
|
+
this.screenShareTrack.readyState === "live") {
|
|
375
|
+
return this.screenShareTrack;
|
|
376
|
+
}
|
|
377
|
+
return this.localVideoTrack;
|
|
378
|
+
}
|
|
379
|
+
getOutgoingVideoStream() {
|
|
380
|
+
if (this.screenShareActive &&
|
|
381
|
+
this.screenShareStream &&
|
|
382
|
+
this.screenShareTrack?.readyState === "live") {
|
|
383
|
+
return this.screenShareStream;
|
|
384
|
+
}
|
|
385
|
+
return this.localVideoStream;
|
|
386
|
+
}
|
|
369
387
|
emitLocalAudioState() {
|
|
370
388
|
const state = this.getLocalAudioState();
|
|
371
389
|
this.localAudioStateCallbacks.forEach((callback) => callback(state));
|