@fishjam-cloud/webrtc-client 0.23.0 → 0.25.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
@@ -1,6 +1,11 @@
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 warn: (arg: unknown, ...args: unknown[]) => void;
6
+ readonly error: (arg: unknown, ...args: unknown[]) => void;
7
+ };
8
+
4
9
  declare enum Variant {
5
10
  VARIANT_UNSPECIFIED = 0,
6
11
  VARIANT_LOW = 1,
@@ -76,7 +81,7 @@ interface MediaEvent_UpdateTrackMetadata {
76
81
  metadataJson: string;
77
82
  }
78
83
  declare const MediaEvent_UpdateTrackMetadata: MessageFns$1<MediaEvent_UpdateTrackMetadata>;
79
- /** Sent when peer wants to renegatiate connection due to adding a track or removing a track */
84
+ /** Sent when peer wants to renegotiate connection due to adding a track or removing a track */
80
85
  interface MediaEvent_RenegotiateTracks {
81
86
  }
82
87
  declare const MediaEvent_RenegotiateTracks: MessageFns$1<MediaEvent_RenegotiateTracks>;
@@ -91,7 +96,7 @@ interface MediaEvent_SdpOffer {
91
96
  trackIdToMetadataJson: {
92
97
  [key: string]: string;
93
98
  };
94
- /** Maps track_id to its bitrate. The track_id in the TrackBitrates message is ignored (we use the map key), so it can be ommited. */
99
+ /** Maps track_id to its bitrate. The track_id in the TrackBitrates message is ignored (we use the map key), so it can be omitted. */
95
100
  trackIdToBitrates: {
96
101
  [key: string]: MediaEvent_TrackBitrates;
97
102
  };
@@ -434,6 +439,13 @@ interface Endpoint {
434
439
  */
435
440
  tracks: Map<string, TrackContext>;
436
441
  }
442
+ type WebRTCEndpointProps = {
443
+ /**
444
+ * Enables Fishjam SDK's debug logs in the console.
445
+ */
446
+ debug?: boolean;
447
+ };
448
+ type Logger = ReturnType<typeof getLogger>;
437
449
 
438
450
  declare class ConnectionManager {
439
451
  private readonly connection;
@@ -482,10 +494,11 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
482
494
  private readonly local;
483
495
  private readonly commandsQueue;
484
496
  private proposedIceServers;
497
+ private logger;
485
498
  bandwidthEstimation: bigint;
486
499
  connectionManager?: ConnectionManager;
487
500
  private clearConnectionCallbacks;
488
- constructor();
501
+ constructor(props?: WebRTCEndpointProps);
489
502
  /**
490
503
  * Tries to connect to the RTC Engine. If user is successfully connected then {@link WebRTCEndpointEvents.connected}
491
504
  * will be emitted.
@@ -551,10 +564,11 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
551
564
  * @param trackMetadata - Any information about this track that other endpoints will
552
565
  * receive in {@link WebRTCEndpointEvents.endpointAdded}. E.g. this can source of the track - whether it's
553
566
  * screensharing, webcam or some other media device.
554
- * @param simulcastConfig - Simulcast configuration. By default simulcast is disabled.
555
- * For more information refer to {@link SimulcastConfig}.
556
- * @param maxBandwidth - maximal bandwidth this track can use.
557
- * Defaults to 0 which is unlimited.
567
+ * @param _simulcastConfig - Simulcast configuration parameter. **Currently ignored** - simulcast is disabled
568
+ * regardless of the value passed. This is a temporary change until bandwidth estimation is implemented or
569
+ * manual track selection support is added. For more information refer to {@link SimulcastConfig}.
570
+ * @param _maxBandwidth - maximal bandwidth this track can use. **Currently processed with a threshold check**:
571
+ * if the value is a positive number, it will be used; otherwise, it defaults to 0 (unlimited).
558
572
  * This option has no effect for simulcast and audio tracks.
559
573
  * For simulcast tracks use `{@link WebRTCEndpoint.setTrackBandwidth}.
560
574
  * @returns {string} Returns id of added track
@@ -569,7 +583,7 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
569
583
  * .getTracks()
570
584
  * .forEach((track) => localStream.addTrack(track));
571
585
  * } catch (error) {
572
- * console.error("Couldn't get microphone permission:", error);
586
+ * this.logger.error("Couldn't get microphone permission:", error);
573
587
  * }
574
588
  *
575
589
  * try {
@@ -580,7 +594,7 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
580
594
  * .getTracks()
581
595
  * .forEach((track) => localStream.addTrack(track));
582
596
  * } catch (error) {
583
- * console.error("Couldn't get camera permission:", error);
597
+ * this.logger.error("Couldn't get camera permission:", error);
584
598
  * }
585
599
  *
586
600
  * localStream
@@ -588,7 +602,7 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
588
602
  * .forEach((track) => webrtc.addTrack(track, localStream));
589
603
  * ```
590
604
  */
591
- addTrack(track: MediaStreamTrack, trackMetadata?: unknown, simulcastConfig?: MediaEvent_Track_SimulcastConfig, maxBandwidth?: TrackBandwidthLimit): Promise<string>;
605
+ addTrack(track: MediaStreamTrack, trackMetadata?: unknown, _simulcastConfig?: MediaEvent_Track_SimulcastConfig, _maxBandwidth?: TrackBandwidthLimit): Promise<string>;
592
606
  /**
593
607
  * Replaces a track that is being sent to the RTC Engine.
594
608
  * @param trackId - Audio or video track.
@@ -607,7 +621,7 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
607
621
  * .getTracks()
608
622
  * .forEach((track) => localStream.addTrack(track));
609
623
  * } catch (error) {
610
- * console.error("Couldn't get camera permission:", error);
624
+ * this.logger.error("Couldn't get camera permission:", error);
611
625
  * }
612
626
  * let oldTrackId;
613
627
  * localStream
@@ -630,7 +644,7 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
630
644
  * webrtc.replaceTrack(oldTrackId, videoTrack);
631
645
  * })
632
646
  * .catch((error) => {
633
- * console.error('Error switching camera', error);
647
+ * this.logger.error('Error switching camera', error);
634
648
  * })
635
649
  * ```
636
650
  */
@@ -669,7 +683,7 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
669
683
  * .getTracks()
670
684
  * .forEach((track) => localStream.addTrack(track));
671
685
  * } catch (error) {
672
- * console.error("Couldn't get camera permission:", error);
686
+ * this.logger.error("Couldn't get camera permission:", error);
673
687
  * }
674
688
  *
675
689
  * let trackId
@@ -763,4 +777,4 @@ declare class WebRTCEndpoint extends WebRTCEndpoint_base {
763
777
  private onIceConnectionStateChange;
764
778
  }
765
779
 
766
- export { type BandwidthLimit, type EncodingReason, type Endpoint, 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 };
780
+ export { type BandwidthLimit, 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 };
package/dist/index.mjs CHANGED
@@ -1,3 +1,14 @@
1
+ // src/logger.ts
2
+ var FISHJAM_PREFIX = "[FISHJAM]";
3
+ var getLogger = (enableLogging) => ({
4
+ warn: (arg, ...args) => {
5
+ if (enableLogging) console.warn(FISHJAM_PREFIX, arg, ...args);
6
+ },
7
+ error: (arg, ...args) => {
8
+ if (enableLogging) console.error(FISHJAM_PREFIX, arg, ...args);
9
+ }
10
+ });
11
+
1
12
  // ../protobufs/fishjam/media_events/peer/peer.ts
2
13
  import { BinaryReader as BinaryReader2, BinaryWriter as BinaryWriter2 } from "@bufbuild/protobuf/wire";
3
14
 
@@ -4417,11 +4428,13 @@ var WebRTCEndpoint = class extends EventEmitter2 {
4417
4428
  local;
4418
4429
  commandsQueue;
4419
4430
  proposedIceServers = [];
4431
+ logger;
4420
4432
  bandwidthEstimation = BigInt(0);
4421
4433
  connectionManager;
4422
4434
  clearConnectionCallbacks = null;
4423
- constructor() {
4435
+ constructor(props = {}) {
4424
4436
  super();
4437
+ this.logger = getLogger(!!props.debug);
4425
4438
  const sendEvent = (mediaEvent) => this.sendMediaEvent(mediaEvent);
4426
4439
  const emit = (events, ...args) => {
4427
4440
  this.emit(events, ...args);
@@ -4575,7 +4588,7 @@ var WebRTCEndpoint = class extends EventEmitter2 {
4575
4588
  const { trackId, status } = event.vadNotification;
4576
4589
  this.remote.setRemoteTrackVadStatus(trackId, status);
4577
4590
  } else if (event.error) {
4578
- console.warn("signaling error", {
4591
+ this.logger.warn("signaling error", {
4579
4592
  message: event.error.message
4580
4593
  });
4581
4594
  this.emit("signalingError", {
@@ -4618,7 +4631,7 @@ var WebRTCEndpoint = class extends EventEmitter2 {
4618
4631
  try {
4619
4632
  await this.connectionManager.setRemoteDescription({ sdp: data.sdp, type: "answer" });
4620
4633
  } catch (err) {
4621
- console.error(err);
4634
+ this.logger.error(err);
4622
4635
  }
4623
4636
  };
4624
4637
  /**
@@ -4627,10 +4640,11 @@ var WebRTCEndpoint = class extends EventEmitter2 {
4627
4640
  * @param trackMetadata - Any information about this track that other endpoints will
4628
4641
  * receive in {@link WebRTCEndpointEvents.endpointAdded}. E.g. this can source of the track - whether it's
4629
4642
  * screensharing, webcam or some other media device.
4630
- * @param simulcastConfig - Simulcast configuration. By default simulcast is disabled.
4631
- * For more information refer to {@link SimulcastConfig}.
4632
- * @param maxBandwidth - maximal bandwidth this track can use.
4633
- * Defaults to 0 which is unlimited.
4643
+ * @param _simulcastConfig - Simulcast configuration parameter. **Currently ignored** - simulcast is disabled
4644
+ * regardless of the value passed. This is a temporary change until bandwidth estimation is implemented or
4645
+ * manual track selection support is added. For more information refer to {@link SimulcastConfig}.
4646
+ * @param _maxBandwidth - maximal bandwidth this track can use. **Currently processed with a threshold check**:
4647
+ * if the value is a positive number, it will be used; otherwise, it defaults to 0 (unlimited).
4634
4648
  * This option has no effect for simulcast and audio tracks.
4635
4649
  * For simulcast tracks use `{@link WebRTCEndpoint.setTrackBandwidth}.
4636
4650
  * @returns {string} Returns id of added track
@@ -4645,7 +4659,7 @@ var WebRTCEndpoint = class extends EventEmitter2 {
4645
4659
  * .getTracks()
4646
4660
  * .forEach((track) => localStream.addTrack(track));
4647
4661
  * } catch (error) {
4648
- * console.error("Couldn't get microphone permission:", error);
4662
+ * this.logger.error("Couldn't get microphone permission:", error);
4649
4663
  * }
4650
4664
  *
4651
4665
  * try {
@@ -4656,7 +4670,7 @@ var WebRTCEndpoint = class extends EventEmitter2 {
4656
4670
  * .getTracks()
4657
4671
  * .forEach((track) => localStream.addTrack(track));
4658
4672
  * } catch (error) {
4659
- * console.error("Couldn't get camera permission:", error);
4673
+ * this.logger.error("Couldn't get camera permission:", error);
4660
4674
  * }
4661
4675
  *
4662
4676
  * localStream
@@ -4664,14 +4678,20 @@ var WebRTCEndpoint = class extends EventEmitter2 {
4664
4678
  * .forEach((track) => webrtc.addTrack(track, localStream));
4665
4679
  * ```
4666
4680
  */
4667
- async addTrack(track, trackMetadata, simulcastConfig = {
4681
+ async addTrack(track, trackMetadata, _simulcastConfig = {
4668
4682
  enabled: false,
4669
4683
  enabledVariants: [],
4670
4684
  disabledVariants: []
4671
- }, maxBandwidth = 0) {
4685
+ }, _maxBandwidth = 0) {
4672
4686
  const resolutionNotifier = new Deferred();
4673
4687
  const trackId = this.getTrackId(uuidv4());
4674
4688
  const stream = new MediaStream();
4689
+ const simulcastConfig = {
4690
+ enabled: false,
4691
+ enabledVariants: [],
4692
+ disabledVariants: []
4693
+ };
4694
+ const maxBandwidth = typeof _maxBandwidth === "number" && _maxBandwidth > 0 ? _maxBandwidth : 0;
4675
4695
  try {
4676
4696
  stream.addTrack(track);
4677
4697
  this.commandsQueue.pushCommand({
@@ -4712,7 +4732,7 @@ var WebRTCEndpoint = class extends EventEmitter2 {
4712
4732
  * .getTracks()
4713
4733
  * .forEach((track) => localStream.addTrack(track));
4714
4734
  * } catch (error) {
4715
- * console.error("Couldn't get camera permission:", error);
4735
+ * this.logger.error("Couldn't get camera permission:", error);
4716
4736
  * }
4717
4737
  * let oldTrackId;
4718
4738
  * localStream
@@ -4735,7 +4755,7 @@ var WebRTCEndpoint = class extends EventEmitter2 {
4735
4755
  * webrtc.replaceTrack(oldTrackId, videoTrack);
4736
4756
  * })
4737
4757
  * .catch((error) => {
4738
- * console.error('Error switching camera', error);
4758
+ * this.logger.error('Error switching camera', error);
4739
4759
  * })
4740
4760
  * ```
4741
4761
  */
@@ -4790,7 +4810,7 @@ var WebRTCEndpoint = class extends EventEmitter2 {
4790
4810
  * .getTracks()
4791
4811
  * .forEach((track) => localStream.addTrack(track));
4792
4812
  * } catch (error) {
4793
- * console.error("Couldn't get camera permission:", error);
4813
+ * this.logger.error("Couldn't get camera permission:", error);
4794
4814
  * }
4795
4815
  *
4796
4816
  * let trackId
@@ -4918,19 +4938,19 @@ var WebRTCEndpoint = class extends EventEmitter2 {
4918
4938
  this.localTrackManager.updateSenders();
4919
4939
  const offer = await connection.getConnection().createOffer();
4920
4940
  if (!this.connectionManager) {
4921
- console.warn("RTCPeerConnection stopped or restarted");
4941
+ this.logger.warn("RTCPeerConnection stopped or restarted");
4922
4942
  return;
4923
4943
  }
4924
4944
  await connection.getConnection().setLocalDescription(offer);
4925
4945
  if (!this.connectionManager) {
4926
- console.warn("RTCPeerConnection stopped or restarted");
4946
+ this.logger.warn("RTCPeerConnection stopped or restarted");
4927
4947
  return;
4928
4948
  }
4929
4949
  const sdpOffer = this.local.createSdpOfferEvent(offer);
4930
4950
  this.sendMediaEvent({ sdpOffer });
4931
4951
  this.local.setLocalTrackStatusToOffered();
4932
4952
  } catch (error) {
4933
- console.error(error);
4953
+ this.logger.error(error);
4934
4954
  }
4935
4955
  }
4936
4956
  onOfferData = async (offerData) => {
@@ -4974,7 +4994,7 @@ var WebRTCEndpoint = class extends EventEmitter2 {
4974
4994
  }
4975
4995
  await this.connectionManager.addIceCandidate(iceCandidate);
4976
4996
  } catch (error) {
4977
- console.error(error);
4997
+ this.logger.error(error);
4978
4998
  }
4979
4999
  };
4980
5000
  onLocalCandidate = (event) => {
@@ -4988,7 +5008,7 @@ var WebRTCEndpoint = class extends EventEmitter2 {
4988
5008
  this.sendMediaEvent({ candidate });
4989
5009
  };
4990
5010
  onIceCandidateError = (event) => {
4991
- console.warn(event);
5011
+ this.logger.warn(event);
4992
5012
  };
4993
5013
  onConnectionStateChange = (event) => {
4994
5014
  switch (this.localTrackManager.connection?.getConnection().connectionState) {
@@ -5003,7 +5023,7 @@ var WebRTCEndpoint = class extends EventEmitter2 {
5003
5023
  onIceConnectionStateChange = (event) => {
5004
5024
  switch (this.localTrackManager.connection?.getConnection().iceConnectionState) {
5005
5025
  case "disconnected":
5006
- console.warn("ICE connection: disconnected");
5026
+ this.logger.warn("ICE connection: disconnected");
5007
5027
  this.sendMediaEvent({ renegotiateTracks: MediaEvent_RenegotiateTracks.create() });
5008
5028
  break;
5009
5029
  case "failed":
@@ -5018,5 +5038,6 @@ var WebRTCEndpoint = class extends EventEmitter2 {
5018
5038
  export {
5019
5039
  MediaEvent_Track_SimulcastConfig as SimulcastConfig,
5020
5040
  Variant,
5021
- WebRTCEndpoint
5041
+ WebRTCEndpoint,
5042
+ getLogger
5022
5043
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fishjam-cloud/webrtc-client",
3
- "version": "0.23.0",
3
+ "version": "0.25.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",
@@ -70,10 +70,11 @@
70
70
  },
71
71
  "lint-staged": {
72
72
  "*": [
73
- "yarn format:check"
73
+ "yarn format"
74
74
  ],
75
75
  "*.(js|ts|tsx)": [
76
- "yarn lint:check"
76
+ "yarn lint"
77
77
  ]
78
- }
78
+ },
79
+ "stableVersion": "0.24.0"
79
80
  }