@whereby.com/media 5.0.2 → 6.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,7 +1057,9 @@ type SignalIceEndOfCandidatesMessage = {
1057
1057
  clientId: string;
1058
1058
  };
1059
1059
  interface WebRTCProvider {
1060
- getMediaConstraints: () => MediaStreamConstraints;
1060
+ getMediaConstraints: () => GetConstraintsOptions;
1061
+ browser?: string;
1062
+ version?: number;
1061
1063
  }
1062
1064
  type GetMediaConstraintsOptions = {
1063
1065
  disableAEC: boolean;
@@ -1065,27 +1067,32 @@ type GetMediaConstraintsOptions = {
1065
1067
  hd: boolean;
1066
1068
  lax: boolean;
1067
1069
  lowDataMode: boolean;
1070
+ audioWanted: boolean;
1071
+ videoWanted: boolean;
1068
1072
  preferredDeviceIds: {
1069
- audioId?: boolean | string | null | {
1070
- ideal?: string | null;
1071
- exact?: string | null;
1073
+ audioId?: {
1074
+ ideal?: string;
1075
+ exact?: string;
1072
1076
  };
1073
- videoId?: boolean | string | null | {
1074
- ideal?: string | null;
1075
- exact?: string | null;
1077
+ videoId?: {
1078
+ ideal?: string;
1079
+ exact?: string;
1076
1080
  };
1077
1081
  };
1078
1082
  resolution?: string;
1079
1083
  simulcast: boolean;
1080
1084
  widescreen: boolean;
1081
- usingAspectRatio16x9: boolean;
1082
1085
  };
1086
+ interface GetSettingsFromTrackResult extends Omit<MediaTrackSettings, "deviceId"> {
1087
+ deviceId?: string;
1088
+ label?: string;
1089
+ }
1083
1090
  type GetConstraintsOptions = {
1084
1091
  devices: MediaDeviceInfo[];
1085
1092
  audioId?: boolean | string;
1086
1093
  videoId?: boolean | string;
1087
1094
  type?: "ideal" | "exact";
1088
- options: Omit<GetMediaConstraintsOptions, "preferredDeviceIds">;
1095
+ options: Omit<GetMediaConstraintsOptions, "preferredDeviceIds" | "audioWanted" | "videoWanted">;
1089
1096
  };
1090
1097
  type GetStreamOptions = {
1091
1098
  replaceStream?: MediaStream;
@@ -1096,8 +1103,13 @@ type GetStreamResult = {
1096
1103
  replacedTracks?: MediaStreamTrack[];
1097
1104
  stream: MediaStream;
1098
1105
  };
1106
+ interface BuildDeviceListOptions {
1107
+ devices: MediaDeviceInfo[];
1108
+ busyDeviceIds: string[];
1109
+ kind: MediaDeviceKind;
1110
+ }
1099
1111
  type UpdatedDeviceInfo = {
1100
- deviceId?: string | null;
1112
+ deviceId?: string;
1101
1113
  kind?: MediaDeviceKind;
1102
1114
  label?: string;
1103
1115
  };
@@ -1112,16 +1124,8 @@ type GetUpdatedDevicesResult = {
1112
1124
  removedDevices: UpdatedDevicesInfo;
1113
1125
  };
1114
1126
  type GetDeviceDataResult = {
1115
- audio: {
1116
- deviceId: string;
1117
- label: string;
1118
- kind: string;
1119
- };
1120
- video: {
1121
- deviceId: string;
1122
- label: string;
1123
- kind: string;
1124
- };
1127
+ audio: GetSettingsFromTrackResult;
1128
+ video: GetSettingsFromTrackResult;
1125
1129
  };
1126
1130
  type SignalIceServer = {
1127
1131
  credential: string;
@@ -1155,36 +1159,47 @@ interface RemoveScreenshareStreamOptions {
1155
1159
  requestedByClientId?: string;
1156
1160
  }
1157
1161
 
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;
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;
1160
1164
 
1161
1165
  declare const isMobile: boolean;
1162
1166
  declare class NoDevicesError extends Error {
1163
1167
  constructor(...args: any);
1164
1168
  }
1165
1169
  declare function enumerate(): Promise<MediaDeviceInfo[]>;
1166
- declare function buildDeviceList({ busyDeviceIds, devices, kind }: any): any;
1167
- declare function getUserMedia(constraints: any): Promise<MediaStream>;
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>;
1168
1179
  declare function getDeviceData({ audioTrack, videoTrack, devices, stoppedVideoTrack, lastAudioId, lastVideoId, }: {
1169
- audioTrack?: MediaStreamTrack | null;
1170
- videoTrack?: MediaStreamTrack | null;
1180
+ audioTrack?: MediaStreamTrack;
1181
+ videoTrack?: MediaStreamTrack;
1171
1182
  devices: MediaDeviceInfo[];
1172
- stoppedVideoTrack?: boolean;
1183
+ stoppedVideoTrack?: MediaStreamTrack;
1173
1184
  lastAudioId?: string | undefined;
1174
1185
  lastVideoId?: string | undefined;
1175
1186
  }): GetDeviceDataResult;
1176
1187
  declare function stopStreamTracks(stream: MediaStream, only?: "audio" | "video" | false): void;
1177
1188
  declare function replaceTracksInStream(stream: MediaStream, newStream: MediaStream, only: "audio" | "video" | false): MediaStreamTrack[];
1178
- declare function getStream(constraintOpt: any, { replaceStream, fallback }?: GetStreamOptions): Promise<GetStreamResult>;
1189
+ declare function getStream(constraintOpt: GetConstraintsOptions, { replaceStream, fallback }?: GetStreamOptions): Promise<GetStreamResult>;
1179
1190
  declare function hasGetDisplayMedia(): boolean;
1180
- declare function getDisplayMedia(constraints?: DisplayMediaStreamOptions, contentHint?: string): Promise<MediaStream>;
1181
- declare function compareLocalDevices(before: MediaDeviceInfo[], after: MediaDeviceInfo[]): any;
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
+ }>;
1182
1197
  declare function getUpdatedDevices({ oldDevices, newDevices, currentAudioId, currentVideoId, currentSpeakerId, }: {
1183
1198
  oldDevices: MediaDeviceInfo[];
1184
1199
  newDevices: MediaDeviceInfo[];
1185
- currentAudioId?: string | undefined;
1186
- currentVideoId?: string | undefined;
1187
- currentSpeakerId?: string | undefined;
1200
+ currentAudioId?: string;
1201
+ currentVideoId?: string;
1202
+ currentSpeakerId?: string;
1188
1203
  }): GetUpdatedDevicesResult;
1189
1204
 
1190
1205
  interface P2PSessionOptions {
@@ -1614,7 +1629,7 @@ declare class VegaRtcManager implements RtcManager {
1614
1629
  _roomSessionId: any;
1615
1630
  _emitter: any;
1616
1631
  _serverSocket: ServerSocket;
1617
- _webrtcProvider: any;
1632
+ _webrtcProvider: WebRTCProvider;
1618
1633
  _features: any;
1619
1634
  _eventClaim?: any;
1620
1635
  _vegaConnection: VegaConnection | null;
@@ -1943,4 +1958,4 @@ declare const STREAM_TYPES: {
1943
1958
  };
1944
1959
 
1945
1960
  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 };
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 };
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 };
package/dist/index.mjs CHANGED
@@ -2505,11 +2505,75 @@ 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;
2508
2572
  const logger$6 = new Logger();
2509
2573
  const ICE_PUBLIC_IP_GATHERING_TIMEOUT = 3 * 1000;
2510
2574
  const ICE_RESTART_DELAY = 2 * 1000;
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;
2575
+ const browserName$1 = (_b = adapter$1.browserDetails) === null || _b === void 0 ? void 0 : _b.browser;
2576
+ const browserVersion = adapter$1.browserDetails.version;
2513
2577
  let unloading$1 = false;
2514
2578
  if (browserName$1 === "chrome") {
2515
2579
  window.document.addEventListener("beforeunload", () => {
@@ -3494,7 +3558,7 @@ class P2pRtcManager {
3494
3558
  }
3495
3559
  else {
3496
3560
  if (localStream.getVideoTracks().length === 0) {
3497
- const constraints = this._webrtcProvider.getMediaConstraints().video;
3561
+ const constraints = getConstraints(this._webrtcProvider.getMediaConstraints()).video;
3498
3562
  if (!constraints) {
3499
3563
  return;
3500
3564
  }
@@ -4363,10 +4427,10 @@ const STREAM_TYPES = {
4363
4427
  screenshare: "screenshare",
4364
4428
  };
4365
4429
 
4366
- var _a$1;
4367
- const adapter$1 = (_a$1 = adapterRaw.default) !== null && _a$1 !== void 0 ? _a$1 : adapterRaw;
4430
+ var _a;
4431
+ const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
4368
4432
  const logger$2 = new Logger();
4369
- const browserName = adapter$1.browserDetails.browser;
4433
+ const browserName = adapter.browserDetails.browser;
4370
4434
  let unloading = false;
4371
4435
  const RESTARTICE_ERROR_RETRY_THRESHOLD_IN_MS = 3500;
4372
4436
  const RESTARTICE_ERROR_MAX_RETRY_COUNT = 5;
@@ -5450,7 +5514,7 @@ class VegaRtcManager {
5450
5514
  }, stopCameraDelay);
5451
5515
  }
5452
5516
  else if (localStream.getVideoTracks().length === 0) {
5453
- const constraints = this._webrtcProvider.getMediaConstraints().video;
5517
+ const constraints = getConstraints(this._webrtcProvider.getMediaConstraints()).video;
5454
5518
  navigator.mediaDevices
5455
5519
  .getUserMedia({ video: constraints })
5456
5520
  .then((stream) => {
@@ -6975,73 +7039,6 @@ class BandwidthTester extends EventEmitter {
6975
7039
  }
6976
7040
  }
6977
7041
 
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
-
7045
7042
  const logger = new Logger();
7046
7043
  const isMobile = /mobi/i.test(navigator.userAgent);
7047
7044
  class NoDevicesError extends Error {
@@ -7075,23 +7072,29 @@ function buildDeviceList({ busyDeviceIds, devices, kind }) {
7075
7072
  label: `${busyDeviceIds.includes(d.deviceId) ? "(busy) " : ""}${d.label || d.deviceId.slice(0, 5)}`,
7076
7073
  busy: busyDeviceIds.includes(d.deviceId),
7077
7074
  }));
7078
- return deviceList && deviceList.length !== 0
7079
- ? deviceList
7080
- : [{ [idFieldsByKind[kind]]: "", label: "Default" }];
7075
+ return deviceList && deviceList.length !== 0 ? deviceList : [{ [idFieldsByKind[kind]]: "", label: "Default" }];
7081
7076
  }
7082
7077
  function getUserMedia(constraints) {
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;
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
+ }
7090
7091
  });
7091
7092
  }
7092
7093
  function getSettingsFromTrack(kind, track, devices, lastUsedId) {
7093
7094
  var _a, _b, _c;
7094
- let settings = { deviceId: null };
7095
+ let settings = {
7096
+ deviceId: undefined,
7097
+ };
7095
7098
  if (!track) {
7096
7099
  if (lastUsedId && devices) {
7097
7100
  settings.deviceId = (_a = devices.find((d) => d.deviceId === lastUsedId && d.kind === kind)) === null || _a === void 0 ? void 0 : _a.deviceId;
@@ -7115,11 +7118,10 @@ function getSettingsFromTrack(kind, track, devices, lastUsedId) {
7115
7118
  if (settings.deviceId)
7116
7119
  return settings;
7117
7120
  settings.deviceId = (_c = track.getConstraints()) === null || _c === void 0 ? void 0 : _c.deviceId;
7118
- settings.broken = 1;
7119
7121
  return settings;
7120
7122
  }
7121
7123
  function getDeviceData({ audioTrack, videoTrack, devices, stoppedVideoTrack, lastAudioId, lastVideoId, }) {
7122
- const usable = (d) => ((d === null || d === void 0 ? void 0 : d.readyState) === "live" ? d : null);
7124
+ const usable = (d) => ((d === null || d === void 0 ? void 0 : d.readyState) === "live" ? d : undefined);
7123
7125
  videoTrack = usable(videoTrack) || stoppedVideoTrack;
7124
7126
  audioTrack = usable(audioTrack);
7125
7127
  const video = getSettingsFromTrack("videoinput", videoTrack, devices, lastVideoId);
@@ -7152,7 +7154,7 @@ function getStream(constraintOpt_1) {
7152
7154
  let newConstraints;
7153
7155
  let retryConstraintOpt;
7154
7156
  let stream = null;
7155
- const only = (constraintOpt.audioId === false && "video") || (constraintOpt.videoId === false && "audio");
7157
+ const only = (!constraintOpt.audioId && "video") || (!constraintOpt.videoId && "audio");
7156
7158
  const stopTracks = isMobile || only !== "video";
7157
7159
  const constraints = getConstraints(constraintOpt);
7158
7160
  const addDetails = (err, orgErr) => {
@@ -7163,7 +7165,7 @@ function getStream(constraintOpt_1) {
7163
7165
  return err;
7164
7166
  }
7165
7167
  else {
7166
- return new Error("Unknown error");
7168
+ return new Error("GetStream: gUM rejected without error");
7167
7169
  }
7168
7170
  };
7169
7171
  const getSingleStream = (e) => __awaiter(this, void 0, void 0, function* () {
@@ -7197,12 +7199,18 @@ function getStream(constraintOpt_1) {
7197
7199
  }
7198
7200
  if ((e === null || e === void 0 ? void 0 : e.name) === "OverconstrainedError") {
7199
7201
  const laxConstraints = {
7200
- deviceId: { videoId: null, audioId: null },
7202
+ deviceId: { videoId: true, audioId: true },
7201
7203
  width: { lax: true },
7202
7204
  height: { lax: true },
7203
- "": { audioId: null, videoId: null, lax: true },
7205
+ "": { audioId: true, videoId: true, lax: true },
7204
7206
  };
7205
7207
  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
+ }
7206
7214
  }
7207
7215
  else if ((e === null || e === void 0 ? void 0 : e.name) === "NotFoundError") {
7208
7216
  yield getSingleStream(e);
@@ -7226,7 +7234,7 @@ function getStream(constraintOpt_1) {
7226
7234
  const problemWith = { audio: "audioId", video: "videoId" }[((_a = /(video|audio)/.exec(errMsg)) === null || _a === void 0 ? void 0 : _a[0]) || only || ""];
7227
7235
  if (!stream && problemWith) {
7228
7236
  try {
7229
- stream = yield getUserMedia(getConstraints(Object.assign(Object.assign({}, constraintOpt), { [problemWith]: null })));
7237
+ stream = yield getUserMedia(getConstraints(Object.assign(Object.assign({}, constraintOpt), { [problemWith]: true })));
7230
7238
  }
7231
7239
  catch (e2) {
7232
7240
  logger.warn(`Re-tried ${problemWith} with no constraints, but failed: ${"" + e2}`);
@@ -7286,8 +7294,9 @@ const defaultDisplayMediaConstraints = {
7286
7294
  height: { max: window.screen.height },
7287
7295
  },
7288
7296
  };
7289
- function getDisplayMedia(constraints = defaultDisplayMediaConstraints, contentHint = "detail") {
7290
- return navigator.mediaDevices.getDisplayMedia(constraints).then((stream) => {
7297
+ function getDisplayMedia() {
7298
+ return __awaiter(this, arguments, void 0, function* (constraints = defaultDisplayMediaConstraints, contentHint = "detail") {
7299
+ const stream = yield navigator.mediaDevices.getDisplayMedia(constraints);
7291
7300
  stream.getVideoTracks().forEach((t) => {
7292
7301
  if ("contentHint" in t) {
7293
7302
  t.contentHint = contentHint;
@@ -7345,14 +7354,10 @@ function getUpdatedDevices({ oldDevices, newDevices, currentAudioId, currentVide
7345
7354
  }
7346
7355
  if (currentDeviceId) {
7347
7356
  if (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
- }
7357
+ removedDevices[kind] = changes.removed[currentDeviceId];
7353
7358
  }
7354
7359
  if (changes.changed[currentDeviceId]) {
7355
- changedDevices[kind] = { deviceId: currentDeviceId };
7360
+ changedDevices[kind] = changes.changed[currentDeviceId];
7356
7361
  }
7357
7362
  }
7358
7363
  if (Object.keys(changes.added).length > 0) {
@@ -7360,10 +7365,6 @@ function getUpdatedDevices({ oldDevices, newDevices, currentAudioId, currentVide
7360
7365
  const add = changes.added[deviceAdded];
7361
7366
  addedDevices[kind] = { deviceId: add.deviceId, label: add.label, kind: add.kind };
7362
7367
  }
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
- }
7367
7368
  });
7368
7369
  return { addedDevices, changedDevices, removedDevices };
7369
7370
  }