@fishjam-cloud/webrtc-client 0.30.0 → 0.30.2-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,12 +1,6 @@
1
1
  import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
2
2
  import TypedEmitter from 'typed-emitter';
3
3
 
4
- declare const getLogger: (enableLogging: boolean) => {
5
- readonly debug: (arg: unknown, ...args: unknown[]) => void;
6
- readonly warn: (arg: unknown, ...args: unknown[]) => void;
7
- readonly error: (arg: unknown, ...args: unknown[]) => void;
8
- };
9
-
10
4
  declare enum Variant {
11
5
  VARIANT_UNSPECIFIED = 0,
12
6
  VARIANT_LOW = 1,
@@ -41,6 +35,42 @@ interface MessageFns$2<T> {
41
35
  fromPartial<I extends Exact$2<DeepPartial$2<T>, I>>(object: I): T;
42
36
  }
43
37
 
38
+ interface MediaEvent_Track_SimulcastConfig {
39
+ enabled: boolean;
40
+ enabledVariants: Variant[];
41
+ disabledVariants: Variant[];
42
+ }
43
+ declare const MediaEvent_Track_SimulcastConfig: MessageFns$1<MediaEvent_Track_SimulcastConfig>;
44
+ interface MediaEvent_OfferData_TrackTypes {
45
+ audio: number;
46
+ video: number;
47
+ }
48
+ declare const MediaEvent_OfferData_TrackTypes: MessageFns$1<MediaEvent_OfferData_TrackTypes>;
49
+ type Builtin$1 = Date | Function | Uint8Array | string | number | boolean | undefined;
50
+ type DeepPartial$1<T> = T extends Builtin$1 ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial$1<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial$1<U>> : T extends {} ? {
51
+ [K in keyof T]?: DeepPartial$1<T[K]>;
52
+ } : Partial<T>;
53
+ type KeysOfUnion$1<T> = T extends T ? keyof T : never;
54
+ type Exact$1<P, I extends P> = P extends Builtin$1 ? P : P & {
55
+ [K in keyof P]: Exact$1<P[K], I[K]>;
56
+ } & {
57
+ [K in Exclude<keyof I, KeysOfUnion$1<P>>]: never;
58
+ };
59
+ interface MessageFns$1<T> {
60
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
61
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
62
+ fromJSON(object: any): T;
63
+ toJSON(message: T): unknown;
64
+ create<I extends Exact$1<DeepPartial$1<T>, I>>(base?: I): T;
65
+ fromPartial<I extends Exact$1<DeepPartial$1<T>, I>>(object: I): T;
66
+ }
67
+
68
+ declare const getLogger: (enableLogging: boolean) => {
69
+ readonly debug: (arg: unknown, ...args: unknown[]) => void;
70
+ readonly warn: (arg: unknown, ...args: unknown[]) => void;
71
+ readonly error: (arg: unknown, ...args: unknown[]) => void;
72
+ };
73
+
44
74
  /** Defines any type of message sent from Peer to Membrane RTC Engine */
45
75
  interface MediaEvent$1 {
46
76
  connect?: MediaEvent_Connect | undefined;
@@ -56,36 +86,36 @@ interface MediaEvent$1 {
56
86
  setTargetTrackVariant?: MediaEvent_SetTargetTrackVariant | undefined;
57
87
  unmuteTrack?: MediaEvent_UnmuteTrack | undefined;
58
88
  }
59
- declare const MediaEvent$1: MessageFns$1<MediaEvent$1>;
89
+ declare const MediaEvent$1: MessageFns<MediaEvent$1>;
60
90
  interface MediaEvent_VariantBitrate {
61
91
  variant: Variant;
62
92
  bitrate: number;
63
93
  }
64
- declare const MediaEvent_VariantBitrate: MessageFns$1<MediaEvent_VariantBitrate>;
94
+ declare const MediaEvent_VariantBitrate: MessageFns<MediaEvent_VariantBitrate>;
65
95
  /** Sent when a peer wants to join WebRTC Endpoint. */
66
96
  interface MediaEvent_Connect {
67
97
  metadataJson: string;
68
98
  }
69
- declare const MediaEvent_Connect: MessageFns$1<MediaEvent_Connect>;
99
+ declare const MediaEvent_Connect: MessageFns<MediaEvent_Connect>;
70
100
  /** Sent when a peer disconnects from WebRTC Endpoint. */
71
101
  interface MediaEvent_Disconnect {
72
102
  }
73
- declare const MediaEvent_Disconnect: MessageFns$1<MediaEvent_Disconnect>;
103
+ declare const MediaEvent_Disconnect: MessageFns<MediaEvent_Disconnect>;
74
104
  /** Sent when a peer wants to update its metadata */
75
105
  interface MediaEvent_UpdateEndpointMetadata {
76
106
  metadataJson: string;
77
107
  }
78
- declare const MediaEvent_UpdateEndpointMetadata: MessageFns$1<MediaEvent_UpdateEndpointMetadata>;
108
+ declare const MediaEvent_UpdateEndpointMetadata: MessageFns<MediaEvent_UpdateEndpointMetadata>;
79
109
  /** Sent when a peer wants to update its track's metadata */
80
110
  interface MediaEvent_UpdateTrackMetadata {
81
111
  trackId: string;
82
112
  metadataJson: string;
83
113
  }
84
- declare const MediaEvent_UpdateTrackMetadata: MessageFns$1<MediaEvent_UpdateTrackMetadata>;
114
+ declare const MediaEvent_UpdateTrackMetadata: MessageFns<MediaEvent_UpdateTrackMetadata>;
85
115
  /** Sent when peer wants to renegotiate connection due to adding a track or removing a track */
86
116
  interface MediaEvent_RenegotiateTracks {
87
117
  }
88
- declare const MediaEvent_RenegotiateTracks: MessageFns$1<MediaEvent_RenegotiateTracks>;
118
+ declare const MediaEvent_RenegotiateTracks: MessageFns<MediaEvent_RenegotiateTracks>;
89
119
  /**
90
120
  * Sent as a response to `offerData` media event during renegotiation
91
121
  * Maps contain only information about current peer's `sendonly` tracks.
@@ -105,65 +135,35 @@ interface MediaEvent_SdpOffer {
105
135
  [key: string]: string;
106
136
  };
107
137
  }
108
- declare const MediaEvent_SdpOffer: MessageFns$1<MediaEvent_SdpOffer>;
138
+ declare const MediaEvent_SdpOffer: MessageFns<MediaEvent_SdpOffer>;
109
139
  /** Sent when Peer wants to update its track's bitrate */
110
140
  interface MediaEvent_TrackBitrates {
111
141
  trackId: string;
112
142
  /** Bitrate of each variant. For non-simulcast tracks use VARIANT_UNSPECIFIED. */
113
143
  variantBitrates: MediaEvent_VariantBitrate[];
114
144
  }
115
- declare const MediaEvent_TrackBitrates: MessageFns$1<MediaEvent_TrackBitrates>;
145
+ declare const MediaEvent_TrackBitrates: MessageFns<MediaEvent_TrackBitrates>;
116
146
  /** Sent when client disables one of the track variants */
117
147
  interface MediaEvent_DisableTrackVariant {
118
148
  trackId: string;
119
149
  variant: Variant;
120
150
  }
121
- declare const MediaEvent_DisableTrackVariant: MessageFns$1<MediaEvent_DisableTrackVariant>;
151
+ declare const MediaEvent_DisableTrackVariant: MessageFns<MediaEvent_DisableTrackVariant>;
122
152
  /** Sent when client enables one of the track variants */
123
153
  interface MediaEvent_EnableTrackVariant {
124
154
  trackId: string;
125
155
  variant: Variant;
126
156
  }
127
- declare const MediaEvent_EnableTrackVariant: MessageFns$1<MediaEvent_EnableTrackVariant>;
157
+ declare const MediaEvent_EnableTrackVariant: MessageFns<MediaEvent_EnableTrackVariant>;
128
158
  interface MediaEvent_SetTargetTrackVariant {
129
159
  trackId: string;
130
160
  variant: Variant;
131
161
  }
132
- declare const MediaEvent_SetTargetTrackVariant: MessageFns$1<MediaEvent_SetTargetTrackVariant>;
162
+ declare const MediaEvent_SetTargetTrackVariant: MessageFns<MediaEvent_SetTargetTrackVariant>;
133
163
  interface MediaEvent_UnmuteTrack {
134
164
  trackId: string;
135
165
  }
136
- declare const MediaEvent_UnmuteTrack: MessageFns$1<MediaEvent_UnmuteTrack>;
137
- type Builtin$1 = Date | Function | Uint8Array | string | number | boolean | undefined;
138
- type DeepPartial$1<T> = T extends Builtin$1 ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial$1<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial$1<U>> : T extends {} ? {
139
- [K in keyof T]?: DeepPartial$1<T[K]>;
140
- } : Partial<T>;
141
- type KeysOfUnion$1<T> = T extends T ? keyof T : never;
142
- type Exact$1<P, I extends P> = P extends Builtin$1 ? P : P & {
143
- [K in keyof P]: Exact$1<P[K], I[K]>;
144
- } & {
145
- [K in Exclude<keyof I, KeysOfUnion$1<P>>]: never;
146
- };
147
- interface MessageFns$1<T> {
148
- encode(message: T, writer?: BinaryWriter): BinaryWriter;
149
- decode(input: BinaryReader | Uint8Array, length?: number): T;
150
- fromJSON(object: any): T;
151
- toJSON(message: T): unknown;
152
- create<I extends Exact$1<DeepPartial$1<T>, I>>(base?: I): T;
153
- fromPartial<I extends Exact$1<DeepPartial$1<T>, I>>(object: I): T;
154
- }
155
-
156
- interface MediaEvent_Track_SimulcastConfig {
157
- enabled: boolean;
158
- enabledVariants: Variant[];
159
- disabledVariants: Variant[];
160
- }
161
- declare const MediaEvent_Track_SimulcastConfig: MessageFns<MediaEvent_Track_SimulcastConfig>;
162
- interface MediaEvent_OfferData_TrackTypes {
163
- audio: number;
164
- video: number;
165
- }
166
- declare const MediaEvent_OfferData_TrackTypes: MessageFns<MediaEvent_OfferData_TrackTypes>;
166
+ declare const MediaEvent_UnmuteTrack: MessageFns<MediaEvent_UnmuteTrack>;
167
167
  type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
168
168
  type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
169
169
  [K in keyof T]?: DeepPartial<T[K]>;
@@ -200,13 +200,14 @@ type TrackKind = 'audio' | 'video';
200
200
  */
201
201
  type VadStatus = 'speech' | 'silence';
202
202
  /**
203
- * Type describing maximal bandwidth that can be used, in kbps. 0 is interpreted as unlimited bandwidth.
203
+ * Type describing maximal bandwidth that can be used, in kbps.
204
+ * Video limits are clamped to `MAX_BANDWIDTH_LIMITS`; 0 is interpreted as "use the cap".
204
205
  */
205
206
  type BandwidthLimit = number;
206
207
  /**
207
208
  * Type describing bandwidth limit for simulcast track.
208
209
  * It is a mapping (encoding => BandwidthLimit).
209
- * If encoding isn't present in this mapping, it will be assumed that this particular encoding shouldn't have any bandwidth limit
210
+ * If encoding isn't present in this mapping, the cap from `MAX_BANDWIDTH_LIMITS.simulcast` is used for it.
210
211
  */
211
212
  type SimulcastBandwidthLimit = Map<Variant, BandwidthLimit>;
212
213
  /**
@@ -495,6 +496,25 @@ type WebRTCEndpointProps = {
495
496
  };
496
497
  type Logger = ReturnType<typeof getLogger>;
497
498
 
499
+ /**
500
+ * Hard caps (in kbps) for the bitrate of an outgoing video track.
501
+ * A limit passed to the SDK is never allowed to exceed these values, and an unset (0) limit resolves to them.
502
+ */
503
+ declare const MAX_BANDWIDTH_LIMITS: {
504
+ readonly singleStream: BandwidthLimit;
505
+ readonly simulcast: {
506
+ readonly 1: BandwidthLimit;
507
+ readonly 2: BandwidthLimit;
508
+ readonly 3: BandwidthLimit;
509
+ };
510
+ };
511
+ /**
512
+ * Resolves a user-provided video bandwidth limit against {@link MAX_BANDWIDTH_LIMITS}.
513
+ * - a number is a single-stream limit; 0 or negative means "use the cap", higher values are clamped to it
514
+ * - a Map holds per-variant simulcast limits; each variant is resolved the same way
515
+ */
516
+ declare const resolveBandwidthLimit: (limit: TrackBandwidthLimit) => TrackBandwidthLimit;
517
+
498
518
  declare class ConnectionManager {
499
519
  private readonly connection;
500
520
  constructor(iceServers: RTCIceServer[]);
@@ -726,7 +746,7 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
726
746
  * In case trackId points at the simulcast track bandwidth is split between all of the variant streams proportionally to their resolution.
727
747
  *
728
748
  * @param {string} trackId
729
- * @param {BandwidthLimit} bandwidth in kbps
749
+ * @param {BandwidthLimit} bandwidth in kbps, clamped to `MAX_BANDWIDTH_LIMITS.singleStream`
730
750
  * @returns {Promise<boolean>} success
731
751
  */
732
752
  setTrackBandwidth(trackId: string, bandwidth: BandwidthLimit): Promise<void>;
@@ -735,7 +755,7 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
735
755
  *
736
756
  * @param {string} trackId - id of the track
737
757
  * @param {string} rid - rid of the encoding
738
- * @param {BandwidthLimit} bandwidth - desired max bandwidth used by the encoding (in kbps)
758
+ * @param {BandwidthLimit} bandwidth - desired max bandwidth used by the encoding (in kbps), clamped to `MAX_BANDWIDTH_LIMITS.simulcast[rid]`
739
759
  * @returns
740
760
  */
741
761
  setEncodingBandwidth(trackId: string, rid: Variant, bandwidth: BandwidthLimit): Promise<void>;
@@ -896,4 +916,4 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
896
916
  private onIceConnectionStateChange;
897
917
  }
898
918
 
899
- export { type BandwidthLimit, type DataCallback, type DataChannelMessagePayload, type DataChannelOptions, type DataChannelType, type EncodingReason, type Endpoint, type Logger, type MediaEvent, type SerializedMediaEvent, type SimulcastBandwidthLimit, MediaEvent_Track_SimulcastConfig as SimulcastConfig, type TrackBandwidthLimit, type TrackContext, type TrackContextEvents, type TrackKind, type VadStatus, Variant, WebRTCEndpoint, type WebRTCEndpointEvents, getLogger };
919
+ export { type BandwidthLimit, type DataCallback, type DataChannelMessagePayload, type DataChannelOptions, type DataChannelType, type EncodingReason, type Endpoint, type Logger, MAX_BANDWIDTH_LIMITS, type MediaEvent, type SerializedMediaEvent, type SimulcastBandwidthLimit, MediaEvent_Track_SimulcastConfig as SimulcastConfig, type TrackBandwidthLimit, type TrackContext, type TrackContextEvents, type TrackKind, type VadStatus, Variant, WebRTCEndpoint, type WebRTCEndpointEvents, getLogger, resolveBandwidthLimit };
package/dist/index.mjs CHANGED
@@ -1,20 +1,3 @@
1
- // src/logger.ts
2
- var FISHJAM_PREFIX = "[FISHJAM]";
3
- var getLogger = (enableLogging) => ({
4
- debug: (arg, ...args) => {
5
- if (enableLogging) console.debug(FISHJAM_PREFIX, arg, ...args);
6
- },
7
- warn: (arg, ...args) => {
8
- if (enableLogging) console.warn(FISHJAM_PREFIX, arg, ...args);
9
- },
10
- error: (arg, ...args) => {
11
- if (enableLogging) console.error(FISHJAM_PREFIX, arg, ...args);
12
- }
13
- });
14
-
15
- // ../protobufs/fishjam/media_events/peer/peer.ts
16
- import { BinaryReader as BinaryReader2, BinaryWriter as BinaryWriter2 } from "@bufbuild/protobuf/wire";
17
-
18
1
  // ../protobufs/fishjam/media_events/shared.ts
19
2
  import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
20
3
  var Variant = /* @__PURE__ */ ((Variant4) => {
@@ -162,7 +145,67 @@ function isSet(value) {
162
145
  return value !== null && value !== void 0;
163
146
  }
164
147
 
148
+ // src/bitrate.ts
149
+ var MAX_BANDWIDTH_LIMITS = {
150
+ singleStream: 1500,
151
+ simulcast: {
152
+ [1 /* VARIANT_LOW */]: 150,
153
+ [2 /* VARIANT_MEDIUM */]: 500,
154
+ [3 /* VARIANT_HIGH */]: 1500
155
+ }
156
+ };
157
+ var SIMULCAST_VARIANTS = [1 /* VARIANT_LOW */, 2 /* VARIANT_MEDIUM */, 3 /* VARIANT_HIGH */];
158
+ var isSimulcastVariant = (variant) => SIMULCAST_VARIANTS.includes(variant);
159
+ var resolveAgainstCap = (limit, cap, label) => {
160
+ if (!limit || limit <= 0) return cap;
161
+ if (limit > cap) {
162
+ console.warn(`[Fishjam] ${label} bandwidth limit ${limit} kbps exceeds the cap of ${cap} kbps, using the cap`);
163
+ return cap;
164
+ }
165
+ return limit;
166
+ };
167
+ var resolveBandwidthLimit = (limit) => {
168
+ if (typeof limit === "number") return resolveAgainstCap(limit, MAX_BANDWIDTH_LIMITS.singleStream, "single stream");
169
+ const resolved = /* @__PURE__ */ new Map();
170
+ for (const variant of SIMULCAST_VARIANTS) {
171
+ resolved.set(variant, resolveAgainstCap(limit.get(variant), MAX_BANDWIDTH_LIMITS.simulcast[variant], Variant[variant]));
172
+ }
173
+ return resolved;
174
+ };
175
+ var resolveVariantBandwidthLimit = (variant, limit) => {
176
+ const cap = isSimulcastVariant(variant) ? MAX_BANDWIDTH_LIMITS.simulcast[variant] : MAX_BANDWIDTH_LIMITS.singleStream;
177
+ return resolveAgainstCap(limit, cap, Variant[variant]);
178
+ };
179
+ var kbpsToBps = (kbps) => kbps * 1024;
180
+ var defaultBitrates = {
181
+ audio: 5e4,
182
+ video: kbpsToBps(MAX_BANDWIDTH_LIMITS.singleStream)
183
+ };
184
+ var UNLIMITED_BANDWIDTH = 0;
185
+ var defaultSimulcastBitrates = {
186
+ [3 /* VARIANT_HIGH */]: kbpsToBps(MAX_BANDWIDTH_LIMITS.simulcast[3 /* VARIANT_HIGH */]),
187
+ [2 /* VARIANT_MEDIUM */]: kbpsToBps(MAX_BANDWIDTH_LIMITS.simulcast[2 /* VARIANT_MEDIUM */]),
188
+ [1 /* VARIANT_LOW */]: kbpsToBps(MAX_BANDWIDTH_LIMITS.simulcast[1 /* VARIANT_LOW */]),
189
+ [0 /* VARIANT_UNSPECIFIED */]: 0,
190
+ [-1 /* UNRECOGNIZED */]: 0
191
+ };
192
+
193
+ // src/logger.ts
194
+ var FISHJAM_PREFIX = "[FISHJAM]";
195
+ var getLogger = (enableLogging) => ({
196
+ debug: (arg, ...args) => {
197
+ if (enableLogging) console.debug(FISHJAM_PREFIX, arg, ...args);
198
+ },
199
+ warn: (arg, ...args) => {
200
+ if (enableLogging) console.warn(FISHJAM_PREFIX, arg, ...args);
201
+ },
202
+ error: (arg, ...args) => {
203
+ if (enableLogging) console.error(FISHJAM_PREFIX, arg, ...args);
204
+ }
205
+ });
206
+
165
207
  // ../protobufs/fishjam/media_events/peer/peer.ts
208
+ import { BinaryReader as BinaryReader2, BinaryWriter as BinaryWriter2 } from "@bufbuild/protobuf/wire";
166
209
  function createBaseMediaEvent() {
167
210
  return {
168
211
  connect: void 0,
@@ -3963,18 +4006,15 @@ var TrackContextImpl = class extends EventEmitter2 {
3963
4006
  }
3964
4007
  };
3965
4008
 
3966
- // src/bitrate.ts
3967
- var defaultBitrates = {
3968
- audio: 5e4,
3969
- video: 25e5
3970
- };
3971
- var UNLIMITED_BANDWIDTH = 0;
3972
- var defaultSimulcastBitrates = {
3973
- [3 /* VARIANT_HIGH */]: 25e5,
3974
- [2 /* VARIANT_MEDIUM */]: 5e5,
3975
- [1 /* VARIANT_LOW */]: 15e4,
3976
- [0 /* VARIANT_UNSPECIFIED */]: 0,
3977
- [-1 /* UNRECOGNIZED */]: 0
4009
+ // src/tracks/bitrates.ts
4010
+ var getVariantBitrates = (trackContext) => {
4011
+ const kind = trackContext.track?.kind ?? trackContext.trackKind;
4012
+ if (kind === "audio") return [{ variant: 0 /* VARIANT_UNSPECIFIED */, bitrate: defaultBitrates.audio }];
4013
+ const { maxBandwidth } = trackContext;
4014
+ if (typeof maxBandwidth === "number") {
4015
+ return [{ variant: 0 /* VARIANT_UNSPECIFIED */, bitrate: kbpsToBps(maxBandwidth) || defaultBitrates.video }];
4016
+ }
4017
+ return [...maxBandwidth.entries()].map(([variant, limit]) => ({ variant, bitrate: kbpsToBps(limit) }));
3978
4018
  };
3979
4019
 
3980
4020
  // src/tracks/bandwidth.ts
@@ -4367,9 +4407,10 @@ var Local = class {
4367
4407
  const trackManager = this.localTracks[trackId];
4368
4408
  if (!trackManager) throw new Error(`Cannot find ${trackId}`);
4369
4409
  await trackManager.setTrackBandwidth(bandwidth);
4410
+ trackManager.trackContext.maxBandwidth = bandwidth;
4370
4411
  const trackBitrates = MediaEvent_TrackBitrates.create({
4371
4412
  trackId,
4372
- variantBitrates: [{ variant: 0 /* VARIANT_UNSPECIFIED */, bitrate: bandwidth }]
4413
+ variantBitrates: getVariantBitrates(trackManager.trackContext)
4373
4414
  });
4374
4415
  this.sendMediaEvent(MediaEvent.create({ trackBitrates }));
4375
4416
  this.emit("localTrackBandwidthSet", {
@@ -4390,19 +4431,11 @@ var Local = class {
4390
4431
  const trackManager = this.localTracks[trackId];
4391
4432
  if (!trackManager) throw new Error(`Cannot find ${trackId}`);
4392
4433
  await trackManager.setEncodingBandwidth(rid, bandwidth);
4393
- const bitrates = trackManager.getTrackBitrates();
4394
- let variantBitrates = [];
4395
- if (typeof bitrates === "number") {
4396
- variantBitrates = [{ variant: 0 /* VARIANT_UNSPECIFIED */, bitrate: bitrates }];
4397
- } else if (bitrates) {
4398
- variantBitrates = Object.entries(bitrates).map(([variant, bitrate]) => ({
4399
- variant: Number(variant),
4400
- bitrate
4401
- }));
4402
- }
4434
+ const { maxBandwidth } = trackManager.trackContext;
4435
+ if (maxBandwidth instanceof Map) maxBandwidth.set(rid, bandwidth);
4403
4436
  const trackBitrates = MediaEvent_TrackBitrates.create({
4404
4437
  trackId,
4405
- variantBitrates
4438
+ variantBitrates: getVariantBitrates(trackManager.trackContext)
4406
4439
  });
4407
4440
  this.sendMediaEvent(MediaEvent.create({ trackBitrates }));
4408
4441
  this.emit("localTrackEncodingBandwidthSet", {
@@ -4471,8 +4504,13 @@ var Local = class {
4471
4504
  (acc, { id, trackContext }) => ({ ...acc, [id]: JSON.stringify(trackContext.metadata) }),
4472
4505
  {}
4473
4506
  );
4474
- // TODO add bitrates
4475
- getTrackIdToTrackBitrates = () => Object.values(this.localTracks).reduce((acc, { id }) => ({ ...acc, [id]: { bitrate: 15e5 } }), {});
4507
+ getTrackIdToTrackBitrates = () => Object.values(this.localTracks).reduce(
4508
+ (acc, { id, trackContext }) => ({
4509
+ ...acc,
4510
+ [id]: MediaEvent_TrackBitrates.create({ trackId: id, variantBitrates: getVariantBitrates(trackContext) })
4511
+ }),
4512
+ {}
4513
+ );
4476
4514
  getMidToTrackId = () => {
4477
4515
  if (!this.connection) return {};
4478
4516
  const mappingFromTransceivers = this.getTransceiverMapping();
@@ -5078,7 +5116,7 @@ var WebRTCEndpoint = class extends EventEmitter3 {
5078
5116
  const resolutionNotifier = new Deferred();
5079
5117
  const trackId = this.getTrackId(uuidv4());
5080
5118
  const trackStream = stream ?? new MediaStream();
5081
- const resolvedMaxBandwidth = typeof maxBandwidth === "number" && maxBandwidth > 0 ? maxBandwidth : 0;
5119
+ const resolvedMaxBandwidth = track.kind === "video" ? resolveBandwidthLimit(maxBandwidth) : 0;
5082
5120
  try {
5083
5121
  if (!stream) trackStream.addTrack(track);
5084
5122
  this.commandsQueue.pushCommand({
@@ -5171,24 +5209,24 @@ var WebRTCEndpoint = class extends EventEmitter3 {
5171
5209
  * In case trackId points at the simulcast track bandwidth is split between all of the variant streams proportionally to their resolution.
5172
5210
  *
5173
5211
  * @param {string} trackId
5174
- * @param {BandwidthLimit} bandwidth in kbps
5212
+ * @param {BandwidthLimit} bandwidth in kbps, clamped to `MAX_BANDWIDTH_LIMITS.singleStream`
5175
5213
  * @returns {Promise<boolean>} success
5176
5214
  */
5177
5215
  setTrackBandwidth(trackId, bandwidth) {
5178
5216
  if (!this.connectionManager) throw new Error(`There is no active RTCPeerConnection`);
5179
- return this.local.setTrackBandwidth(trackId, bandwidth);
5217
+ return this.local.setTrackBandwidth(trackId, resolveBandwidthLimit(bandwidth));
5180
5218
  }
5181
5219
  /**
5182
5220
  * Updates maximum bandwidth for the given simulcast encoding of the given track.
5183
5221
  *
5184
5222
  * @param {string} trackId - id of the track
5185
5223
  * @param {string} rid - rid of the encoding
5186
- * @param {BandwidthLimit} bandwidth - desired max bandwidth used by the encoding (in kbps)
5224
+ * @param {BandwidthLimit} bandwidth - desired max bandwidth used by the encoding (in kbps), clamped to `MAX_BANDWIDTH_LIMITS.simulcast[rid]`
5187
5225
  * @returns
5188
5226
  */
5189
5227
  async setEncodingBandwidth(trackId, rid, bandwidth) {
5190
5228
  if (!this.connectionManager) throw new Error(`There is no active RTCPeerConnection`);
5191
- return await this.local.setEncodingBandwidth(trackId, rid, bandwidth);
5229
+ return await this.local.setEncodingBandwidth(trackId, rid, resolveVariantBandwidthLimit(rid, bandwidth));
5192
5230
  }
5193
5231
  /**
5194
5232
  * Removes a track from connection that was sent to the RTC Engine.
@@ -5485,8 +5523,10 @@ var WebRTCEndpoint = class extends EventEmitter3 {
5485
5523
  };
5486
5524
  };
5487
5525
  export {
5526
+ MAX_BANDWIDTH_LIMITS,
5488
5527
  MediaEvent_Track_SimulcastConfig as SimulcastConfig,
5489
5528
  Variant,
5490
5529
  WebRTCEndpoint,
5491
- getLogger
5530
+ getLogger,
5531
+ resolveBandwidthLimit
5492
5532
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fishjam-cloud/webrtc-client",
3
- "version": "0.30.0",
3
+ "version": "0.30.2-rc.0",
4
4
  "description": "Typescript client library for ExWebRTC/WebRTC endpoint in Membrane RTC Engine",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Fishjam Team",