@fishjam-cloud/js-server-sdk 0.25.3 → 0.25.5

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.
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var package_default = {
3
3
  name: "@fishjam-cloud/js-server-sdk",
4
- version: "0.25.3",
4
+ version: "0.25.5",
5
5
  description: "Fishjam server SDK for JavaScript",
6
6
  homepage: "https://github.com/fishjam-cloud/js-server-sdk",
7
7
  author: "Fishjam Team",
package/dist/index.d.mts CHANGED
@@ -759,7 +759,7 @@ declare class FishjamWSNotifier extends FishjamWSNotifier_base {
759
759
  private isExpectedEvent;
760
760
  }
761
761
 
762
- declare const expectedEventsList: readonly ["trackData", "trackImage"];
762
+ declare const expectedEventsList: readonly ["trackData"];
763
763
  /**
764
764
  * @useDeclaredType
765
765
  */
@@ -793,6 +793,7 @@ declare class FishjamAgent extends FishjamAgent_base {
793
793
  private readonly client;
794
794
  private resolveConnectionPromise;
795
795
  private readonly connectionPromise;
796
+ private readonly pendingImageCaptures;
796
797
  constructor(config: FishjamConfig, agentToken: string, callbacks?: AgentCallbacks);
797
798
  /**
798
799
  * Await Agent connection to Fishjam.
@@ -822,9 +823,14 @@ declare class FishjamAgent extends FishjamAgent_base {
822
823
  sendData(trackId: TrackId, data: Uint8Array): void;
823
824
  /**
824
825
  * Request a captured image from the given track
826
+ * @param trackId - the track to capture an image from
827
+ * @param timeoutMs - timeout in milliseconds (default: 5000)
828
+ * @returns a promise that resolves with the captured image data
825
829
  */
826
- captureImage(trackId: TrackId): void;
830
+ captureImage(trackId: string, timeoutMs?: number): Promise<IncomingTrackImage>;
827
831
  disconnect(): void;
832
+ private handleTrackImageMessage;
833
+ private rejectPendingCaptures;
828
834
  private dispatchNotification;
829
835
  private setupConnection;
830
836
  private isExpectedEvent;
package/dist/index.d.ts CHANGED
@@ -759,7 +759,7 @@ declare class FishjamWSNotifier extends FishjamWSNotifier_base {
759
759
  private isExpectedEvent;
760
760
  }
761
761
 
762
- declare const expectedEventsList: readonly ["trackData", "trackImage"];
762
+ declare const expectedEventsList: readonly ["trackData"];
763
763
  /**
764
764
  * @useDeclaredType
765
765
  */
@@ -793,6 +793,7 @@ declare class FishjamAgent extends FishjamAgent_base {
793
793
  private readonly client;
794
794
  private resolveConnectionPromise;
795
795
  private readonly connectionPromise;
796
+ private readonly pendingImageCaptures;
796
797
  constructor(config: FishjamConfig, agentToken: string, callbacks?: AgentCallbacks);
797
798
  /**
798
799
  * Await Agent connection to Fishjam.
@@ -822,9 +823,14 @@ declare class FishjamAgent extends FishjamAgent_base {
822
823
  sendData(trackId: TrackId, data: Uint8Array): void;
823
824
  /**
824
825
  * Request a captured image from the given track
826
+ * @param trackId - the track to capture an image from
827
+ * @param timeoutMs - timeout in milliseconds (default: 5000)
828
+ * @returns a promise that resolves with the captured image data
825
829
  */
826
- captureImage(trackId: TrackId): void;
830
+ captureImage(trackId: string, timeoutMs?: number): Promise<IncomingTrackImage>;
827
831
  disconnect(): void;
832
+ private handleTrackImageMessage;
833
+ private rejectPendingCaptures;
828
834
  private dispatchNotification;
829
835
  private setupConnection;
830
836
  private isExpectedEvent;
package/dist/index.js CHANGED
@@ -5349,18 +5349,22 @@ var FishjamWSNotifier = class extends import_events.EventEmitter {
5349
5349
  // src/agent.ts
5350
5350
  var import_events2 = require("events");
5351
5351
  var import_uuid = require("uuid");
5352
- var expectedEventsList2 = ["trackData", "trackImage"];
5352
+ var expectedEventsList2 = ["trackData"];
5353
5353
  var FishjamAgent = class extends import_events2.EventEmitter {
5354
5354
  client;
5355
5355
  resolveConnectionPromise = null;
5356
5356
  connectionPromise;
5357
+ pendingImageCaptures = /* @__PURE__ */ new Map();
5357
5358
  constructor(config, agentToken, callbacks) {
5358
5359
  super();
5359
5360
  const fishjamUrl = getFishjamUrl(config);
5360
5361
  const websocketUrl = `${httpToWebsocket(fishjamUrl)}/socket/agent/websocket`;
5361
5362
  this.client = new WebSocket(websocketUrl);
5362
5363
  this.client.binaryType = "arraybuffer";
5363
- this.client.onclose = (message) => callbacks?.onClose?.(message.code, message.reason);
5364
+ this.client.onclose = (message) => {
5365
+ this.rejectPendingCaptures("WebSocket closed");
5366
+ callbacks?.onClose?.(message.code, message.reason);
5367
+ };
5364
5368
  this.client.onerror = (message) => callbacks?.onError?.(message);
5365
5369
  this.client.onmessage = (message) => this.dispatchNotification(message);
5366
5370
  this.client.onopen = () => this.setupConnection(agentToken);
@@ -5417,18 +5421,55 @@ var FishjamAgent = class extends import_events2.EventEmitter {
5417
5421
  }
5418
5422
  /**
5419
5423
  * Request a captured image from the given track
5424
+ * @param trackId - the track to capture an image from
5425
+ * @param timeoutMs - timeout in milliseconds (default: 5000)
5426
+ * @returns a promise that resolves with the captured image data
5420
5427
  */
5421
- captureImage(trackId) {
5422
- const msg = AgentRequest.encode({ captureImage: { trackId } }).finish();
5423
- this.client.send(msg);
5428
+ captureImage(trackId, timeoutMs = 5e3) {
5429
+ if (this.pendingImageCaptures.has(trackId)) {
5430
+ return Promise.reject(new Error(`captureImage already pending for track ${trackId}`));
5431
+ }
5432
+ return new Promise((resolve, reject) => {
5433
+ const timer = setTimeout(() => {
5434
+ this.pendingImageCaptures.delete(trackId);
5435
+ reject(new Error(`captureImage timed out after ${timeoutMs}ms for track ${trackId}`));
5436
+ }, timeoutMs);
5437
+ this.pendingImageCaptures.set(trackId, { resolve, reject, timer });
5438
+ const msg = AgentRequest.encode({ captureImage: { trackId } }).finish();
5439
+ try {
5440
+ this.client.send(msg);
5441
+ } catch (error) {
5442
+ clearTimeout(timer);
5443
+ this.pendingImageCaptures.delete(trackId);
5444
+ reject(error);
5445
+ }
5446
+ });
5424
5447
  }
5425
5448
  disconnect() {
5449
+ this.rejectPendingCaptures("Agent disconnected");
5426
5450
  this.client.close();
5427
5451
  }
5452
+ handleTrackImageMessage({ trackImage }) {
5453
+ if (!trackImage) return;
5454
+ const pending = this.pendingImageCaptures.get(trackImage.trackId);
5455
+ if (pending) {
5456
+ clearTimeout(pending.timer);
5457
+ this.pendingImageCaptures.delete(trackImage.trackId);
5458
+ pending.resolve(trackImage);
5459
+ }
5460
+ }
5461
+ rejectPendingCaptures(reason) {
5462
+ for (const [trackId, { reject, timer }] of this.pendingImageCaptures) {
5463
+ clearTimeout(timer);
5464
+ reject(new Error(`${reason}: captureImage rejected for track ${trackId}`));
5465
+ }
5466
+ this.pendingImageCaptures.clear();
5467
+ }
5428
5468
  dispatchNotification(message) {
5429
5469
  try {
5430
5470
  const data = new Uint8Array(message.data);
5431
5471
  const decodedMessage = AgentResponse.decode(data);
5472
+ this.handleTrackImageMessage(decodedMessage);
5432
5473
  const [notification, msg] = Object.entries(decodedMessage).find(([_k, v]) => v);
5433
5474
  if (!this.isExpectedEvent(notification)) return;
5434
5475
  this.emit(notification, msg);
@@ -5489,7 +5530,7 @@ var mapException = (error, entity) => {
5489
5530
  // package.json
5490
5531
  var package_default = {
5491
5532
  name: "@fishjam-cloud/js-server-sdk",
5492
- version: "0.25.3",
5533
+ version: "0.25.5",
5493
5534
  description: "Fishjam server SDK for JavaScript",
5494
5535
  homepage: "https://github.com/fishjam-cloud/js-server-sdk",
5495
5536
  author: "Fishjam Team",
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "./chunk-4UDMIEMT.mjs";
3
+ } from "./chunk-NUDP3SRJ.mjs";
4
4
 
5
5
  // ../fishjam-openapi/dist/index.js
6
6
  import globalAxios2 from "axios";
@@ -5301,18 +5301,22 @@ var FishjamWSNotifier = class extends EventEmitter {
5301
5301
  // src/agent.ts
5302
5302
  import { EventEmitter as EventEmitter2 } from "events";
5303
5303
  import { v4 as uuid4 } from "uuid";
5304
- var expectedEventsList2 = ["trackData", "trackImage"];
5304
+ var expectedEventsList2 = ["trackData"];
5305
5305
  var FishjamAgent = class extends EventEmitter2 {
5306
5306
  client;
5307
5307
  resolveConnectionPromise = null;
5308
5308
  connectionPromise;
5309
+ pendingImageCaptures = /* @__PURE__ */ new Map();
5309
5310
  constructor(config, agentToken, callbacks) {
5310
5311
  super();
5311
5312
  const fishjamUrl = getFishjamUrl(config);
5312
5313
  const websocketUrl = `${httpToWebsocket(fishjamUrl)}/socket/agent/websocket`;
5313
5314
  this.client = new WebSocket(websocketUrl);
5314
5315
  this.client.binaryType = "arraybuffer";
5315
- this.client.onclose = (message) => callbacks?.onClose?.(message.code, message.reason);
5316
+ this.client.onclose = (message) => {
5317
+ this.rejectPendingCaptures("WebSocket closed");
5318
+ callbacks?.onClose?.(message.code, message.reason);
5319
+ };
5316
5320
  this.client.onerror = (message) => callbacks?.onError?.(message);
5317
5321
  this.client.onmessage = (message) => this.dispatchNotification(message);
5318
5322
  this.client.onopen = () => this.setupConnection(agentToken);
@@ -5369,18 +5373,55 @@ var FishjamAgent = class extends EventEmitter2 {
5369
5373
  }
5370
5374
  /**
5371
5375
  * Request a captured image from the given track
5376
+ * @param trackId - the track to capture an image from
5377
+ * @param timeoutMs - timeout in milliseconds (default: 5000)
5378
+ * @returns a promise that resolves with the captured image data
5372
5379
  */
5373
- captureImage(trackId) {
5374
- const msg = AgentRequest.encode({ captureImage: { trackId } }).finish();
5375
- this.client.send(msg);
5380
+ captureImage(trackId, timeoutMs = 5e3) {
5381
+ if (this.pendingImageCaptures.has(trackId)) {
5382
+ return Promise.reject(new Error(`captureImage already pending for track ${trackId}`));
5383
+ }
5384
+ return new Promise((resolve, reject) => {
5385
+ const timer = setTimeout(() => {
5386
+ this.pendingImageCaptures.delete(trackId);
5387
+ reject(new Error(`captureImage timed out after ${timeoutMs}ms for track ${trackId}`));
5388
+ }, timeoutMs);
5389
+ this.pendingImageCaptures.set(trackId, { resolve, reject, timer });
5390
+ const msg = AgentRequest.encode({ captureImage: { trackId } }).finish();
5391
+ try {
5392
+ this.client.send(msg);
5393
+ } catch (error) {
5394
+ clearTimeout(timer);
5395
+ this.pendingImageCaptures.delete(trackId);
5396
+ reject(error);
5397
+ }
5398
+ });
5376
5399
  }
5377
5400
  disconnect() {
5401
+ this.rejectPendingCaptures("Agent disconnected");
5378
5402
  this.client.close();
5379
5403
  }
5404
+ handleTrackImageMessage({ trackImage }) {
5405
+ if (!trackImage) return;
5406
+ const pending = this.pendingImageCaptures.get(trackImage.trackId);
5407
+ if (pending) {
5408
+ clearTimeout(pending.timer);
5409
+ this.pendingImageCaptures.delete(trackImage.trackId);
5410
+ pending.resolve(trackImage);
5411
+ }
5412
+ }
5413
+ rejectPendingCaptures(reason) {
5414
+ for (const [trackId, { reject, timer }] of this.pendingImageCaptures) {
5415
+ clearTimeout(timer);
5416
+ reject(new Error(`${reason}: captureImage rejected for track ${trackId}`));
5417
+ }
5418
+ this.pendingImageCaptures.clear();
5419
+ }
5380
5420
  dispatchNotification(message) {
5381
5421
  try {
5382
5422
  const data = new Uint8Array(message.data);
5383
5423
  const decodedMessage = AgentResponse.decode(data);
5424
+ this.handleTrackImageMessage(decodedMessage);
5384
5425
  const [notification, msg] = Object.entries(decodedMessage).find(([_k, v]) => v);
5385
5426
  if (!this.isExpectedEvent(notification)) return;
5386
5427
  this.emit(notification, msg);
@@ -31,7 +31,7 @@ var import_genai = require("@google/genai");
31
31
  // package.json
32
32
  var package_default = {
33
33
  name: "@fishjam-cloud/js-server-sdk",
34
- version: "0.25.3",
34
+ version: "0.25.5",
35
35
  description: "Fishjam server SDK for JavaScript",
36
36
  homepage: "https://github.com/fishjam-cloud/js-server-sdk",
37
37
  author: "Fishjam Team",
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "../chunk-4UDMIEMT.mjs";
3
+ } from "../chunk-NUDP3SRJ.mjs";
4
4
 
5
5
  // src/integrations/gemini.ts
6
6
  import { GoogleGenAI } from "@google/genai";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fishjam-cloud/js-server-sdk",
3
- "version": "0.25.3",
3
+ "version": "0.25.5",
4
4
  "description": "Fishjam server SDK for JavaScript",
5
5
  "homepage": "https://github.com/fishjam-cloud/js-server-sdk",
6
6
  "author": "Fishjam Team",