@whereby.com/media 2.6.7 → 2.6.9

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.mjs CHANGED
@@ -2146,7 +2146,7 @@ var _a$4;
2146
2146
  const adapter$4 = (_a$4 = adapterRaw.default) !== null && _a$4 !== void 0 ? _a$4 : adapterRaw;
2147
2147
  const logger$7 = new Logger();
2148
2148
  class Session {
2149
- constructor({ peerConnectionId, bandwidth, deprioritizeH264Encoding, incrementAnalyticMetric, }) {
2149
+ constructor({ peerConnectionId, clientId, bandwidth, peerConnectionConfig, deprioritizeH264Encoding, shouldAddLocalVideo, incrementAnalyticMetric, }) {
2150
2150
  this.peerConnectionId = peerConnectionId;
2151
2151
  this.relayCandidateSeen = false;
2152
2152
  this.serverReflexiveCandidateSeen = false;
@@ -2155,7 +2155,24 @@ class Session {
2155
2155
  this.ipv6HostCandidateTeredoSeen = false;
2156
2156
  this.ipv6HostCandidate6to4Seen = false;
2157
2157
  this.mdnsHostCandidateSeen = false;
2158
- this.pc = null;
2158
+ this.peerConnectionConfig = peerConnectionConfig;
2159
+ this.shouldAddLocalVideo = shouldAddLocalVideo;
2160
+ this.clientId = clientId;
2161
+ this.pc = new RTCPeerConnection(this.peerConnectionConfig);
2162
+ this.signalingState = this.pc.signalingState;
2163
+ this.pc.addEventListener("signalingstatechange", () => {
2164
+ if (this.signalingState === this.pc.signalingState) {
2165
+ return;
2166
+ }
2167
+ this.signalingState = this.pc.signalingState;
2168
+ if (this.pc.signalingState === "stable") {
2169
+ this.isOperationPending = false;
2170
+ const action = this.pending.shift();
2171
+ if (action) {
2172
+ action.apply();
2173
+ }
2174
+ }
2175
+ });
2159
2176
  this.wasEverConnected = false;
2160
2177
  this.connectionStatus = null;
2161
2178
  this.stats = {
@@ -2175,27 +2192,6 @@ class Session {
2175
2192
  this._deprioritizeH264Encoding = deprioritizeH264Encoding;
2176
2193
  this._incrementAnalyticMetric = incrementAnalyticMetric;
2177
2194
  }
2178
- setAndGetPeerConnection({ clientId, constraints, peerConnectionConfig, shouldAddLocalVideo, }) {
2179
- this.peerConnectionConfig = peerConnectionConfig;
2180
- this.shouldAddLocalVideo = shouldAddLocalVideo;
2181
- this.clientId = clientId;
2182
- this.pc = new RTCPeerConnection(peerConnectionConfig);
2183
- this.signalingState = this.pc.signalingState;
2184
- this.pc.addEventListener("signalingstatechange", () => {
2185
- if (this.signalingState === this.pc.signalingState) {
2186
- return;
2187
- }
2188
- this.signalingState = this.pc.signalingState;
2189
- if (this.pc.signalingState === "stable") {
2190
- this.isOperationPending = false;
2191
- const action = this.pending.shift();
2192
- if (action) {
2193
- action.apply();
2194
- }
2195
- }
2196
- });
2197
- return this.pc;
2198
- }
2199
2195
  addStream(stream) {
2200
2196
  this.streamIds.push(stream.id);
2201
2197
  this.streams.push(stream);
@@ -2288,8 +2284,6 @@ class Session {
2288
2284
  const desc = { type: message.type, sdp };
2289
2285
  return this._setRemoteDescription(desc).then(() => {
2290
2286
  return setVideoBandwidthUsingSetParameters(this.pc, this.bandwidth);
2291
- }, (e) => {
2292
- logger$7.warn("Could not set remote description from remote answer: ", e);
2293
2287
  });
2294
2288
  }
2295
2289
  addIceCandidate(candidate) {
@@ -2332,7 +2326,7 @@ class Session {
2332
2326
  return this.pc && this.pc.connectionState === "connected";
2333
2327
  }
2334
2328
  replaceTrack(oldTrack, newTrack) {
2335
- var _a;
2329
+ var _a, _b;
2336
2330
  const pc = this.pc;
2337
2331
  if (!pc) {
2338
2332
  rtcStats.sendEvent("P2PReplaceTrackNoPC", {
@@ -2423,11 +2417,12 @@ class Session {
2423
2417
  setTimeout(() => {
2424
2418
  pc.onnegotiationneeded = onn;
2425
2419
  }, 0);
2426
- if (pc.localDescription.type === "offer") {
2420
+ if (((_b = pc.localDescription) === null || _b === void 0 ? void 0 : _b.type) === "offer") {
2427
2421
  return pc
2428
2422
  .createOffer()
2429
2423
  .then((offer) => {
2430
- offer.sdp = replaceSSRCs(pc.localDescription.sdp, offer.sdp);
2424
+ var _a;
2425
+ offer.sdp = replaceSSRCs((_a = pc.localDescription) === null || _a === void 0 ? void 0 : _a.sdp, offer.sdp);
2431
2426
  return pc.setLocalDescription(offer);
2432
2427
  })
2433
2428
  .then(() => {
@@ -2440,12 +2435,14 @@ class Session {
2440
2435
  return pc.createAnswer();
2441
2436
  })
2442
2437
  .then((answer) => {
2443
- answer.sdp = replaceSSRCs(pc.localDescription.sdp, answer.sdp);
2438
+ var _a;
2439
+ answer.sdp = replaceSSRCs((_a = pc.localDescription) === null || _a === void 0 ? void 0 : _a.sdp, answer.sdp);
2444
2440
  return pc.setLocalDescription(answer);
2445
2441
  });
2446
2442
  }
2447
2443
  }
2448
2444
  changeBandwidth(bandwidth) {
2445
+ var _a;
2449
2446
  if (bandwidth === this.bandwidth) {
2450
2447
  return;
2451
2448
  }
@@ -2454,22 +2451,24 @@ class Session {
2454
2451
  return;
2455
2452
  }
2456
2453
  this.bandwidth = bandwidth;
2457
- if (!this.pc.localDescription || this.pc.localDescription.type === "") {
2454
+ if (((_a = this.pc.localDescription) === null || _a === void 0 ? void 0 : _a.type) === "") {
2455
+ this._incrementAnalyticMetric("P2PChangeBandwidthEmptySDPType");
2456
+ return;
2457
+ }
2458
+ if (!this.pc.localDescription) {
2458
2459
  return;
2459
2460
  }
2460
2461
  setVideoBandwidthUsingSetParameters(this.pc, this.bandwidth);
2461
2462
  }
2462
2463
  setAudioOnly(enable, excludedTrackIds = []) {
2463
- this.pc
2464
- .getTransceivers()
2465
- .filter((videoTransceiver) => {
2464
+ var _a;
2465
+ (_a = this.pc) === null || _a === void 0 ? void 0 : _a.getTransceivers().filter((videoTransceiver) => {
2466
2466
  var _a, _b, _c, _d, _e, _f;
2467
2467
  return (videoTransceiver === null || videoTransceiver === void 0 ? void 0 : videoTransceiver.direction) !== "recvonly" &&
2468
2468
  ((_b = (_a = videoTransceiver === null || videoTransceiver === void 0 ? void 0 : videoTransceiver.receiver) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === "video" &&
2469
2469
  !excludedTrackIds.includes((_d = (_c = videoTransceiver === null || videoTransceiver === void 0 ? void 0 : videoTransceiver.receiver) === null || _c === void 0 ? void 0 : _c.track) === null || _d === void 0 ? void 0 : _d.id) &&
2470
2470
  !excludedTrackIds.includes((_f = (_e = videoTransceiver === null || videoTransceiver === void 0 ? void 0 : videoTransceiver.sender) === null || _e === void 0 ? void 0 : _e.track) === null || _f === void 0 ? void 0 : _f.id);
2471
- })
2472
- .forEach((videoTransceiver) => {
2471
+ }).forEach((videoTransceiver) => {
2473
2472
  videoTransceiver.direction = enable ? "sendonly" : "sendrecv";
2474
2473
  });
2475
2474
  }
@@ -2590,9 +2589,6 @@ var rtcManagerEvents = {
2590
2589
  SFU_CONNECTION_INFO: "sfu_connection_info",
2591
2590
  COLOCATION_SPEAKER: "colocation_speaker",
2592
2591
  DOMINANT_SPEAKER: "dominant_speaker",
2593
- PC_SLD_FAILURE: "pc_sld_failure",
2594
- PC_ON_ANSWER_FAILURE: "pc_on_answer_failure",
2595
- PC_ON_OFFER_FAILURE: "pc_on_offer_failure",
2596
2592
  };
2597
2593
 
2598
2594
  var _a$2, _b$1, _c;
@@ -2635,10 +2631,12 @@ class P2pRtcManager {
2635
2631
  this._audioTrackOnEnded = () => {
2636
2632
  rtcStats.sendEvent("audio_ended", { unloading: unloading$1 });
2637
2633
  this._emit(rtcManagerEvents.MICROPHONE_STOPPED_WORKING, {});
2634
+ this.analytics.micTrackEndedCount++;
2638
2635
  };
2639
2636
  this._videoTrackOnEnded = () => {
2640
2637
  rtcStats.sendEvent("video_ended", { unloading: unloading$1 });
2641
2638
  this._emit(rtcManagerEvents.CAMERA_STOPPED_WORKING, {});
2639
+ this.analytics.camTrackEndedCount++;
2642
2640
  };
2643
2641
  this._updateAndScheduleMediaServersRefresh({
2644
2642
  sfuServer,
@@ -2659,6 +2657,14 @@ class P2pRtcManager {
2659
2657
  numIceIpv6TeredoSeen: 0,
2660
2658
  numIceIpv6SixToFour: 0,
2661
2659
  numIceMdnsSeen: 0,
2660
+ micTrackEndedCount: 0,
2661
+ camTrackEndedCount: 0,
2662
+ numPcSldFailure: 0,
2663
+ numPcOnAnswerFailure: 0,
2664
+ numPcOnOfferFailure: 0,
2665
+ P2PChangeBandwidthEmptySDPType: 0,
2666
+ P2PNegotiationNeeded: 0,
2667
+ P2PSessionAlreadyCreated: 0,
2662
2668
  };
2663
2669
  }
2664
2670
  numberOfPeerconnections() {
@@ -2778,7 +2784,7 @@ class P2pRtcManager {
2778
2784
  logger$6.warn("No RTCPeerConnection on SDP_OFFER", data);
2779
2785
  return;
2780
2786
  }
2781
- const offer = this._transformIncomingSdp(data.message, session.pc);
2787
+ const offer = this._transformIncomingSdp(data.message);
2782
2788
  (_b = (_a = session
2783
2789
  .handleOffer(offer)
2784
2790
  .then((answer) => {
@@ -2787,7 +2793,7 @@ class P2pRtcManager {
2787
2793
  message: this._transformOutgoingSdp(answer),
2788
2794
  });
2789
2795
  })).catch) === null || _b === void 0 ? void 0 : _b.call(_a, (e) => {
2790
- this._emit(rtcManagerEvents.PC_ON_OFFER_FAILURE, e);
2796
+ this.analytics.numPcOnOfferFailure++;
2791
2797
  });
2792
2798
  }),
2793
2799
  this._serverSocket.on(RELAY_MESSAGES.SDP_ANSWER, (data) => {
@@ -2797,9 +2803,10 @@ class P2pRtcManager {
2797
2803
  logger$6.warn("No RTCPeerConnection on SDP_ANSWER", data);
2798
2804
  return;
2799
2805
  }
2800
- const answer = this._transformIncomingSdp(data.message, session.pc);
2806
+ const answer = this._transformIncomingSdp(data.message);
2801
2807
  (_b = (_a = session.handleAnswer(answer)) === null || _a === void 0 ? void 0 : _a.catch) === null || _b === void 0 ? void 0 : _b.call(_a, (e) => {
2802
- this._emit(rtcManagerEvents.PC_ON_ANSWER_FAILURE, e);
2808
+ logger$6.warn("Could not set remote description from remote answer: ", e);
2809
+ this.analytics.numPcOnAnswerFailure++;
2803
2810
  });
2804
2811
  }),
2805
2812
  this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, (payload) => {
@@ -2935,7 +2942,7 @@ class P2pRtcManager {
2935
2942
  }
2936
2943
  return this.peerConnections[peerConnectionId];
2937
2944
  }
2938
- _getOrCreateSession(peerConnectionId, initialBandwidth) {
2945
+ _getOrCreateSession({ peerConnectionId, clientId, initialBandwidth, peerConnectionConfig, shouldAddLocalVideo, }) {
2939
2946
  let session = this.peerConnections[peerConnectionId];
2940
2947
  if (session === undefined) {
2941
2948
  const deprioritizeH264Encoding = browserName$1 === "safari" &&
@@ -2944,12 +2951,22 @@ class P2pRtcManager {
2944
2951
  this._features.deprioritizeH264OnSafari;
2945
2952
  this.peerConnections[peerConnectionId] = session = new Session({
2946
2953
  peerConnectionId,
2954
+ clientId,
2955
+ peerConnectionConfig,
2947
2956
  bandwidth: initialBandwidth,
2948
2957
  deprioritizeH264Encoding,
2958
+ shouldAddLocalVideo,
2949
2959
  incrementAnalyticMetric: (metric) => this.analytics[metric]++,
2950
2960
  });
2951
2961
  this.totalSessionsCreated++;
2952
2962
  }
2963
+ else {
2964
+ this.analytics.P2PSessionAlreadyCreated++;
2965
+ rtcStats.sendEvent("P2PSessionAlreadyCreated", {
2966
+ clientId,
2967
+ peerConnectionId,
2968
+ });
2969
+ }
2953
2970
  return session;
2954
2971
  }
2955
2972
  _getLocalCameraStream() {
@@ -2965,7 +2982,7 @@ class P2pRtcManager {
2965
2982
  const streamIds = this._getNonLocalCameraStreamIds();
2966
2983
  return streamIds.length === 0 ? null : this.localStreams[streamIds[0]];
2967
2984
  }
2968
- _transformIncomingSdp(original, _) {
2985
+ _transformIncomingSdp(original) {
2969
2986
  return { type: original.type, sdp: original.sdpU };
2970
2987
  }
2971
2988
  _transformOutgoingSdp(original) {
@@ -2978,34 +2995,33 @@ class P2pRtcManager {
2978
2995
  if (!clientId) {
2979
2996
  throw new Error("clientId is missing");
2980
2997
  }
2981
- const session = this._getOrCreateSession(peerConnectionId, initialBandwidth);
2998
+ const peerConnectionConfig = {
2999
+ iceServers: this._features.turnServersOn ? this._turnServers : this._iceServers,
3000
+ };
2982
3001
  const constraints = { optional: [] };
3002
+ constraints.optional.push({ rtcStatsRoomSessionId: this._roomSessionId });
3003
+ constraints.optional.push({ rtcStatsClientId: this._selfId });
3004
+ constraints.optional.push({ rtcStatsPeerId: peerConnectionId });
3005
+ constraints.optional.push({ rtcStatsConferenceId: this._roomName });
2983
3006
  if (browserName$1 === "chrome") {
2984
3007
  constraints.optional.push({
2985
3008
  googCpuOveruseDetection: true,
2986
3009
  });
3010
+ peerConnectionConfig.sdpSemantics = "unified-plan";
2987
3011
  }
2988
- constraints.optional.push({ rtcStatsRoomSessionId: this._roomSessionId });
2989
- constraints.optional.push({ rtcStatsClientId: this._selfId });
2990
- constraints.optional.push({ rtcStatsPeerId: peerConnectionId });
2991
- constraints.optional.push({ rtcStatsConferenceId: this._roomName });
2992
- const peerConnectionConfig = {
2993
- iceServers: this._features.turnServersOn ? this._turnServers : this._iceServers,
2994
- };
2995
3012
  peerConnectionConfig.iceServers = turnServerOverride(peerConnectionConfig.iceServers, this._features.turnServerOverrideHost);
2996
3013
  external_stun_servers(peerConnectionConfig, this._features);
2997
3014
  maybeTurnOnly(peerConnectionConfig, this._features);
2998
- if (browserName$1 === "chrome") {
2999
- peerConnectionConfig.sdpSemantics = "unified-plan";
3000
- }
3001
- const pc = session.setAndGetPeerConnection({
3002
- constraints,
3015
+ const session = this._getOrCreateSession({
3016
+ peerConnectionId,
3017
+ clientId,
3018
+ initialBandwidth,
3003
3019
  peerConnectionConfig,
3004
3020
  shouldAddLocalVideo,
3005
- clientId,
3006
3021
  });
3007
3022
  setTimeout(() => this._emit(rtcManagerEvents.NEW_PC), 0);
3008
3023
  this.analytics.numNewPc++;
3024
+ const { pc } = session;
3009
3025
  pc.ontrack = (event) => {
3010
3026
  const stream = event.streams[0];
3011
3027
  if (stream.id === "default" && stream.getAudioTracks().length === 0) {
@@ -3348,7 +3364,7 @@ class P2pRtcManager {
3348
3364
  pc.setLocalDescription(offer)
3349
3365
  .catch((e) => {
3350
3366
  logger$6.warn("RTCPeerConnection.setLocalDescription() failed with local offer", e);
3351
- this._emit(rtcManagerEvents.PC_SLD_FAILURE, e);
3367
+ this.analytics.numPcSldFailure++;
3352
3368
  throw e;
3353
3369
  })
3354
3370
  .then(() => {
@@ -3364,7 +3380,7 @@ class P2pRtcManager {
3364
3380
  }
3365
3381
  _withForcedRenegotiation(session, action) {
3366
3382
  const pc = session.pc;
3367
- const originalOnnegotationneeded = pc.onnegotationneeded;
3383
+ const originalOnnegotationneeded = pc.onnegotiationneeded;
3368
3384
  pc.onnegotiationneeded = null;
3369
3385
  action();
3370
3386
  this._negotiatePeerConnection(session.clientId, session);
@@ -3429,7 +3445,7 @@ class P2pRtcManager {
3429
3445
  if (!session.publicHostCandidateSeen &&
3430
3446
  !session.relayCandidateSeen &&
3431
3447
  !session.serverReflexiveCandidateSeen) {
3432
- if (pc.iceConnectionState !== "connected" || pc.iceConnectionState !== "completed")
3448
+ if (pc.iceConnectionState !== "connected" && pc.iceConnectionState !== "completed")
3433
3449
  this.analytics.numIceNoPublicIpGatheredIn3sec++;
3434
3450
  }
3435
3451
  }, ICE_PUBLIC_IP_GATHERING_TIMEOUT);
@@ -3513,6 +3529,8 @@ class P2pRtcManager {
3513
3529
  }
3514
3530
  };
3515
3531
  pc.onnegotiationneeded = () => {
3532
+ this.analytics.P2PNegotiationNeeded++;
3533
+ rtcStats.sendEvent("P2PNegotiationNeeded", {});
3516
3534
  if (pc.iceConnectionState === "new" || !session.connectionStatus) {
3517
3535
  return;
3518
3536
  }
@@ -4525,10 +4543,12 @@ class VegaRtcManager {
4525
4543
  this._audioTrackOnEnded = () => {
4526
4544
  rtcStats.sendEvent("audio_ended", { unloading });
4527
4545
  this._emitToPWA(rtcManagerEvents.MICROPHONE_STOPPED_WORKING, {});
4546
+ this.analytics.micTrackEndedCount++;
4528
4547
  };
4529
4548
  this._videoTrackOnEnded = () => {
4530
4549
  rtcStats.sendEvent("video_ended", { unloading });
4531
4550
  this._emitToPWA(rtcManagerEvents.CAMERA_STOPPED_WORKING, {});
4551
+ this.analytics.camTrackEndedCount++;
4532
4552
  };
4533
4553
  this._updateAndScheduleMediaServersRefresh({
4534
4554
  sfuServer,
@@ -4555,6 +4575,8 @@ class VegaRtcManager {
4555
4575
  vegaIceRestartMissingTransport: 0,
4556
4576
  vegaIceRestartWrongTransportId: 0,
4557
4577
  vegaNonErrorRejectionValueGUMError: 0,
4578
+ micTrackEndedCount: 0,
4579
+ camTrackEndedCount: 0,
4558
4580
  };
4559
4581
  }
4560
4582
  _updateAndScheduleMediaServersRefresh({ iceServers, turnServers, sfuServer, sfuServers, mediaserverConfigTtlSeconds, }) {
@@ -7008,8 +7030,12 @@ class BandwidthTester extends EventEmitter {
7008
7030
  this._sendTransport.getStats(),
7009
7031
  this._receiveTransport.getStats(),
7010
7032
  ]);
7011
- const { recvStats: [remoteRecvStats = null] = [] } = yield this._vegaConnection.request("getTransportStats");
7012
- const { availableOutgoingBitrate = 5000000 } = remoteRecvStats || {};
7033
+ let availableOutgoingBitrate = 5000000;
7034
+ try {
7035
+ availableOutgoingBitrate = (yield this._vegaConnection.request("getTransportStats")).recvStats[0]
7036
+ .availableOutgoingBitrate;
7037
+ }
7038
+ catch (_a) { }
7013
7039
  let outboundPackets = 0;
7014
7040
  let remotePacketsLost = 0;
7015
7041
  localSendStats.forEach((localSendStat) => {