@scalemule/nextjs 0.0.38 → 0.0.39

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.js CHANGED
@@ -3089,6 +3089,7 @@ var RealtimeService = class extends ServiceModule {
3089
3089
  super(...arguments);
3090
3090
  this.basePath = "/v1/realtime";
3091
3091
  this.ws = null;
3092
+ this.usedTicketAuth = false;
3092
3093
  this.subscriptions = /* @__PURE__ */ new Map();
3093
3094
  this.presenceCallbacks = /* @__PURE__ */ new Map();
3094
3095
  this.statusCallbacks = /* @__PURE__ */ new Set();
@@ -3237,8 +3238,10 @@ var RealtimeService = class extends ServiceModule {
3237
3238
  const ticketData = await ticketRes.json();
3238
3239
  const ticket = ticketData.ticket;
3239
3240
  wsUrl = baseUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
3241
+ this.usedTicketAuth = true;
3240
3242
  } else {
3241
3243
  wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
3244
+ this.usedTicketAuth = false;
3242
3245
  }
3243
3246
  this.ws = new WebSocket(wsUrl);
3244
3247
  } catch {
@@ -3247,8 +3250,21 @@ var RealtimeService = class extends ServiceModule {
3247
3250
  }
3248
3251
  this.ws.onopen = () => {
3249
3252
  this.reconnectAttempt = 0;
3250
- this.authenticate();
3253
+ if (!this.usedTicketAuth) {
3254
+ this.authenticate();
3255
+ }
3251
3256
  this.startHeartbeat();
3257
+ if (this.usedTicketAuth) {
3258
+ setTimeout(() => {
3259
+ if (!this.authenticated) {
3260
+ this.authenticated = true;
3261
+ this.setStatus("connected");
3262
+ for (const channel of this.subscriptions.keys()) {
3263
+ this.sendWs({ type: "subscribe", channel });
3264
+ }
3265
+ }
3266
+ }, 2e3);
3267
+ }
3252
3268
  };
3253
3269
  this.ws.onmessage = (event) => {
3254
3270
  try {
package/dist/index.mjs CHANGED
@@ -3087,6 +3087,7 @@ var RealtimeService = class extends ServiceModule {
3087
3087
  super(...arguments);
3088
3088
  this.basePath = "/v1/realtime";
3089
3089
  this.ws = null;
3090
+ this.usedTicketAuth = false;
3090
3091
  this.subscriptions = /* @__PURE__ */ new Map();
3091
3092
  this.presenceCallbacks = /* @__PURE__ */ new Map();
3092
3093
  this.statusCallbacks = /* @__PURE__ */ new Set();
@@ -3235,8 +3236,10 @@ var RealtimeService = class extends ServiceModule {
3235
3236
  const ticketData = await ticketRes.json();
3236
3237
  const ticket = ticketData.ticket;
3237
3238
  wsUrl = baseUrl.replace(/^http/, "ws") + `/v1/realtime/ws?ticket=${encodeURIComponent(ticket)}`;
3239
+ this.usedTicketAuth = true;
3238
3240
  } else {
3239
3241
  wsUrl = baseUrl.replace(/^http/, "ws") + "/v1/realtime/ws";
3242
+ this.usedTicketAuth = false;
3240
3243
  }
3241
3244
  this.ws = new WebSocket(wsUrl);
3242
3245
  } catch {
@@ -3245,8 +3248,21 @@ var RealtimeService = class extends ServiceModule {
3245
3248
  }
3246
3249
  this.ws.onopen = () => {
3247
3250
  this.reconnectAttempt = 0;
3248
- this.authenticate();
3251
+ if (!this.usedTicketAuth) {
3252
+ this.authenticate();
3253
+ }
3249
3254
  this.startHeartbeat();
3255
+ if (this.usedTicketAuth) {
3256
+ setTimeout(() => {
3257
+ if (!this.authenticated) {
3258
+ this.authenticated = true;
3259
+ this.setStatus("connected");
3260
+ for (const channel of this.subscriptions.keys()) {
3261
+ this.sendWs({ type: "subscribe", channel });
3262
+ }
3263
+ }
3264
+ }, 2e3);
3265
+ }
3250
3266
  };
3251
3267
  this.ws.onmessage = (event) => {
3252
3268
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/nextjs",
3
- "version": "0.0.38",
3
+ "version": "0.0.39",
4
4
  "description": "ScaleMule SDK for Next.js applications - authentication, storage, and user management",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -52,7 +52,7 @@
52
52
  "clean": "rm -rf dist"
53
53
  },
54
54
  "dependencies": {
55
- "@scalemule/sdk": "^0.0.30"
55
+ "@scalemule/sdk": "^0.0.31"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "next": ">=14.0.0",