@whereby.com/media 7.0.1 → 8.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/index.d.ts CHANGED
@@ -482,7 +482,7 @@ type SignalIceEndOfCandidatesMessage = {
482
482
  clientId: string;
483
483
  };
484
484
  interface WebRTCProvider {
485
- getMediaConstraints: () => MediaStreamConstraints;
485
+ getMediaOptions: () => GetConstraintsOptions;
486
486
  }
487
487
  type GetMediaConstraintsOptions = {
488
488
  disableAEC: boolean;
@@ -503,7 +503,6 @@ type GetMediaConstraintsOptions = {
503
503
  resolution?: string;
504
504
  simulcast: boolean;
505
505
  widescreen: boolean;
506
- usingAspectRatio16x9: boolean;
507
506
  };
508
507
  type GetConstraintsOptions = {
509
508
  devices: MediaDeviceInfo[];
@@ -1189,7 +1188,6 @@ declare function getUpdatedDevices({ oldDevices, newDevices, currentAudioId, cur
1189
1188
  }): GetUpdatedDevicesResult;
1190
1189
 
1191
1190
  interface P2PSessionOptions {
1192
- peerConnectionId: string;
1193
1191
  clientId: string;
1194
1192
  bandwidth: number;
1195
1193
  peerConnectionConfig: RTCConfiguration;
@@ -1197,7 +1195,6 @@ interface P2PSessionOptions {
1197
1195
  incrementAnalyticMetric: P2PIncrementAnalyticMetric;
1198
1196
  }
1199
1197
  declare class Session {
1200
- peerConnectionId: any;
1201
1198
  relayCandidateSeen: boolean;
1202
1199
  serverReflexiveCandidateSeen: boolean;
1203
1200
  publicHostCandidateSeen: boolean;
@@ -1223,7 +1220,7 @@ declare class Session {
1223
1220
  srdComplete: any;
1224
1221
  _incrementAnalyticMetric: P2PIncrementAnalyticMetric;
1225
1222
  pendingReplaceTrackActions: (() => Promise<void>)[];
1226
- constructor({ peerConnectionId, clientId, bandwidth, peerConnectionConfig, deprioritizeH264Encoding, incrementAnalyticMetric, }: P2PSessionOptions);
1223
+ constructor({ clientId, bandwidth, peerConnectionConfig, deprioritizeH264Encoding, incrementAnalyticMetric, }: P2PSessionOptions);
1227
1224
  addStream(stream: MediaStream): void;
1228
1225
  addTrack(track: MediaStreamTrack, stream?: MediaStream): void;
1229
1226
  removeTrack(track: MediaStreamTrack): void;
@@ -1241,7 +1238,6 @@ declare class Session {
1241
1238
  }
1242
1239
 
1243
1240
  interface CreateSessionOptions {
1244
- peerConnectionId: string;
1245
1241
  clientId: string;
1246
1242
  initialBandwidth: number;
1247
1243
  isOfferer: boolean;
@@ -1343,9 +1339,9 @@ declare class P2pRtcManager implements RtcManager {
1343
1339
  _setJitterBufferTarget(pc: RTCPeerConnection): void;
1344
1340
  _emitServerEvent(eventName: string, data?: any): void;
1345
1341
  _emit(eventName: string, data?: any): void;
1346
- _getSession(peerConnectionId: string): Session | null;
1347
- _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId }: CreateSessionOptions): Session;
1348
- _cleanup(peerConnectionId: string): void;
1342
+ _getSession(clientId: string): Session | null;
1343
+ _createSession({ clientId, initialBandwidth, isOfferer }: CreateSessionOptions): Session;
1344
+ _cleanup(clientId: string): void;
1349
1345
  _forEachPeerConnection(func: any): void;
1350
1346
  _addStreamToPeerConnections(stream: MediaStream): void;
1351
1347
  _addTrackToPeerConnections(track: MediaStreamTrack, stream?: MediaStream): void;
@@ -1362,11 +1358,6 @@ declare class P2pRtcManager implements RtcManager {
1362
1358
  _negotiatePeerConnection({ clientId, session, constraints, isInitialOffer, }: NegotiatePeerConnectionOptions): void;
1363
1359
  _withForcedRenegotiation(session: Session, action: any): void;
1364
1360
  _changeBandwidthForAllClients(isJoining: boolean): number;
1365
- _createP2pSession({ clientId, initialBandwidth, isOfferer, }: {
1366
- clientId: string;
1367
- initialBandwidth: number;
1368
- isOfferer: boolean;
1369
- }): Session;
1370
1361
  acceptNewStream({ streamId, clientId }: {
1371
1362
  streamId: string;
1372
1363
  clientId: string;
package/dist/index.mjs CHANGED
@@ -2196,8 +2196,7 @@ var _a$4;
2196
2196
  const adapter$4 = (_a$4 = adapterRaw.default) !== null && _a$4 !== void 0 ? _a$4 : adapterRaw;
2197
2197
  const logger$7 = new Logger();
2198
2198
  class Session {
2199
- constructor({ peerConnectionId, clientId, bandwidth, peerConnectionConfig, deprioritizeH264Encoding, incrementAnalyticMetric, }) {
2200
- this.peerConnectionId = peerConnectionId;
2199
+ constructor({ clientId, bandwidth, peerConnectionConfig, deprioritizeH264Encoding, incrementAnalyticMetric, }) {
2201
2200
  this.relayCandidateSeen = false;
2202
2201
  this.serverReflexiveCandidateSeen = false;
2203
2202
  this.publicHostCandidateSeen = false;
@@ -2513,11 +2512,78 @@ var rtcManagerEvents = {
2513
2512
 
2514
2513
  var _a$2, _b$1;
2515
2514
  const adapter$2 = (_a$2 = adapterRaw.default) !== null && _a$2 !== void 0 ? _a$2 : adapterRaw;
2515
+ const isSafari = ((_b$1 = adapter$2.browserDetails) === null || _b$1 === void 0 ? void 0 : _b$1.browser) === "safari";
2516
+ const parseResolution = (res) => res.split(/[^\d]/g).map((n) => parseInt(n, 10));
2517
+ function getMediaConstraints({ disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }) {
2518
+ var _a, _b;
2519
+ let HIGH_HEIGHT = 480;
2520
+ let LOW_HEIGHT = 240;
2521
+ if (hd) {
2522
+ HIGH_HEIGHT = lax || isSafari ? 720 : { min: 360, ideal: 720 };
2523
+ }
2524
+ if (simulcast) {
2525
+ if (hd === false) {
2526
+ HIGH_HEIGHT = 360;
2527
+ LOW_HEIGHT = 270;
2528
+ }
2529
+ else {
2530
+ LOW_HEIGHT = 360;
2531
+ }
2532
+ }
2533
+ const constraints = {
2534
+ audio: Object.assign({}, (preferredDeviceIds.audioId && { deviceId: preferredDeviceIds.audioId })),
2535
+ video: Object.assign(Object.assign({}, (preferredDeviceIds.videoId ? { deviceId: preferredDeviceIds.videoId } : { facingMode: "user" })), { height: lowDataMode ? LOW_HEIGHT : HIGH_HEIGHT, frameRate: lowDataMode && !simulcast ? 15 : 24 }),
2536
+ };
2537
+ if (lax) {
2538
+ if (!((_a = constraints.audio) === null || _a === void 0 ? void 0 : _a.deviceId))
2539
+ constraints.audio = true;
2540
+ (_b = constraints.video) === null || _b === void 0 ? true : delete _b.facingMode;
2541
+ return constraints;
2542
+ }
2543
+ if (resolution) {
2544
+ const [w, h, fps] = parseResolution(resolution);
2545
+ if (w)
2546
+ constraints.video.width = { exact: w };
2547
+ if (h)
2548
+ constraints.video.height = { exact: h };
2549
+ if (fps)
2550
+ constraints.video.frameRate = { exact: fps };
2551
+ delete constraints.video.facingMode;
2552
+ }
2553
+ else {
2554
+ constraints.video.aspectRatio = widescreen ? 16 / 9 : 4 / 3;
2555
+ }
2556
+ if (disableAGC)
2557
+ constraints.audio.autoGainControl = false;
2558
+ if (disableAEC)
2559
+ constraints.audio.echoCancellation = false;
2560
+ return constraints;
2561
+ }
2562
+ function getConstraints({ devices, videoId, audioId, options, type = "ideal" }) {
2563
+ const audioDevices = devices.filter((d) => d.kind === "audioinput");
2564
+ const videoDevices = devices.filter((d) => d.kind === "videoinput");
2565
+ const useDefaultAudio = !audioId || !audioDevices.some((d) => d.deviceId === audioId);
2566
+ const useDefaultVideo = !videoId || !videoDevices.some((d) => d.deviceId === videoId);
2567
+ const constraints = getMediaConstraints(Object.assign({ preferredDeviceIds: {
2568
+ audioId: useDefaultAudio ? null : { [type]: audioId },
2569
+ videoId: useDefaultVideo ? null : { [type]: videoId },
2570
+ } }, options));
2571
+ if (audioId === false || !audioDevices.length) {
2572
+ delete constraints.audio;
2573
+ }
2574
+ if (videoId === false || !videoDevices.length) {
2575
+ delete constraints.video;
2576
+ }
2577
+ return constraints;
2578
+ }
2579
+
2580
+ var _a$1, _b;
2581
+ const adapter$1 = (_a$1 = adapterRaw.default) !== null && _a$1 !== void 0 ? _a$1 : adapterRaw;
2516
2582
  const logger$6 = new Logger();
2517
2583
  const ICE_PUBLIC_IP_GATHERING_TIMEOUT = 3 * 1000;
2518
2584
  const ICE_RESTART_DELAY = 2 * 1000;
2519
- const browserName$1 = (_b$1 = adapter$2.browserDetails) === null || _b$1 === void 0 ? void 0 : _b$1.browser;
2520
- const browserVersion = adapter$2.browserDetails.version;
2585
+ const browserName$1 = (_b = adapter$1.browserDetails) === null || _b === void 0 ? void 0 : _b.browser;
2586
+ const browserVersion = adapter$1.browserDetails.version;
2521
2587
  let unloading$1 = false;
2522
2588
  if (browserName$1 === "chrome") {
2523
2589
  window.document.addEventListener("beforeunload", () => {
@@ -2667,8 +2733,8 @@ class P2pRtcManager {
2667
2733
  }
2668
2734
  disconnectAll() {
2669
2735
  logger$6.info("disconnectAll()");
2670
- Object.keys(this.peerConnections).forEach((peerConnectionId) => {
2671
- this.disconnect(peerConnectionId);
2736
+ Object.keys(this.peerConnections).forEach((clientId) => {
2737
+ this.disconnect(clientId);
2672
2738
  });
2673
2739
  this.peerConnections = {};
2674
2740
  this._socketListenerDeregisterFunctions.forEach((func) => {
@@ -2867,16 +2933,14 @@ class P2pRtcManager {
2867
2933
  _emit(eventName, data) {
2868
2934
  this._emitter.emit(eventName, data);
2869
2935
  }
2870
- _getSession(peerConnectionId) {
2871
- if (!(peerConnectionId in this.peerConnections)) {
2936
+ _getSession(clientId) {
2937
+ if (!(clientId in this.peerConnections)) {
2872
2938
  return null;
2873
2939
  }
2874
- return this.peerConnections[peerConnectionId];
2940
+ return this.peerConnections[clientId];
2875
2941
  }
2876
- _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId }) {
2877
- if (!peerConnectionId) {
2878
- throw new Error("peerConnectionId is missing");
2879
- }
2942
+ _createSession({ clientId, initialBandwidth, isOfferer }) {
2943
+ var _a, _b;
2880
2944
  if (!clientId) {
2881
2945
  throw new Error("clientId is missing");
2882
2946
  }
@@ -2891,17 +2955,121 @@ class P2pRtcManager {
2891
2955
  browserVersion >= 14 &&
2892
2956
  this._features.deprioritizeH264OnSafari;
2893
2957
  const session = new Session({
2894
- peerConnectionId,
2895
2958
  clientId,
2896
2959
  peerConnectionConfig,
2897
2960
  bandwidth: initialBandwidth,
2898
2961
  deprioritizeH264Encoding,
2899
2962
  incrementAnalyticMetric: (metric) => this.analytics[metric]++,
2900
2963
  });
2901
- this.peerConnections[peerConnectionId] = session;
2964
+ this.peerConnections[clientId] = session;
2902
2965
  setTimeout(() => this._emit(rtcManagerEvents.NEW_PC), 0);
2903
2966
  this.analytics.numNewPc++;
2904
2967
  const { pc } = session;
2968
+ pc.onicegatheringstatechange = (event) => {
2969
+ const connection = event.target;
2970
+ switch (connection.iceGatheringState) {
2971
+ case "gathering":
2972
+ if (this._icePublicIPGatheringTimeoutID)
2973
+ clearTimeout(this._icePublicIPGatheringTimeoutID);
2974
+ this._icePublicIPGatheringTimeoutID = setTimeout(() => {
2975
+ if (!session.publicHostCandidateSeen &&
2976
+ !session.relayCandidateSeen &&
2977
+ !session.serverReflexiveCandidateSeen) {
2978
+ if (pc.iceConnectionState !== "connected" && pc.iceConnectionState !== "completed")
2979
+ this.analytics.numIceNoPublicIpGatheredIn3sec++;
2980
+ }
2981
+ }, ICE_PUBLIC_IP_GATHERING_TIMEOUT);
2982
+ break;
2983
+ case "complete":
2984
+ if (this._icePublicIPGatheringTimeoutID)
2985
+ clearTimeout(this._icePublicIPGatheringTimeoutID);
2986
+ this._icePublicIPGatheringTimeoutID = null;
2987
+ break;
2988
+ }
2989
+ };
2990
+ pc.onicecandidate = (event) => {
2991
+ if (event.candidate) {
2992
+ if (event.candidate.type === "relayed") {
2993
+ this.analytics.P2PRelayedIceCandidate++;
2994
+ }
2995
+ switch (event.candidate.type) {
2996
+ case "host":
2997
+ const address = event.candidate.address;
2998
+ if (!address) {
2999
+ break;
3000
+ }
3001
+ try {
3002
+ if (ipRegex.v4({ exact: true }).test(address)) {
3003
+ const ipv4 = checkIp(address);
3004
+ if (ipv4.isPublicIp)
3005
+ session.publicHostCandidateSeen = true;
3006
+ }
3007
+ else if (ipRegex.v6({ exact: true }).test(address.replace(/^\[(.*)\]/, "$1"))) {
3008
+ const ipv6 = new Address6(address.replace(/^\[(.*)\]/, "$1"));
3009
+ session.ipv6HostCandidateSeen = true;
3010
+ if (ipv6.getScope() === "Global") {
3011
+ session.publicHostCandidateSeen = true;
3012
+ }
3013
+ if (ipv6.isTeredo()) {
3014
+ session.ipv6HostCandidateTeredoSeen = true;
3015
+ }
3016
+ if (ipv6.is6to4()) {
3017
+ session.ipv6HostCandidate6to4Seen = true;
3018
+ }
3019
+ }
3020
+ else {
3021
+ const uuidv4 = address.replace(/.local/, "");
3022
+ if (uuidv4 && validate(uuidv4, 4)) {
3023
+ session.mdnsHostCandidateSeen = true;
3024
+ }
3025
+ }
3026
+ }
3027
+ catch (error) {
3028
+ logger$6.info("Error during parsing candidates! Error: ", { error });
3029
+ }
3030
+ break;
3031
+ case "srflx":
3032
+ session.serverReflexiveCandidateSeen = true;
3033
+ break;
3034
+ case "relayed":
3035
+ case "relay":
3036
+ session.relayCandidateSeen = true;
3037
+ break;
3038
+ }
3039
+ this._emitServerEvent(RELAY_MESSAGES.ICE_CANDIDATE, {
3040
+ receiverId: clientId,
3041
+ message: event.candidate,
3042
+ });
3043
+ }
3044
+ else {
3045
+ this._emitServerEvent(RELAY_MESSAGES.ICE_END_OF_CANDIDATES, {
3046
+ receiverId: clientId,
3047
+ });
3048
+ if (!session.publicHostCandidateSeen &&
3049
+ !session.relayCandidateSeen &&
3050
+ !session.serverReflexiveCandidateSeen &&
3051
+ pc.iceConnectionState !== "connected" &&
3052
+ pc.iceConnectionState !== "completed") {
3053
+ this.analytics.numIceNoPublicIpGathered++;
3054
+ }
3055
+ if (session.ipv6HostCandidateSeen) {
3056
+ this.analytics.numIceIpv6Seen++;
3057
+ if (session.ipv6HostCandidate6to4Seen)
3058
+ this.analytics.numIceIpv6SixToFour++;
3059
+ if (session.ipv6HostCandidateTeredoSeen)
3060
+ this.analytics.numIceIpv6TeredoSeen++;
3061
+ }
3062
+ if (session.mdnsHostCandidateSeen)
3063
+ this.analytics.numIceMdnsSeen++;
3064
+ }
3065
+ };
3066
+ pc.onnegotiationneeded = () => {
3067
+ if (pc.iceConnectionState === "new" || !session.connectionStatus) {
3068
+ return;
3069
+ }
3070
+ logger$6.info(`onnegotiationneeded client ${clientId}`);
3071
+ this._negotiatePeerConnection({ clientId, session });
3072
+ };
2905
3073
  pc.ontrack = (event) => {
2906
3074
  const stream = event.streams[0];
2907
3075
  if (!stream) {
@@ -3033,16 +3201,22 @@ class P2pRtcManager {
3033
3201
  });
3034
3202
  }
3035
3203
  }
3204
+ if (this._features.increaseIncomingMediaBufferOn) {
3205
+ this._setJitterBufferTarget(pc);
3206
+ }
3207
+ if (((_b = (_a = this._localCameraStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks()) === null || _b === void 0 ? void 0 : _b.length) && this._stoppedVideoTrack) {
3208
+ pc.addTrack(this._stoppedVideoTrack, this._localCameraStream);
3209
+ }
3036
3210
  return session;
3037
3211
  }
3038
- _cleanup(peerConnectionId) {
3039
- const session = this._getSession(peerConnectionId);
3212
+ _cleanup(clientId) {
3213
+ const session = this._getSession(clientId);
3040
3214
  if (!session) {
3041
- logger$6.warn("No RTCPeerConnection in RTCManager.disconnect()", peerConnectionId);
3215
+ logger$6.warn("No RTCPeerConnection in RTCManager.disconnect()", clientId);
3042
3216
  return;
3043
3217
  }
3044
3218
  session.close();
3045
- delete this.peerConnections[peerConnectionId];
3219
+ delete this.peerConnections[clientId];
3046
3220
  }
3047
3221
  _forEachPeerConnection(func) {
3048
3222
  Object.values(this.peerConnections).forEach((peerConnection) => {
@@ -3143,7 +3317,7 @@ class P2pRtcManager {
3143
3317
  else {
3144
3318
  initialBandwidth = this._changeBandwidthForAllClients(true);
3145
3319
  }
3146
- session = this._createP2pSession({
3320
+ session = this._createSession({
3147
3321
  clientId,
3148
3322
  initialBandwidth,
3149
3323
  isOfferer: true,
@@ -3307,128 +3481,6 @@ class P2pRtcManager {
3307
3481
  });
3308
3482
  return bandwidth;
3309
3483
  }
3310
- _createP2pSession({ clientId, initialBandwidth, isOfferer = false, }) {
3311
- var _a, _b;
3312
- const session = this._createSession({
3313
- peerConnectionId: clientId,
3314
- clientId,
3315
- initialBandwidth,
3316
- isOfferer,
3317
- });
3318
- const pc = session.pc;
3319
- if (this._features.increaseIncomingMediaBufferOn) {
3320
- this._setJitterBufferTarget(pc);
3321
- }
3322
- if (((_b = (_a = this._localCameraStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks()) === null || _b === void 0 ? void 0 : _b.length) && this._stoppedVideoTrack) {
3323
- pc.addTrack(this._stoppedVideoTrack, this._localCameraStream);
3324
- }
3325
- pc.onicegatheringstatechange = (event) => {
3326
- const connection = event.target;
3327
- switch (connection.iceGatheringState) {
3328
- case "gathering":
3329
- if (this._icePublicIPGatheringTimeoutID)
3330
- clearTimeout(this._icePublicIPGatheringTimeoutID);
3331
- this._icePublicIPGatheringTimeoutID = setTimeout(() => {
3332
- if (!session.publicHostCandidateSeen &&
3333
- !session.relayCandidateSeen &&
3334
- !session.serverReflexiveCandidateSeen) {
3335
- if (pc.iceConnectionState !== "connected" && pc.iceConnectionState !== "completed")
3336
- this.analytics.numIceNoPublicIpGatheredIn3sec++;
3337
- }
3338
- }, ICE_PUBLIC_IP_GATHERING_TIMEOUT);
3339
- break;
3340
- case "complete":
3341
- if (this._icePublicIPGatheringTimeoutID)
3342
- clearTimeout(this._icePublicIPGatheringTimeoutID);
3343
- this._icePublicIPGatheringTimeoutID = null;
3344
- break;
3345
- }
3346
- };
3347
- pc.onicecandidate = (event) => {
3348
- if (event.candidate) {
3349
- if (event.candidate.type === "relayed") {
3350
- this.analytics.P2PRelayedIceCandidate++;
3351
- }
3352
- switch (event.candidate.type) {
3353
- case "host":
3354
- const address = event.candidate.address;
3355
- if (!address) {
3356
- break;
3357
- }
3358
- try {
3359
- if (ipRegex.v4({ exact: true }).test(address)) {
3360
- const ipv4 = checkIp(address);
3361
- if (ipv4.isPublicIp)
3362
- session.publicHostCandidateSeen = true;
3363
- }
3364
- else if (ipRegex.v6({ exact: true }).test(address.replace(/^\[(.*)\]/, "$1"))) {
3365
- const ipv6 = new Address6(address.replace(/^\[(.*)\]/, "$1"));
3366
- session.ipv6HostCandidateSeen = true;
3367
- if (ipv6.getScope() === "Global") {
3368
- session.publicHostCandidateSeen = true;
3369
- }
3370
- if (ipv6.isTeredo()) {
3371
- session.ipv6HostCandidateTeredoSeen = true;
3372
- }
3373
- if (ipv6.is6to4()) {
3374
- session.ipv6HostCandidate6to4Seen = true;
3375
- }
3376
- }
3377
- else {
3378
- const uuidv4 = address.replace(/.local/, "");
3379
- if (uuidv4 && validate(uuidv4, 4)) {
3380
- session.mdnsHostCandidateSeen = true;
3381
- }
3382
- }
3383
- }
3384
- catch (error) {
3385
- logger$6.info("Error during parsing candidates! Error: ", { error });
3386
- }
3387
- break;
3388
- case "srflx":
3389
- session.serverReflexiveCandidateSeen = true;
3390
- break;
3391
- case "relayed":
3392
- case "relay":
3393
- session.relayCandidateSeen = true;
3394
- break;
3395
- }
3396
- this._emitServerEvent(RELAY_MESSAGES.ICE_CANDIDATE, {
3397
- receiverId: clientId,
3398
- message: event.candidate,
3399
- });
3400
- }
3401
- else {
3402
- this._emitServerEvent(RELAY_MESSAGES.ICE_END_OF_CANDIDATES, {
3403
- receiverId: clientId,
3404
- });
3405
- if (!session.publicHostCandidateSeen &&
3406
- !session.relayCandidateSeen &&
3407
- !session.serverReflexiveCandidateSeen &&
3408
- pc.iceConnectionState !== "connected" &&
3409
- pc.iceConnectionState !== "completed") {
3410
- this.analytics.numIceNoPublicIpGathered++;
3411
- }
3412
- if (session.ipv6HostCandidateSeen) {
3413
- this.analytics.numIceIpv6Seen++;
3414
- if (session.ipv6HostCandidate6to4Seen)
3415
- this.analytics.numIceIpv6SixToFour++;
3416
- if (session.ipv6HostCandidateTeredoSeen)
3417
- this.analytics.numIceIpv6TeredoSeen++;
3418
- }
3419
- if (session.mdnsHostCandidateSeen)
3420
- this.analytics.numIceMdnsSeen++;
3421
- }
3422
- };
3423
- pc.onnegotiationneeded = () => {
3424
- if (pc.iceConnectionState === "new" || !session.connectionStatus) {
3425
- return;
3426
- }
3427
- logger$6.info(`onnegotiationneeded client ${clientId}`);
3428
- this._negotiatePeerConnection({ clientId, session });
3429
- };
3430
- return session;
3431
- }
3432
3484
  acceptNewStream({ streamId, clientId }) {
3433
3485
  logger$6.info("acceptNewStream() [streamId: %s}, clientId: %s]", streamId, clientId);
3434
3486
  let session = this._getSession(clientId);
@@ -3442,7 +3494,7 @@ class P2pRtcManager {
3442
3494
  else {
3443
3495
  initialBandwidth = this._changeBandwidthForAllClients(true);
3444
3496
  }
3445
- session = this._createP2pSession({
3497
+ session = this._createSession({
3446
3498
  clientId,
3447
3499
  initialBandwidth,
3448
3500
  isOfferer: false,
@@ -3511,7 +3563,7 @@ class P2pRtcManager {
3511
3563
  }
3512
3564
  else {
3513
3565
  if (localStream.getVideoTracks().length === 0) {
3514
- const constraints = this._webrtcProvider.getMediaConstraints().video;
3566
+ const constraints = getConstraints(this._webrtcProvider.getMediaOptions()).video;
3515
3567
  if (!constraints) {
3516
3568
  return;
3517
3569
  }
@@ -4380,10 +4432,10 @@ const STREAM_TYPES = {
4380
4432
  screenshare: "screenshare",
4381
4433
  };
4382
4434
 
4383
- var _a$1;
4384
- const adapter$1 = (_a$1 = adapterRaw.default) !== null && _a$1 !== void 0 ? _a$1 : adapterRaw;
4435
+ var _a;
4436
+ const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
4385
4437
  const logger$2 = new Logger();
4386
- const browserName = adapter$1.browserDetails.browser;
4438
+ const browserName = adapter.browserDetails.browser;
4387
4439
  let unloading = false;
4388
4440
  const RESTARTICE_ERROR_RETRY_THRESHOLD_IN_MS = 3500;
4389
4441
  const RESTARTICE_ERROR_MAX_RETRY_COUNT = 5;
@@ -5470,7 +5522,7 @@ class VegaRtcManager {
5470
5522
  }, stopCameraDelay);
5471
5523
  }
5472
5524
  else if (localStream.getVideoTracks().length === 0) {
5473
- const constraints = this._webrtcProvider.getMediaConstraints().video;
5525
+ const constraints = getConstraints(this._webrtcProvider.getMediaOptions()).video;
5474
5526
  navigator.mediaDevices
5475
5527
  .getUserMedia({ video: constraints })
5476
5528
  .then((stream) => {
@@ -6995,73 +7047,6 @@ class BandwidthTester extends EventEmitter {
6995
7047
  }
6996
7048
  }
6997
7049
 
6998
- var _a, _b;
6999
- const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
7000
- const isSafari = ((_b = adapter.browserDetails) === null || _b === void 0 ? void 0 : _b.browser) === "safari";
7001
- const parseResolution = (res) => res.split(/[^\d]/g).map((n) => parseInt(n, 10));
7002
- function getMediaConstraints({ disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }) {
7003
- var _a, _b;
7004
- let HIGH_HEIGHT = 480;
7005
- let LOW_HEIGHT = 240;
7006
- if (hd) {
7007
- HIGH_HEIGHT = lax || isSafari ? 720 : { min: 360, ideal: 720 };
7008
- }
7009
- if (simulcast) {
7010
- if (hd === false) {
7011
- HIGH_HEIGHT = 360;
7012
- LOW_HEIGHT = 270;
7013
- }
7014
- else {
7015
- LOW_HEIGHT = 360;
7016
- }
7017
- }
7018
- const constraints = {
7019
- audio: Object.assign({}, (preferredDeviceIds.audioId && { deviceId: preferredDeviceIds.audioId })),
7020
- video: Object.assign(Object.assign({}, (preferredDeviceIds.videoId ? { deviceId: preferredDeviceIds.videoId } : { facingMode: "user" })), { height: lowDataMode ? LOW_HEIGHT : HIGH_HEIGHT, frameRate: lowDataMode && !simulcast ? 15 : 24 }),
7021
- };
7022
- if (lax) {
7023
- if (!((_a = constraints.audio) === null || _a === void 0 ? void 0 : _a.deviceId))
7024
- constraints.audio = true;
7025
- (_b = constraints.video) === null || _b === void 0 ? true : delete _b.facingMode;
7026
- return constraints;
7027
- }
7028
- if (resolution) {
7029
- const [w, h, fps] = parseResolution(resolution);
7030
- if (w)
7031
- constraints.video.width = { exact: w };
7032
- if (h)
7033
- constraints.video.height = { exact: h };
7034
- if (fps)
7035
- constraints.video.frameRate = { exact: fps };
7036
- delete constraints.video.facingMode;
7037
- }
7038
- else {
7039
- constraints.video.aspectRatio = widescreen ? 16 / 9 : 4 / 3;
7040
- }
7041
- if (disableAGC)
7042
- constraints.audio.autoGainControl = false;
7043
- if (disableAEC)
7044
- constraints.audio.echoCancellation = false;
7045
- return constraints;
7046
- }
7047
- function getConstraints({ devices, videoId, audioId, options, type = "ideal" }) {
7048
- const audioDevices = devices.filter((d) => d.kind === "audioinput");
7049
- const videoDevices = devices.filter((d) => d.kind === "videoinput");
7050
- const useDefaultAudio = !audioId || !audioDevices.some((d) => d.deviceId === audioId);
7051
- const useDefaultVideo = !videoId || !videoDevices.some((d) => d.deviceId === videoId);
7052
- const constraints = getMediaConstraints(Object.assign({ preferredDeviceIds: {
7053
- audioId: useDefaultAudio ? null : { [type]: audioId },
7054
- videoId: useDefaultVideo ? null : { [type]: videoId },
7055
- } }, options));
7056
- if (audioId === false || !audioDevices.length) {
7057
- delete constraints.audio;
7058
- }
7059
- if (videoId === false || !videoDevices.length) {
7060
- delete constraints.video;
7061
- }
7062
- return constraints;
7063
- }
7064
-
7065
7050
  const logger = new Logger();
7066
7051
  const isMobile = /mobi/i.test(navigator.userAgent);
7067
7052
  class NoDevicesError extends Error {
@@ -7135,7 +7120,6 @@ function getSettingsFromTrack(kind, track, devices, lastUsedId) {
7135
7120
  if (settings.deviceId)
7136
7121
  return settings;
7137
7122
  settings.deviceId = (_c = track.getConstraints()) === null || _c === void 0 ? void 0 : _c.deviceId;
7138
- settings.broken = 1;
7139
7123
  return settings;
7140
7124
  }
7141
7125
  function getDeviceData({ audioTrack, videoTrack, devices, stoppedVideoTrack, lastAudioId, lastVideoId, }) {