@scalemule/sdk 0.0.30 → 0.0.31

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
@@ -1502,6 +1502,7 @@ interface PresenceEvent {
1502
1502
  declare class RealtimeService extends ServiceModule {
1503
1503
  protected basePath: string;
1504
1504
  private ws;
1505
+ private usedTicketAuth;
1505
1506
  private subscriptions;
1506
1507
  private presenceCallbacks;
1507
1508
  private statusCallbacks;
package/dist/index.d.ts CHANGED
@@ -1502,6 +1502,7 @@ interface PresenceEvent {
1502
1502
  declare class RealtimeService extends ServiceModule {
1503
1503
  protected basePath: string;
1504
1504
  private ws;
1505
+ private usedTicketAuth;
1505
1506
  private subscriptions;
1506
1507
  private presenceCallbacks;
1507
1508
  private statusCallbacks;
package/dist/index.js CHANGED
@@ -3647,6 +3647,7 @@ var RealtimeService = class extends ServiceModule {
3647
3647
  super(...arguments);
3648
3648
  this.basePath = "/v1/realtime";
3649
3649
  this.ws = null;
3650
+ this.usedTicketAuth = false;
3650
3651
  this.subscriptions = /* @__PURE__ */ new Map();
3651
3652
  this.presenceCallbacks = /* @__PURE__ */ new Map();
3652
3653
  this.statusCallbacks = /* @__PURE__ */ new Set();
@@ -3795,8 +3796,10 @@ var RealtimeService = class extends ServiceModule {
3795
3796
  const ticketData = await ticketRes.json();
3796
3797
  const ticket = ticketData.ticket;
3797
3798
  wsUrl = baseUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
3799
+ this.usedTicketAuth = true;
3798
3800
  } else {
3799
3801
  wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
3802
+ this.usedTicketAuth = false;
3800
3803
  }
3801
3804
  this.ws = new WebSocket(wsUrl);
3802
3805
  } catch {
@@ -3805,8 +3808,21 @@ var RealtimeService = class extends ServiceModule {
3805
3808
  }
3806
3809
  this.ws.onopen = () => {
3807
3810
  this.reconnectAttempt = 0;
3808
- this.authenticate();
3811
+ if (!this.usedTicketAuth) {
3812
+ this.authenticate();
3813
+ }
3809
3814
  this.startHeartbeat();
3815
+ if (this.usedTicketAuth) {
3816
+ setTimeout(() => {
3817
+ if (!this.authenticated) {
3818
+ this.authenticated = true;
3819
+ this.setStatus("connected");
3820
+ for (const channel of this.subscriptions.keys()) {
3821
+ this.sendWs({ type: "subscribe", channel });
3822
+ }
3823
+ }
3824
+ }, 2e3);
3825
+ }
3810
3826
  };
3811
3827
  this.ws.onmessage = (event) => {
3812
3828
  try {
package/dist/index.mjs CHANGED
@@ -3276,6 +3276,7 @@ var RealtimeService = class extends ServiceModule {
3276
3276
  super(...arguments);
3277
3277
  this.basePath = "/v1/realtime";
3278
3278
  this.ws = null;
3279
+ this.usedTicketAuth = false;
3279
3280
  this.subscriptions = /* @__PURE__ */ new Map();
3280
3281
  this.presenceCallbacks = /* @__PURE__ */ new Map();
3281
3282
  this.statusCallbacks = /* @__PURE__ */ new Set();
@@ -3424,8 +3425,10 @@ var RealtimeService = class extends ServiceModule {
3424
3425
  const ticketData = await ticketRes.json();
3425
3426
  const ticket = ticketData.ticket;
3426
3427
  wsUrl = baseUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
3428
+ this.usedTicketAuth = true;
3427
3429
  } else {
3428
3430
  wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
3431
+ this.usedTicketAuth = false;
3429
3432
  }
3430
3433
  this.ws = new WebSocket(wsUrl);
3431
3434
  } catch {
@@ -3434,8 +3437,21 @@ var RealtimeService = class extends ServiceModule {
3434
3437
  }
3435
3438
  this.ws.onopen = () => {
3436
3439
  this.reconnectAttempt = 0;
3437
- this.authenticate();
3440
+ if (!this.usedTicketAuth) {
3441
+ this.authenticate();
3442
+ }
3438
3443
  this.startHeartbeat();
3444
+ if (this.usedTicketAuth) {
3445
+ setTimeout(() => {
3446
+ if (!this.authenticated) {
3447
+ this.authenticated = true;
3448
+ this.setStatus("connected");
3449
+ for (const channel of this.subscriptions.keys()) {
3450
+ this.sendWs({ type: "subscribe", channel });
3451
+ }
3452
+ }
3453
+ }, 2e3);
3454
+ }
3439
3455
  };
3440
3456
  this.ws.onmessage = (event) => {
3441
3457
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/sdk",
3
- "version": "0.0.30",
3
+ "version": "0.0.31",
4
4
  "description": "Official TypeScript/JavaScript SDK for ScaleMule Backend-as-a-Service",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",