@fishjam-cloud/js-server-sdk 0.22.0 → 0.22.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
@@ -643,6 +643,10 @@ type FishjamConfig = {
643
643
  };
644
644
  type ErrorEventHandler = (msg: Event) => void;
645
645
  type CloseEventHandler = (code: number, reason: string) => void;
646
+ type AgentCallbacks = {
647
+ onError?: ErrorEventHandler;
648
+ onClose?: CloseEventHandler;
649
+ };
646
650
 
647
651
  type WithRoomId<T> = {
648
652
  [P in keyof T]: NonNullable<T[P]> extends {
@@ -713,7 +717,9 @@ type IncomingTrackData = Omit<NonNullable<AgentResponse_TrackData>, 'peerId'> &
713
717
  type OutgoingTrackData = Omit<NonNullable<AgentRequest_TrackData>, 'peerId'> & {
714
718
  peerId: PeerId;
715
719
  };
716
- type AgentTrack = Track;
720
+ type AgentTrack = Omit<Track, 'id'> & {
721
+ id: TrackId;
722
+ };
717
723
  type TrackType = 'audio' | 'video';
718
724
  type AudioCodecParameters = {
719
725
  encoding: 'opus' | 'pcm16';
@@ -731,12 +737,21 @@ type AgentEvents = {
731
737
  declare const FishjamAgent_base: new () => TypedEventEmitter<AgentEvents>;
732
738
  declare class FishjamAgent extends FishjamAgent_base {
733
739
  private readonly client;
734
- constructor(config: FishjamConfig, agentToken: string, onError: ErrorEventHandler, onClose: CloseEventHandler);
740
+ constructor(config: FishjamConfig, agentToken: string, callbacks?: AgentCallbacks);
735
741
  /**
736
742
  * Creates an outgoing audio track for the agent
737
743
  * @returns a new audio track
738
744
  */
739
745
  createTrack(codecParameters: AudioCodecParameters, metadata?: object): AgentTrack;
746
+ /**
747
+ * Interrupt track indentified by `trackId`.
748
+ *
749
+ * Any audio that has been sent by the agent, but not played
750
+ * by Fishjam will be cleared and be prevented from playing.
751
+ *
752
+ * Audio sent after the interrupt will be played normally.
753
+ */
754
+ interruptTrack(trackId: TrackId): void;
740
755
  /**
741
756
  * Deletes an outgoing audio track for the agent
742
757
  */
@@ -745,6 +760,7 @@ declare class FishjamAgent extends FishjamAgent_base {
745
760
  * Send audio data for the given track
746
761
  */
747
762
  sendData(trackId: TrackId, data: Uint8Array): void;
763
+ disconnect(): void;
748
764
  private dispatchNotification;
749
765
  private setupConnection;
750
766
  private isExpectedEvent;
@@ -787,14 +803,14 @@ declare class FishjamClient {
787
803
  /**
788
804
  * Create a new peer assigned to a room.
789
805
  */
790
- createPeer(roomId: RoomId, options?: PeerOptions): Promise<{
806
+ createPeer(roomId: RoomId, options?: PeerOptionsWebRTC): Promise<{
791
807
  peer: Peer;
792
808
  peerToken: string;
793
809
  }>;
794
810
  /**
795
811
  * Create a new agent assigned to a room.
796
812
  */
797
- createAgent(roomId: RoomId, options: PeerOptions | undefined, onError: ErrorEventHandler, onClose: CloseEventHandler): Promise<{
813
+ createAgent(roomId: RoomId, options?: PeerOptionsAgent, callbacks?: AgentCallbacks): Promise<{
798
814
  agent: FishjamAgent;
799
815
  peer: Peer;
800
816
  }>;
@@ -860,4 +876,4 @@ declare class ServiceUnavailableException extends FishjamBaseException {
860
876
  declare class UnknownException extends FishjamBaseException {
861
877
  }
862
878
 
863
- export { type AgentEvents, type AgentTrack, type AudioCodecParameters, BadRequestException, type Brand, type CloseEventHandler, type ErrorEventHandler, type ExpectedAgentEvents, type ExpectedEvents, FishjamAgent, FishjamBaseException, FishjamClient, type FishjamConfig, FishjamNotFoundException, FishjamWSNotifier, ForbiddenException, type IncomingTrackData, MissingFishjamIdException, type NotificationEvents, type OutgoingTrackData, type Peer, type PeerAdded, type PeerConnected, type PeerCrashed, type PeerDeleted, type PeerDisconnected, type PeerId, type PeerMetadataUpdated, PeerNotFoundException, type PeerOptions, PeerStatus, type Room, type RoomConfig, RoomConfigRoomTypeEnum, RoomConfigVideoCodecEnum, type RoomCrashed, type RoomCreated, type RoomDeleted, type RoomId, RoomNotFoundException, ServerMessage, ServiceUnavailableException, type StreamConnected, type StreamDisconnected, type StreamerToken, type TrackAdded, type TrackId, type TrackMetadataUpdated, type TrackRemoved, type TrackType, UnauthorizedException, UnknownException, type ViewerConnected, type ViewerDisconnected, type ViewerToken };
879
+ export { type AgentCallbacks, type AgentEvents, type AgentTrack, type AudioCodecParameters, BadRequestException, type Brand, type CloseEventHandler, type ErrorEventHandler, type ExpectedAgentEvents, type ExpectedEvents, FishjamAgent, FishjamBaseException, FishjamClient, type FishjamConfig, FishjamNotFoundException, FishjamWSNotifier, ForbiddenException, type IncomingTrackData, MissingFishjamIdException, type NotificationEvents, type OutgoingTrackData, type Peer, type PeerAdded, type PeerConnected, type PeerCrashed, type PeerDeleted, type PeerDisconnected, type PeerId, type PeerMetadataUpdated, PeerNotFoundException, type PeerOptions, PeerStatus, type Room, type RoomConfig, RoomConfigRoomTypeEnum, RoomConfigVideoCodecEnum, type RoomCrashed, type RoomCreated, type RoomDeleted, type RoomId, RoomNotFoundException, ServerMessage, ServiceUnavailableException, type StreamConnected, type StreamDisconnected, type StreamerToken, type TrackAdded, type TrackId, type TrackMetadataUpdated, type TrackRemoved, type TrackType, UnauthorizedException, UnknownException, type ViewerConnected, type ViewerDisconnected, type ViewerToken };
package/dist/index.d.ts CHANGED
@@ -643,6 +643,10 @@ type FishjamConfig = {
643
643
  };
644
644
  type ErrorEventHandler = (msg: Event) => void;
645
645
  type CloseEventHandler = (code: number, reason: string) => void;
646
+ type AgentCallbacks = {
647
+ onError?: ErrorEventHandler;
648
+ onClose?: CloseEventHandler;
649
+ };
646
650
 
647
651
  type WithRoomId<T> = {
648
652
  [P in keyof T]: NonNullable<T[P]> extends {
@@ -713,7 +717,9 @@ type IncomingTrackData = Omit<NonNullable<AgentResponse_TrackData>, 'peerId'> &
713
717
  type OutgoingTrackData = Omit<NonNullable<AgentRequest_TrackData>, 'peerId'> & {
714
718
  peerId: PeerId;
715
719
  };
716
- type AgentTrack = Track;
720
+ type AgentTrack = Omit<Track, 'id'> & {
721
+ id: TrackId;
722
+ };
717
723
  type TrackType = 'audio' | 'video';
718
724
  type AudioCodecParameters = {
719
725
  encoding: 'opus' | 'pcm16';
@@ -731,12 +737,21 @@ type AgentEvents = {
731
737
  declare const FishjamAgent_base: new () => TypedEventEmitter<AgentEvents>;
732
738
  declare class FishjamAgent extends FishjamAgent_base {
733
739
  private readonly client;
734
- constructor(config: FishjamConfig, agentToken: string, onError: ErrorEventHandler, onClose: CloseEventHandler);
740
+ constructor(config: FishjamConfig, agentToken: string, callbacks?: AgentCallbacks);
735
741
  /**
736
742
  * Creates an outgoing audio track for the agent
737
743
  * @returns a new audio track
738
744
  */
739
745
  createTrack(codecParameters: AudioCodecParameters, metadata?: object): AgentTrack;
746
+ /**
747
+ * Interrupt track indentified by `trackId`.
748
+ *
749
+ * Any audio that has been sent by the agent, but not played
750
+ * by Fishjam will be cleared and be prevented from playing.
751
+ *
752
+ * Audio sent after the interrupt will be played normally.
753
+ */
754
+ interruptTrack(trackId: TrackId): void;
740
755
  /**
741
756
  * Deletes an outgoing audio track for the agent
742
757
  */
@@ -745,6 +760,7 @@ declare class FishjamAgent extends FishjamAgent_base {
745
760
  * Send audio data for the given track
746
761
  */
747
762
  sendData(trackId: TrackId, data: Uint8Array): void;
763
+ disconnect(): void;
748
764
  private dispatchNotification;
749
765
  private setupConnection;
750
766
  private isExpectedEvent;
@@ -787,14 +803,14 @@ declare class FishjamClient {
787
803
  /**
788
804
  * Create a new peer assigned to a room.
789
805
  */
790
- createPeer(roomId: RoomId, options?: PeerOptions): Promise<{
806
+ createPeer(roomId: RoomId, options?: PeerOptionsWebRTC): Promise<{
791
807
  peer: Peer;
792
808
  peerToken: string;
793
809
  }>;
794
810
  /**
795
811
  * Create a new agent assigned to a room.
796
812
  */
797
- createAgent(roomId: RoomId, options: PeerOptions | undefined, onError: ErrorEventHandler, onClose: CloseEventHandler): Promise<{
813
+ createAgent(roomId: RoomId, options?: PeerOptionsAgent, callbacks?: AgentCallbacks): Promise<{
798
814
  agent: FishjamAgent;
799
815
  peer: Peer;
800
816
  }>;
@@ -860,4 +876,4 @@ declare class ServiceUnavailableException extends FishjamBaseException {
860
876
  declare class UnknownException extends FishjamBaseException {
861
877
  }
862
878
 
863
- export { type AgentEvents, type AgentTrack, type AudioCodecParameters, BadRequestException, type Brand, type CloseEventHandler, type ErrorEventHandler, type ExpectedAgentEvents, type ExpectedEvents, FishjamAgent, FishjamBaseException, FishjamClient, type FishjamConfig, FishjamNotFoundException, FishjamWSNotifier, ForbiddenException, type IncomingTrackData, MissingFishjamIdException, type NotificationEvents, type OutgoingTrackData, type Peer, type PeerAdded, type PeerConnected, type PeerCrashed, type PeerDeleted, type PeerDisconnected, type PeerId, type PeerMetadataUpdated, PeerNotFoundException, type PeerOptions, PeerStatus, type Room, type RoomConfig, RoomConfigRoomTypeEnum, RoomConfigVideoCodecEnum, type RoomCrashed, type RoomCreated, type RoomDeleted, type RoomId, RoomNotFoundException, ServerMessage, ServiceUnavailableException, type StreamConnected, type StreamDisconnected, type StreamerToken, type TrackAdded, type TrackId, type TrackMetadataUpdated, type TrackRemoved, type TrackType, UnauthorizedException, UnknownException, type ViewerConnected, type ViewerDisconnected, type ViewerToken };
879
+ export { type AgentCallbacks, type AgentEvents, type AgentTrack, type AudioCodecParameters, BadRequestException, type Brand, type CloseEventHandler, type ErrorEventHandler, type ExpectedAgentEvents, type ExpectedEvents, FishjamAgent, FishjamBaseException, FishjamClient, type FishjamConfig, FishjamNotFoundException, FishjamWSNotifier, ForbiddenException, type IncomingTrackData, MissingFishjamIdException, type NotificationEvents, type OutgoingTrackData, type Peer, type PeerAdded, type PeerConnected, type PeerCrashed, type PeerDeleted, type PeerDisconnected, type PeerId, type PeerMetadataUpdated, PeerNotFoundException, type PeerOptions, PeerStatus, type Room, type RoomConfig, RoomConfigRoomTypeEnum, RoomConfigVideoCodecEnum, type RoomCrashed, type RoomCreated, type RoomDeleted, type RoomId, RoomNotFoundException, ServerMessage, ServiceUnavailableException, type StreamConnected, type StreamDisconnected, type StreamerToken, type TrackAdded, type TrackId, type TrackMetadataUpdated, type TrackRemoved, type TrackType, UnauthorizedException, UnknownException, type ViewerConnected, type ViewerDisconnected, type ViewerToken };
package/dist/index.js CHANGED
@@ -19519,6 +19519,7 @@ var FishjamWSNotifier = class extends import_events.EventEmitter {
19519
19519
  const fishjamUrl = getFishjamUrl(config);
19520
19520
  const websocketUrl = `${httpToWebsocket(fishjamUrl)}/socket/server/websocket`;
19521
19521
  this.client = new WebSocket(websocketUrl);
19522
+ this.client.binaryType = "arraybuffer";
19522
19523
  this.client.onerror = (message) => onError(message);
19523
19524
  this.client.onclose = (message) => onClose(message.code, message.reason);
19524
19525
  this.client.onmessage = (message) => this.dispatchNotification(message);
@@ -19526,7 +19527,8 @@ var FishjamWSNotifier = class extends import_events.EventEmitter {
19526
19527
  }
19527
19528
  dispatchNotification(message) {
19528
19529
  try {
19529
- const decodedMessage = import_fishjam_proto.ServerMessage.decode(message.data);
19530
+ const data = new Uint8Array(message.data);
19531
+ const decodedMessage = import_fishjam_proto.ServerMessage.decode(data);
19530
19532
  const [notification, msg] = Object.entries(decodedMessage).find(([_k, v]) => v);
19531
19533
  if (!this.isExpectedEvent(notification)) return;
19532
19534
  this.emit(notification, msg);
@@ -19554,14 +19556,14 @@ var import_fishjam_proto2 = __toESM(require_dist2());
19554
19556
  var expectedEventsList2 = ["trackData"];
19555
19557
  var FishjamAgent = class extends import_events2.EventEmitter {
19556
19558
  client;
19557
- constructor(config, agentToken, onError, onClose) {
19559
+ constructor(config, agentToken, callbacks) {
19558
19560
  super();
19559
19561
  const fishjamUrl = getFishjamUrl(config);
19560
19562
  const websocketUrl = `${httpToWebsocket(fishjamUrl)}/socket/agent/websocket`;
19561
19563
  this.client = new WebSocket(websocketUrl);
19562
19564
  this.client.binaryType = "arraybuffer";
19563
- this.client.onerror = (message) => onError(message);
19564
- this.client.onclose = (message) => onClose(message.code, message.reason);
19565
+ this.client.onclose = (message) => callbacks?.onClose?.(message.code, message.reason);
19566
+ this.client.onerror = (message) => callbacks?.onError?.(message);
19565
19567
  this.client.onmessage = (message) => this.dispatchNotification(message);
19566
19568
  this.client.onopen = () => this.setupConnection(agentToken);
19567
19569
  }
@@ -19580,6 +19582,18 @@ var FishjamAgent = class extends import_events2.EventEmitter {
19580
19582
  this.client.send(addTrack);
19581
19583
  return track;
19582
19584
  }
19585
+ /**
19586
+ * Interrupt track indentified by `trackId`.
19587
+ *
19588
+ * Any audio that has been sent by the agent, but not played
19589
+ * by Fishjam will be cleared and be prevented from playing.
19590
+ *
19591
+ * Audio sent after the interrupt will be played normally.
19592
+ */
19593
+ interruptTrack(trackId) {
19594
+ const msg = import_fishjam_proto2.AgentRequest.encode({ interruptTrack: { trackId } }).finish();
19595
+ this.client.send(msg);
19596
+ }
19583
19597
  /**
19584
19598
  * Deletes an outgoing audio track for the agent
19585
19599
  */
@@ -19594,6 +19608,9 @@ var FishjamAgent = class extends import_events2.EventEmitter {
19594
19608
  const trackData = import_fishjam_proto2.AgentRequest.encode({ trackData: { trackId, data } }).finish();
19595
19609
  this.client.send(trackData);
19596
19610
  }
19611
+ disconnect() {
19612
+ this.client.close();
19613
+ }
19597
19614
  dispatchNotification(message) {
19598
19615
  try {
19599
19616
  const data = new Uint8Array(message.data);
@@ -19738,7 +19755,7 @@ var FishjamClient = class {
19738
19755
  /**
19739
19756
  * Create a new agent assigned to a room.
19740
19757
  */
19741
- async createAgent(roomId, options = {}, onError, onClose) {
19758
+ async createAgent(roomId, options = {}, callbacks) {
19742
19759
  try {
19743
19760
  const response = await this.roomApi.addPeer(roomId, {
19744
19761
  type: "agent",
@@ -19747,7 +19764,7 @@ var FishjamClient = class {
19747
19764
  const {
19748
19765
  data: { data }
19749
19766
  } = response;
19750
- const agent = new FishjamAgent(this.fishjamConfig, data.token, onError, onClose);
19767
+ const agent = new FishjamAgent(this.fishjamConfig, data.token, callbacks);
19751
19768
  return { agent, peer: data.peer };
19752
19769
  } catch (error) {
19753
19770
  throw mapException(error);
package/dist/index.mjs CHANGED
@@ -19494,6 +19494,7 @@ var FishjamWSNotifier = class extends EventEmitter {
19494
19494
  const fishjamUrl = getFishjamUrl(config);
19495
19495
  const websocketUrl = `${httpToWebsocket(fishjamUrl)}/socket/server/websocket`;
19496
19496
  this.client = new WebSocket(websocketUrl);
19497
+ this.client.binaryType = "arraybuffer";
19497
19498
  this.client.onerror = (message) => onError(message);
19498
19499
  this.client.onclose = (message) => onClose(message.code, message.reason);
19499
19500
  this.client.onmessage = (message) => this.dispatchNotification(message);
@@ -19501,7 +19502,8 @@ var FishjamWSNotifier = class extends EventEmitter {
19501
19502
  }
19502
19503
  dispatchNotification(message) {
19503
19504
  try {
19504
- const decodedMessage = import_fishjam_proto.ServerMessage.decode(message.data);
19505
+ const data = new Uint8Array(message.data);
19506
+ const decodedMessage = import_fishjam_proto.ServerMessage.decode(data);
19505
19507
  const [notification, msg] = Object.entries(decodedMessage).find(([_k, v]) => v);
19506
19508
  if (!this.isExpectedEvent(notification)) return;
19507
19509
  this.emit(notification, msg);
@@ -19529,14 +19531,14 @@ import { v4 as uuid4 } from "uuid";
19529
19531
  var expectedEventsList2 = ["trackData"];
19530
19532
  var FishjamAgent = class extends EventEmitter2 {
19531
19533
  client;
19532
- constructor(config, agentToken, onError, onClose) {
19534
+ constructor(config, agentToken, callbacks) {
19533
19535
  super();
19534
19536
  const fishjamUrl = getFishjamUrl(config);
19535
19537
  const websocketUrl = `${httpToWebsocket(fishjamUrl)}/socket/agent/websocket`;
19536
19538
  this.client = new WebSocket(websocketUrl);
19537
19539
  this.client.binaryType = "arraybuffer";
19538
- this.client.onerror = (message) => onError(message);
19539
- this.client.onclose = (message) => onClose(message.code, message.reason);
19540
+ this.client.onclose = (message) => callbacks?.onClose?.(message.code, message.reason);
19541
+ this.client.onerror = (message) => callbacks?.onError?.(message);
19540
19542
  this.client.onmessage = (message) => this.dispatchNotification(message);
19541
19543
  this.client.onopen = () => this.setupConnection(agentToken);
19542
19544
  }
@@ -19555,6 +19557,18 @@ var FishjamAgent = class extends EventEmitter2 {
19555
19557
  this.client.send(addTrack);
19556
19558
  return track;
19557
19559
  }
19560
+ /**
19561
+ * Interrupt track indentified by `trackId`.
19562
+ *
19563
+ * Any audio that has been sent by the agent, but not played
19564
+ * by Fishjam will be cleared and be prevented from playing.
19565
+ *
19566
+ * Audio sent after the interrupt will be played normally.
19567
+ */
19568
+ interruptTrack(trackId) {
19569
+ const msg = import_fishjam_proto2.AgentRequest.encode({ interruptTrack: { trackId } }).finish();
19570
+ this.client.send(msg);
19571
+ }
19558
19572
  /**
19559
19573
  * Deletes an outgoing audio track for the agent
19560
19574
  */
@@ -19569,6 +19583,9 @@ var FishjamAgent = class extends EventEmitter2 {
19569
19583
  const trackData = import_fishjam_proto2.AgentRequest.encode({ trackData: { trackId, data } }).finish();
19570
19584
  this.client.send(trackData);
19571
19585
  }
19586
+ disconnect() {
19587
+ this.client.close();
19588
+ }
19572
19589
  dispatchNotification(message) {
19573
19590
  try {
19574
19591
  const data = new Uint8Array(message.data);
@@ -19713,7 +19730,7 @@ var FishjamClient = class {
19713
19730
  /**
19714
19731
  * Create a new agent assigned to a room.
19715
19732
  */
19716
- async createAgent(roomId, options = {}, onError, onClose) {
19733
+ async createAgent(roomId, options = {}, callbacks) {
19717
19734
  try {
19718
19735
  const response = await this.roomApi.addPeer(roomId, {
19719
19736
  type: "agent",
@@ -19722,7 +19739,7 @@ var FishjamClient = class {
19722
19739
  const {
19723
19740
  data: { data }
19724
19741
  } = response;
19725
- const agent = new FishjamAgent(this.fishjamConfig, data.token, onError, onClose);
19742
+ const agent = new FishjamAgent(this.fishjamConfig, data.token, callbacks);
19726
19743
  return { agent, peer: data.peer };
19727
19744
  } catch (error) {
19728
19745
  throw mapException(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fishjam-cloud/js-server-sdk",
3
- "version": "0.22.0",
3
+ "version": "0.22.1",
4
4
  "description": "Fishjam server SDK for JavaScript",
5
5
  "homepage": "https://github.com/fishjam-cloud/js-server-sdk",
6
6
  "author": "Fishjam Team",
@@ -55,8 +55,8 @@
55
55
  "uuid": "^11.1.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@fishjam-cloud/fishjam-openapi": "0.22.0",
59
- "@fishjam-cloud/fishjam-proto": "0.22.0",
58
+ "@fishjam-cloud/fishjam-openapi": "0.22.1",
59
+ "@fishjam-cloud/fishjam-proto": "0.22.1",
60
60
  "@openapitools/openapi-generator-cli": "^2.18.4",
61
61
  "@types/node": "^22.13.16",
62
62
  "@types/websocket": "^1.0.10",