@whereby.com/media 1.21.1 → 1.22.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 {
@@ -3787,46 +3824,53 @@ class P2pRtcManager {
3787
3824
  this._negotiatePeerConnection(clientId, session, Object.assign({}, this.offerOptions, { iceRestart: true }));
3788
3825
  }
3789
3826
  }
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;
3827
+ _setCodecPreferences(pc) {
3828
+ return __awaiter(this, void 0, void 0, function* () {
3829
+ const { p2pVp9On, p2pAv1On, redOn, preferHardwareDecodingOn } = this._features;
3830
+ if (!(p2pVp9On || p2pAv1On || redOn || preferHardwareDecodingOn)) {
3831
+ return;
3832
+ }
3833
+ try {
3834
+ const audioTransceivers = pc
3835
+ .getTransceivers()
3836
+ .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"; });
3837
+ audioTransceivers.forEach((audioTransceiver) => {
3838
+ if (typeof RTCRtpSender.getCapabilities === "undefined")
3839
+ return;
3840
+ const capabilities = RTCRtpSender.getCapabilities("audio");
3841
+ for (let i = 0; i < capabilities.codecs.length; i++) {
3842
+ if (redOn && capabilities.codecs[i].mimeType.toLowerCase() === "audio/red") {
3843
+ capabilities.codecs.unshift(capabilities.codecs.splice(i, 1)[0]);
3844
+ break;
3845
+ }
3803
3846
  }
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
- }
3847
+ if (typeof audioTransceiver.setCodecPreferences === "undefined")
3848
+ return;
3849
+ audioTransceiver.setCodecPreferences(capabilities.codecs);
3850
+ });
3851
+ const videoTransceivers = pc
3852
+ .getTransceivers()
3853
+ .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"; });
3854
+ yield Promise.all(videoTransceivers.map((videoTransceiver) => __awaiter(this, void 0, void 0, function* () {
3855
+ if (RTCRtpReceiver.getCapabilities === undefined)
3856
+ return;
3857
+ if (videoTransceiver.setCodecPreferences === undefined)
3858
+ return;
3859
+ const capabilities = RTCRtpReceiver.getCapabilities("video");
3860
+ if (p2pVp9On || p2pAv1On || preferHardwareDecodingOn) {
3861
+ capabilities.codecs = yield sortCodecs(capabilities.codecs, {
3862
+ vp9On: p2pVp9On,
3863
+ av1On: p2pAv1On,
3864
+ preferHardwareDecodingOn,
3865
+ });
3866
+ }
3867
+ videoTransceiver.setCodecPreferences(capabilities.codecs);
3868
+ })));
3869
+ }
3870
+ catch (error) {
3871
+ logger$7.error("Error during setting setCodecPreferences:", error);
3872
+ }
3873
+ });
3830
3874
  }
3831
3875
  _negotiatePeerConnection(clientId, session, constraints) {
3832
3876
  if (!session) {
@@ -3841,11 +3885,9 @@ class P2pRtcManager {
3841
3885
  return;
3842
3886
  }
3843
3887
  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)
3888
+ const { p2pVp9On, redOn, rtpAbsCaptureTimeOn, cleanSdpOn } = this._features;
3889
+ this._setCodecPreferences(pc).then(() => pc
3890
+ .createOffer(constraints || this.offerOptions)
3849
3891
  .then((offer) => {
3850
3892
  if (rtpAbsCaptureTimeOn)
3851
3893
  offer.sdp = addAbsCaptureTimeExtMap(offer.sdp);
@@ -3869,7 +3911,7 @@ class P2pRtcManager {
3869
3911
  })
3870
3912
  .catch((e) => {
3871
3913
  logger$7.warn("RTCPeerConnection.createOffer() failed to create local offer", e);
3872
- });
3914
+ }));
3873
3915
  }
3874
3916
  _withForcedRenegotiation(session, action) {
3875
3917
  const pc = session.pc;
@@ -8057,7 +8099,7 @@ exports.setClientProvider = setClientProvider;
8057
8099
  exports.setCodecPreferenceSDP = setCodecPreferenceSDP;
8058
8100
  exports.setPeerConnectionsForTests = setPeerConnectionsForTests;
8059
8101
  exports.setVideoBandwidthUsingSetParameters = setVideoBandwidthUsingSetParameters;
8060
- exports.sortCodecsByMimeType = sortCodecsByMimeType;
8102
+ exports.sortCodecs = sortCodecs;
8061
8103
  exports.standardDeviation = standardDeviation;
8062
8104
  exports.startPerformanceMonitor = startPerformanceMonitor;
8063
8105
  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
 
@@ -1666,4 +1663,4 @@ declare class RtcStream {
1666
1663
  static getTypeFromId(id: string): string;
1667
1664
  }
1668
1665
 
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 };
1666
+ 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, 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
 
@@ -1666,4 +1663,4 @@ declare class RtcStream {
1666
1663
  static getTypeFromId(id: string): string;
1667
1664
  }
1668
1665
 
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 };
1666
+ 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, 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
 
@@ -1666,4 +1663,4 @@ declare class RtcStream {
1666
1663
  static getTypeFromId(id: string): string;
1667
1664
  }
1668
1665
 
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 };
1666
+ 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, 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 {
@@ -3762,46 +3799,53 @@ class P2pRtcManager {
3762
3799
  this._negotiatePeerConnection(clientId, session, Object.assign({}, this.offerOptions, { iceRestart: true }));
3763
3800
  }
3764
3801
  }
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;
3802
+ _setCodecPreferences(pc) {
3803
+ return __awaiter(this, void 0, void 0, function* () {
3804
+ const { p2pVp9On, p2pAv1On, redOn, preferHardwareDecodingOn } = this._features;
3805
+ if (!(p2pVp9On || p2pAv1On || redOn || preferHardwareDecodingOn)) {
3806
+ return;
3807
+ }
3808
+ try {
3809
+ const audioTransceivers = 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) === "audio"; });
3812
+ audioTransceivers.forEach((audioTransceiver) => {
3813
+ if (typeof RTCRtpSender.getCapabilities === "undefined")
3814
+ return;
3815
+ const capabilities = RTCRtpSender.getCapabilities("audio");
3816
+ for (let i = 0; i < capabilities.codecs.length; i++) {
3817
+ if (redOn && capabilities.codecs[i].mimeType.toLowerCase() === "audio/red") {
3818
+ capabilities.codecs.unshift(capabilities.codecs.splice(i, 1)[0]);
3819
+ break;
3820
+ }
3778
3821
  }
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
- }
3822
+ if (typeof audioTransceiver.setCodecPreferences === "undefined")
3823
+ return;
3824
+ audioTransceiver.setCodecPreferences(capabilities.codecs);
3825
+ });
3826
+ const videoTransceivers = pc
3827
+ .getTransceivers()
3828
+ .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"; });
3829
+ yield Promise.all(videoTransceivers.map((videoTransceiver) => __awaiter(this, void 0, void 0, function* () {
3830
+ if (RTCRtpReceiver.getCapabilities === undefined)
3831
+ return;
3832
+ if (videoTransceiver.setCodecPreferences === undefined)
3833
+ return;
3834
+ const capabilities = RTCRtpReceiver.getCapabilities("video");
3835
+ if (p2pVp9On || p2pAv1On || preferHardwareDecodingOn) {
3836
+ capabilities.codecs = yield sortCodecs(capabilities.codecs, {
3837
+ vp9On: p2pVp9On,
3838
+ av1On: p2pAv1On,
3839
+ preferHardwareDecodingOn,
3840
+ });
3841
+ }
3842
+ videoTransceiver.setCodecPreferences(capabilities.codecs);
3843
+ })));
3844
+ }
3845
+ catch (error) {
3846
+ logger$7.error("Error during setting setCodecPreferences:", error);
3847
+ }
3848
+ });
3805
3849
  }
3806
3850
  _negotiatePeerConnection(clientId, session, constraints) {
3807
3851
  if (!session) {
@@ -3816,11 +3860,9 @@ class P2pRtcManager {
3816
3860
  return;
3817
3861
  }
3818
3862
  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)
3863
+ const { p2pVp9On, redOn, rtpAbsCaptureTimeOn, cleanSdpOn } = this._features;
3864
+ this._setCodecPreferences(pc).then(() => pc
3865
+ .createOffer(constraints || this.offerOptions)
3824
3866
  .then((offer) => {
3825
3867
  if (rtpAbsCaptureTimeOn)
3826
3868
  offer.sdp = addAbsCaptureTimeExtMap(offer.sdp);
@@ -3844,7 +3886,7 @@ class P2pRtcManager {
3844
3886
  })
3845
3887
  .catch((e) => {
3846
3888
  logger$7.warn("RTCPeerConnection.createOffer() failed to create local offer", e);
3847
- });
3889
+ }));
3848
3890
  }
3849
3891
  _withForcedRenegotiation(session, action) {
3850
3892
  const pc = session.pc;
@@ -7948,4 +7990,4 @@ var RtcEventNames;
7948
7990
  RtcEventNames["stream_added"] = "stream_added";
7949
7991
  })(RtcEventNames || (RtcEventNames = {}));
7950
7992
 
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 };
7993
+ 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 {
@@ -3762,46 +3799,53 @@ class P2pRtcManager {
3762
3799
  this._negotiatePeerConnection(clientId, session, Object.assign({}, this.offerOptions, { iceRestart: true }));
3763
3800
  }
3764
3801
  }
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;
3802
+ _setCodecPreferences(pc) {
3803
+ return __awaiter(this, void 0, void 0, function* () {
3804
+ const { p2pVp9On, p2pAv1On, redOn, preferHardwareDecodingOn } = this._features;
3805
+ if (!(p2pVp9On || p2pAv1On || redOn || preferHardwareDecodingOn)) {
3806
+ return;
3807
+ }
3808
+ try {
3809
+ const audioTransceivers = 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) === "audio"; });
3812
+ audioTransceivers.forEach((audioTransceiver) => {
3813
+ if (typeof RTCRtpSender.getCapabilities === "undefined")
3814
+ return;
3815
+ const capabilities = RTCRtpSender.getCapabilities("audio");
3816
+ for (let i = 0; i < capabilities.codecs.length; i++) {
3817
+ if (redOn && capabilities.codecs[i].mimeType.toLowerCase() === "audio/red") {
3818
+ capabilities.codecs.unshift(capabilities.codecs.splice(i, 1)[0]);
3819
+ break;
3820
+ }
3778
3821
  }
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
- }
3822
+ if (typeof audioTransceiver.setCodecPreferences === "undefined")
3823
+ return;
3824
+ audioTransceiver.setCodecPreferences(capabilities.codecs);
3825
+ });
3826
+ const videoTransceivers = pc
3827
+ .getTransceivers()
3828
+ .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"; });
3829
+ yield Promise.all(videoTransceivers.map((videoTransceiver) => __awaiter(this, void 0, void 0, function* () {
3830
+ if (RTCRtpReceiver.getCapabilities === undefined)
3831
+ return;
3832
+ if (videoTransceiver.setCodecPreferences === undefined)
3833
+ return;
3834
+ const capabilities = RTCRtpReceiver.getCapabilities("video");
3835
+ if (p2pVp9On || p2pAv1On || preferHardwareDecodingOn) {
3836
+ capabilities.codecs = yield sortCodecs(capabilities.codecs, {
3837
+ vp9On: p2pVp9On,
3838
+ av1On: p2pAv1On,
3839
+ preferHardwareDecodingOn,
3840
+ });
3841
+ }
3842
+ videoTransceiver.setCodecPreferences(capabilities.codecs);
3843
+ })));
3844
+ }
3845
+ catch (error) {
3846
+ logger$7.error("Error during setting setCodecPreferences:", error);
3847
+ }
3848
+ });
3805
3849
  }
3806
3850
  _negotiatePeerConnection(clientId, session, constraints) {
3807
3851
  if (!session) {
@@ -3816,11 +3860,9 @@ class P2pRtcManager {
3816
3860
  return;
3817
3861
  }
3818
3862
  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)
3863
+ const { p2pVp9On, redOn, rtpAbsCaptureTimeOn, cleanSdpOn } = this._features;
3864
+ this._setCodecPreferences(pc).then(() => pc
3865
+ .createOffer(constraints || this.offerOptions)
3824
3866
  .then((offer) => {
3825
3867
  if (rtpAbsCaptureTimeOn)
3826
3868
  offer.sdp = addAbsCaptureTimeExtMap(offer.sdp);
@@ -3844,7 +3886,7 @@ class P2pRtcManager {
3844
3886
  })
3845
3887
  .catch((e) => {
3846
3888
  logger$7.warn("RTCPeerConnection.createOffer() failed to create local offer", e);
3847
- });
3889
+ }));
3848
3890
  }
3849
3891
  _withForcedRenegotiation(session, action) {
3850
3892
  const pc = session.pc;
@@ -7948,5 +7990,5 @@ var RtcEventNames;
7948
7990
  RtcEventNames["stream_added"] = "stream_added";
7949
7991
  })(RtcEventNames || (RtcEventNames = {}));
7950
7992
 
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 };
7993
+ 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
7994
  //# 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.22.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {