@fishjam-cloud/webrtc-client 0.25.3 → 0.26.0-rc.1

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
@@ -563,6 +563,24 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
563
563
  * ```
564
564
  */
565
565
  connect: (metadata: unknown) => void;
566
+ /**
567
+ * Returns the current audio level for a local audio track, if available.
568
+ *
569
+ * This method only works for local **audio** tracks that have been negotiated
570
+ * with the remote peer and for which an underlying `RTCRtpSender` and
571
+ * statistics are available.
572
+ *
573
+ * @param trackId - Identifier of the local track to query, as used when
574
+ * adding or managing local tracks on this endpoint.
575
+ * @returns A promise that resolves to `{ level: number }` when an audio
576
+ * level can be determined for the given track, or `null` if:
577
+ * - the track does not exist,
578
+ * - the track is not an audio track,
579
+ * - the track has not yet been negotiated / no sender exists
580
+ */
581
+ getLocalTrackAudioLevel(trackId: string): Promise<{
582
+ level: number;
583
+ } | null>;
566
584
  /**
567
585
  * Feeds media event received from RTC Engine to {@link WebRTCEndpoint}.
568
586
  * This function should be called whenever some media event from RTC Engine
@@ -615,10 +633,8 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
615
633
  * @param trackMetadata - Any information about this track that other endpoints will
616
634
  * receive in {@link WebRTCEndpointEvents.endpointAdded}. E.g. this can source of the track - whether it's
617
635
  * screensharing, webcam or some other media device.
618
- * @param _simulcastConfig - Simulcast configuration parameter. **Currently ignored** - simulcast is disabled
619
- * regardless of the value passed. This is a temporary change until bandwidth estimation is implemented or
620
- * manual track selection support is added. For more information refer to {@link SimulcastConfig}.
621
- * @param _maxBandwidth - maximal bandwidth this track can use. **Currently processed with a threshold check**:
636
+ * @param simulcastConfig - Simulcast configuration. For more information refer to {@link SimulcastConfig}.
637
+ * @param maxBandwidth - maximal bandwidth this track can use. **Currently processed with a threshold check**:
622
638
  * if the value is a positive number, it will be used; otherwise, it defaults to 0 (unlimited).
623
639
  * This option has no effect for simulcast and audio tracks.
624
640
  * For simulcast tracks use `{@link WebRTCEndpoint.setTrackBandwidth}.
@@ -653,7 +669,7 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
653
669
  * .forEach((track) => webrtc.addTrack(track, localStream));
654
670
  * ```
655
671
  */
656
- addTrack(track: MediaStreamTrack, trackMetadata?: unknown, _simulcastConfig?: MediaEvent_Track_SimulcastConfig, _maxBandwidth?: TrackBandwidthLimit): Promise<string>;
672
+ addTrack(track: MediaStreamTrack, trackMetadata?: unknown, simulcastConfig?: MediaEvent_Track_SimulcastConfig, maxBandwidth?: TrackBandwidthLimit, stream?: MediaStream): Promise<string>;
657
673
  /**
658
674
  * Replaces a track that is being sent to the RTC Engine.
659
675
  * @param trackId - Audio or video track.
package/dist/index.mjs CHANGED
@@ -4152,9 +4152,9 @@ var LocalTrack = class {
4152
4152
  const stream = this.trackContext.stream;
4153
4153
  const oldTrack = this.trackContext.track;
4154
4154
  if (!this.sender) throw Error("There is no RTCRtpSender for this track id!");
4155
- stream?.getTracks().forEach((track) => {
4156
- stream?.removeTrack(track);
4157
- });
4155
+ if (oldTrack) {
4156
+ stream?.removeTrack(oldTrack);
4157
+ }
4158
4158
  if (newTrack) {
4159
4159
  stream?.addTrack(newTrack);
4160
4160
  }
@@ -4236,6 +4236,18 @@ var LocalTrack = class {
4236
4236
  {}
4237
4237
  );
4238
4238
  };
4239
+ getAudioLevel = async () => {
4240
+ if (!this.sender) return null;
4241
+ try {
4242
+ const stats = await this.sender.getStats();
4243
+ const source = [...stats.values()].find(
4244
+ (r) => r.type === "media-source" && r.kind === "audio" && typeof r.audioLevel === "number"
4245
+ );
4246
+ return source ? { level: source.audioLevel } : null;
4247
+ } catch {
4248
+ return null;
4249
+ }
4250
+ };
4239
4251
  createTrackVariantBitratesEvent = () => {
4240
4252
  };
4241
4253
  };
@@ -4454,6 +4466,9 @@ var Local = class {
4454
4466
  localTrack.addTrackToConnection();
4455
4467
  });
4456
4468
  };
4469
+ getLocalTrackAudioLevel = async (trackId) => {
4470
+ return this.localTracks[trackId]?.getAudioLevel() ?? null;
4471
+ };
4457
4472
  };
4458
4473
 
4459
4474
  // src/tracks/LocalTrackManager.ts
@@ -4785,6 +4800,24 @@ var WebRTCEndpoint = class extends EventEmitter3 {
4785
4800
  const connect = MediaEvent_Connect.create({ metadataJson: JSON.stringify(metadata) });
4786
4801
  this.sendMediaEvent({ connect });
4787
4802
  };
4803
+ /**
4804
+ * Returns the current audio level for a local audio track, if available.
4805
+ *
4806
+ * This method only works for local **audio** tracks that have been negotiated
4807
+ * with the remote peer and for which an underlying `RTCRtpSender` and
4808
+ * statistics are available.
4809
+ *
4810
+ * @param trackId - Identifier of the local track to query, as used when
4811
+ * adding or managing local tracks on this endpoint.
4812
+ * @returns A promise that resolves to `{ level: number }` when an audio
4813
+ * level can be determined for the given track, or `null` if:
4814
+ * - the track does not exist,
4815
+ * - the track is not an audio track,
4816
+ * - the track has not yet been negotiated / no sender exists
4817
+ */
4818
+ getLocalTrackAudioLevel(trackId) {
4819
+ return this.local.getLocalTrackAudioLevel(trackId);
4820
+ }
4788
4821
  /**
4789
4822
  * Feeds media event received from RTC Engine to {@link WebRTCEndpoint}.
4790
4823
  * This function should be called whenever some media event from RTC Engine
@@ -4966,10 +4999,8 @@ var WebRTCEndpoint = class extends EventEmitter3 {
4966
4999
  * @param trackMetadata - Any information about this track that other endpoints will
4967
5000
  * receive in {@link WebRTCEndpointEvents.endpointAdded}. E.g. this can source of the track - whether it's
4968
5001
  * screensharing, webcam or some other media device.
4969
- * @param _simulcastConfig - Simulcast configuration parameter. **Currently ignored** - simulcast is disabled
4970
- * regardless of the value passed. This is a temporary change until bandwidth estimation is implemented or
4971
- * manual track selection support is added. For more information refer to {@link SimulcastConfig}.
4972
- * @param _maxBandwidth - maximal bandwidth this track can use. **Currently processed with a threshold check**:
5002
+ * @param simulcastConfig - Simulcast configuration. For more information refer to {@link SimulcastConfig}.
5003
+ * @param maxBandwidth - maximal bandwidth this track can use. **Currently processed with a threshold check**:
4973
5004
  * if the value is a positive number, it will be used; otherwise, it defaults to 0 (unlimited).
4974
5005
  * This option has no effect for simulcast and audio tracks.
4975
5006
  * For simulcast tracks use `{@link WebRTCEndpoint.setTrackBandwidth}.
@@ -5004,25 +5035,27 @@ var WebRTCEndpoint = class extends EventEmitter3 {
5004
5035
  * .forEach((track) => webrtc.addTrack(track, localStream));
5005
5036
  * ```
5006
5037
  */
5007
- async addTrack(track, trackMetadata, _simulcastConfig = {
5038
+ async addTrack(track, trackMetadata, simulcastConfig = {
5008
5039
  enabled: false,
5009
5040
  enabledVariants: [],
5010
5041
  disabledVariants: []
5011
- }, _maxBandwidth = 0) {
5042
+ }, maxBandwidth = 0, stream) {
5012
5043
  const resolutionNotifier = new Deferred();
5013
5044
  const trackId = this.getTrackId(uuidv4());
5014
- const stream = new MediaStream();
5015
- const simulcastConfig = {
5016
- enabled: false,
5017
- enabledVariants: [],
5018
- disabledVariants: []
5019
- };
5020
- const maxBandwidth = typeof _maxBandwidth === "number" && _maxBandwidth > 0 ? _maxBandwidth : 0;
5045
+ const trackStream = stream ?? new MediaStream();
5046
+ const resolvedMaxBandwidth = typeof maxBandwidth === "number" && maxBandwidth > 0 ? maxBandwidth : 0;
5021
5047
  try {
5022
- stream.addTrack(track);
5048
+ if (!stream) trackStream.addTrack(track);
5023
5049
  this.commandsQueue.pushCommand({
5024
- handler: async () => this.localTrackManager.addTrackHandler(trackId, track, stream, trackMetadata, simulcastConfig, maxBandwidth),
5025
- parse: () => this.localTrackManager.parseAddTrack(track, simulcastConfig, maxBandwidth),
5050
+ handler: async () => this.localTrackManager.addTrackHandler(
5051
+ trackId,
5052
+ track,
5053
+ trackStream,
5054
+ trackMetadata,
5055
+ simulcastConfig,
5056
+ resolvedMaxBandwidth
5057
+ ),
5058
+ parse: () => this.localTrackManager.parseAddTrack(track, simulcastConfig, resolvedMaxBandwidth),
5026
5059
  resolve: "after-renegotiation",
5027
5060
  resolutionNotifier
5028
5061
  });
@@ -5033,10 +5066,10 @@ var WebRTCEndpoint = class extends EventEmitter3 {
5033
5066
  this.emit("localTrackAdded", {
5034
5067
  trackId,
5035
5068
  track,
5036
- stream,
5069
+ stream: trackStream,
5037
5070
  trackMetadata,
5038
5071
  simulcastConfig,
5039
- maxBandwidth
5072
+ maxBandwidth: resolvedMaxBandwidth
5040
5073
  });
5041
5074
  return trackId;
5042
5075
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fishjam-cloud/webrtc-client",
3
- "version": "0.25.3",
3
+ "version": "0.26.0-rc.1",
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",