@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/index.cjs
CHANGED
|
@@ -2231,10 +2231,6 @@ class Session {
|
|
|
2231
2231
|
});
|
|
2232
2232
|
this.wasEverConnected = false;
|
|
2233
2233
|
this.connectionStatus = null;
|
|
2234
|
-
this.stats = {
|
|
2235
|
-
totalSent: 0,
|
|
2236
|
-
totalRecv: 0,
|
|
2237
|
-
};
|
|
2238
2234
|
this.bandwidth = bandwidth || 0;
|
|
2239
2235
|
this.pending = [];
|
|
2240
2236
|
this.isOperationPending = false;
|
|
@@ -2244,25 +2240,18 @@ class Session {
|
|
|
2244
2240
|
this.afterConnected = new Promise((resolve) => {
|
|
2245
2241
|
this.registerConnected = resolve;
|
|
2246
2242
|
});
|
|
2247
|
-
this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
|
|
2248
2243
|
this._deprioritizeH264Encoding = deprioritizeH264Encoding;
|
|
2249
2244
|
this._incrementAnalyticMetric = incrementAnalyticMetric;
|
|
2250
2245
|
}
|
|
2251
2246
|
addStream(stream) {
|
|
2252
2247
|
this.streamIds.push(stream.id);
|
|
2253
2248
|
this.streams.push(stream);
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
});
|
|
2261
|
-
}
|
|
2262
|
-
else {
|
|
2263
|
-
rtcStats.sendEvent("P2PNoAddTrackSupport", {});
|
|
2264
|
-
this.pc.addStream(stream);
|
|
2265
|
-
}
|
|
2249
|
+
stream.getAudioTracks().forEach((track) => {
|
|
2250
|
+
this.pc.addTrack(track, stream);
|
|
2251
|
+
});
|
|
2252
|
+
stream.getVideoTracks().forEach((track) => {
|
|
2253
|
+
this.pc.addTrack(track, stream);
|
|
2254
|
+
});
|
|
2266
2255
|
}
|
|
2267
2256
|
addTrack(track, stream) {
|
|
2268
2257
|
if (!stream) {
|
|
@@ -2288,17 +2277,12 @@ class Session {
|
|
|
2288
2277
|
if (streamIndex !== -1) {
|
|
2289
2278
|
this.streams.splice(streamIndex, 1);
|
|
2290
2279
|
}
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
});
|
|
2298
|
-
}
|
|
2299
|
-
else if (this.pc.removeStream) {
|
|
2300
|
-
this.pc.removeStream(stream);
|
|
2301
|
-
}
|
|
2280
|
+
stream.getTracks().forEach((track) => {
|
|
2281
|
+
const sender = this.pc.getSenders().find((sender) => sender.track === track);
|
|
2282
|
+
if (sender) {
|
|
2283
|
+
this.pc.removeTrack(sender);
|
|
2284
|
+
}
|
|
2285
|
+
});
|
|
2302
2286
|
}
|
|
2303
2287
|
_setRemoteDescription(desc) {
|
|
2304
2288
|
if (this._deprioritizeH264Encoding)
|
|
@@ -2397,12 +2381,6 @@ class Session {
|
|
|
2397
2381
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2398
2382
|
logger$7.info("replacetrack() [oldTrackId: %s, newTrackId: %s]", oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id, newTrack.id);
|
|
2399
2383
|
if (newTrack.readyState === "ended") {
|
|
2400
|
-
rtcStats.sendEvent("P2PReplaceTrackNewTrackEnded", {
|
|
2401
|
-
newTrackId: newTrack.id,
|
|
2402
|
-
newTrackKind: newTrack.kind,
|
|
2403
|
-
newTrackIsEffect: trackAnnotations(newTrack).isEffectTrack,
|
|
2404
|
-
});
|
|
2405
|
-
this._incrementAnalyticMetric("P2PReplaceTrackNewTrackEnded");
|
|
2406
2384
|
throw new Error(`refusing to replace track trackId: ${newTrack.id} kind: ${newTrack.kind} with readyState: ${newTrack.readyState}`);
|
|
2407
2385
|
}
|
|
2408
2386
|
const pc = this.pc;
|
|
@@ -2417,20 +2395,6 @@ class Session {
|
|
|
2417
2395
|
return (track === null || track === void 0 ? void 0 : track.kind) === newTrack.kind && !trackAnnotations(track).fromGetDisplayMedia;
|
|
2418
2396
|
});
|
|
2419
2397
|
if (sender) {
|
|
2420
|
-
this._incrementAnalyticMetric("P2PReplaceTrackOldTrackNotFound");
|
|
2421
|
-
const track = sender.track;
|
|
2422
|
-
rtcStats.sendEvent("P2PReplaceTrackOldTrackNotFound", {
|
|
2423
|
-
targetTrackId: track === null || track === void 0 ? void 0 : track.id,
|
|
2424
|
-
targetTrackKind: track === null || track === void 0 ? void 0 : track.kind,
|
|
2425
|
-
targetTrackIsEffect: track && trackAnnotations(track).isEffectTrack,
|
|
2426
|
-
targetTrackReadyState: track === null || track === void 0 ? void 0 : track.readyState,
|
|
2427
|
-
newTrackId: newTrack.id,
|
|
2428
|
-
newTrackKind: newTrack.kind,
|
|
2429
|
-
newTrackIsEffect: trackAnnotations(newTrack).isEffectTrack,
|
|
2430
|
-
oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
|
|
2431
|
-
oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
|
|
2432
|
-
oldTrackIsEffect: oldTrack && trackAnnotations(oldTrack).isEffectTrack,
|
|
2433
|
-
});
|
|
2434
2398
|
return yield sender.replaceTrack(newTrack);
|
|
2435
2399
|
}
|
|
2436
2400
|
let stream = this.streams.find((s) => s.getTracks().find((t) => t.id === newTrack.id));
|
|
@@ -2451,15 +2415,6 @@ class Session {
|
|
|
2451
2415
|
this._incrementAnalyticMetric("P2PReplaceTrackNoStream");
|
|
2452
2416
|
throw new Error("replaceTrack: No stream?");
|
|
2453
2417
|
}
|
|
2454
|
-
rtcStats.sendEvent("P2PReplaceTrackSourceKindNotFound", {
|
|
2455
|
-
oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
|
|
2456
|
-
oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
|
|
2457
|
-
oldTrackIsEffect: oldTrack && trackAnnotations(oldTrack).isEffectTrack,
|
|
2458
|
-
newTrackId: newTrack.id,
|
|
2459
|
-
newTrackKind: newTrack.kind,
|
|
2460
|
-
newTrackIsEffect: trackAnnotations(newTrack).isEffectTrack,
|
|
2461
|
-
});
|
|
2462
|
-
this._incrementAnalyticMetric("P2PReplaceTrackSourceKindNotFound");
|
|
2463
2418
|
pc.addTrack(newTrack, stream);
|
|
2464
2419
|
});
|
|
2465
2420
|
}
|
|
@@ -2562,12 +2517,6 @@ var rtcManagerEvents = {
|
|
|
2562
2517
|
DOMINANT_SPEAKER: "dominant_speaker",
|
|
2563
2518
|
};
|
|
2564
2519
|
|
|
2565
|
-
const CAMERA_STREAM_ID = "0";
|
|
2566
|
-
const STREAM_TYPES = {
|
|
2567
|
-
webcam: "webcam",
|
|
2568
|
-
screenshare: "screenshare",
|
|
2569
|
-
};
|
|
2570
|
-
|
|
2571
2520
|
var _a$2, _b$1;
|
|
2572
2521
|
const adapter$2 = (_a$2 = adapterRaw.default) !== null && _a$2 !== void 0 ? _a$2 : adapterRaw;
|
|
2573
2522
|
const logger$6 = new Logger();
|
|
@@ -2588,8 +2537,6 @@ class P2pRtcManager {
|
|
|
2588
2537
|
this._roomName = name;
|
|
2589
2538
|
this._roomSessionId = session && session.id;
|
|
2590
2539
|
this.peerConnections = {};
|
|
2591
|
-
this.localStreams = {};
|
|
2592
|
-
this.enabledLocalStreamIds = [];
|
|
2593
2540
|
this._screenshareVideoTrackIds = [];
|
|
2594
2541
|
this._socketListenerDeregisterFunctions = [];
|
|
2595
2542
|
this._localStreamDeregisterFunction = null;
|
|
@@ -2599,7 +2546,6 @@ class P2pRtcManager {
|
|
|
2599
2546
|
this._features = features || {};
|
|
2600
2547
|
this._isAudioOnlyMode = false;
|
|
2601
2548
|
this._closed = false;
|
|
2602
|
-
this.skipEmittingServerMessageCount = 0;
|
|
2603
2549
|
this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
|
|
2604
2550
|
this._audioTrackOnEnded = () => {
|
|
2605
2551
|
rtcStats.sendEvent("audio_ended", { unloading: unloading$1 });
|
|
@@ -2634,13 +2580,8 @@ class P2pRtcManager {
|
|
|
2634
2580
|
numPcOnAnswerFailure: 0,
|
|
2635
2581
|
numPcOnOfferFailure: 0,
|
|
2636
2582
|
P2PChangeBandwidthEmptySDPType: 0,
|
|
2637
|
-
P2PSessionAlreadyCreated: 0,
|
|
2638
2583
|
P2PReplaceTrackNoStream: 0,
|
|
2639
|
-
P2PReplaceTrackNewTrackEnded: 0,
|
|
2640
2584
|
P2PReplaceTrackNewTrackNotInStream: 0,
|
|
2641
|
-
P2PReplaceTrackOldTrackNotFound: 0,
|
|
2642
|
-
P2PReplaceTrackWithoutPC: 0,
|
|
2643
|
-
P2PReplaceTrackSourceKindNotFound: 0,
|
|
2644
2585
|
P2POnTrackNoStream: 0,
|
|
2645
2586
|
P2PSetCodecPreferenceError: 0,
|
|
2646
2587
|
P2PCreateOfferNoSDP: 0,
|
|
@@ -2648,6 +2589,7 @@ class P2pRtcManager {
|
|
|
2648
2589
|
P2PMicNotWorking: 0,
|
|
2649
2590
|
P2PLocalNetworkFailed: 0,
|
|
2650
2591
|
P2PRelayedIceCandidate: 0,
|
|
2592
|
+
P2PStartScreenshareNoStream: 0,
|
|
2651
2593
|
};
|
|
2652
2594
|
}
|
|
2653
2595
|
numberOfPeerconnections() {
|
|
@@ -2656,52 +2598,64 @@ class P2pRtcManager {
|
|
|
2656
2598
|
isInitializedWith({ selfId, roomName, isSfu }) {
|
|
2657
2599
|
return this._selfId === selfId && this._roomName === roomName && !isSfu;
|
|
2658
2600
|
}
|
|
2659
|
-
|
|
2660
|
-
|
|
2601
|
+
addCameraStream(stream, { beforeEffectTracks = [] } = { beforeEffectTracks: [] }) {
|
|
2602
|
+
logger$6.info("addCameraStream: [stream.id: %s]", stream.id);
|
|
2603
|
+
if (stream === this._localCameraStream) {
|
|
2661
2604
|
return;
|
|
2662
2605
|
}
|
|
2663
|
-
this.
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
if (audioTrack) {
|
|
2669
|
-
|
|
2670
|
-
this._monitorAudioTrack(audioTrack);
|
|
2671
|
-
}
|
|
2672
|
-
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "audio");
|
|
2673
|
-
if (beforeEffectTrack) {
|
|
2674
|
-
this._monitorAudioTrack(beforeEffectTrack);
|
|
2675
|
-
}
|
|
2606
|
+
this._localCameraStream = stream;
|
|
2607
|
+
this._addStreamToPeerConnections(stream);
|
|
2608
|
+
const videoTrack = stream.getVideoTracks()[0];
|
|
2609
|
+
const audioTrack = stream.getAudioTracks()[0];
|
|
2610
|
+
if (audioTrack) {
|
|
2611
|
+
if (!trackAnnotations(audioTrack).isEffectTrack) {
|
|
2612
|
+
this._monitorAudioTrack(audioTrack);
|
|
2676
2613
|
}
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
}
|
|
2681
|
-
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "video");
|
|
2682
|
-
if (beforeEffectTrack) {
|
|
2683
|
-
this._monitorVideoTrack(beforeEffectTrack);
|
|
2684
|
-
}
|
|
2614
|
+
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "audio");
|
|
2615
|
+
if (beforeEffectTrack) {
|
|
2616
|
+
this._monitorAudioTrack(beforeEffectTrack);
|
|
2685
2617
|
}
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2618
|
+
}
|
|
2619
|
+
if (videoTrack) {
|
|
2620
|
+
if (!trackAnnotations(videoTrack).isEffectTrack) {
|
|
2621
|
+
this._monitorVideoTrack(videoTrack);
|
|
2689
2622
|
}
|
|
2690
|
-
const
|
|
2691
|
-
|
|
2692
|
-
this.
|
|
2693
|
-
}
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2623
|
+
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "video");
|
|
2624
|
+
if (beforeEffectTrack) {
|
|
2625
|
+
this._monitorVideoTrack(beforeEffectTrack);
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
this._enableStopResumeVideoForBrowserSDK(stream);
|
|
2629
|
+
}
|
|
2630
|
+
_enableStopResumeVideoForBrowserSDK(stream) {
|
|
2631
|
+
if (this._localStreamDeregisterFunction) {
|
|
2632
|
+
this._localStreamDeregisterFunction();
|
|
2633
|
+
this._localStreamDeregisterFunction = null;
|
|
2634
|
+
}
|
|
2635
|
+
const localStreamHandler = (e) => {
|
|
2636
|
+
const { enable, track } = e.detail;
|
|
2637
|
+
this._handleStopOrResumeVideo({ enable, track });
|
|
2638
|
+
};
|
|
2639
|
+
stream.addEventListener("stopresumevideo", localStreamHandler);
|
|
2640
|
+
this._localStreamDeregisterFunction = () => {
|
|
2641
|
+
stream.removeEventListener("stopresumevideo", localStreamHandler);
|
|
2642
|
+
};
|
|
2643
|
+
}
|
|
2644
|
+
addScreenshareStream(stream) {
|
|
2645
|
+
logger$6.info("addScreenshareStream() [stream.id: %s]", stream.id);
|
|
2646
|
+
if (stream === this._localScreenshareStream) {
|
|
2698
2647
|
return;
|
|
2699
2648
|
}
|
|
2649
|
+
this._localScreenshareStream = stream;
|
|
2700
2650
|
this._screenshareVideoTrackIds.push(stream.getVideoTracks()[0].id);
|
|
2701
|
-
this.
|
|
2702
|
-
|
|
2651
|
+
this._emitServerEvent(PROTOCOL_REQUESTS.START_SCREENSHARE, {
|
|
2652
|
+
streamId: stream.id,
|
|
2653
|
+
hasAudioTrack: !!stream.getAudioTracks().length,
|
|
2654
|
+
});
|
|
2655
|
+
this._addStreamToPeerConnections(stream);
|
|
2703
2656
|
}
|
|
2704
2657
|
replaceTrack(oldTrack, newTrack) {
|
|
2658
|
+
logger$6.info("replaceTrack() [kind: %s, oldTrackId: %s, newTrackId: %s]", newTrack.kind, oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id, newTrack.id);
|
|
2705
2659
|
if (newTrack.kind === "audio" && !trackAnnotations(newTrack).isEffectTrack) {
|
|
2706
2660
|
this._monitorAudioTrack(newTrack);
|
|
2707
2661
|
}
|
|
@@ -2715,6 +2669,7 @@ class P2pRtcManager {
|
|
|
2715
2669
|
this.disconnectAll();
|
|
2716
2670
|
}
|
|
2717
2671
|
disconnectAll() {
|
|
2672
|
+
logger$6.info("disconnectAll()");
|
|
2718
2673
|
Object.keys(this.peerConnections).forEach((peerConnectionId) => {
|
|
2719
2674
|
this.disconnect(peerConnectionId);
|
|
2720
2675
|
});
|
|
@@ -2740,10 +2695,11 @@ class P2pRtcManager {
|
|
|
2740
2695
|
this._updateAndScheduleMediaServersRefresh(data);
|
|
2741
2696
|
}),
|
|
2742
2697
|
this._serverSocket.on(RELAY_MESSAGES.READY_TO_RECEIVE_OFFER, (data) => {
|
|
2743
|
-
logger$6.info(`
|
|
2698
|
+
logger$6.info(`Got ready_to_receive_offer from client ${data.clientId}`);
|
|
2744
2699
|
this._connect(data.clientId);
|
|
2745
2700
|
}),
|
|
2746
2701
|
this._serverSocket.on(RELAY_MESSAGES.ICE_CANDIDATE, (data) => {
|
|
2702
|
+
logger$6.info(`Got ice_candidate from client ${data.clientId}`);
|
|
2747
2703
|
const session = this._getSession(data.clientId);
|
|
2748
2704
|
if (!session) {
|
|
2749
2705
|
logger$6.warn("No RTCPeerConnection on ICE_CANDIDATE", data);
|
|
@@ -2752,7 +2708,7 @@ class P2pRtcManager {
|
|
|
2752
2708
|
session.addIceCandidate(data.message);
|
|
2753
2709
|
}),
|
|
2754
2710
|
this._serverSocket.on(RELAY_MESSAGES.ICE_END_OF_CANDIDATES, (data) => {
|
|
2755
|
-
logger$6.info(`
|
|
2711
|
+
logger$6.info(`Got end_of_ice_candidates from client ${data.clientId}`);
|
|
2756
2712
|
const session = this._getSession(data.clientId);
|
|
2757
2713
|
if (!session) {
|
|
2758
2714
|
logger$6.warn("No RTCPeerConnection on ICE_END_OF_CANDIDATES", data);
|
|
@@ -2762,7 +2718,7 @@ class P2pRtcManager {
|
|
|
2762
2718
|
}),
|
|
2763
2719
|
this._serverSocket.on(RELAY_MESSAGES.SDP_OFFER, (data) => {
|
|
2764
2720
|
var _a, _b;
|
|
2765
|
-
logger$6.info(`
|
|
2721
|
+
logger$6.info(`Got offer from client ${data.clientId}, isInitialOffer: ${Boolean(data.message.isInitialOffer)}`);
|
|
2766
2722
|
const session = this._getSession(data.clientId);
|
|
2767
2723
|
if (!session) {
|
|
2768
2724
|
logger$6.warn("No RTCPeerConnection on SDP_OFFER", data);
|
|
@@ -2785,6 +2741,7 @@ class P2pRtcManager {
|
|
|
2785
2741
|
(_b = (_a = session
|
|
2786
2742
|
.handleOffer(sdp)
|
|
2787
2743
|
.then((answer) => {
|
|
2744
|
+
logger$6.info(`Sending answer to client ${data.clientId}`);
|
|
2788
2745
|
this._emitServerEvent(RELAY_MESSAGES.SDP_ANSWER, {
|
|
2789
2746
|
receiverId: data.clientId,
|
|
2790
2747
|
message: answer,
|
|
@@ -2795,7 +2752,7 @@ class P2pRtcManager {
|
|
|
2795
2752
|
}),
|
|
2796
2753
|
this._serverSocket.on(RELAY_MESSAGES.SDP_ANSWER, (data) => {
|
|
2797
2754
|
var _a, _b;
|
|
2798
|
-
logger$6.info(`
|
|
2755
|
+
logger$6.info(`Got answer from client ${data.clientId}`);
|
|
2799
2756
|
const session = this._getSession(data.clientId);
|
|
2800
2757
|
if (!session) {
|
|
2801
2758
|
logger$6.warn("No RTCPeerConnection on SDP_ANSWER", data);
|
|
@@ -2853,11 +2810,12 @@ class P2pRtcManager {
|
|
|
2853
2810
|
});
|
|
2854
2811
|
}
|
|
2855
2812
|
setRemoteScreenshareVideoTrackIds(remoteScreenshareVideoTrackIds = []) {
|
|
2856
|
-
|
|
2857
|
-
this._screenshareVideoTrackIds = [
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2813
|
+
var _a, _b;
|
|
2814
|
+
this._screenshareVideoTrackIds = [...remoteScreenshareVideoTrackIds];
|
|
2815
|
+
const localScreenShareTrack = (_b = (_a = this._localScreenshareStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks()) === null || _b === void 0 ? void 0 : _b[0];
|
|
2816
|
+
if (localScreenShareTrack) {
|
|
2817
|
+
this._screenshareVideoTrackIds.push(localScreenShareTrack.id);
|
|
2818
|
+
}
|
|
2861
2819
|
}
|
|
2862
2820
|
setRoomSessionId(roomSessionId) {
|
|
2863
2821
|
this._roomSessionId = roomSessionId;
|
|
@@ -2903,7 +2861,6 @@ class P2pRtcManager {
|
|
|
2903
2861
|
}
|
|
2904
2862
|
if (this._features.awaitJoinRoomFinished && !this._serverSocket.joinRoomFinished) {
|
|
2905
2863
|
rtcStats.sendEvent("skip_emitting_server_message", { eventName });
|
|
2906
|
-
this.skipEmittingServerMessageCount++;
|
|
2907
2864
|
}
|
|
2908
2865
|
else {
|
|
2909
2866
|
this._serverSocket.emit(eventName, data);
|
|
@@ -2912,34 +2869,12 @@ class P2pRtcManager {
|
|
|
2912
2869
|
_emit(eventName, data) {
|
|
2913
2870
|
this._emitter.emit(eventName, data);
|
|
2914
2871
|
}
|
|
2915
|
-
_addEnabledLocalStreamId(streamId) {
|
|
2916
|
-
this.enabledLocalStreamIds.push(streamId);
|
|
2917
|
-
}
|
|
2918
|
-
_deleteEnabledLocalStreamId(streamId) {
|
|
2919
|
-
const index = this.enabledLocalStreamIds.indexOf(streamId);
|
|
2920
|
-
if (index !== -1) {
|
|
2921
|
-
this.enabledLocalStreamIds.splice(index, 1);
|
|
2922
|
-
}
|
|
2923
|
-
}
|
|
2924
2872
|
_getSession(peerConnectionId) {
|
|
2925
2873
|
if (!(peerConnectionId in this.peerConnections)) {
|
|
2926
2874
|
return null;
|
|
2927
2875
|
}
|
|
2928
2876
|
return this.peerConnections[peerConnectionId];
|
|
2929
2877
|
}
|
|
2930
|
-
_getLocalCameraStream() {
|
|
2931
|
-
return this.localStreams[CAMERA_STREAM_ID];
|
|
2932
|
-
}
|
|
2933
|
-
_getNonLocalCameraStreamIds() {
|
|
2934
|
-
return Object.keys(this.localStreams).filter((streamId) => streamId !== CAMERA_STREAM_ID);
|
|
2935
|
-
}
|
|
2936
|
-
_isScreensharingLocally() {
|
|
2937
|
-
return this._getNonLocalCameraStreamIds().length > 0;
|
|
2938
|
-
}
|
|
2939
|
-
_getFirstLocalNonCameraStream() {
|
|
2940
|
-
const streamIds = this._getNonLocalCameraStreamIds();
|
|
2941
|
-
return streamIds.length === 0 ? null : this.localStreams[streamIds[0]];
|
|
2942
|
-
}
|
|
2943
2878
|
_createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId }) {
|
|
2944
2879
|
if (!peerConnectionId) {
|
|
2945
2880
|
throw new Error("peerConnectionId is missing");
|
|
@@ -3072,29 +3007,34 @@ class P2pRtcManager {
|
|
|
3072
3007
|
break;
|
|
3073
3008
|
}
|
|
3074
3009
|
};
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
session.addStream(localCameraStream);
|
|
3010
|
+
if (this._localCameraStream) {
|
|
3011
|
+
session.addStream(this._localCameraStream);
|
|
3078
3012
|
}
|
|
3079
|
-
|
|
3080
|
-
if (id === CAMERA_STREAM_ID) {
|
|
3081
|
-
return;
|
|
3082
|
-
}
|
|
3083
|
-
const screenshareStream = this.localStreams[id];
|
|
3013
|
+
if (this._localScreenshareStream) {
|
|
3084
3014
|
if (isOfferer) {
|
|
3085
|
-
session.addStream(
|
|
3015
|
+
session.addStream(this._localScreenshareStream);
|
|
3086
3016
|
}
|
|
3087
3017
|
else {
|
|
3088
3018
|
session.afterConnected.then(() => {
|
|
3019
|
+
if (!this._localScreenshareStream)
|
|
3020
|
+
return;
|
|
3089
3021
|
this._emitServerEvent(PROTOCOL_REQUESTS.START_SCREENSHARE, {
|
|
3090
3022
|
receiverId: session.clientId,
|
|
3091
|
-
streamId:
|
|
3092
|
-
hasAudioTrack: !!
|
|
3023
|
+
streamId: this._localScreenshareStream.id,
|
|
3024
|
+
hasAudioTrack: !!this._localScreenshareStream.getAudioTracks().length,
|
|
3025
|
+
});
|
|
3026
|
+
this._withForcedRenegotiation(session, () => {
|
|
3027
|
+
if (this._localScreenshareStream) {
|
|
3028
|
+
session.addStream(this._localScreenshareStream);
|
|
3029
|
+
}
|
|
3030
|
+
else {
|
|
3031
|
+
this.analytics.P2PStartScreenshareNoStream++;
|
|
3032
|
+
rtcStats.sendEvent("P2PStartScreenshareNoStream", {});
|
|
3033
|
+
}
|
|
3093
3034
|
});
|
|
3094
|
-
this._withForcedRenegotiation(session, () => session.addStream(screenshareStream));
|
|
3095
3035
|
});
|
|
3096
3036
|
}
|
|
3097
|
-
}
|
|
3037
|
+
}
|
|
3098
3038
|
return session;
|
|
3099
3039
|
}
|
|
3100
3040
|
_cleanup(peerConnectionId) {
|
|
@@ -3128,11 +3068,6 @@ class P2pRtcManager {
|
|
|
3128
3068
|
if (session.pc.connectionState === "closed")
|
|
3129
3069
|
return;
|
|
3130
3070
|
logger$6.info("Session doesn't have a connected PeerConnection, adding pending action!");
|
|
3131
|
-
this.analytics.P2PReplaceTrackWithoutPC++;
|
|
3132
|
-
rtcStats.sendEvent("P2PReplaceTrackWithoutPC", {
|
|
3133
|
-
connectionState: session.pc.connectionState,
|
|
3134
|
-
iceConnectionState: session.pc.iceConnectionState,
|
|
3135
|
-
});
|
|
3136
3071
|
const promise = new Promise((resolve, reject) => {
|
|
3137
3072
|
const action = () => __awaiter(this, void 0, void 0, function* () {
|
|
3138
3073
|
try {
|
|
@@ -3164,14 +3099,6 @@ class P2pRtcManager {
|
|
|
3164
3099
|
this._withForcedRenegotiation(session, () => session.removeTrack(track));
|
|
3165
3100
|
});
|
|
3166
3101
|
}
|
|
3167
|
-
_addLocalStream(streamId, stream) {
|
|
3168
|
-
this._addEnabledLocalStreamId(streamId);
|
|
3169
|
-
this.localStreams[streamId] = stream;
|
|
3170
|
-
}
|
|
3171
|
-
_removeLocalStream(streamId) {
|
|
3172
|
-
delete this.localStreams[streamId];
|
|
3173
|
-
this._deleteEnabledLocalStreamId(streamId);
|
|
3174
|
-
}
|
|
3175
3102
|
_updateAndScheduleMediaServersRefresh({ iceServers, turnServers, mediaserverConfigTtlSeconds, }) {
|
|
3176
3103
|
this._iceServers = iceServers;
|
|
3177
3104
|
this._turnServers = turnServers;
|
|
@@ -3332,6 +3259,7 @@ class P2pRtcManager {
|
|
|
3332
3259
|
type: offer.type,
|
|
3333
3260
|
isInitialOffer,
|
|
3334
3261
|
};
|
|
3262
|
+
logger$6.info(`sending offer to client ${clientId}`);
|
|
3335
3263
|
this._emitServerEvent(RELAY_MESSAGES.SDP_OFFER, {
|
|
3336
3264
|
receiverId: clientId,
|
|
3337
3265
|
message,
|
|
@@ -3381,6 +3309,7 @@ class P2pRtcManager {
|
|
|
3381
3309
|
return bandwidth;
|
|
3382
3310
|
}
|
|
3383
3311
|
_createP2pSession({ clientId, initialBandwidth, isOfferer = false, }) {
|
|
3312
|
+
var _a, _b;
|
|
3384
3313
|
const session = this._createSession({
|
|
3385
3314
|
peerConnectionId: clientId,
|
|
3386
3315
|
clientId,
|
|
@@ -3391,9 +3320,8 @@ class P2pRtcManager {
|
|
|
3391
3320
|
if (this._features.increaseIncomingMediaBufferOn) {
|
|
3392
3321
|
this._setJitterBufferTarget(pc);
|
|
3393
3322
|
}
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
pc.addTrack(this._stoppedVideoTrack, localCameraStream);
|
|
3323
|
+
if (((_b = (_a = this._localCameraStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks()) === null || _b === void 0 ? void 0 : _b.length) && this._stoppedVideoTrack) {
|
|
3324
|
+
pc.addTrack(this._stoppedVideoTrack, this._localCameraStream);
|
|
3397
3325
|
}
|
|
3398
3326
|
pc.onicegatheringstatechange = (event) => {
|
|
3399
3327
|
const connection = event.target;
|
|
@@ -3497,11 +3425,13 @@ class P2pRtcManager {
|
|
|
3497
3425
|
if (pc.iceConnectionState === "new" || !session.connectionStatus) {
|
|
3498
3426
|
return;
|
|
3499
3427
|
}
|
|
3428
|
+
logger$6.info(`onnegotiationneeded client ${clientId}`);
|
|
3500
3429
|
this._negotiatePeerConnection({ clientId, session });
|
|
3501
3430
|
};
|
|
3502
3431
|
return session;
|
|
3503
3432
|
}
|
|
3504
3433
|
acceptNewStream({ streamId, clientId }) {
|
|
3434
|
+
logger$6.info("acceptNewStream() [streamId: %s}, clientId: %s]", streamId, clientId);
|
|
3505
3435
|
let session = this._getSession(clientId);
|
|
3506
3436
|
if (session && streamId !== clientId) {
|
|
3507
3437
|
return session;
|
|
@@ -3524,6 +3454,7 @@ class P2pRtcManager {
|
|
|
3524
3454
|
return session;
|
|
3525
3455
|
}
|
|
3526
3456
|
disconnect(clientId) {
|
|
3457
|
+
logger$6.info("disconnect() [clientId: %s]", clientId);
|
|
3527
3458
|
this._cleanup(clientId);
|
|
3528
3459
|
this._changeBandwidthForAllClients(false);
|
|
3529
3460
|
const numPeers = this.numberOfPeerconnections();
|
|
@@ -3555,6 +3486,7 @@ class P2pRtcManager {
|
|
|
3555
3486
|
}
|
|
3556
3487
|
stopOrResumeVideo(localStream, enable) {
|
|
3557
3488
|
var _a;
|
|
3489
|
+
logger$6.info("stopOrResumeVideo() [enable: %s]", enable);
|
|
3558
3490
|
if (!["chrome", "safari"].includes(browserName$1)) {
|
|
3559
3491
|
return;
|
|
3560
3492
|
}
|
|
@@ -3603,19 +3535,11 @@ class P2pRtcManager {
|
|
|
3603
3535
|
}
|
|
3604
3536
|
}
|
|
3605
3537
|
}
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
streamId,
|
|
3609
|
-
hasAudioTrack: !!stream.getAudioTracks().length,
|
|
3610
|
-
});
|
|
3611
|
-
this._wasScreenSharing = true;
|
|
3612
|
-
this._addStreamToPeerConnections(stream);
|
|
3613
|
-
}
|
|
3614
|
-
removeStream(streamId, stream, requestedByClientId) {
|
|
3615
|
-
this._removeLocalStream(streamId);
|
|
3538
|
+
removeScreenshareStream(stream, { requestedByClientId } = {}) {
|
|
3539
|
+
logger$6.info("removeScreenshareStream() [stream.id: %s, requestedByClientId: %s]", stream.id, requestedByClientId);
|
|
3616
3540
|
this._removeStreamFromPeerConnections(stream);
|
|
3617
|
-
this.
|
|
3618
|
-
this.
|
|
3541
|
+
this._emitServerEvent(PROTOCOL_REQUESTS.STOP_SCREENSHARE, { streamId: stream.id, requestedByClientId });
|
|
3542
|
+
delete this._localScreenshareStream;
|
|
3619
3543
|
}
|
|
3620
3544
|
hasClient(clientId) {
|
|
3621
3545
|
return Object.keys(this.peerConnections).includes(clientId);
|
|
@@ -4447,6 +4371,12 @@ function createVegaConnectionManager(config) {
|
|
|
4447
4371
|
return { connect, updateHostList, networkIsUp, networkIsPossiblyDown };
|
|
4448
4372
|
}
|
|
4449
4373
|
|
|
4374
|
+
const CAMERA_STREAM_ID = "0";
|
|
4375
|
+
const STREAM_TYPES = {
|
|
4376
|
+
webcam: "webcam",
|
|
4377
|
+
screenshare: "screenshare",
|
|
4378
|
+
};
|
|
4379
|
+
|
|
4450
4380
|
var _a$1;
|
|
4451
4381
|
const adapter$1 = (_a$1 = adapterRaw.default) !== null && _a$1 !== void 0 ? _a$1 : adapterRaw;
|
|
4452
4382
|
const logger$2 = new Logger();
|
|
@@ -5390,7 +5320,7 @@ class VegaRtcManager {
|
|
|
5390
5320
|
(_a = this._vegaConnection) === null || _a === void 0 ? void 0 : _a.message("eventClaim", { eventClaim });
|
|
5391
5321
|
}
|
|
5392
5322
|
}
|
|
5393
|
-
replaceTrack(
|
|
5323
|
+
replaceTrack(_, track) {
|
|
5394
5324
|
if (track.kind === "audio") {
|
|
5395
5325
|
if (!trackAnnotations(track).isEffectTrack) {
|
|
5396
5326
|
this._monitorAudioTrack(track);
|
|
@@ -5406,8 +5336,8 @@ class VegaRtcManager {
|
|
|
5406
5336
|
this._replaceWebcamTrack();
|
|
5407
5337
|
}
|
|
5408
5338
|
}
|
|
5409
|
-
|
|
5410
|
-
logger$2.info("
|
|
5339
|
+
removeScreenshareStream(stream, { requestedByClientId } = { requestedByClientId: undefined }) {
|
|
5340
|
+
logger$2.info("removeScreenshareStream() [streamId:%s, requestedByClientId:%s]", stream.id, requestedByClientId);
|
|
5411
5341
|
this._emitToSignal(PROTOCOL_REQUESTS.STOP_SCREENSHARE, {
|
|
5412
5342
|
streamId: OUTBOUND_SCREEN_OUTBOUND_STREAM_ID,
|
|
5413
5343
|
requestedByClientId,
|
|
@@ -5424,57 +5354,58 @@ class VegaRtcManager {
|
|
|
5424
5354
|
(_b = (_a = this._micAnalyserDebugger) === null || _a === void 0 ? void 0 : _a.onScoreUpdated) === null || _b === void 0 ? void 0 : _b.call(_a, data);
|
|
5425
5355
|
this._sendMicScore(this._micPaused ? 0 : data.out);
|
|
5426
5356
|
}
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
this._monitorVideoTrack(videoTrack);
|
|
5437
|
-
}
|
|
5438
|
-
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "video");
|
|
5439
|
-
if (beforeEffectTrack) {
|
|
5440
|
-
this._monitorVideoTrack(beforeEffectTrack);
|
|
5441
|
-
}
|
|
5357
|
+
addCameraStream(stream, { audioPaused, videoPaused, beforeEffectTracks = [] } = { beforeEffectTracks: [] }) {
|
|
5358
|
+
this._micPaused = audioPaused;
|
|
5359
|
+
this._webcamPaused = videoPaused;
|
|
5360
|
+
const videoTrack = stream.getVideoTracks()[0];
|
|
5361
|
+
const audioTrack = stream.getAudioTracks()[0];
|
|
5362
|
+
if (videoTrack) {
|
|
5363
|
+
this._sendWebcam(videoTrack);
|
|
5364
|
+
if (!trackAnnotations(videoTrack).isEffectTrack) {
|
|
5365
|
+
this._monitorVideoTrack(videoTrack);
|
|
5442
5366
|
}
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
this.
|
|
5446
|
-
if (!trackAnnotations(audioTrack).isEffectTrack) {
|
|
5447
|
-
this._monitorAudioTrack(audioTrack);
|
|
5448
|
-
}
|
|
5449
|
-
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "audio");
|
|
5450
|
-
if (beforeEffectTrack) {
|
|
5451
|
-
this._monitorAudioTrack(beforeEffectTrack);
|
|
5452
|
-
}
|
|
5367
|
+
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "video");
|
|
5368
|
+
if (beforeEffectTrack) {
|
|
5369
|
+
this._monitorVideoTrack(beforeEffectTrack);
|
|
5453
5370
|
}
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5371
|
+
}
|
|
5372
|
+
if (audioTrack) {
|
|
5373
|
+
this._sendMic(audioTrack);
|
|
5374
|
+
this._syncMicAnalyser();
|
|
5375
|
+
if (!trackAnnotations(audioTrack).isEffectTrack) {
|
|
5376
|
+
this._monitorAudioTrack(audioTrack);
|
|
5377
|
+
}
|
|
5378
|
+
const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "audio");
|
|
5379
|
+
if (beforeEffectTrack) {
|
|
5380
|
+
this._monitorAudioTrack(beforeEffectTrack);
|
|
5457
5381
|
}
|
|
5458
|
-
const localStreamHandler = (e) => {
|
|
5459
|
-
const { enable, track } = e.detail;
|
|
5460
|
-
this._webcamPaused = !enable;
|
|
5461
|
-
this._pauseResumeWebcam();
|
|
5462
|
-
this._handleStopOrResumeVideo({ enable, track });
|
|
5463
|
-
};
|
|
5464
|
-
stream.addEventListener("stopresumevideo", localStreamHandler);
|
|
5465
|
-
this._localStreamDeregisterFunction = () => {
|
|
5466
|
-
stream.removeEventListener("stopresumevideo", localStreamHandler);
|
|
5467
|
-
};
|
|
5468
5382
|
}
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
this._sendScreenAudio(audioTrack);
|
|
5476
|
-
this._emitScreenshareStarted();
|
|
5383
|
+
this._enableStopResumeVideoForBrowserSDK(stream);
|
|
5384
|
+
}
|
|
5385
|
+
_enableStopResumeVideoForBrowserSDK(stream) {
|
|
5386
|
+
if (this._localStreamDeregisterFunction) {
|
|
5387
|
+
this._localStreamDeregisterFunction();
|
|
5388
|
+
this._localStreamDeregisterFunction = null;
|
|
5477
5389
|
}
|
|
5390
|
+
const localStreamHandler = (e) => {
|
|
5391
|
+
const { enable, track } = e.detail;
|
|
5392
|
+
this._webcamPaused = !enable;
|
|
5393
|
+
this._pauseResumeWebcam();
|
|
5394
|
+
this._handleStopOrResumeVideo({ enable, track });
|
|
5395
|
+
};
|
|
5396
|
+
stream.addEventListener("stopresumevideo", localStreamHandler);
|
|
5397
|
+
this._localStreamDeregisterFunction = () => {
|
|
5398
|
+
stream.removeEventListener("stopresumevideo", localStreamHandler);
|
|
5399
|
+
};
|
|
5400
|
+
}
|
|
5401
|
+
addScreenshareStream(stream) {
|
|
5402
|
+
const videoTrack = stream.getVideoTracks()[0];
|
|
5403
|
+
const audioTrack = stream.getAudioTracks()[0];
|
|
5404
|
+
if (videoTrack)
|
|
5405
|
+
this._sendScreenVideo(videoTrack);
|
|
5406
|
+
if (audioTrack)
|
|
5407
|
+
this._sendScreenAudio(audioTrack);
|
|
5408
|
+
this._emitScreenshareStarted();
|
|
5478
5409
|
}
|
|
5479
5410
|
_syncMicAnalyser() {
|
|
5480
5411
|
if (this._micTrack && this._colocation && !this._micAnalyser) {
|