@whereby.com/media 1.21.1 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -2635,7 +2635,9 @@ function getPreferredOrder(availableCodecs, { vp9On, av1On }) {
2635
2635
  return availableCodecs;
2636
2636
  }
2637
2637
  function sortCodecsByMimeType(codecs, features) {
2638
- const availableCodecs = codecs.map(({ mimeType }) => mimeType).filter((value, index, array) => array.indexOf(value) === index);
2638
+ const availableCodecs = codecs
2639
+ .map(({ mimeType }) => mimeType)
2640
+ .filter((value, index, array) => array.indexOf(value) === index);
2639
2641
  const preferredOrder = getPreferredOrder(availableCodecs, features);
2640
2642
  return codecs.sort((a, b) => {
2641
2643
  const indexA = preferredOrder.indexOf(a.mimeType.toLowerCase());
@@ -2645,6 +2647,41 @@ function sortCodecsByMimeType(codecs, features) {
2645
2647
  return orderA - orderB;
2646
2648
  });
2647
2649
  }
2650
+ function getIsCodecDecodingPowerEfficient(codec) {
2651
+ return __awaiter(this, void 0, void 0, function* () {
2652
+ const { powerEfficient } = yield navigator.mediaCapabilities.decodingInfo({
2653
+ type: "webrtc",
2654
+ video: {
2655
+ width: 1280,
2656
+ height: 720,
2657
+ bitrate: 2580,
2658
+ framerate: 24,
2659
+ contentType: codec,
2660
+ },
2661
+ });
2662
+ return powerEfficient;
2663
+ });
2664
+ }
2665
+ function sortCodecsByPowerEfficiency(codecs) {
2666
+ return __awaiter(this, void 0, void 0, function* () {
2667
+ const codecPowerEfficiencyEntries = yield Promise.all(codecs.map(({ mimeType }) => getIsCodecDecodingPowerEfficient(mimeType).then((val) => [mimeType, val])));
2668
+ const codecPowerEfficiencies = Object.fromEntries(codecPowerEfficiencyEntries);
2669
+ const sorted = codecs.sort((a, b) => {
2670
+ const aPowerEfficient = codecPowerEfficiencies[a.mimeType];
2671
+ const bPowerEfficient = codecPowerEfficiencies[b.mimeType];
2672
+ return aPowerEfficient === bPowerEfficient ? 0 : aPowerEfficient ? -1 : 1;
2673
+ });
2674
+ return sorted;
2675
+ });
2676
+ }
2677
+ function sortCodecs(codecs, features) {
2678
+ return __awaiter(this, void 0, void 0, function* () {
2679
+ if (features.preferHardwareDecodingOn) {
2680
+ codecs = yield sortCodecsByPowerEfficiency(codecs);
2681
+ }
2682
+ return sortCodecsByMimeType(codecs, features);
2683
+ });
2684
+ }
2648
2685
 
2649
2686
  const logger$8 = new Logger();
2650
2687
  class ReconnectManager extends EventEmitter {
@@ -2674,10 +2711,10 @@ class ReconnectManager extends EventEmitter {
2674
2711
  socket.on(PROTOCOL_RESPONSES.SCREENSHARE_STOPPED, (payload) => this._onScreenshareChanged(payload, false));
2675
2712
  }
2676
2713
  _onRoomJoined(payload) {
2677
- var _a, _b;
2714
+ var _a;
2678
2715
  return __awaiter(this, void 0, void 0, function* () {
2679
2716
  this.reconnectThresholdInMs = (payload.disconnectTimeout || 0) * 0.8;
2680
- if (!((_a = payload.room) === null || _a === void 0 ? void 0 : _a.clients)) {
2717
+ if (payload === null || payload === void 0 ? void 0 : payload.error) {
2681
2718
  this.emit(PROTOCOL_RESPONSES.ROOM_JOINED, payload);
2682
2719
  return;
2683
2720
  }
@@ -2685,7 +2722,7 @@ class ReconnectManager extends EventEmitter {
2685
2722
  this.emit(PROTOCOL_RESPONSES.ROOM_JOINED, payload);
2686
2723
  return;
2687
2724
  }
2688
- const myDeviceId = (_b = payload.room.clients.find((c) => payload.selfId === c.id)) === null || _b === void 0 ? void 0 : _b.deviceId;
2725
+ const myDeviceId = (_a = payload.room.clients.find((c) => payload.selfId === c.id)) === null || _a === void 0 ? void 0 : _a.deviceId;
2689
2726
  if (!myDeviceId) {
2690
2727
  this.emit(PROTOCOL_RESPONSES.ROOM_JOINED, payload);
2691
2728
  return;
@@ -3332,7 +3369,12 @@ class P2pRtcManager {
3332
3369
  this._emit(rtcManagerEvents.PC_ON_ANSWER_FAILURE, e);
3333
3370
  });
3334
3371
  }),
3335
- this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, ({ room: { sfuServer: isSfu } }) => {
3372
+ this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, (payload) => {
3373
+ var _a, _b;
3374
+ if (payload === null || payload === void 0 ? void 0 : payload.error) {
3375
+ return;
3376
+ }
3377
+ const isSfu = (_b = (_a = payload === null || payload === void 0 ? void 0 : payload.room) === null || _a === void 0 ? void 0 : _a.sfuServer) !== null && _b !== void 0 ? _b : false;
3336
3378
  if (isSfu || !this._wasScreenSharing)
3337
3379
  return;
3338
3380
  const screenShareStreamId = Object.keys(this.localStreams).find((id) => id !== CAMERA_STREAM_ID);
@@ -3787,46 +3829,53 @@ class P2pRtcManager {
3787
3829
  this._negotiatePeerConnection(clientId, session, Object.assign({}, this.offerOptions, { iceRestart: true }));
3788
3830
  }
3789
3831
  }
3790
- _setCodecPreferences(pc, { p2pVp9On, p2pAv1On, redOn, }) {
3791
- try {
3792
- const audioTransceivers = pc
3793
- .getTransceivers()
3794
- .filter((transceiver) => { var _a, _b; return ((_b = (_a = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === "audio"; });
3795
- audioTransceivers.forEach((audioTransceiver) => {
3796
- if (typeof RTCRtpSender.getCapabilities === "undefined")
3797
- return;
3798
- const capabilities = RTCRtpSender.getCapabilities("audio");
3799
- for (let i = 0; i < capabilities.codecs.length; i++) {
3800
- if (redOn && capabilities.codecs[i].mimeType.toLowerCase() === "audio/red") {
3801
- capabilities.codecs.unshift(capabilities.codecs.splice(i, 1)[0]);
3802
- break;
3832
+ _setCodecPreferences(pc) {
3833
+ return __awaiter(this, void 0, void 0, function* () {
3834
+ const { p2pVp9On, p2pAv1On, redOn, preferHardwareDecodingOn } = this._features;
3835
+ if (!(p2pVp9On || p2pAv1On || redOn || preferHardwareDecodingOn)) {
3836
+ return;
3837
+ }
3838
+ try {
3839
+ const audioTransceivers = pc
3840
+ .getTransceivers()
3841
+ .filter((transceiver) => { var _a, _b; return ((_b = (_a = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === "audio"; });
3842
+ audioTransceivers.forEach((audioTransceiver) => {
3843
+ if (typeof RTCRtpSender.getCapabilities === "undefined")
3844
+ return;
3845
+ const capabilities = RTCRtpSender.getCapabilities("audio");
3846
+ for (let i = 0; i < capabilities.codecs.length; i++) {
3847
+ if (redOn && capabilities.codecs[i].mimeType.toLowerCase() === "audio/red") {
3848
+ capabilities.codecs.unshift(capabilities.codecs.splice(i, 1)[0]);
3849
+ break;
3850
+ }
3803
3851
  }
3804
- }
3805
- if (typeof audioTransceiver.setCodecPreferences === "undefined")
3806
- return;
3807
- audioTransceiver.setCodecPreferences(capabilities.codecs);
3808
- });
3809
- const videoTransceivers = pc
3810
- .getTransceivers()
3811
- .filter((transceiver) => { var _a, _b; return ((_b = (_a = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === "video"; });
3812
- videoTransceivers.forEach((videoTransceiver) => {
3813
- if (RTCRtpReceiver.getCapabilities === undefined)
3814
- return;
3815
- const capabilities = RTCRtpReceiver.getCapabilities("video");
3816
- if (p2pVp9On || p2pAv1On) {
3817
- capabilities.codecs = sortCodecsByMimeType(capabilities.codecs, {
3818
- vp9On: p2pVp9On,
3819
- av1On: p2pAv1On,
3820
- });
3821
- }
3822
- if (videoTransceiver.setCodecPreferences === undefined)
3823
- return;
3824
- videoTransceiver.setCodecPreferences(capabilities.codecs);
3825
- });
3826
- }
3827
- catch (error) {
3828
- logger$7.error("Error during setting setCodecPreferences:", error);
3829
- }
3852
+ if (typeof audioTransceiver.setCodecPreferences === "undefined")
3853
+ return;
3854
+ audioTransceiver.setCodecPreferences(capabilities.codecs);
3855
+ });
3856
+ const videoTransceivers = pc
3857
+ .getTransceivers()
3858
+ .filter((transceiver) => { var _a, _b; return ((_b = (_a = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === "video"; });
3859
+ yield Promise.all(videoTransceivers.map((videoTransceiver) => __awaiter(this, void 0, void 0, function* () {
3860
+ if (RTCRtpReceiver.getCapabilities === undefined)
3861
+ return;
3862
+ if (videoTransceiver.setCodecPreferences === undefined)
3863
+ return;
3864
+ const capabilities = RTCRtpReceiver.getCapabilities("video");
3865
+ if (p2pVp9On || p2pAv1On || preferHardwareDecodingOn) {
3866
+ capabilities.codecs = yield sortCodecs(capabilities.codecs, {
3867
+ vp9On: p2pVp9On,
3868
+ av1On: p2pAv1On,
3869
+ preferHardwareDecodingOn,
3870
+ });
3871
+ }
3872
+ videoTransceiver.setCodecPreferences(capabilities.codecs);
3873
+ })));
3874
+ }
3875
+ catch (error) {
3876
+ logger$7.error("Error during setting setCodecPreferences:", error);
3877
+ }
3878
+ });
3830
3879
  }
3831
3880
  _negotiatePeerConnection(clientId, session, constraints) {
3832
3881
  if (!session) {
@@ -3841,11 +3890,9 @@ class P2pRtcManager {
3841
3890
  return;
3842
3891
  }
3843
3892
  session.isOperationPending = true;
3844
- const { p2pVp9On, p2pAv1On, redOn, rtpAbsCaptureTimeOn, cleanSdpOn } = this._features;
3845
- if (p2pVp9On || p2pAv1On || redOn) {
3846
- this._setCodecPreferences(pc, { p2pVp9On, p2pAv1On, redOn });
3847
- }
3848
- pc.createOffer(constraints || this.offerOptions)
3893
+ const { p2pVp9On, redOn, rtpAbsCaptureTimeOn, cleanSdpOn } = this._features;
3894
+ this._setCodecPreferences(pc).then(() => pc
3895
+ .createOffer(constraints || this.offerOptions)
3849
3896
  .then((offer) => {
3850
3897
  if (rtpAbsCaptureTimeOn)
3851
3898
  offer.sdp = addAbsCaptureTimeExtMap(offer.sdp);
@@ -3869,7 +3916,7 @@ class P2pRtcManager {
3869
3916
  })
3870
3917
  .catch((e) => {
3871
3918
  logger$7.warn("RTCPeerConnection.createOffer() failed to create local offer", e);
3872
- });
3919
+ }));
3873
3920
  }
3874
3921
  _withForcedRenegotiation(session, action) {
3875
3922
  const pc = session.pc;
@@ -5077,7 +5124,10 @@ class VegaRtcManager {
5077
5124
  return;
5078
5125
  }
5079
5126
  this._updateAndScheduleMediaServersRefresh(data);
5080
- }), this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, () => {
5127
+ }), this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, (payload) => {
5128
+ if (payload === null || payload === void 0 ? void 0 : payload.error) {
5129
+ return;
5130
+ }
5081
5131
  if (this._screenVideoTrack)
5082
5132
  this._emitScreenshareStarted();
5083
5133
  if (this._features.sfuReconnectV2On && !this._hasVegaConnection && this._reconnect) {
@@ -8057,7 +8107,7 @@ exports.setClientProvider = setClientProvider;
8057
8107
  exports.setCodecPreferenceSDP = setCodecPreferenceSDP;
8058
8108
  exports.setPeerConnectionsForTests = setPeerConnectionsForTests;
8059
8109
  exports.setVideoBandwidthUsingSetParameters = setVideoBandwidthUsingSetParameters;
8060
- exports.sortCodecsByMimeType = sortCodecsByMimeType;
8110
+ exports.sortCodecs = sortCodecs;
8061
8111
  exports.standardDeviation = standardDeviation;
8062
8112
  exports.startPerformanceMonitor = startPerformanceMonitor;
8063
8113
  exports.stopStreamTracks = stopStreamTracks;
package/dist/index.d.cts CHANGED
@@ -541,11 +541,7 @@ declare class P2pRtcManager implements RtcManager {
541
541
  _monitorVideoTrack(track: CustomMediaStreamTrack): void;
542
542
  _connect(clientId: string): Promise<any>;
543
543
  _maybeRestartIce(clientId: string, session: any): void;
544
- _setCodecPreferences(pc: RTCPeerConnection, { p2pVp9On, p2pAv1On, redOn, }: {
545
- p2pVp9On?: boolean;
546
- p2pAv1On?: boolean;
547
- redOn?: boolean;
548
- }): void;
544
+ _setCodecPreferences(pc: RTCPeerConnection): Promise<void>;
549
545
  _negotiatePeerConnection(clientId: string, session: any, constraints?: any): void;
550
546
  _withForcedRenegotiation(session: any, action: any): void;
551
547
  _changeBandwidthForAllClients(isJoining: boolean): number;
@@ -617,10 +613,11 @@ interface Codec {
617
613
  mimeType: string;
618
614
  sdpFmtpLine?: string;
619
615
  }
620
- declare function sortCodecsByMimeType(codecs: Codec[], features: {
616
+ declare function sortCodecs(codecs: Codec[], features: {
621
617
  vp9On?: boolean;
622
618
  av1On?: boolean;
623
- }): Codec[];
619
+ preferHardwareDecodingOn?: boolean;
620
+ }): Promise<Codec[]>;
624
621
 
625
622
  declare function getOptimalBitrate(width: number, height: number, frameRate: number): number;
626
623
 
@@ -746,6 +743,7 @@ interface Spotlight {
746
743
  clientId: string;
747
744
  streamId: string;
748
745
  }
746
+ type RoomMode = "normal" | "group";
749
747
  interface AudioEnabledEvent {
750
748
  clientId: string;
751
749
  isAudioEnabled: boolean;
@@ -826,10 +824,50 @@ interface BreakoutConfig {
826
824
  } | null;
827
825
  startedAt?: Date | null;
828
826
  }
829
- interface RoomJoinedEvent {
830
- error?: string;
827
+ interface RoomLockedError {
828
+ error: "room_locked";
829
+ isClaimed: boolean;
831
830
  isLocked: boolean;
832
- room?: {
831
+ selfId: string;
832
+ logoUrl?: string;
833
+ knockPageBackgroundImageUrl?: string;
834
+ }
835
+ interface RoomFullError {
836
+ error: "room_full";
837
+ isClaimed: boolean;
838
+ }
839
+ interface RoomConcurrencyControlsError {
840
+ error: "room_concurrency_control_error";
841
+ }
842
+ interface CannotJoinUnclaimedRoomError {
843
+ error: "room_unclaimed";
844
+ }
845
+ interface OrganizationPlanExhaustedError {
846
+ error: "free_tier_exhausted";
847
+ }
848
+ interface RoomMeetingTimeExhaustedError {
849
+ error: "room_meeting_time_exhausted";
850
+ }
851
+ interface MaxViewerLimitReachedError {
852
+ error: "max_viewer_limit_reached";
853
+ isClaimed: boolean;
854
+ }
855
+ interface HostPresenceControlsError {
856
+ error: "host_presence_controls_error";
857
+ }
858
+ interface InternalServerError {
859
+ error: "internal_server_error";
860
+ }
861
+ type ForbiddenErrorNames = "missing_parameters" | "invalid_parameters" | "invalid_room_name" | "invalid_key" | "invalid_avatar";
862
+ interface ForbiddenError {
863
+ error: ForbiddenErrorNames;
864
+ }
865
+ type RoomJoinedErrors = RoomLockedError | RoomFullError | RoomConcurrencyControlsError | CannotJoinUnclaimedRoomError | OrganizationPlanExhaustedError | RoomMeetingTimeExhaustedError | MaxViewerLimitReachedError | HostPresenceControlsError | ForbiddenError | InternalServerError;
866
+ interface RoomJoinedSuccess {
867
+ room: {
868
+ mode: RoomMode;
869
+ isClaimed: boolean;
870
+ isLocked: boolean;
833
871
  clients: SignalClient[];
834
872
  knockers: SignalKnocker[];
835
873
  spotlights: Spotlight[];
@@ -839,10 +877,11 @@ interface RoomJoinedEvent {
839
877
  } | null;
840
878
  };
841
879
  selfId: string;
842
- breakoutGroup: string | null;
843
- clientClaim?: string;
880
+ breakoutGroup?: string | null;
881
+ clientClaim: string;
844
882
  breakout?: BreakoutConfig;
845
883
  }
884
+ type RoomJoinedEvent = RoomJoinedErrors | RoomJoinedSuccess;
846
885
  interface BreakoutSessionUpdatedEvent extends BreakoutConfig {
847
886
  }
848
887
  interface RoomKnockedEvent {
@@ -1666,4 +1705,4 @@ declare class RtcStream {
1666
1705
  static getTypeFromId(id: string): string;
1667
1706
  }
1668
1707
 
1669
- export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type BreakoutConfig, type BreakoutGroupJoinedEvent, type BreakoutSessionUpdatedEvent, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Codec, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, type StatsSubscription, TYPES, type TrackStats, type TurnTransportProtocol, type UpdatedDeviceInfo, type UpdatedDevicesInfo, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, type ViewStats, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDevice, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecsByMimeType, type ssrcStats, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, turnServerOverride, variance };
1708
+ export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type BreakoutConfig, type BreakoutGroupJoinedEvent, type BreakoutSessionUpdatedEvent, type CannotJoinUnclaimedRoomError, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Codec, type Credentials, type CustomMediaStreamTrack, EVENTS, type ForbiddenError, type ForbiddenErrorNames, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type HostPresenceControlsError, type IdentifyDeviceRequest, type InternalServerError, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type MaxViewerLimitReachedError, type NewClientEvent, NoDevicesError, type OrganizationPlanExhaustedError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomConcurrencyControlsError, type RoomFullError, type RoomJoinedErrors, type RoomJoinedEvent, type RoomJoinedSuccess, type RoomKnockedEvent, type RoomLockedError, type RoomLockedEvent, type RoomMeetingTimeExhaustedError, type RoomMode, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, type StatsSubscription, TYPES, type TrackStats, type TurnTransportProtocol, type UpdatedDeviceInfo, type UpdatedDevicesInfo, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, type ViewStats, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDevice, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, type ssrcStats, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, turnServerOverride, variance };
package/dist/index.d.mts CHANGED
@@ -541,11 +541,7 @@ declare class P2pRtcManager implements RtcManager {
541
541
  _monitorVideoTrack(track: CustomMediaStreamTrack): void;
542
542
  _connect(clientId: string): Promise<any>;
543
543
  _maybeRestartIce(clientId: string, session: any): void;
544
- _setCodecPreferences(pc: RTCPeerConnection, { p2pVp9On, p2pAv1On, redOn, }: {
545
- p2pVp9On?: boolean;
546
- p2pAv1On?: boolean;
547
- redOn?: boolean;
548
- }): void;
544
+ _setCodecPreferences(pc: RTCPeerConnection): Promise<void>;
549
545
  _negotiatePeerConnection(clientId: string, session: any, constraints?: any): void;
550
546
  _withForcedRenegotiation(session: any, action: any): void;
551
547
  _changeBandwidthForAllClients(isJoining: boolean): number;
@@ -617,10 +613,11 @@ interface Codec {
617
613
  mimeType: string;
618
614
  sdpFmtpLine?: string;
619
615
  }
620
- declare function sortCodecsByMimeType(codecs: Codec[], features: {
616
+ declare function sortCodecs(codecs: Codec[], features: {
621
617
  vp9On?: boolean;
622
618
  av1On?: boolean;
623
- }): Codec[];
619
+ preferHardwareDecodingOn?: boolean;
620
+ }): Promise<Codec[]>;
624
621
 
625
622
  declare function getOptimalBitrate(width: number, height: number, frameRate: number): number;
626
623
 
@@ -746,6 +743,7 @@ interface Spotlight {
746
743
  clientId: string;
747
744
  streamId: string;
748
745
  }
746
+ type RoomMode = "normal" | "group";
749
747
  interface AudioEnabledEvent {
750
748
  clientId: string;
751
749
  isAudioEnabled: boolean;
@@ -826,10 +824,50 @@ interface BreakoutConfig {
826
824
  } | null;
827
825
  startedAt?: Date | null;
828
826
  }
829
- interface RoomJoinedEvent {
830
- error?: string;
827
+ interface RoomLockedError {
828
+ error: "room_locked";
829
+ isClaimed: boolean;
831
830
  isLocked: boolean;
832
- room?: {
831
+ selfId: string;
832
+ logoUrl?: string;
833
+ knockPageBackgroundImageUrl?: string;
834
+ }
835
+ interface RoomFullError {
836
+ error: "room_full";
837
+ isClaimed: boolean;
838
+ }
839
+ interface RoomConcurrencyControlsError {
840
+ error: "room_concurrency_control_error";
841
+ }
842
+ interface CannotJoinUnclaimedRoomError {
843
+ error: "room_unclaimed";
844
+ }
845
+ interface OrganizationPlanExhaustedError {
846
+ error: "free_tier_exhausted";
847
+ }
848
+ interface RoomMeetingTimeExhaustedError {
849
+ error: "room_meeting_time_exhausted";
850
+ }
851
+ interface MaxViewerLimitReachedError {
852
+ error: "max_viewer_limit_reached";
853
+ isClaimed: boolean;
854
+ }
855
+ interface HostPresenceControlsError {
856
+ error: "host_presence_controls_error";
857
+ }
858
+ interface InternalServerError {
859
+ error: "internal_server_error";
860
+ }
861
+ type ForbiddenErrorNames = "missing_parameters" | "invalid_parameters" | "invalid_room_name" | "invalid_key" | "invalid_avatar";
862
+ interface ForbiddenError {
863
+ error: ForbiddenErrorNames;
864
+ }
865
+ type RoomJoinedErrors = RoomLockedError | RoomFullError | RoomConcurrencyControlsError | CannotJoinUnclaimedRoomError | OrganizationPlanExhaustedError | RoomMeetingTimeExhaustedError | MaxViewerLimitReachedError | HostPresenceControlsError | ForbiddenError | InternalServerError;
866
+ interface RoomJoinedSuccess {
867
+ room: {
868
+ mode: RoomMode;
869
+ isClaimed: boolean;
870
+ isLocked: boolean;
833
871
  clients: SignalClient[];
834
872
  knockers: SignalKnocker[];
835
873
  spotlights: Spotlight[];
@@ -839,10 +877,11 @@ interface RoomJoinedEvent {
839
877
  } | null;
840
878
  };
841
879
  selfId: string;
842
- breakoutGroup: string | null;
843
- clientClaim?: string;
880
+ breakoutGroup?: string | null;
881
+ clientClaim: string;
844
882
  breakout?: BreakoutConfig;
845
883
  }
884
+ type RoomJoinedEvent = RoomJoinedErrors | RoomJoinedSuccess;
846
885
  interface BreakoutSessionUpdatedEvent extends BreakoutConfig {
847
886
  }
848
887
  interface RoomKnockedEvent {
@@ -1666,4 +1705,4 @@ declare class RtcStream {
1666
1705
  static getTypeFromId(id: string): string;
1667
1706
  }
1668
1707
 
1669
- export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type BreakoutConfig, type BreakoutGroupJoinedEvent, type BreakoutSessionUpdatedEvent, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Codec, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, type StatsSubscription, TYPES, type TrackStats, type TurnTransportProtocol, type UpdatedDeviceInfo, type UpdatedDevicesInfo, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, type ViewStats, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDevice, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecsByMimeType, type ssrcStats, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, turnServerOverride, variance };
1708
+ export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type BreakoutConfig, type BreakoutGroupJoinedEvent, type BreakoutSessionUpdatedEvent, type CannotJoinUnclaimedRoomError, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Codec, type Credentials, type CustomMediaStreamTrack, EVENTS, type ForbiddenError, type ForbiddenErrorNames, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type HostPresenceControlsError, type IdentifyDeviceRequest, type InternalServerError, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type MaxViewerLimitReachedError, type NewClientEvent, NoDevicesError, type OrganizationPlanExhaustedError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomConcurrencyControlsError, type RoomFullError, type RoomJoinedErrors, type RoomJoinedEvent, type RoomJoinedSuccess, type RoomKnockedEvent, type RoomLockedError, type RoomLockedEvent, type RoomMeetingTimeExhaustedError, type RoomMode, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, type StatsSubscription, TYPES, type TrackStats, type TurnTransportProtocol, type UpdatedDeviceInfo, type UpdatedDevicesInfo, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, type ViewStats, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDevice, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, type ssrcStats, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, turnServerOverride, variance };
package/dist/index.d.ts CHANGED
@@ -541,11 +541,7 @@ declare class P2pRtcManager implements RtcManager {
541
541
  _monitorVideoTrack(track: CustomMediaStreamTrack): void;
542
542
  _connect(clientId: string): Promise<any>;
543
543
  _maybeRestartIce(clientId: string, session: any): void;
544
- _setCodecPreferences(pc: RTCPeerConnection, { p2pVp9On, p2pAv1On, redOn, }: {
545
- p2pVp9On?: boolean;
546
- p2pAv1On?: boolean;
547
- redOn?: boolean;
548
- }): void;
544
+ _setCodecPreferences(pc: RTCPeerConnection): Promise<void>;
549
545
  _negotiatePeerConnection(clientId: string, session: any, constraints?: any): void;
550
546
  _withForcedRenegotiation(session: any, action: any): void;
551
547
  _changeBandwidthForAllClients(isJoining: boolean): number;
@@ -617,10 +613,11 @@ interface Codec {
617
613
  mimeType: string;
618
614
  sdpFmtpLine?: string;
619
615
  }
620
- declare function sortCodecsByMimeType(codecs: Codec[], features: {
616
+ declare function sortCodecs(codecs: Codec[], features: {
621
617
  vp9On?: boolean;
622
618
  av1On?: boolean;
623
- }): Codec[];
619
+ preferHardwareDecodingOn?: boolean;
620
+ }): Promise<Codec[]>;
624
621
 
625
622
  declare function getOptimalBitrate(width: number, height: number, frameRate: number): number;
626
623
 
@@ -746,6 +743,7 @@ interface Spotlight {
746
743
  clientId: string;
747
744
  streamId: string;
748
745
  }
746
+ type RoomMode = "normal" | "group";
749
747
  interface AudioEnabledEvent {
750
748
  clientId: string;
751
749
  isAudioEnabled: boolean;
@@ -826,10 +824,50 @@ interface BreakoutConfig {
826
824
  } | null;
827
825
  startedAt?: Date | null;
828
826
  }
829
- interface RoomJoinedEvent {
830
- error?: string;
827
+ interface RoomLockedError {
828
+ error: "room_locked";
829
+ isClaimed: boolean;
831
830
  isLocked: boolean;
832
- room?: {
831
+ selfId: string;
832
+ logoUrl?: string;
833
+ knockPageBackgroundImageUrl?: string;
834
+ }
835
+ interface RoomFullError {
836
+ error: "room_full";
837
+ isClaimed: boolean;
838
+ }
839
+ interface RoomConcurrencyControlsError {
840
+ error: "room_concurrency_control_error";
841
+ }
842
+ interface CannotJoinUnclaimedRoomError {
843
+ error: "room_unclaimed";
844
+ }
845
+ interface OrganizationPlanExhaustedError {
846
+ error: "free_tier_exhausted";
847
+ }
848
+ interface RoomMeetingTimeExhaustedError {
849
+ error: "room_meeting_time_exhausted";
850
+ }
851
+ interface MaxViewerLimitReachedError {
852
+ error: "max_viewer_limit_reached";
853
+ isClaimed: boolean;
854
+ }
855
+ interface HostPresenceControlsError {
856
+ error: "host_presence_controls_error";
857
+ }
858
+ interface InternalServerError {
859
+ error: "internal_server_error";
860
+ }
861
+ type ForbiddenErrorNames = "missing_parameters" | "invalid_parameters" | "invalid_room_name" | "invalid_key" | "invalid_avatar";
862
+ interface ForbiddenError {
863
+ error: ForbiddenErrorNames;
864
+ }
865
+ type RoomJoinedErrors = RoomLockedError | RoomFullError | RoomConcurrencyControlsError | CannotJoinUnclaimedRoomError | OrganizationPlanExhaustedError | RoomMeetingTimeExhaustedError | MaxViewerLimitReachedError | HostPresenceControlsError | ForbiddenError | InternalServerError;
866
+ interface RoomJoinedSuccess {
867
+ room: {
868
+ mode: RoomMode;
869
+ isClaimed: boolean;
870
+ isLocked: boolean;
833
871
  clients: SignalClient[];
834
872
  knockers: SignalKnocker[];
835
873
  spotlights: Spotlight[];
@@ -839,10 +877,11 @@ interface RoomJoinedEvent {
839
877
  } | null;
840
878
  };
841
879
  selfId: string;
842
- breakoutGroup: string | null;
843
- clientClaim?: string;
880
+ breakoutGroup?: string | null;
881
+ clientClaim: string;
844
882
  breakout?: BreakoutConfig;
845
883
  }
884
+ type RoomJoinedEvent = RoomJoinedErrors | RoomJoinedSuccess;
846
885
  interface BreakoutSessionUpdatedEvent extends BreakoutConfig {
847
886
  }
848
887
  interface RoomKnockedEvent {
@@ -1666,4 +1705,4 @@ declare class RtcStream {
1666
1705
  static getTypeFromId(id: string): string;
1667
1706
  }
1668
1707
 
1669
- export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type BreakoutConfig, type BreakoutGroupJoinedEvent, type BreakoutSessionUpdatedEvent, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Codec, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, type StatsSubscription, TYPES, type TrackStats, type TurnTransportProtocol, type UpdatedDeviceInfo, type UpdatedDevicesInfo, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, type ViewStats, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDevice, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecsByMimeType, type ssrcStats, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, turnServerOverride, variance };
1708
+ export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type BreakoutConfig, type BreakoutGroupJoinedEvent, type BreakoutSessionUpdatedEvent, type CannotJoinUnclaimedRoomError, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Codec, type Credentials, type CustomMediaStreamTrack, EVENTS, type ForbiddenError, type ForbiddenErrorNames, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type HostPresenceControlsError, type IdentifyDeviceRequest, type InternalServerError, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type MaxViewerLimitReachedError, type NewClientEvent, NoDevicesError, type OrganizationPlanExhaustedError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomConcurrencyControlsError, type RoomFullError, type RoomJoinedErrors, type RoomJoinedEvent, type RoomJoinedSuccess, type RoomKnockedEvent, type RoomLockedError, type RoomLockedEvent, type RoomMeetingTimeExhaustedError, type RoomMode, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, type StatsSubscription, TYPES, type TrackStats, type TurnTransportProtocol, type UpdatedDeviceInfo, type UpdatedDevicesInfo, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, type ViewStats, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDevice, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, type ssrcStats, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, turnServerOverride, variance };
package/dist/index.mjs CHANGED
@@ -2610,7 +2610,9 @@ function getPreferredOrder(availableCodecs, { vp9On, av1On }) {
2610
2610
  return availableCodecs;
2611
2611
  }
2612
2612
  function sortCodecsByMimeType(codecs, features) {
2613
- const availableCodecs = codecs.map(({ mimeType }) => mimeType).filter((value, index, array) => array.indexOf(value) === index);
2613
+ const availableCodecs = codecs
2614
+ .map(({ mimeType }) => mimeType)
2615
+ .filter((value, index, array) => array.indexOf(value) === index);
2614
2616
  const preferredOrder = getPreferredOrder(availableCodecs, features);
2615
2617
  return codecs.sort((a, b) => {
2616
2618
  const indexA = preferredOrder.indexOf(a.mimeType.toLowerCase());
@@ -2620,6 +2622,41 @@ function sortCodecsByMimeType(codecs, features) {
2620
2622
  return orderA - orderB;
2621
2623
  });
2622
2624
  }
2625
+ function getIsCodecDecodingPowerEfficient(codec) {
2626
+ return __awaiter(this, void 0, void 0, function* () {
2627
+ const { powerEfficient } = yield navigator.mediaCapabilities.decodingInfo({
2628
+ type: "webrtc",
2629
+ video: {
2630
+ width: 1280,
2631
+ height: 720,
2632
+ bitrate: 2580,
2633
+ framerate: 24,
2634
+ contentType: codec,
2635
+ },
2636
+ });
2637
+ return powerEfficient;
2638
+ });
2639
+ }
2640
+ function sortCodecsByPowerEfficiency(codecs) {
2641
+ return __awaiter(this, void 0, void 0, function* () {
2642
+ const codecPowerEfficiencyEntries = yield Promise.all(codecs.map(({ mimeType }) => getIsCodecDecodingPowerEfficient(mimeType).then((val) => [mimeType, val])));
2643
+ const codecPowerEfficiencies = Object.fromEntries(codecPowerEfficiencyEntries);
2644
+ const sorted = codecs.sort((a, b) => {
2645
+ const aPowerEfficient = codecPowerEfficiencies[a.mimeType];
2646
+ const bPowerEfficient = codecPowerEfficiencies[b.mimeType];
2647
+ return aPowerEfficient === bPowerEfficient ? 0 : aPowerEfficient ? -1 : 1;
2648
+ });
2649
+ return sorted;
2650
+ });
2651
+ }
2652
+ function sortCodecs(codecs, features) {
2653
+ return __awaiter(this, void 0, void 0, function* () {
2654
+ if (features.preferHardwareDecodingOn) {
2655
+ codecs = yield sortCodecsByPowerEfficiency(codecs);
2656
+ }
2657
+ return sortCodecsByMimeType(codecs, features);
2658
+ });
2659
+ }
2623
2660
 
2624
2661
  const logger$8 = new Logger();
2625
2662
  class ReconnectManager extends EventEmitter {
@@ -2649,10 +2686,10 @@ class ReconnectManager extends EventEmitter {
2649
2686
  socket.on(PROTOCOL_RESPONSES.SCREENSHARE_STOPPED, (payload) => this._onScreenshareChanged(payload, false));
2650
2687
  }
2651
2688
  _onRoomJoined(payload) {
2652
- var _a, _b;
2689
+ var _a;
2653
2690
  return __awaiter(this, void 0, void 0, function* () {
2654
2691
  this.reconnectThresholdInMs = (payload.disconnectTimeout || 0) * 0.8;
2655
- if (!((_a = payload.room) === null || _a === void 0 ? void 0 : _a.clients)) {
2692
+ if (payload === null || payload === void 0 ? void 0 : payload.error) {
2656
2693
  this.emit(PROTOCOL_RESPONSES.ROOM_JOINED, payload);
2657
2694
  return;
2658
2695
  }
@@ -2660,7 +2697,7 @@ class ReconnectManager extends EventEmitter {
2660
2697
  this.emit(PROTOCOL_RESPONSES.ROOM_JOINED, payload);
2661
2698
  return;
2662
2699
  }
2663
- const myDeviceId = (_b = payload.room.clients.find((c) => payload.selfId === c.id)) === null || _b === void 0 ? void 0 : _b.deviceId;
2700
+ const myDeviceId = (_a = payload.room.clients.find((c) => payload.selfId === c.id)) === null || _a === void 0 ? void 0 : _a.deviceId;
2664
2701
  if (!myDeviceId) {
2665
2702
  this.emit(PROTOCOL_RESPONSES.ROOM_JOINED, payload);
2666
2703
  return;
@@ -3307,7 +3344,12 @@ class P2pRtcManager {
3307
3344
  this._emit(rtcManagerEvents.PC_ON_ANSWER_FAILURE, e);
3308
3345
  });
3309
3346
  }),
3310
- this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, ({ room: { sfuServer: isSfu } }) => {
3347
+ this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, (payload) => {
3348
+ var _a, _b;
3349
+ if (payload === null || payload === void 0 ? void 0 : payload.error) {
3350
+ return;
3351
+ }
3352
+ const isSfu = (_b = (_a = payload === null || payload === void 0 ? void 0 : payload.room) === null || _a === void 0 ? void 0 : _a.sfuServer) !== null && _b !== void 0 ? _b : false;
3311
3353
  if (isSfu || !this._wasScreenSharing)
3312
3354
  return;
3313
3355
  const screenShareStreamId = Object.keys(this.localStreams).find((id) => id !== CAMERA_STREAM_ID);
@@ -3762,46 +3804,53 @@ class P2pRtcManager {
3762
3804
  this._negotiatePeerConnection(clientId, session, Object.assign({}, this.offerOptions, { iceRestart: true }));
3763
3805
  }
3764
3806
  }
3765
- _setCodecPreferences(pc, { p2pVp9On, p2pAv1On, redOn, }) {
3766
- try {
3767
- const audioTransceivers = pc
3768
- .getTransceivers()
3769
- .filter((transceiver) => { var _a, _b; return ((_b = (_a = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === "audio"; });
3770
- audioTransceivers.forEach((audioTransceiver) => {
3771
- if (typeof RTCRtpSender.getCapabilities === "undefined")
3772
- return;
3773
- const capabilities = RTCRtpSender.getCapabilities("audio");
3774
- for (let i = 0; i < capabilities.codecs.length; i++) {
3775
- if (redOn && capabilities.codecs[i].mimeType.toLowerCase() === "audio/red") {
3776
- capabilities.codecs.unshift(capabilities.codecs.splice(i, 1)[0]);
3777
- break;
3807
+ _setCodecPreferences(pc) {
3808
+ return __awaiter(this, void 0, void 0, function* () {
3809
+ const { p2pVp9On, p2pAv1On, redOn, preferHardwareDecodingOn } = this._features;
3810
+ if (!(p2pVp9On || p2pAv1On || redOn || preferHardwareDecodingOn)) {
3811
+ return;
3812
+ }
3813
+ try {
3814
+ const audioTransceivers = pc
3815
+ .getTransceivers()
3816
+ .filter((transceiver) => { var _a, _b; return ((_b = (_a = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === "audio"; });
3817
+ audioTransceivers.forEach((audioTransceiver) => {
3818
+ if (typeof RTCRtpSender.getCapabilities === "undefined")
3819
+ return;
3820
+ const capabilities = RTCRtpSender.getCapabilities("audio");
3821
+ for (let i = 0; i < capabilities.codecs.length; i++) {
3822
+ if (redOn && capabilities.codecs[i].mimeType.toLowerCase() === "audio/red") {
3823
+ capabilities.codecs.unshift(capabilities.codecs.splice(i, 1)[0]);
3824
+ break;
3825
+ }
3778
3826
  }
3779
- }
3780
- if (typeof audioTransceiver.setCodecPreferences === "undefined")
3781
- return;
3782
- audioTransceiver.setCodecPreferences(capabilities.codecs);
3783
- });
3784
- const videoTransceivers = pc
3785
- .getTransceivers()
3786
- .filter((transceiver) => { var _a, _b; return ((_b = (_a = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === "video"; });
3787
- videoTransceivers.forEach((videoTransceiver) => {
3788
- if (RTCRtpReceiver.getCapabilities === undefined)
3789
- return;
3790
- const capabilities = RTCRtpReceiver.getCapabilities("video");
3791
- if (p2pVp9On || p2pAv1On) {
3792
- capabilities.codecs = sortCodecsByMimeType(capabilities.codecs, {
3793
- vp9On: p2pVp9On,
3794
- av1On: p2pAv1On,
3795
- });
3796
- }
3797
- if (videoTransceiver.setCodecPreferences === undefined)
3798
- return;
3799
- videoTransceiver.setCodecPreferences(capabilities.codecs);
3800
- });
3801
- }
3802
- catch (error) {
3803
- logger$7.error("Error during setting setCodecPreferences:", error);
3804
- }
3827
+ if (typeof audioTransceiver.setCodecPreferences === "undefined")
3828
+ return;
3829
+ audioTransceiver.setCodecPreferences(capabilities.codecs);
3830
+ });
3831
+ const videoTransceivers = pc
3832
+ .getTransceivers()
3833
+ .filter((transceiver) => { var _a, _b; return ((_b = (_a = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === "video"; });
3834
+ yield Promise.all(videoTransceivers.map((videoTransceiver) => __awaiter(this, void 0, void 0, function* () {
3835
+ if (RTCRtpReceiver.getCapabilities === undefined)
3836
+ return;
3837
+ if (videoTransceiver.setCodecPreferences === undefined)
3838
+ return;
3839
+ const capabilities = RTCRtpReceiver.getCapabilities("video");
3840
+ if (p2pVp9On || p2pAv1On || preferHardwareDecodingOn) {
3841
+ capabilities.codecs = yield sortCodecs(capabilities.codecs, {
3842
+ vp9On: p2pVp9On,
3843
+ av1On: p2pAv1On,
3844
+ preferHardwareDecodingOn,
3845
+ });
3846
+ }
3847
+ videoTransceiver.setCodecPreferences(capabilities.codecs);
3848
+ })));
3849
+ }
3850
+ catch (error) {
3851
+ logger$7.error("Error during setting setCodecPreferences:", error);
3852
+ }
3853
+ });
3805
3854
  }
3806
3855
  _negotiatePeerConnection(clientId, session, constraints) {
3807
3856
  if (!session) {
@@ -3816,11 +3865,9 @@ class P2pRtcManager {
3816
3865
  return;
3817
3866
  }
3818
3867
  session.isOperationPending = true;
3819
- const { p2pVp9On, p2pAv1On, redOn, rtpAbsCaptureTimeOn, cleanSdpOn } = this._features;
3820
- if (p2pVp9On || p2pAv1On || redOn) {
3821
- this._setCodecPreferences(pc, { p2pVp9On, p2pAv1On, redOn });
3822
- }
3823
- pc.createOffer(constraints || this.offerOptions)
3868
+ const { p2pVp9On, redOn, rtpAbsCaptureTimeOn, cleanSdpOn } = this._features;
3869
+ this._setCodecPreferences(pc).then(() => pc
3870
+ .createOffer(constraints || this.offerOptions)
3824
3871
  .then((offer) => {
3825
3872
  if (rtpAbsCaptureTimeOn)
3826
3873
  offer.sdp = addAbsCaptureTimeExtMap(offer.sdp);
@@ -3844,7 +3891,7 @@ class P2pRtcManager {
3844
3891
  })
3845
3892
  .catch((e) => {
3846
3893
  logger$7.warn("RTCPeerConnection.createOffer() failed to create local offer", e);
3847
- });
3894
+ }));
3848
3895
  }
3849
3896
  _withForcedRenegotiation(session, action) {
3850
3897
  const pc = session.pc;
@@ -5052,7 +5099,10 @@ class VegaRtcManager {
5052
5099
  return;
5053
5100
  }
5054
5101
  this._updateAndScheduleMediaServersRefresh(data);
5055
- }), this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, () => {
5102
+ }), this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, (payload) => {
5103
+ if (payload === null || payload === void 0 ? void 0 : payload.error) {
5104
+ return;
5105
+ }
5056
5106
  if (this._screenVideoTrack)
5057
5107
  this._emitScreenshareStarted();
5058
5108
  if (this._features.sfuReconnectV2On && !this._hasVegaConnection && this._reconnect) {
@@ -7948,4 +7998,4 @@ var RtcEventNames;
7948
7998
  RtcEventNames["stream_added"] = "stream_added";
7949
7999
  })(RtcEventNames || (RtcEventNames = {}));
7950
8000
 
7951
- export { BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDevice, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecsByMimeType, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, turnServerOverride, variance };
8001
+ export { BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDevice, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, turnServerOverride, variance };
@@ -2610,7 +2610,9 @@ function getPreferredOrder(availableCodecs, { vp9On, av1On }) {
2610
2610
  return availableCodecs;
2611
2611
  }
2612
2612
  function sortCodecsByMimeType(codecs, features) {
2613
- const availableCodecs = codecs.map(({ mimeType }) => mimeType).filter((value, index, array) => array.indexOf(value) === index);
2613
+ const availableCodecs = codecs
2614
+ .map(({ mimeType }) => mimeType)
2615
+ .filter((value, index, array) => array.indexOf(value) === index);
2614
2616
  const preferredOrder = getPreferredOrder(availableCodecs, features);
2615
2617
  return codecs.sort((a, b) => {
2616
2618
  const indexA = preferredOrder.indexOf(a.mimeType.toLowerCase());
@@ -2620,6 +2622,41 @@ function sortCodecsByMimeType(codecs, features) {
2620
2622
  return orderA - orderB;
2621
2623
  });
2622
2624
  }
2625
+ function getIsCodecDecodingPowerEfficient(codec) {
2626
+ return __awaiter(this, void 0, void 0, function* () {
2627
+ const { powerEfficient } = yield navigator.mediaCapabilities.decodingInfo({
2628
+ type: "webrtc",
2629
+ video: {
2630
+ width: 1280,
2631
+ height: 720,
2632
+ bitrate: 2580,
2633
+ framerate: 24,
2634
+ contentType: codec,
2635
+ },
2636
+ });
2637
+ return powerEfficient;
2638
+ });
2639
+ }
2640
+ function sortCodecsByPowerEfficiency(codecs) {
2641
+ return __awaiter(this, void 0, void 0, function* () {
2642
+ const codecPowerEfficiencyEntries = yield Promise.all(codecs.map(({ mimeType }) => getIsCodecDecodingPowerEfficient(mimeType).then((val) => [mimeType, val])));
2643
+ const codecPowerEfficiencies = Object.fromEntries(codecPowerEfficiencyEntries);
2644
+ const sorted = codecs.sort((a, b) => {
2645
+ const aPowerEfficient = codecPowerEfficiencies[a.mimeType];
2646
+ const bPowerEfficient = codecPowerEfficiencies[b.mimeType];
2647
+ return aPowerEfficient === bPowerEfficient ? 0 : aPowerEfficient ? -1 : 1;
2648
+ });
2649
+ return sorted;
2650
+ });
2651
+ }
2652
+ function sortCodecs(codecs, features) {
2653
+ return __awaiter(this, void 0, void 0, function* () {
2654
+ if (features.preferHardwareDecodingOn) {
2655
+ codecs = yield sortCodecsByPowerEfficiency(codecs);
2656
+ }
2657
+ return sortCodecsByMimeType(codecs, features);
2658
+ });
2659
+ }
2623
2660
 
2624
2661
  const logger$8 = new Logger();
2625
2662
  class ReconnectManager extends EventEmitter {
@@ -2649,10 +2686,10 @@ class ReconnectManager extends EventEmitter {
2649
2686
  socket.on(PROTOCOL_RESPONSES.SCREENSHARE_STOPPED, (payload) => this._onScreenshareChanged(payload, false));
2650
2687
  }
2651
2688
  _onRoomJoined(payload) {
2652
- var _a, _b;
2689
+ var _a;
2653
2690
  return __awaiter(this, void 0, void 0, function* () {
2654
2691
  this.reconnectThresholdInMs = (payload.disconnectTimeout || 0) * 0.8;
2655
- if (!((_a = payload.room) === null || _a === void 0 ? void 0 : _a.clients)) {
2692
+ if (payload === null || payload === void 0 ? void 0 : payload.error) {
2656
2693
  this.emit(PROTOCOL_RESPONSES.ROOM_JOINED, payload);
2657
2694
  return;
2658
2695
  }
@@ -2660,7 +2697,7 @@ class ReconnectManager extends EventEmitter {
2660
2697
  this.emit(PROTOCOL_RESPONSES.ROOM_JOINED, payload);
2661
2698
  return;
2662
2699
  }
2663
- const myDeviceId = (_b = payload.room.clients.find((c) => payload.selfId === c.id)) === null || _b === void 0 ? void 0 : _b.deviceId;
2700
+ const myDeviceId = (_a = payload.room.clients.find((c) => payload.selfId === c.id)) === null || _a === void 0 ? void 0 : _a.deviceId;
2664
2701
  if (!myDeviceId) {
2665
2702
  this.emit(PROTOCOL_RESPONSES.ROOM_JOINED, payload);
2666
2703
  return;
@@ -3307,7 +3344,12 @@ class P2pRtcManager {
3307
3344
  this._emit(rtcManagerEvents.PC_ON_ANSWER_FAILURE, e);
3308
3345
  });
3309
3346
  }),
3310
- this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, ({ room: { sfuServer: isSfu } }) => {
3347
+ this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, (payload) => {
3348
+ var _a, _b;
3349
+ if (payload === null || payload === void 0 ? void 0 : payload.error) {
3350
+ return;
3351
+ }
3352
+ const isSfu = (_b = (_a = payload === null || payload === void 0 ? void 0 : payload.room) === null || _a === void 0 ? void 0 : _a.sfuServer) !== null && _b !== void 0 ? _b : false;
3311
3353
  if (isSfu || !this._wasScreenSharing)
3312
3354
  return;
3313
3355
  const screenShareStreamId = Object.keys(this.localStreams).find((id) => id !== CAMERA_STREAM_ID);
@@ -3762,46 +3804,53 @@ class P2pRtcManager {
3762
3804
  this._negotiatePeerConnection(clientId, session, Object.assign({}, this.offerOptions, { iceRestart: true }));
3763
3805
  }
3764
3806
  }
3765
- _setCodecPreferences(pc, { p2pVp9On, p2pAv1On, redOn, }) {
3766
- try {
3767
- const audioTransceivers = pc
3768
- .getTransceivers()
3769
- .filter((transceiver) => { var _a, _b; return ((_b = (_a = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === "audio"; });
3770
- audioTransceivers.forEach((audioTransceiver) => {
3771
- if (typeof RTCRtpSender.getCapabilities === "undefined")
3772
- return;
3773
- const capabilities = RTCRtpSender.getCapabilities("audio");
3774
- for (let i = 0; i < capabilities.codecs.length; i++) {
3775
- if (redOn && capabilities.codecs[i].mimeType.toLowerCase() === "audio/red") {
3776
- capabilities.codecs.unshift(capabilities.codecs.splice(i, 1)[0]);
3777
- break;
3807
+ _setCodecPreferences(pc) {
3808
+ return __awaiter(this, void 0, void 0, function* () {
3809
+ const { p2pVp9On, p2pAv1On, redOn, preferHardwareDecodingOn } = this._features;
3810
+ if (!(p2pVp9On || p2pAv1On || redOn || preferHardwareDecodingOn)) {
3811
+ return;
3812
+ }
3813
+ try {
3814
+ const audioTransceivers = pc
3815
+ .getTransceivers()
3816
+ .filter((transceiver) => { var _a, _b; return ((_b = (_a = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === "audio"; });
3817
+ audioTransceivers.forEach((audioTransceiver) => {
3818
+ if (typeof RTCRtpSender.getCapabilities === "undefined")
3819
+ return;
3820
+ const capabilities = RTCRtpSender.getCapabilities("audio");
3821
+ for (let i = 0; i < capabilities.codecs.length; i++) {
3822
+ if (redOn && capabilities.codecs[i].mimeType.toLowerCase() === "audio/red") {
3823
+ capabilities.codecs.unshift(capabilities.codecs.splice(i, 1)[0]);
3824
+ break;
3825
+ }
3778
3826
  }
3779
- }
3780
- if (typeof audioTransceiver.setCodecPreferences === "undefined")
3781
- return;
3782
- audioTransceiver.setCodecPreferences(capabilities.codecs);
3783
- });
3784
- const videoTransceivers = pc
3785
- .getTransceivers()
3786
- .filter((transceiver) => { var _a, _b; return ((_b = (_a = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === "video"; });
3787
- videoTransceivers.forEach((videoTransceiver) => {
3788
- if (RTCRtpReceiver.getCapabilities === undefined)
3789
- return;
3790
- const capabilities = RTCRtpReceiver.getCapabilities("video");
3791
- if (p2pVp9On || p2pAv1On) {
3792
- capabilities.codecs = sortCodecsByMimeType(capabilities.codecs, {
3793
- vp9On: p2pVp9On,
3794
- av1On: p2pAv1On,
3795
- });
3796
- }
3797
- if (videoTransceiver.setCodecPreferences === undefined)
3798
- return;
3799
- videoTransceiver.setCodecPreferences(capabilities.codecs);
3800
- });
3801
- }
3802
- catch (error) {
3803
- logger$7.error("Error during setting setCodecPreferences:", error);
3804
- }
3827
+ if (typeof audioTransceiver.setCodecPreferences === "undefined")
3828
+ return;
3829
+ audioTransceiver.setCodecPreferences(capabilities.codecs);
3830
+ });
3831
+ const videoTransceivers = pc
3832
+ .getTransceivers()
3833
+ .filter((transceiver) => { var _a, _b; return ((_b = (_a = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === "video"; });
3834
+ yield Promise.all(videoTransceivers.map((videoTransceiver) => __awaiter(this, void 0, void 0, function* () {
3835
+ if (RTCRtpReceiver.getCapabilities === undefined)
3836
+ return;
3837
+ if (videoTransceiver.setCodecPreferences === undefined)
3838
+ return;
3839
+ const capabilities = RTCRtpReceiver.getCapabilities("video");
3840
+ if (p2pVp9On || p2pAv1On || preferHardwareDecodingOn) {
3841
+ capabilities.codecs = yield sortCodecs(capabilities.codecs, {
3842
+ vp9On: p2pVp9On,
3843
+ av1On: p2pAv1On,
3844
+ preferHardwareDecodingOn,
3845
+ });
3846
+ }
3847
+ videoTransceiver.setCodecPreferences(capabilities.codecs);
3848
+ })));
3849
+ }
3850
+ catch (error) {
3851
+ logger$7.error("Error during setting setCodecPreferences:", error);
3852
+ }
3853
+ });
3805
3854
  }
3806
3855
  _negotiatePeerConnection(clientId, session, constraints) {
3807
3856
  if (!session) {
@@ -3816,11 +3865,9 @@ class P2pRtcManager {
3816
3865
  return;
3817
3866
  }
3818
3867
  session.isOperationPending = true;
3819
- const { p2pVp9On, p2pAv1On, redOn, rtpAbsCaptureTimeOn, cleanSdpOn } = this._features;
3820
- if (p2pVp9On || p2pAv1On || redOn) {
3821
- this._setCodecPreferences(pc, { p2pVp9On, p2pAv1On, redOn });
3822
- }
3823
- pc.createOffer(constraints || this.offerOptions)
3868
+ const { p2pVp9On, redOn, rtpAbsCaptureTimeOn, cleanSdpOn } = this._features;
3869
+ this._setCodecPreferences(pc).then(() => pc
3870
+ .createOffer(constraints || this.offerOptions)
3824
3871
  .then((offer) => {
3825
3872
  if (rtpAbsCaptureTimeOn)
3826
3873
  offer.sdp = addAbsCaptureTimeExtMap(offer.sdp);
@@ -3844,7 +3891,7 @@ class P2pRtcManager {
3844
3891
  })
3845
3892
  .catch((e) => {
3846
3893
  logger$7.warn("RTCPeerConnection.createOffer() failed to create local offer", e);
3847
- });
3894
+ }));
3848
3895
  }
3849
3896
  _withForcedRenegotiation(session, action) {
3850
3897
  const pc = session.pc;
@@ -5052,7 +5099,10 @@ class VegaRtcManager {
5052
5099
  return;
5053
5100
  }
5054
5101
  this._updateAndScheduleMediaServersRefresh(data);
5055
- }), this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, () => {
5102
+ }), this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, (payload) => {
5103
+ if (payload === null || payload === void 0 ? void 0 : payload.error) {
5104
+ return;
5105
+ }
5056
5106
  if (this._screenVideoTrack)
5057
5107
  this._emitScreenshareStarted();
5058
5108
  if (this._features.sfuReconnectV2On && !this._hasVegaConnection && this._reconnect) {
@@ -7948,5 +7998,5 @@ var RtcEventNames;
7948
7998
  RtcEventNames["stream_added"] = "stream_added";
7949
7999
  })(RtcEventNames || (RtcEventNames = {}));
7950
8000
 
7951
- export { BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDevice, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecsByMimeType, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, turnServerOverride, variance };
8001
+ export { BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDevice, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, turnServerOverride, variance };
7952
8002
  //# sourceMappingURL=legacy-esm.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@whereby.com/media",
3
3
  "description": "Media library for Whereby",
4
- "version": "1.21.1",
4
+ "version": "1.23.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {