@fishjam-cloud/webrtc-client 0.25.3 → 0.26.0-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
@@ -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
package/dist/index.mjs CHANGED
@@ -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
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.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",