@whereby.com/media 6.0.0 → 7.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.d.ts CHANGED
@@ -1057,9 +1057,7 @@ type SignalIceEndOfCandidatesMessage = {
1057
1057
  clientId: string;
1058
1058
  };
1059
1059
  interface WebRTCProvider {
1060
- getMediaConstraints: () => GetConstraintsOptions;
1061
- browser?: string;
1062
- version?: number;
1060
+ getMediaConstraints: () => MediaStreamConstraints;
1063
1061
  }
1064
1062
  type GetMediaConstraintsOptions = {
1065
1063
  disableAEC: boolean;
@@ -1067,32 +1065,27 @@ type GetMediaConstraintsOptions = {
1067
1065
  hd: boolean;
1068
1066
  lax: boolean;
1069
1067
  lowDataMode: boolean;
1070
- audioWanted: boolean;
1071
- videoWanted: boolean;
1072
1068
  preferredDeviceIds: {
1073
- audioId?: {
1074
- ideal?: string;
1075
- exact?: string;
1069
+ audioId?: boolean | string | null | {
1070
+ ideal?: string | null;
1071
+ exact?: string | null;
1076
1072
  };
1077
- videoId?: {
1078
- ideal?: string;
1079
- exact?: string;
1073
+ videoId?: boolean | string | null | {
1074
+ ideal?: string | null;
1075
+ exact?: string | null;
1080
1076
  };
1081
1077
  };
1082
1078
  resolution?: string;
1083
1079
  simulcast: boolean;
1084
1080
  widescreen: boolean;
1081
+ usingAspectRatio16x9: boolean;
1085
1082
  };
1086
- interface GetSettingsFromTrackResult extends Omit<MediaTrackSettings, "deviceId"> {
1087
- deviceId?: string;
1088
- label?: string;
1089
- }
1090
1083
  type GetConstraintsOptions = {
1091
1084
  devices: MediaDeviceInfo[];
1092
1085
  audioId?: boolean | string;
1093
1086
  videoId?: boolean | string;
1094
1087
  type?: "ideal" | "exact";
1095
- options: Omit<GetMediaConstraintsOptions, "preferredDeviceIds" | "audioWanted" | "videoWanted">;
1088
+ options: Omit<GetMediaConstraintsOptions, "preferredDeviceIds">;
1096
1089
  };
1097
1090
  type GetStreamOptions = {
1098
1091
  replaceStream?: MediaStream;
@@ -1103,13 +1096,8 @@ type GetStreamResult = {
1103
1096
  replacedTracks?: MediaStreamTrack[];
1104
1097
  stream: MediaStream;
1105
1098
  };
1106
- interface BuildDeviceListOptions {
1107
- devices: MediaDeviceInfo[];
1108
- busyDeviceIds: string[];
1109
- kind: MediaDeviceKind;
1110
- }
1111
1099
  type UpdatedDeviceInfo = {
1112
- deviceId?: string;
1100
+ deviceId?: string | null;
1113
1101
  kind?: MediaDeviceKind;
1114
1102
  label?: string;
1115
1103
  };
@@ -1124,8 +1112,16 @@ type GetUpdatedDevicesResult = {
1124
1112
  removedDevices: UpdatedDevicesInfo;
1125
1113
  };
1126
1114
  type GetDeviceDataResult = {
1127
- audio: GetSettingsFromTrackResult;
1128
- video: GetSettingsFromTrackResult;
1115
+ audio: {
1116
+ deviceId: string;
1117
+ label: string;
1118
+ kind: string;
1119
+ };
1120
+ video: {
1121
+ deviceId: string;
1122
+ label: string;
1123
+ kind: string;
1124
+ };
1129
1125
  };
1130
1126
  type SignalIceServer = {
1131
1127
  credential: string;
@@ -1159,47 +1155,36 @@ interface RemoveScreenshareStreamOptions {
1159
1155
  requestedByClientId?: string;
1160
1156
  }
1161
1157
 
1162
- declare function getMediaConstraints({ audioWanted, videoWanted, disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }: GetMediaConstraintsOptions): MediaStreamConstraints;
1163
- declare function getConstraints({ devices, videoId, audioId, options, type }: GetConstraintsOptions): MediaStreamConstraints;
1158
+ declare function getMediaConstraints({ disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }: GetMediaConstraintsOptions): any;
1159
+ declare function getConstraints({ devices, videoId, audioId, options, type }: GetConstraintsOptions): any;
1164
1160
 
1165
1161
  declare const isMobile: boolean;
1166
1162
  declare class NoDevicesError extends Error {
1167
1163
  constructor(...args: any);
1168
1164
  }
1169
1165
  declare function enumerate(): Promise<MediaDeviceInfo[]>;
1170
- declare function buildDeviceList({ busyDeviceIds, devices, kind }: BuildDeviceListOptions): {
1171
- [x: string]: string | boolean;
1172
- label: string;
1173
- busy: boolean;
1174
- }[] | {
1175
- [x: string]: string;
1176
- label: string;
1177
- }[];
1178
- declare function getUserMedia(constraints: MediaStreamConstraints): Promise<MediaStream>;
1166
+ declare function buildDeviceList({ busyDeviceIds, devices, kind }: any): any;
1167
+ declare function getUserMedia(constraints: any): Promise<MediaStream>;
1179
1168
  declare function getDeviceData({ audioTrack, videoTrack, devices, stoppedVideoTrack, lastAudioId, lastVideoId, }: {
1180
- audioTrack?: MediaStreamTrack;
1181
- videoTrack?: MediaStreamTrack;
1169
+ audioTrack?: MediaStreamTrack | null;
1170
+ videoTrack?: MediaStreamTrack | null;
1182
1171
  devices: MediaDeviceInfo[];
1183
- stoppedVideoTrack?: MediaStreamTrack;
1172
+ stoppedVideoTrack?: boolean;
1184
1173
  lastAudioId?: string | undefined;
1185
1174
  lastVideoId?: string | undefined;
1186
1175
  }): GetDeviceDataResult;
1187
1176
  declare function stopStreamTracks(stream: MediaStream, only?: "audio" | "video" | false): void;
1188
1177
  declare function replaceTracksInStream(stream: MediaStream, newStream: MediaStream, only: "audio" | "video" | false): MediaStreamTrack[];
1189
- declare function getStream(constraintOpt: GetConstraintsOptions, { replaceStream, fallback }?: GetStreamOptions): Promise<GetStreamResult>;
1178
+ declare function getStream(constraintOpt: any, { replaceStream, fallback }?: GetStreamOptions): Promise<GetStreamResult>;
1190
1179
  declare function hasGetDisplayMedia(): boolean;
1191
- declare function getDisplayMedia(constraints?: DisplayMediaStreamOptions, contentHint?: "detail" | "motion" | "text"): Promise<MediaStream>;
1192
- declare function compareLocalDevices(before: MediaDeviceInfo[], after: MediaDeviceInfo[]): Record<MediaDeviceKind, {
1193
- removed: Record<string, MediaDeviceInfo>;
1194
- added: Record<string, MediaDeviceInfo>;
1195
- changed: Record<string, MediaDeviceInfo>;
1196
- }>;
1180
+ declare function getDisplayMedia(constraints?: DisplayMediaStreamOptions, contentHint?: string): Promise<MediaStream>;
1181
+ declare function compareLocalDevices(before: MediaDeviceInfo[], after: MediaDeviceInfo[]): any;
1197
1182
  declare function getUpdatedDevices({ oldDevices, newDevices, currentAudioId, currentVideoId, currentSpeakerId, }: {
1198
1183
  oldDevices: MediaDeviceInfo[];
1199
1184
  newDevices: MediaDeviceInfo[];
1200
- currentAudioId?: string;
1201
- currentVideoId?: string;
1202
- currentSpeakerId?: string;
1185
+ currentAudioId?: string | undefined;
1186
+ currentVideoId?: string | undefined;
1187
+ currentSpeakerId?: string | undefined;
1203
1188
  }): GetUpdatedDevicesResult;
1204
1189
 
1205
1190
  interface P2PSessionOptions {
@@ -1629,7 +1614,7 @@ declare class VegaRtcManager implements RtcManager {
1629
1614
  _roomSessionId: any;
1630
1615
  _emitter: any;
1631
1616
  _serverSocket: ServerSocket;
1632
- _webrtcProvider: WebRTCProvider;
1617
+ _webrtcProvider: any;
1633
1618
  _features: any;
1634
1619
  _eventClaim?: any;
1635
1620
  _vegaConnection: VegaConnection | null;
@@ -1958,4 +1943,4 @@ declare const STREAM_TYPES: {
1958
1943
  };
1959
1944
 
1960
1945
  export { ADDITIONAL_SCREEN_SHARE_SETTINGS, AUDIO_SETTINGS, BandwidthTester, CAMERA_STREAM_ID, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, SCREEN_SHARE_SETTINGS, SCREEN_SHARE_SIMULCAST_SETTINGS, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VIDEO_SETTINGS_HD, VIDEO_SETTINGS_SD, VIDEO_SETTINGS_VP9, VIDEO_SETTINGS_VP9_LOW_BANDWIDTH, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDeviceAsync, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, issueDetectorOrMetricEnabled, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, trackAnnotations, turnServerOverride, variance };
1961
- export type { AddCameraStreamOptions, AddSpotlightRequest, AudioEnableRequest, AudioEnableRequestedEvent, AudioEnabledEvent, BreakoutConfig, BreakoutGroupJoinedEvent, BreakoutSessionUpdatedEvent, BuildDeviceListOptions, CannotJoinUnclaimedRoomError, ChatMessage, ClientKickedEvent, ClientLeftEvent, ClientMetadataPayload, ClientMetadataReceivedEvent, ClientRole, ClientUnableToJoinEvent, CloudRecordingStartedEvent, Codec, Credentials, ForbiddenError, ForbiddenErrorNames, GetConstraintsOptions, GetDeviceDataResult, GetMediaConstraintsOptions, GetSettingsFromTrackResult, GetStreamOptions, GetStreamResult, GetUpdatedDevicesResult, HostPresenceControlsError, IdentifyDeviceRequest, InternalServerError, InvalidAssistantKeyError, IssuesAndMetricsByView, JoinRoomRequest, KnockAcceptedEvent, KnockRejectedEvent, KnockRoomRequest, KnockerLeftEvent, LiveTranscriptionStartedEvent, LiveTranscriptionStoppedEvent, MaxViewerLimitReachedError, Metric, NewClientEvent, OrganizationAssistantNotEnabledError, OrganizationAssistantNotFoundError, OrganizationPlanExhaustedError, RemoveScreenshareStreamOptions, RemoveSpotlightRequest, RoleName, RoomConcurrencyControlsError, RoomEmptyError, RoomFullError, RoomJoinPermissionDeniedError, RoomJoinedErrors, RoomJoinedEvent, RoomJoinedSuccess, RoomKnockedEvent, RoomLockedError, RoomLockedEvent, RoomMeetingTimeExhaustedError, RoomMode, RoomSessionEndedEvent, RtcClientConnectionStatusChangedPayload, RtcEventEmitter, RtcEvents, RtcLocalStreamTrackAddedPayload, RtcLocalStreamTrackRemovedPayload, RtcManager, RtcManagerCreatedPayload, RtcManagerOptions, RtcStreamAddedPayload, ScreenshareStartedEvent, ScreenshareStoppedEvent, SendClientMetadataRequest, SignalClient, SignalEvents, SignalIceCandidateMessage, SignalIceEndOfCandidatesMessage, SignalIceServer, SignalKnocker, SignalMediaServerConfig, SignalRTCSessionDescription, SignalReadyToReceiveOfferMessage, SignalRequests, SignalRoom, SignalSDPMessage, SignalSFUServer, SignalTurnServer, SocketConf, SocketManager, Spotlight, SpotlightAddedEvent, SpotlightRemovedEvent, StatsMonitorOptions, StatsMonitorState, StatsSubscription, TurnTransportProtocol, UniqueRoleAlreadyInRoomError, UpdatedDeviceInfo, UpdatedDevicesInfo, VegaRtcManagerOptions, VideoEnableRequest, VideoEnableRequestedEvent, VideoEnabledEvent, WebRTCProvider };
1946
+ export type { AddCameraStreamOptions, AddSpotlightRequest, AudioEnableRequest, AudioEnableRequestedEvent, AudioEnabledEvent, BreakoutConfig, BreakoutGroupJoinedEvent, BreakoutSessionUpdatedEvent, CannotJoinUnclaimedRoomError, ChatMessage, ClientKickedEvent, ClientLeftEvent, ClientMetadataPayload, ClientMetadataReceivedEvent, ClientRole, ClientUnableToJoinEvent, CloudRecordingStartedEvent, Codec, Credentials, ForbiddenError, ForbiddenErrorNames, GetConstraintsOptions, GetDeviceDataResult, GetMediaConstraintsOptions, GetStreamOptions, GetStreamResult, GetUpdatedDevicesResult, HostPresenceControlsError, IdentifyDeviceRequest, InternalServerError, InvalidAssistantKeyError, IssuesAndMetricsByView, JoinRoomRequest, KnockAcceptedEvent, KnockRejectedEvent, KnockRoomRequest, KnockerLeftEvent, LiveTranscriptionStartedEvent, LiveTranscriptionStoppedEvent, MaxViewerLimitReachedError, Metric, NewClientEvent, OrganizationAssistantNotEnabledError, OrganizationAssistantNotFoundError, OrganizationPlanExhaustedError, RemoveScreenshareStreamOptions, RemoveSpotlightRequest, RoleName, RoomConcurrencyControlsError, RoomEmptyError, RoomFullError, RoomJoinPermissionDeniedError, RoomJoinedErrors, RoomJoinedEvent, RoomJoinedSuccess, RoomKnockedEvent, RoomLockedError, RoomLockedEvent, RoomMeetingTimeExhaustedError, RoomMode, RoomSessionEndedEvent, RtcClientConnectionStatusChangedPayload, RtcEventEmitter, RtcEvents, RtcLocalStreamTrackAddedPayload, RtcLocalStreamTrackRemovedPayload, RtcManager, RtcManagerCreatedPayload, RtcManagerOptions, RtcStreamAddedPayload, ScreenshareStartedEvent, ScreenshareStoppedEvent, SendClientMetadataRequest, SignalClient, SignalEvents, SignalIceCandidateMessage, SignalIceEndOfCandidatesMessage, SignalIceServer, SignalKnocker, SignalMediaServerConfig, SignalRTCSessionDescription, SignalReadyToReceiveOfferMessage, SignalRequests, SignalRoom, SignalSDPMessage, SignalSFUServer, SignalTurnServer, SocketConf, SocketManager, Spotlight, SpotlightAddedEvent, SpotlightRemovedEvent, StatsMonitorOptions, StatsMonitorState, StatsSubscription, TurnTransportProtocol, UniqueRoleAlreadyInRoomError, UpdatedDeviceInfo, UpdatedDevicesInfo, VegaRtcManagerOptions, VideoEnableRequest, VideoEnableRequestedEvent, VideoEnabledEvent, WebRTCProvider };
package/dist/index.mjs CHANGED
@@ -2505,75 +2505,11 @@ var rtcManagerEvents = {
2505
2505
 
2506
2506
  var _a$2, _b$1;
2507
2507
  const adapter$2 = (_a$2 = adapterRaw.default) !== null && _a$2 !== void 0 ? _a$2 : adapterRaw;
2508
- const isSafari = ((_b$1 = adapter$2.browserDetails) === null || _b$1 === void 0 ? void 0 : _b$1.browser) === "safari";
2509
- const parseResolution = (res) => res.split(/[^\d]/g).map((n) => parseInt(n, 10));
2510
- function getMediaConstraints({ audioWanted, videoWanted, disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }) {
2511
- let HIGH_HEIGHT = 480;
2512
- let LOW_HEIGHT = 240;
2513
- if (hd) {
2514
- HIGH_HEIGHT = lax || isSafari ? 720 : { min: 360, ideal: 720 };
2515
- }
2516
- if (simulcast) {
2517
- if (hd === false) {
2518
- HIGH_HEIGHT = 360;
2519
- LOW_HEIGHT = 270;
2520
- }
2521
- else {
2522
- LOW_HEIGHT = 360;
2523
- }
2524
- }
2525
- const { audioId, videoId } = preferredDeviceIds;
2526
- const constraints = Object.assign(Object.assign({}, (audioWanted && {
2527
- audio: Object.assign(Object.assign(Object.assign({}, (audioId ? { deviceId: audioId } : {})), (disableAGC ? { autoGainControl: false } : {})), (disableAEC ? { echoCancellation: false } : {})),
2528
- })), (videoWanted && {
2529
- video: Object.assign({ height: lowDataMode ? LOW_HEIGHT : HIGH_HEIGHT, frameRate: lowDataMode && !simulcast ? 15 : 24 }, (videoId ? { deviceId: videoId } : { facingMode: "user" })),
2530
- }));
2531
- if (lax) {
2532
- if (audioWanted && !audioId)
2533
- constraints.audio = true;
2534
- if (videoWanted && !videoId && typeof constraints.video === "object") {
2535
- delete constraints.video.facingMode;
2536
- }
2537
- return constraints;
2538
- }
2539
- if (videoWanted && typeof constraints.video === "object") {
2540
- if (resolution) {
2541
- const [w, h, fps] = parseResolution(resolution);
2542
- if (w)
2543
- constraints.video.width = { exact: w };
2544
- if (h)
2545
- constraints.video.height = { exact: h };
2546
- if (fps)
2547
- constraints.video.frameRate = { exact: fps };
2548
- delete constraints.video.facingMode;
2549
- }
2550
- else {
2551
- constraints.video.aspectRatio = widescreen ? 16 / 9 : 4 / 3;
2552
- }
2553
- }
2554
- return constraints;
2555
- }
2556
- function getConstraints({ devices, videoId, audioId, options, type = "ideal" }) {
2557
- const audioDevices = devices.filter((d) => d.kind === "audioinput");
2558
- const videoDevices = devices.filter((d) => d.kind === "videoinput");
2559
- const preferredDeviceIds = {};
2560
- if (typeof audioId === "string" && audioDevices.some((d) => d.deviceId === audioId)) {
2561
- preferredDeviceIds.audioId = { [type]: audioId };
2562
- }
2563
- if (typeof videoId === "string" && videoDevices.some((d) => d.deviceId === videoId)) {
2564
- preferredDeviceIds.videoId = { [type]: videoId };
2565
- }
2566
- const constraints = getMediaConstraints(Object.assign({ preferredDeviceIds, audioWanted: Boolean(audioId) && audioDevices.length > 0, videoWanted: Boolean(videoId) && videoDevices.length > 0 }, options));
2567
- return constraints;
2568
- }
2569
-
2570
- var _a$1, _b;
2571
- const adapter$1 = (_a$1 = adapterRaw.default) !== null && _a$1 !== void 0 ? _a$1 : adapterRaw;
2572
2508
  const logger$6 = new Logger();
2573
2509
  const ICE_PUBLIC_IP_GATHERING_TIMEOUT = 3 * 1000;
2574
2510
  const ICE_RESTART_DELAY = 2 * 1000;
2575
- const browserName$1 = (_b = adapter$1.browserDetails) === null || _b === void 0 ? void 0 : _b.browser;
2576
- const browserVersion = adapter$1.browserDetails.version;
2511
+ const browserName$1 = (_b$1 = adapter$2.browserDetails) === null || _b$1 === void 0 ? void 0 : _b$1.browser;
2512
+ const browserVersion = adapter$2.browserDetails.version;
2577
2513
  let unloading$1 = false;
2578
2514
  if (browserName$1 === "chrome") {
2579
2515
  window.document.addEventListener("beforeunload", () => {
@@ -3558,7 +3494,7 @@ class P2pRtcManager {
3558
3494
  }
3559
3495
  else {
3560
3496
  if (localStream.getVideoTracks().length === 0) {
3561
- const constraints = getConstraints(this._webrtcProvider.getMediaConstraints()).video;
3497
+ const constraints = this._webrtcProvider.getMediaConstraints().video;
3562
3498
  if (!constraints) {
3563
3499
  return;
3564
3500
  }
@@ -4427,10 +4363,10 @@ const STREAM_TYPES = {
4427
4363
  screenshare: "screenshare",
4428
4364
  };
4429
4365
 
4430
- var _a;
4431
- const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
4366
+ var _a$1;
4367
+ const adapter$1 = (_a$1 = adapterRaw.default) !== null && _a$1 !== void 0 ? _a$1 : adapterRaw;
4432
4368
  const logger$2 = new Logger();
4433
- const browserName = adapter.browserDetails.browser;
4369
+ const browserName = adapter$1.browserDetails.browser;
4434
4370
  let unloading = false;
4435
4371
  const RESTARTICE_ERROR_RETRY_THRESHOLD_IN_MS = 3500;
4436
4372
  const RESTARTICE_ERROR_MAX_RETRY_COUNT = 5;
@@ -5514,7 +5450,7 @@ class VegaRtcManager {
5514
5450
  }, stopCameraDelay);
5515
5451
  }
5516
5452
  else if (localStream.getVideoTracks().length === 0) {
5517
- const constraints = getConstraints(this._webrtcProvider.getMediaConstraints()).video;
5453
+ const constraints = this._webrtcProvider.getMediaConstraints().video;
5518
5454
  navigator.mediaDevices
5519
5455
  .getUserMedia({ video: constraints })
5520
5456
  .then((stream) => {
@@ -7039,6 +6975,73 @@ class BandwidthTester extends EventEmitter {
7039
6975
  }
7040
6976
  }
7041
6977
 
6978
+ var _a, _b;
6979
+ const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
6980
+ const isSafari = ((_b = adapter.browserDetails) === null || _b === void 0 ? void 0 : _b.browser) === "safari";
6981
+ const parseResolution = (res) => res.split(/[^\d]/g).map((n) => parseInt(n, 10));
6982
+ function getMediaConstraints({ disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }) {
6983
+ var _a, _b;
6984
+ let HIGH_HEIGHT = 480;
6985
+ let LOW_HEIGHT = 240;
6986
+ if (hd) {
6987
+ HIGH_HEIGHT = lax || isSafari ? 720 : { min: 360, ideal: 720 };
6988
+ }
6989
+ if (simulcast) {
6990
+ if (hd === false) {
6991
+ HIGH_HEIGHT = 360;
6992
+ LOW_HEIGHT = 270;
6993
+ }
6994
+ else {
6995
+ LOW_HEIGHT = 360;
6996
+ }
6997
+ }
6998
+ const constraints = {
6999
+ audio: Object.assign({}, (preferredDeviceIds.audioId && { deviceId: preferredDeviceIds.audioId })),
7000
+ video: Object.assign(Object.assign({}, (preferredDeviceIds.videoId ? { deviceId: preferredDeviceIds.videoId } : { facingMode: "user" })), { height: lowDataMode ? LOW_HEIGHT : HIGH_HEIGHT, frameRate: lowDataMode && !simulcast ? 15 : 24 }),
7001
+ };
7002
+ if (lax) {
7003
+ if (!((_a = constraints.audio) === null || _a === void 0 ? void 0 : _a.deviceId))
7004
+ constraints.audio = true;
7005
+ (_b = constraints.video) === null || _b === void 0 ? true : delete _b.facingMode;
7006
+ return constraints;
7007
+ }
7008
+ if (resolution) {
7009
+ const [w, h, fps] = parseResolution(resolution);
7010
+ if (w)
7011
+ constraints.video.width = { exact: w };
7012
+ if (h)
7013
+ constraints.video.height = { exact: h };
7014
+ if (fps)
7015
+ constraints.video.frameRate = { exact: fps };
7016
+ delete constraints.video.facingMode;
7017
+ }
7018
+ else {
7019
+ constraints.video.aspectRatio = widescreen ? 16 / 9 : 4 / 3;
7020
+ }
7021
+ if (disableAGC)
7022
+ constraints.audio.autoGainControl = false;
7023
+ if (disableAEC)
7024
+ constraints.audio.echoCancellation = false;
7025
+ return constraints;
7026
+ }
7027
+ function getConstraints({ devices, videoId, audioId, options, type = "ideal" }) {
7028
+ const audioDevices = devices.filter((d) => d.kind === "audioinput");
7029
+ const videoDevices = devices.filter((d) => d.kind === "videoinput");
7030
+ const useDefaultAudio = !audioId || !audioDevices.some((d) => d.deviceId === audioId);
7031
+ const useDefaultVideo = !videoId || !videoDevices.some((d) => d.deviceId === videoId);
7032
+ const constraints = getMediaConstraints(Object.assign({ preferredDeviceIds: {
7033
+ audioId: useDefaultAudio ? null : { [type]: audioId },
7034
+ videoId: useDefaultVideo ? null : { [type]: videoId },
7035
+ } }, options));
7036
+ if (audioId === false || !audioDevices.length) {
7037
+ delete constraints.audio;
7038
+ }
7039
+ if (videoId === false || !videoDevices.length) {
7040
+ delete constraints.video;
7041
+ }
7042
+ return constraints;
7043
+ }
7044
+
7042
7045
  const logger = new Logger();
7043
7046
  const isMobile = /mobi/i.test(navigator.userAgent);
7044
7047
  class NoDevicesError extends Error {
@@ -7072,29 +7075,23 @@ function buildDeviceList({ busyDeviceIds, devices, kind }) {
7072
7075
  label: `${busyDeviceIds.includes(d.deviceId) ? "(busy) " : ""}${d.label || d.deviceId.slice(0, 5)}`,
7073
7076
  busy: busyDeviceIds.includes(d.deviceId),
7074
7077
  }));
7075
- return deviceList && deviceList.length !== 0 ? deviceList : [{ [idFieldsByKind[kind]]: "", label: "Default" }];
7078
+ return deviceList && deviceList.length !== 0
7079
+ ? deviceList
7080
+ : [{ [idFieldsByKind[kind]]: "", label: "Default" }];
7076
7081
  }
7077
7082
  function getUserMedia(constraints) {
7078
- return __awaiter(this, void 0, void 0, function* () {
7079
- if (!constraints.audio && !constraints.video) {
7080
- throw new NoDevicesError("No provided devices");
7081
- }
7082
- try {
7083
- const stream = yield navigator.mediaDevices.getUserMedia(constraints);
7084
- return stream;
7085
- }
7086
- catch (error) {
7087
- const message = `${error}, ${JSON.stringify(constraints, null, 2)}`;
7088
- logger.error(`getUserMedia ${message}`);
7089
- throw error;
7090
- }
7083
+ if (!constraints.audio && !constraints.video) {
7084
+ return Promise.reject(new NoDevicesError("No provided devices"));
7085
+ }
7086
+ return navigator.mediaDevices.getUserMedia(constraints).catch((error) => {
7087
+ const message = `${error}, ${JSON.stringify(constraints, null, 2)}`;
7088
+ logger.error(`getUserMedia ${message}`);
7089
+ throw error;
7091
7090
  });
7092
7091
  }
7093
7092
  function getSettingsFromTrack(kind, track, devices, lastUsedId) {
7094
7093
  var _a, _b, _c;
7095
- let settings = {
7096
- deviceId: undefined,
7097
- };
7094
+ let settings = { deviceId: null };
7098
7095
  if (!track) {
7099
7096
  if (lastUsedId && devices) {
7100
7097
  settings.deviceId = (_a = devices.find((d) => d.deviceId === lastUsedId && d.kind === kind)) === null || _a === void 0 ? void 0 : _a.deviceId;
@@ -7118,10 +7115,11 @@ function getSettingsFromTrack(kind, track, devices, lastUsedId) {
7118
7115
  if (settings.deviceId)
7119
7116
  return settings;
7120
7117
  settings.deviceId = (_c = track.getConstraints()) === null || _c === void 0 ? void 0 : _c.deviceId;
7118
+ settings.broken = 1;
7121
7119
  return settings;
7122
7120
  }
7123
7121
  function getDeviceData({ audioTrack, videoTrack, devices, stoppedVideoTrack, lastAudioId, lastVideoId, }) {
7124
- const usable = (d) => ((d === null || d === void 0 ? void 0 : d.readyState) === "live" ? d : undefined);
7122
+ const usable = (d) => ((d === null || d === void 0 ? void 0 : d.readyState) === "live" ? d : null);
7125
7123
  videoTrack = usable(videoTrack) || stoppedVideoTrack;
7126
7124
  audioTrack = usable(audioTrack);
7127
7125
  const video = getSettingsFromTrack("videoinput", videoTrack, devices, lastVideoId);
@@ -7154,7 +7152,7 @@ function getStream(constraintOpt_1) {
7154
7152
  let newConstraints;
7155
7153
  let retryConstraintOpt;
7156
7154
  let stream = null;
7157
- const only = (!constraintOpt.audioId && "video") || (!constraintOpt.videoId && "audio");
7155
+ const only = (constraintOpt.audioId === false && "video") || (constraintOpt.videoId === false && "audio");
7158
7156
  const stopTracks = isMobile || only !== "video";
7159
7157
  const constraints = getConstraints(constraintOpt);
7160
7158
  const addDetails = (err, orgErr) => {
@@ -7165,7 +7163,7 @@ function getStream(constraintOpt_1) {
7165
7163
  return err;
7166
7164
  }
7167
7165
  else {
7168
- return new Error("GetStream: gUM rejected without error");
7166
+ return new Error("Unknown error");
7169
7167
  }
7170
7168
  };
7171
7169
  const getSingleStream = (e) => __awaiter(this, void 0, void 0, function* () {
@@ -7199,18 +7197,12 @@ function getStream(constraintOpt_1) {
7199
7197
  }
7200
7198
  if ((e === null || e === void 0 ? void 0 : e.name) === "OverconstrainedError") {
7201
7199
  const laxConstraints = {
7202
- deviceId: { videoId: true, audioId: true },
7200
+ deviceId: { videoId: null, audioId: null },
7203
7201
  width: { lax: true },
7204
7202
  height: { lax: true },
7205
- "": { audioId: true, videoId: true, lax: true },
7203
+ "": { audioId: null, videoId: null, lax: true },
7206
7204
  };
7207
7205
  retryConstraintOpt = laxConstraints[e.constraint || ""];
7208
- if (!constraintOpt.audioId || only === "video") {
7209
- delete retryConstraintOpt.audioId;
7210
- }
7211
- if (!constraintOpt.videoId || only === "audio") {
7212
- delete retryConstraintOpt.videoId;
7213
- }
7214
7206
  }
7215
7207
  else if ((e === null || e === void 0 ? void 0 : e.name) === "NotFoundError") {
7216
7208
  yield getSingleStream(e);
@@ -7234,7 +7226,7 @@ function getStream(constraintOpt_1) {
7234
7226
  const problemWith = { audio: "audioId", video: "videoId" }[((_a = /(video|audio)/.exec(errMsg)) === null || _a === void 0 ? void 0 : _a[0]) || only || ""];
7235
7227
  if (!stream && problemWith) {
7236
7228
  try {
7237
- stream = yield getUserMedia(getConstraints(Object.assign(Object.assign({}, constraintOpt), { [problemWith]: true })));
7229
+ stream = yield getUserMedia(getConstraints(Object.assign(Object.assign({}, constraintOpt), { [problemWith]: null })));
7238
7230
  }
7239
7231
  catch (e2) {
7240
7232
  logger.warn(`Re-tried ${problemWith} with no constraints, but failed: ${"" + e2}`);
@@ -7294,9 +7286,8 @@ const defaultDisplayMediaConstraints = {
7294
7286
  height: { max: window.screen.height },
7295
7287
  },
7296
7288
  };
7297
- function getDisplayMedia() {
7298
- return __awaiter(this, arguments, void 0, function* (constraints = defaultDisplayMediaConstraints, contentHint = "detail") {
7299
- const stream = yield navigator.mediaDevices.getDisplayMedia(constraints);
7289
+ function getDisplayMedia(constraints = defaultDisplayMediaConstraints, contentHint = "detail") {
7290
+ return navigator.mediaDevices.getDisplayMedia(constraints).then((stream) => {
7300
7291
  stream.getVideoTracks().forEach((t) => {
7301
7292
  if ("contentHint" in t) {
7302
7293
  t.contentHint = contentHint;
@@ -7354,10 +7345,14 @@ function getUpdatedDevices({ oldDevices, newDevices, currentAudioId, currentVide
7354
7345
  }
7355
7346
  if (currentDeviceId) {
7356
7347
  if (changes.removed[currentDeviceId]) {
7357
- removedDevices[kind] = changes.removed[currentDeviceId];
7348
+ changedDevices[kind] = { deviceId: null };
7349
+ if (kind === "audiooutput") {
7350
+ const fallbackSpeakerDevice = newDevices.find((d) => d.kind === "audiooutput");
7351
+ changedDevices[kind] = { deviceId: fallbackSpeakerDevice === null || fallbackSpeakerDevice === void 0 ? void 0 : fallbackSpeakerDevice.deviceId };
7352
+ }
7358
7353
  }
7359
7354
  if (changes.changed[currentDeviceId]) {
7360
- changedDevices[kind] = changes.changed[currentDeviceId];
7355
+ changedDevices[kind] = { deviceId: currentDeviceId };
7361
7356
  }
7362
7357
  }
7363
7358
  if (Object.keys(changes.added).length > 0) {
@@ -7365,6 +7360,10 @@ function getUpdatedDevices({ oldDevices, newDevices, currentAudioId, currentVide
7365
7360
  const add = changes.added[deviceAdded];
7366
7361
  addedDevices[kind] = { deviceId: add.deviceId, label: add.label, kind: add.kind };
7367
7362
  }
7363
+ if (Object.keys(changes.removed).length > 0) {
7364
+ const [deviceRemoved] = Object.keys(changes.removed).slice(0, 1);
7365
+ removedDevices[kind] = changes.removed[deviceRemoved];
7366
+ }
7368
7367
  });
7369
7368
  return { addedDevices, changedDevices, removedDevices };
7370
7369
  }