@whereby.com/media 3.1.1 → 5.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/dist/index.cjs +160 -229
- package/dist/index.d.cts +31 -41
- package/dist/index.d.mts +31 -41
- package/dist/index.d.ts +31 -41
- package/dist/index.mjs +160 -229
- package/dist/legacy-esm.js +160 -229
- package/package.json +1 -1
package/dist/legacy-esm.js
CHANGED
|
@@ -2210,10 +2210,6 @@ class Session {
|
|
|
2210
2210
|
});
|
|
2211
2211
|
this.wasEverConnected = false;
|
|
2212
2212
|
this.connectionStatus = null;
|
|
2213
|
-
this.stats = {
|
|
2214
|
-
totalSent: 0,
|
|
2215
|
-
totalRecv: 0,
|
|
2216
|
-
};
|
|
2217
2213
|
this.bandwidth = bandwidth || 0;
|
|
2218
2214
|
this.pending = [];
|
|
2219
2215
|
this.isOperationPending = false;
|
|
@@ -2223,25 +2219,18 @@ class Session {
|
|
|
2223
2219
|
this.afterConnected = new Promise((resolve) => {
|
|
2224
2220
|
this.registerConnected = resolve;
|
|
2225
2221
|
});
|
|
2226
|
-
this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
|
|
2227
2222
|
this._deprioritizeH264Encoding = deprioritizeH264Encoding;
|
|
2228
2223
|
this._incrementAnalyticMetric = incrementAnalyticMetric;
|
|
2229
2224
|
}
|
|
2230
2225
|
addStream(stream) {
|
|
2231
2226
|
this.streamIds.push(stream.id);
|
|
2232
2227
|
this.streams.push(stream);
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
});
|
|
2240
|
-
}
|
|
2241
|
-
else {
|
|
2242
|
-
rtcStats.sendEvent("P2PNoAddTrackSupport", {});
|
|
2243
|
-
this.pc.addStream(stream);
|
|
2244
|
-
}
|
|
2228
|
+
stream.getAudioTracks().forEach((track) => {
|
|
2229
|
+
this.pc.addTrack(track, stream);
|
|
2230
|
+
});
|
|
2231
|
+
stream.getVideoTracks().forEach((track) => {
|
|
2232
|
+
this.pc.addTrack(track, stream);
|
|
2233
|
+
});
|
|
2245
2234
|
}
|
|
2246
2235
|
addTrack(track, stream) {
|
|
2247
2236
|
if (!stream) {
|
|
@@ -2267,17 +2256,12 @@ class Session {
|
|
|
2267
2256
|
if (streamIndex !== -1) {
|
|
2268
2257
|
this.streams.splice(streamIndex, 1);
|
|
2269
2258
|
}
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
});
|
|
2277
|
-
}
|
|
2278
|
-
else if (this.pc.removeStream) {
|
|
2279
|
-
this.pc.removeStream(stream);
|
|
2280
|
-
}
|
|
2259
|
+
stream.getTracks().forEach((track) => {
|
|
2260
|
+
const sender = this.pc.getSenders().find((sender) => sender.track === track);
|
|
2261
|
+
if (sender) {
|
|
2262
|
+
this.pc.removeTrack(sender);
|
|
2263
|
+
}
|
|
2264
|
+
});
|
|
2281
2265
|
}
|
|
2282
2266
|
_setRemoteDescription(desc) {
|
|
2283
2267
|
if (this._deprioritizeH264Encoding)
|
|
@@ -2376,12 +2360,6 @@ class Session {
|
|
|
2376
2360
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2377
2361
|
logger$7.info("replacetrack() [oldTrackId: %s, newTrackId: %s]", oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id, newTrack.id);
|
|
2378
2362
|
if (newTrack.readyState === "ended") {
|
|
2379
|
-
rtcStats.sendEvent("P2PReplaceTrackNewTrackEnded", {
|
|
2380
|
-
newTrackId: newTrack.id,
|
|
2381
|
-
newTrackKind: newTrack.kind,
|
|
2382
|
-
newTrackIsEffect: trackAnnotations(newTrack).isEffectTrack,
|
|
2383
|
-
});
|
|
2384
|
-
this._incrementAnalyticMetric("P2PReplaceTrackNewTrackEnded");
|
|
2385
2363
|
throw new Error(`refusing to replace track trackId: ${newTrack.id} kind: ${newTrack.kind} with readyState: ${newTrack.readyState}`);
|
|
2386
2364
|
}
|
|
2387
2365
|
const pc = this.pc;
|
|
@@ -2396,20 +2374,6 @@ class Session {
|
|
|
2396
2374
|
return (track === null || track === void 0 ? void 0 : track.kind) === newTrack.kind && !trackAnnotations(track).fromGetDisplayMedia;
|
|
2397
2375
|
});
|
|
2398
2376
|
if (sender) {
|
|
2399
|
-
this._incrementAnalyticMetric("P2PReplaceTrackOldTrackNotFound");
|
|
2400
|
-
const track = sender.track;
|
|
2401
|
-
rtcStats.sendEvent("P2PReplaceTrackOldTrackNotFound", {
|
|
2402
|
-
targetTrackId: track === null || track === void 0 ? void 0 : track.id,
|
|
2403
|
-
targetTrackKind: track === null || track === void 0 ? void 0 : track.kind,
|
|
2404
|
-
targetTrackIsEffect: track && trackAnnotations(track).isEffectTrack,
|
|
2405
|
-
targetTrackReadyState: track === null || track === void 0 ? void 0 : track.readyState,
|
|
2406
|
-
newTrackId: newTrack.id,
|
|
2407
|
-
newTrackKind: newTrack.kind,
|
|
2408
|
-
newTrackIsEffect: trackAnnotations(newTrack).isEffectTrack,
|
|
2409
|
-
oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
|
|
2410
|
-
oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
|
|
2411
|
-
oldTrackIsEffect: oldTrack && trackAnnotations(oldTrack).isEffectTrack,
|
|
2412
|
-
});
|
|
2413
2377
|
return yield sender.replaceTrack(newTrack);
|
|
2414
2378
|
}
|
|
2415
2379
|
let stream = this.streams.find((s) => s.getTracks().find((t) => t.id === newTrack.id));
|
|
@@ -2430,15 +2394,6 @@ class Session {
|
|
|
2430
2394
|
this._incrementAnalyticMetric("P2PReplaceTrackNoStream");
|
|
2431
2395
|
throw new Error("replaceTrack: No stream?");
|
|
2432
2396
|
}
|
|
2433
|
-
rtcStats.sendEvent("P2PReplaceTrackSourceKindNotFound", {
|
|
2434
|
-
oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
|
|
2435
|
-
oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
|
|
2436
|
-
oldTrackIsEffect: oldTrack && trackAnnotations(oldTrack).isEffectTrack,
|
|
2437
|
-
newTrackId: newTrack.id,
|
|
2438
|
-
newTrackKind: newTrack.kind,
|
|
2439
|
-
newTrackIsEffect: trackAnnotations(newTrack).isEffectTrack,
|
|
2440
|
-
});
|
|
2441
|
-
this._incrementAnalyticMetric("P2PReplaceTrackSourceKindNotFound");
|
|
2442
2397
|
pc.addTrack(newTrack, stream);
|
|
2443
2398
|
});
|
|
2444
2399
|
}
|
|
@@ -2541,12 +2496,6 @@ var rtcManagerEvents = {
|
|
|
2541
2496
|
DOMINANT_SPEAKER: "dominant_speaker",
|
|
2542
2497
|
};
|
|
2543
2498
|
|
|
2544
|
-
const CAMERA_STREAM_ID = "0";
|
|
2545
|
-
const STREAM_TYPES = {
|
|
2546
|
-
webcam: "webcam",
|
|
2547
|
-
screenshare: "screenshare",
|
|
2548
|
-
};
|
|
2549
|
-
|
|
2550
2499
|
var _a$2, _b$1;
|
|
2551
2500
|
const adapter$2 = (_a$2 = adapterRaw.default) !== null && _a$2 !== void 0 ? _a$2 : adapterRaw;
|
|
2552
2501
|
const logger$6 = new Logger();
|
|
@@ -2567,8 +2516,6 @@ class P2pRtcManager {
|
|
|
2567
2516
|
this._roomName = name;
|
|
2568
2517
|
this._roomSessionId = session && session.id;
|
|
2569
2518
|
this.peerConnections = {};
|
|
2570
|
-
this.localStreams = {};
|
|
2571
|
-
this.enabledLocalStreamIds = [];
|
|
2572
2519
|
this._screenshareVideoTrackIds = [];
|
|
2573
2520
|
this._socketListenerDeregisterFunctions = [];
|
|
2574
2521
|
this._localStreamDeregisterFunction = null;
|
|
@@ -2578,7 +2525,6 @@ class P2pRtcManager {
|
|
|
2578
2525
|
this._features = features || {};
|
|
2579
2526
|
this._isAudioOnlyMode = false;
|
|
2580
2527
|
this._closed = false;
|
|
2581
|
-
this.skipEmittingServerMessageCount = 0;
|
|
2582
2528
|
this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
|
|
2583
2529
|
this._audioTrackOnEnded = () => {
|
|
2584
2530
|
rtcStats.sendEvent("audio_ended", { unloading: unloading$1 });
|
|
@@ -2613,13 +2559,8 @@ class P2pRtcManager {
|
|
|
2613
2559
|
numPcOnAnswerFailure: 0,
|
|
2614
2560
|
numPcOnOfferFailure: 0,
|
|
2615
2561
|
P2PChangeBandwidthEmptySDPType: 0,
|
|
2616
|
-
P2PSessionAlreadyCreated: 0,
|
|
2617
2562
|
P2PReplaceTrackNoStream: 0,
|
|
2618
|
-
P2PReplaceTrackNewTrackEnded: 0,
|
|
2619
2563
|
P2PReplaceTrackNewTrackNotInStream: 0,
|
|
2620
|
-
P2PReplaceTrackOldTrackNotFound: 0,
|
|
2621
|
-
P2PReplaceTrackWithoutPC: 0,
|
|
2622
|
-
P2PReplaceTrackSourceKindNotFound: 0,
|
|
2623
2564
|
P2POnTrackNoStream: 0,
|
|
2624
2565
|
P2PSetCodecPreferenceError: 0,
|
|
2625
2566
|
P2PCreateOfferNoSDP: 0,
|
|
@@ -2627,6 +2568,7 @@ class P2pRtcManager {
|
|
|
2627
2568
|
P2PMicNotWorking: 0,
|
|
2628
2569
|
P2PLocalNetworkFailed: 0,
|
|
2629
2570
|
P2PRelayedIceCandidate: 0,
|
|
2571
|
+
P2PStartScreenshareNoStream: 0,
|
|
2630
2572
|
};
|
|
2631
2573
|
}
|
|
2632
2574
|
numberOfPeerconnections() {
|
|
@@ -2635,52 +2577,64 @@ class P2pRtcManager {
|
|
|
2635
2577
|
isInitializedWith({ selfId, roomName, isSfu }) {
|
|
2636
2578
|
return this._selfId === selfId && this._roomName === roomName && !isSfu;
|
|
2637
2579
|
}
|
|
2638
|
-
|
|
2639
|
-
|
|
2580
|
+
addCameraStream(stream, { beforeEffectTracks = [] } = { beforeEffectTracks: [] }) {
|
|
2581
|
+
logger$6.info("addCameraStream: [stream.id: %s]", stream.id);
|
|
2582
|
+
if (stream === this._localCameraStream) {
|
|
2640
2583
|
return;
|
|
2641
2584
|
}
|
|
2642
|
-
this.
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
if (audioTrack) {
|
|
2648
|
-
|
|
2649
|
-
this._monitorAudioTrack(audioTrack);
|
|
2650
|
-
}
|
|
2651
|
-
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "audio");
|
|
2652
|
-
if (beforeEffectTrack) {
|
|
2653
|
-
this._monitorAudioTrack(beforeEffectTrack);
|
|
2654
|
-
}
|
|
2585
|
+
this._localCameraStream = stream;
|
|
2586
|
+
this._addStreamToPeerConnections(stream);
|
|
2587
|
+
const videoTrack = stream.getVideoTracks()[0];
|
|
2588
|
+
const audioTrack = stream.getAudioTracks()[0];
|
|
2589
|
+
if (audioTrack) {
|
|
2590
|
+
if (!trackAnnotations(audioTrack).isEffectTrack) {
|
|
2591
|
+
this._monitorAudioTrack(audioTrack);
|
|
2655
2592
|
}
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
}
|
|
2660
|
-
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "video");
|
|
2661
|
-
if (beforeEffectTrack) {
|
|
2662
|
-
this._monitorVideoTrack(beforeEffectTrack);
|
|
2663
|
-
}
|
|
2593
|
+
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "audio");
|
|
2594
|
+
if (beforeEffectTrack) {
|
|
2595
|
+
this._monitorAudioTrack(beforeEffectTrack);
|
|
2664
2596
|
}
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2597
|
+
}
|
|
2598
|
+
if (videoTrack) {
|
|
2599
|
+
if (!trackAnnotations(videoTrack).isEffectTrack) {
|
|
2600
|
+
this._monitorVideoTrack(videoTrack);
|
|
2668
2601
|
}
|
|
2669
|
-
const
|
|
2670
|
-
|
|
2671
|
-
this.
|
|
2672
|
-
}
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2602
|
+
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "video");
|
|
2603
|
+
if (beforeEffectTrack) {
|
|
2604
|
+
this._monitorVideoTrack(beforeEffectTrack);
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
this._enableStopResumeVideoForBrowserSDK(stream);
|
|
2608
|
+
}
|
|
2609
|
+
_enableStopResumeVideoForBrowserSDK(stream) {
|
|
2610
|
+
if (this._localStreamDeregisterFunction) {
|
|
2611
|
+
this._localStreamDeregisterFunction();
|
|
2612
|
+
this._localStreamDeregisterFunction = null;
|
|
2613
|
+
}
|
|
2614
|
+
const localStreamHandler = (e) => {
|
|
2615
|
+
const { enable, track } = e.detail;
|
|
2616
|
+
this._handleStopOrResumeVideo({ enable, track });
|
|
2617
|
+
};
|
|
2618
|
+
stream.addEventListener("stopresumevideo", localStreamHandler);
|
|
2619
|
+
this._localStreamDeregisterFunction = () => {
|
|
2620
|
+
stream.removeEventListener("stopresumevideo", localStreamHandler);
|
|
2621
|
+
};
|
|
2622
|
+
}
|
|
2623
|
+
addScreenshareStream(stream) {
|
|
2624
|
+
logger$6.info("addScreenshareStream() [stream.id: %s]", stream.id);
|
|
2625
|
+
if (stream === this._localScreenshareStream) {
|
|
2677
2626
|
return;
|
|
2678
2627
|
}
|
|
2628
|
+
this._localScreenshareStream = stream;
|
|
2679
2629
|
this._screenshareVideoTrackIds.push(stream.getVideoTracks()[0].id);
|
|
2680
|
-
this.
|
|
2681
|
-
|
|
2630
|
+
this._emitServerEvent(PROTOCOL_REQUESTS.START_SCREENSHARE, {
|
|
2631
|
+
streamId: stream.id,
|
|
2632
|
+
hasAudioTrack: !!stream.getAudioTracks().length,
|
|
2633
|
+
});
|
|
2634
|
+
this._addStreamToPeerConnections(stream);
|
|
2682
2635
|
}
|
|
2683
2636
|
replaceTrack(oldTrack, newTrack) {
|
|
2637
|
+
logger$6.info("replaceTrack() [kind: %s, oldTrackId: %s, newTrackId: %s]", newTrack.kind, oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id, newTrack.id);
|
|
2684
2638
|
if (newTrack.kind === "audio" && !trackAnnotations(newTrack).isEffectTrack) {
|
|
2685
2639
|
this._monitorAudioTrack(newTrack);
|
|
2686
2640
|
}
|
|
@@ -2694,6 +2648,7 @@ class P2pRtcManager {
|
|
|
2694
2648
|
this.disconnectAll();
|
|
2695
2649
|
}
|
|
2696
2650
|
disconnectAll() {
|
|
2651
|
+
logger$6.info("disconnectAll()");
|
|
2697
2652
|
Object.keys(this.peerConnections).forEach((peerConnectionId) => {
|
|
2698
2653
|
this.disconnect(peerConnectionId);
|
|
2699
2654
|
});
|
|
@@ -2719,10 +2674,11 @@ class P2pRtcManager {
|
|
|
2719
2674
|
this._updateAndScheduleMediaServersRefresh(data);
|
|
2720
2675
|
}),
|
|
2721
2676
|
this._serverSocket.on(RELAY_MESSAGES.READY_TO_RECEIVE_OFFER, (data) => {
|
|
2722
|
-
logger$6.info(`
|
|
2677
|
+
logger$6.info(`Got ready_to_receive_offer from client ${data.clientId}`);
|
|
2723
2678
|
this._connect(data.clientId);
|
|
2724
2679
|
}),
|
|
2725
2680
|
this._serverSocket.on(RELAY_MESSAGES.ICE_CANDIDATE, (data) => {
|
|
2681
|
+
logger$6.info(`Got ice_candidate from client ${data.clientId}`);
|
|
2726
2682
|
const session = this._getSession(data.clientId);
|
|
2727
2683
|
if (!session) {
|
|
2728
2684
|
logger$6.warn("No RTCPeerConnection on ICE_CANDIDATE", data);
|
|
@@ -2731,7 +2687,7 @@ class P2pRtcManager {
|
|
|
2731
2687
|
session.addIceCandidate(data.message);
|
|
2732
2688
|
}),
|
|
2733
2689
|
this._serverSocket.on(RELAY_MESSAGES.ICE_END_OF_CANDIDATES, (data) => {
|
|
2734
|
-
logger$6.info(`
|
|
2690
|
+
logger$6.info(`Got end_of_ice_candidates from client ${data.clientId}`);
|
|
2735
2691
|
const session = this._getSession(data.clientId);
|
|
2736
2692
|
if (!session) {
|
|
2737
2693
|
logger$6.warn("No RTCPeerConnection on ICE_END_OF_CANDIDATES", data);
|
|
@@ -2741,7 +2697,7 @@ class P2pRtcManager {
|
|
|
2741
2697
|
}),
|
|
2742
2698
|
this._serverSocket.on(RELAY_MESSAGES.SDP_OFFER, (data) => {
|
|
2743
2699
|
var _a, _b;
|
|
2744
|
-
logger$6.info(`
|
|
2700
|
+
logger$6.info(`Got offer from client ${data.clientId}, isInitialOffer: ${Boolean(data.message.isInitialOffer)}`);
|
|
2745
2701
|
const session = this._getSession(data.clientId);
|
|
2746
2702
|
if (!session) {
|
|
2747
2703
|
logger$6.warn("No RTCPeerConnection on SDP_OFFER", data);
|
|
@@ -2764,6 +2720,7 @@ class P2pRtcManager {
|
|
|
2764
2720
|
(_b = (_a = session
|
|
2765
2721
|
.handleOffer(sdp)
|
|
2766
2722
|
.then((answer) => {
|
|
2723
|
+
logger$6.info(`Sending answer to client ${data.clientId}`);
|
|
2767
2724
|
this._emitServerEvent(RELAY_MESSAGES.SDP_ANSWER, {
|
|
2768
2725
|
receiverId: data.clientId,
|
|
2769
2726
|
message: answer,
|
|
@@ -2774,7 +2731,7 @@ class P2pRtcManager {
|
|
|
2774
2731
|
}),
|
|
2775
2732
|
this._serverSocket.on(RELAY_MESSAGES.SDP_ANSWER, (data) => {
|
|
2776
2733
|
var _a, _b;
|
|
2777
|
-
logger$6.info(`
|
|
2734
|
+
logger$6.info(`Got answer from client ${data.clientId}`);
|
|
2778
2735
|
const session = this._getSession(data.clientId);
|
|
2779
2736
|
if (!session) {
|
|
2780
2737
|
logger$6.warn("No RTCPeerConnection on SDP_ANSWER", data);
|
|
@@ -2832,11 +2789,12 @@ class P2pRtcManager {
|
|
|
2832
2789
|
});
|
|
2833
2790
|
}
|
|
2834
2791
|
setRemoteScreenshareVideoTrackIds(remoteScreenshareVideoTrackIds = []) {
|
|
2835
|
-
|
|
2836
|
-
this._screenshareVideoTrackIds = [
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2792
|
+
var _a, _b;
|
|
2793
|
+
this._screenshareVideoTrackIds = [...remoteScreenshareVideoTrackIds];
|
|
2794
|
+
const localScreenShareTrack = (_b = (_a = this._localScreenshareStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks()) === null || _b === void 0 ? void 0 : _b[0];
|
|
2795
|
+
if (localScreenShareTrack) {
|
|
2796
|
+
this._screenshareVideoTrackIds.push(localScreenShareTrack.id);
|
|
2797
|
+
}
|
|
2840
2798
|
}
|
|
2841
2799
|
setRoomSessionId(roomSessionId) {
|
|
2842
2800
|
this._roomSessionId = roomSessionId;
|
|
@@ -2882,7 +2840,6 @@ class P2pRtcManager {
|
|
|
2882
2840
|
}
|
|
2883
2841
|
if (this._features.awaitJoinRoomFinished && !this._serverSocket.joinRoomFinished) {
|
|
2884
2842
|
rtcStats.sendEvent("skip_emitting_server_message", { eventName });
|
|
2885
|
-
this.skipEmittingServerMessageCount++;
|
|
2886
2843
|
}
|
|
2887
2844
|
else {
|
|
2888
2845
|
this._serverSocket.emit(eventName, data);
|
|
@@ -2891,34 +2848,12 @@ class P2pRtcManager {
|
|
|
2891
2848
|
_emit(eventName, data) {
|
|
2892
2849
|
this._emitter.emit(eventName, data);
|
|
2893
2850
|
}
|
|
2894
|
-
_addEnabledLocalStreamId(streamId) {
|
|
2895
|
-
this.enabledLocalStreamIds.push(streamId);
|
|
2896
|
-
}
|
|
2897
|
-
_deleteEnabledLocalStreamId(streamId) {
|
|
2898
|
-
const index = this.enabledLocalStreamIds.indexOf(streamId);
|
|
2899
|
-
if (index !== -1) {
|
|
2900
|
-
this.enabledLocalStreamIds.splice(index, 1);
|
|
2901
|
-
}
|
|
2902
|
-
}
|
|
2903
2851
|
_getSession(peerConnectionId) {
|
|
2904
2852
|
if (!(peerConnectionId in this.peerConnections)) {
|
|
2905
2853
|
return null;
|
|
2906
2854
|
}
|
|
2907
2855
|
return this.peerConnections[peerConnectionId];
|
|
2908
2856
|
}
|
|
2909
|
-
_getLocalCameraStream() {
|
|
2910
|
-
return this.localStreams[CAMERA_STREAM_ID];
|
|
2911
|
-
}
|
|
2912
|
-
_getNonLocalCameraStreamIds() {
|
|
2913
|
-
return Object.keys(this.localStreams).filter((streamId) => streamId !== CAMERA_STREAM_ID);
|
|
2914
|
-
}
|
|
2915
|
-
_isScreensharingLocally() {
|
|
2916
|
-
return this._getNonLocalCameraStreamIds().length > 0;
|
|
2917
|
-
}
|
|
2918
|
-
_getFirstLocalNonCameraStream() {
|
|
2919
|
-
const streamIds = this._getNonLocalCameraStreamIds();
|
|
2920
|
-
return streamIds.length === 0 ? null : this.localStreams[streamIds[0]];
|
|
2921
|
-
}
|
|
2922
2857
|
_createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId }) {
|
|
2923
2858
|
if (!peerConnectionId) {
|
|
2924
2859
|
throw new Error("peerConnectionId is missing");
|
|
@@ -3051,29 +2986,34 @@ class P2pRtcManager {
|
|
|
3051
2986
|
break;
|
|
3052
2987
|
}
|
|
3053
2988
|
};
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
session.addStream(localCameraStream);
|
|
2989
|
+
if (this._localCameraStream) {
|
|
2990
|
+
session.addStream(this._localCameraStream);
|
|
3057
2991
|
}
|
|
3058
|
-
|
|
3059
|
-
if (id === CAMERA_STREAM_ID) {
|
|
3060
|
-
return;
|
|
3061
|
-
}
|
|
3062
|
-
const screenshareStream = this.localStreams[id];
|
|
2992
|
+
if (this._localScreenshareStream) {
|
|
3063
2993
|
if (isOfferer) {
|
|
3064
|
-
session.addStream(
|
|
2994
|
+
session.addStream(this._localScreenshareStream);
|
|
3065
2995
|
}
|
|
3066
2996
|
else {
|
|
3067
2997
|
session.afterConnected.then(() => {
|
|
2998
|
+
if (!this._localScreenshareStream)
|
|
2999
|
+
return;
|
|
3068
3000
|
this._emitServerEvent(PROTOCOL_REQUESTS.START_SCREENSHARE, {
|
|
3069
3001
|
receiverId: session.clientId,
|
|
3070
|
-
streamId:
|
|
3071
|
-
hasAudioTrack: !!
|
|
3002
|
+
streamId: this._localScreenshareStream.id,
|
|
3003
|
+
hasAudioTrack: !!this._localScreenshareStream.getAudioTracks().length,
|
|
3004
|
+
});
|
|
3005
|
+
this._withForcedRenegotiation(session, () => {
|
|
3006
|
+
if (this._localScreenshareStream) {
|
|
3007
|
+
session.addStream(this._localScreenshareStream);
|
|
3008
|
+
}
|
|
3009
|
+
else {
|
|
3010
|
+
this.analytics.P2PStartScreenshareNoStream++;
|
|
3011
|
+
rtcStats.sendEvent("P2PStartScreenshareNoStream", {});
|
|
3012
|
+
}
|
|
3072
3013
|
});
|
|
3073
|
-
this._withForcedRenegotiation(session, () => session.addStream(screenshareStream));
|
|
3074
3014
|
});
|
|
3075
3015
|
}
|
|
3076
|
-
}
|
|
3016
|
+
}
|
|
3077
3017
|
return session;
|
|
3078
3018
|
}
|
|
3079
3019
|
_cleanup(peerConnectionId) {
|
|
@@ -3107,11 +3047,6 @@ class P2pRtcManager {
|
|
|
3107
3047
|
if (session.pc.connectionState === "closed")
|
|
3108
3048
|
return;
|
|
3109
3049
|
logger$6.info("Session doesn't have a connected PeerConnection, adding pending action!");
|
|
3110
|
-
this.analytics.P2PReplaceTrackWithoutPC++;
|
|
3111
|
-
rtcStats.sendEvent("P2PReplaceTrackWithoutPC", {
|
|
3112
|
-
connectionState: session.pc.connectionState,
|
|
3113
|
-
iceConnectionState: session.pc.iceConnectionState,
|
|
3114
|
-
});
|
|
3115
3050
|
const promise = new Promise((resolve, reject) => {
|
|
3116
3051
|
const action = () => __awaiter(this, void 0, void 0, function* () {
|
|
3117
3052
|
try {
|
|
@@ -3143,14 +3078,6 @@ class P2pRtcManager {
|
|
|
3143
3078
|
this._withForcedRenegotiation(session, () => session.removeTrack(track));
|
|
3144
3079
|
});
|
|
3145
3080
|
}
|
|
3146
|
-
_addLocalStream(streamId, stream) {
|
|
3147
|
-
this._addEnabledLocalStreamId(streamId);
|
|
3148
|
-
this.localStreams[streamId] = stream;
|
|
3149
|
-
}
|
|
3150
|
-
_removeLocalStream(streamId) {
|
|
3151
|
-
delete this.localStreams[streamId];
|
|
3152
|
-
this._deleteEnabledLocalStreamId(streamId);
|
|
3153
|
-
}
|
|
3154
3081
|
_updateAndScheduleMediaServersRefresh({ iceServers, turnServers, mediaserverConfigTtlSeconds, }) {
|
|
3155
3082
|
this._iceServers = iceServers;
|
|
3156
3083
|
this._turnServers = turnServers;
|
|
@@ -3311,6 +3238,7 @@ class P2pRtcManager {
|
|
|
3311
3238
|
type: offer.type,
|
|
3312
3239
|
isInitialOffer,
|
|
3313
3240
|
};
|
|
3241
|
+
logger$6.info(`sending offer to client ${clientId}`);
|
|
3314
3242
|
this._emitServerEvent(RELAY_MESSAGES.SDP_OFFER, {
|
|
3315
3243
|
receiverId: clientId,
|
|
3316
3244
|
message,
|
|
@@ -3360,6 +3288,7 @@ class P2pRtcManager {
|
|
|
3360
3288
|
return bandwidth;
|
|
3361
3289
|
}
|
|
3362
3290
|
_createP2pSession({ clientId, initialBandwidth, isOfferer = false, }) {
|
|
3291
|
+
var _a, _b;
|
|
3363
3292
|
const session = this._createSession({
|
|
3364
3293
|
peerConnectionId: clientId,
|
|
3365
3294
|
clientId,
|
|
@@ -3370,9 +3299,8 @@ class P2pRtcManager {
|
|
|
3370
3299
|
if (this._features.increaseIncomingMediaBufferOn) {
|
|
3371
3300
|
this._setJitterBufferTarget(pc);
|
|
3372
3301
|
}
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
pc.addTrack(this._stoppedVideoTrack, localCameraStream);
|
|
3302
|
+
if (((_b = (_a = this._localCameraStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks()) === null || _b === void 0 ? void 0 : _b.length) && this._stoppedVideoTrack) {
|
|
3303
|
+
pc.addTrack(this._stoppedVideoTrack, this._localCameraStream);
|
|
3376
3304
|
}
|
|
3377
3305
|
pc.onicegatheringstatechange = (event) => {
|
|
3378
3306
|
const connection = event.target;
|
|
@@ -3476,11 +3404,13 @@ class P2pRtcManager {
|
|
|
3476
3404
|
if (pc.iceConnectionState === "new" || !session.connectionStatus) {
|
|
3477
3405
|
return;
|
|
3478
3406
|
}
|
|
3407
|
+
logger$6.info(`onnegotiationneeded client ${clientId}`);
|
|
3479
3408
|
this._negotiatePeerConnection({ clientId, session });
|
|
3480
3409
|
};
|
|
3481
3410
|
return session;
|
|
3482
3411
|
}
|
|
3483
3412
|
acceptNewStream({ streamId, clientId }) {
|
|
3413
|
+
logger$6.info("acceptNewStream() [streamId: %s}, clientId: %s]", streamId, clientId);
|
|
3484
3414
|
let session = this._getSession(clientId);
|
|
3485
3415
|
if (session && streamId !== clientId) {
|
|
3486
3416
|
return session;
|
|
@@ -3503,6 +3433,7 @@ class P2pRtcManager {
|
|
|
3503
3433
|
return session;
|
|
3504
3434
|
}
|
|
3505
3435
|
disconnect(clientId) {
|
|
3436
|
+
logger$6.info("disconnect() [clientId: %s]", clientId);
|
|
3506
3437
|
this._cleanup(clientId);
|
|
3507
3438
|
this._changeBandwidthForAllClients(false);
|
|
3508
3439
|
const numPeers = this.numberOfPeerconnections();
|
|
@@ -3534,6 +3465,7 @@ class P2pRtcManager {
|
|
|
3534
3465
|
}
|
|
3535
3466
|
stopOrResumeVideo(localStream, enable) {
|
|
3536
3467
|
var _a;
|
|
3468
|
+
logger$6.info("stopOrResumeVideo() [enable: %s]", enable);
|
|
3537
3469
|
if (!["chrome", "safari"].includes(browserName$1)) {
|
|
3538
3470
|
return;
|
|
3539
3471
|
}
|
|
@@ -3582,19 +3514,11 @@ class P2pRtcManager {
|
|
|
3582
3514
|
}
|
|
3583
3515
|
}
|
|
3584
3516
|
}
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
streamId,
|
|
3588
|
-
hasAudioTrack: !!stream.getAudioTracks().length,
|
|
3589
|
-
});
|
|
3590
|
-
this._wasScreenSharing = true;
|
|
3591
|
-
this._addStreamToPeerConnections(stream);
|
|
3592
|
-
}
|
|
3593
|
-
removeStream(streamId, stream, requestedByClientId) {
|
|
3594
|
-
this._removeLocalStream(streamId);
|
|
3517
|
+
removeScreenshareStream(stream, { requestedByClientId } = {}) {
|
|
3518
|
+
logger$6.info("removeScreenshareStream() [stream.id: %s, requestedByClientId: %s]", stream.id, requestedByClientId);
|
|
3595
3519
|
this._removeStreamFromPeerConnections(stream);
|
|
3596
|
-
this.
|
|
3597
|
-
this.
|
|
3520
|
+
this._emitServerEvent(PROTOCOL_REQUESTS.STOP_SCREENSHARE, { streamId: stream.id, requestedByClientId });
|
|
3521
|
+
delete this._localScreenshareStream;
|
|
3598
3522
|
}
|
|
3599
3523
|
hasClient(clientId) {
|
|
3600
3524
|
return Object.keys(this.peerConnections).includes(clientId);
|
|
@@ -4426,6 +4350,12 @@ function createVegaConnectionManager(config) {
|
|
|
4426
4350
|
return { connect, updateHostList, networkIsUp, networkIsPossiblyDown };
|
|
4427
4351
|
}
|
|
4428
4352
|
|
|
4353
|
+
const CAMERA_STREAM_ID = "0";
|
|
4354
|
+
const STREAM_TYPES = {
|
|
4355
|
+
webcam: "webcam",
|
|
4356
|
+
screenshare: "screenshare",
|
|
4357
|
+
};
|
|
4358
|
+
|
|
4429
4359
|
var _a$1;
|
|
4430
4360
|
const adapter$1 = (_a$1 = adapterRaw.default) !== null && _a$1 !== void 0 ? _a$1 : adapterRaw;
|
|
4431
4361
|
const logger$2 = new Logger();
|
|
@@ -5369,7 +5299,7 @@ class VegaRtcManager {
|
|
|
5369
5299
|
(_a = this._vegaConnection) === null || _a === void 0 ? void 0 : _a.message("eventClaim", { eventClaim });
|
|
5370
5300
|
}
|
|
5371
5301
|
}
|
|
5372
|
-
replaceTrack(
|
|
5302
|
+
replaceTrack(_, track) {
|
|
5373
5303
|
if (track.kind === "audio") {
|
|
5374
5304
|
if (!trackAnnotations(track).isEffectTrack) {
|
|
5375
5305
|
this._monitorAudioTrack(track);
|
|
@@ -5385,8 +5315,8 @@ class VegaRtcManager {
|
|
|
5385
5315
|
this._replaceWebcamTrack();
|
|
5386
5316
|
}
|
|
5387
5317
|
}
|
|
5388
|
-
|
|
5389
|
-
logger$2.info("
|
|
5318
|
+
removeScreenshareStream(stream, { requestedByClientId } = { requestedByClientId: undefined }) {
|
|
5319
|
+
logger$2.info("removeScreenshareStream() [streamId:%s, requestedByClientId:%s]", stream.id, requestedByClientId);
|
|
5390
5320
|
this._emitToSignal(PROTOCOL_REQUESTS.STOP_SCREENSHARE, {
|
|
5391
5321
|
streamId: OUTBOUND_SCREEN_OUTBOUND_STREAM_ID,
|
|
5392
5322
|
requestedByClientId,
|
|
@@ -5403,57 +5333,58 @@ class VegaRtcManager {
|
|
|
5403
5333
|
(_b = (_a = this._micAnalyserDebugger) === null || _a === void 0 ? void 0 : _a.onScoreUpdated) === null || _b === void 0 ? void 0 : _b.call(_a, data);
|
|
5404
5334
|
this._sendMicScore(this._micPaused ? 0 : data.out);
|
|
5405
5335
|
}
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
this._monitorVideoTrack(videoTrack);
|
|
5416
|
-
}
|
|
5417
|
-
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "video");
|
|
5418
|
-
if (beforeEffectTrack) {
|
|
5419
|
-
this._monitorVideoTrack(beforeEffectTrack);
|
|
5420
|
-
}
|
|
5336
|
+
addCameraStream(stream, { audioPaused, videoPaused, beforeEffectTracks = [] } = { beforeEffectTracks: [] }) {
|
|
5337
|
+
this._micPaused = audioPaused;
|
|
5338
|
+
this._webcamPaused = videoPaused;
|
|
5339
|
+
const videoTrack = stream.getVideoTracks()[0];
|
|
5340
|
+
const audioTrack = stream.getAudioTracks()[0];
|
|
5341
|
+
if (videoTrack) {
|
|
5342
|
+
this._sendWebcam(videoTrack);
|
|
5343
|
+
if (!trackAnnotations(videoTrack).isEffectTrack) {
|
|
5344
|
+
this._monitorVideoTrack(videoTrack);
|
|
5421
5345
|
}
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
this.
|
|
5425
|
-
if (!trackAnnotations(audioTrack).isEffectTrack) {
|
|
5426
|
-
this._monitorAudioTrack(audioTrack);
|
|
5427
|
-
}
|
|
5428
|
-
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "audio");
|
|
5429
|
-
if (beforeEffectTrack) {
|
|
5430
|
-
this._monitorAudioTrack(beforeEffectTrack);
|
|
5431
|
-
}
|
|
5346
|
+
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "video");
|
|
5347
|
+
if (beforeEffectTrack) {
|
|
5348
|
+
this._monitorVideoTrack(beforeEffectTrack);
|
|
5432
5349
|
}
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5350
|
+
}
|
|
5351
|
+
if (audioTrack) {
|
|
5352
|
+
this._sendMic(audioTrack);
|
|
5353
|
+
this._syncMicAnalyser();
|
|
5354
|
+
if (!trackAnnotations(audioTrack).isEffectTrack) {
|
|
5355
|
+
this._monitorAudioTrack(audioTrack);
|
|
5356
|
+
}
|
|
5357
|
+
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "audio");
|
|
5358
|
+
if (beforeEffectTrack) {
|
|
5359
|
+
this._monitorAudioTrack(beforeEffectTrack);
|
|
5436
5360
|
}
|
|
5437
|
-
const localStreamHandler = (e) => {
|
|
5438
|
-
const { enable, track } = e.detail;
|
|
5439
|
-
this._webcamPaused = !enable;
|
|
5440
|
-
this._pauseResumeWebcam();
|
|
5441
|
-
this._handleStopOrResumeVideo({ enable, track });
|
|
5442
|
-
};
|
|
5443
|
-
stream.addEventListener("stopresumevideo", localStreamHandler);
|
|
5444
|
-
this._localStreamDeregisterFunction = () => {
|
|
5445
|
-
stream.removeEventListener("stopresumevideo", localStreamHandler);
|
|
5446
|
-
};
|
|
5447
5361
|
}
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
this._sendScreenAudio(audioTrack);
|
|
5455
|
-
this._emitScreenshareStarted();
|
|
5362
|
+
this._enableStopResumeVideoForBrowserSDK(stream);
|
|
5363
|
+
}
|
|
5364
|
+
_enableStopResumeVideoForBrowserSDK(stream) {
|
|
5365
|
+
if (this._localStreamDeregisterFunction) {
|
|
5366
|
+
this._localStreamDeregisterFunction();
|
|
5367
|
+
this._localStreamDeregisterFunction = null;
|
|
5456
5368
|
}
|
|
5369
|
+
const localStreamHandler = (e) => {
|
|
5370
|
+
const { enable, track } = e.detail;
|
|
5371
|
+
this._webcamPaused = !enable;
|
|
5372
|
+
this._pauseResumeWebcam();
|
|
5373
|
+
this._handleStopOrResumeVideo({ enable, track });
|
|
5374
|
+
};
|
|
5375
|
+
stream.addEventListener("stopresumevideo", localStreamHandler);
|
|
5376
|
+
this._localStreamDeregisterFunction = () => {
|
|
5377
|
+
stream.removeEventListener("stopresumevideo", localStreamHandler);
|
|
5378
|
+
};
|
|
5379
|
+
}
|
|
5380
|
+
addScreenshareStream(stream) {
|
|
5381
|
+
const videoTrack = stream.getVideoTracks()[0];
|
|
5382
|
+
const audioTrack = stream.getAudioTracks()[0];
|
|
5383
|
+
if (videoTrack)
|
|
5384
|
+
this._sendScreenVideo(videoTrack);
|
|
5385
|
+
if (audioTrack)
|
|
5386
|
+
this._sendScreenAudio(audioTrack);
|
|
5387
|
+
this._emitScreenshareStarted();
|
|
5457
5388
|
}
|
|
5458
5389
|
_syncMicAnalyser() {
|
|
5459
5390
|
if (this._micTrack && this._colocation && !this._micAnalyser) {
|