@kokimoki/app 1.4.0 → 1.4.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.
@@ -34,6 +34,7 @@ export declare class KokimokiClient<ClientContextT = any> extends KokimokiClient
34
34
  private _autoReconnect;
35
35
  private _reconnectTimeout;
36
36
  private _pingInterval;
37
+ private _clientTokenKey;
37
38
  constructor(host: string, appId: string, code?: string);
38
39
  get id(): string;
39
40
  get connectionId(): string;
@@ -34,6 +34,7 @@ export class KokimokiClient extends EventEmitter {
34
34
  _autoReconnect = true;
35
35
  _reconnectTimeout = 0;
36
36
  _pingInterval;
37
+ _clientTokenKey = "KM_TOKEN";
37
38
  constructor(host, appId, code = "") {
38
39
  super();
39
40
  this.host = host;
@@ -52,6 +53,15 @@ export class KokimokiClient extends EventEmitter {
52
53
  this.ws.send(pingBuffer);
53
54
  }
54
55
  }, 5000);
56
+ // Detect devtools
57
+ if (window.top && frameElement) {
58
+ this._clientTokenKey = `KM_TOKEN/${frameElement.id}`;
59
+ window.addEventListener("message", (e) => {
60
+ if (e.data === "km:clearStorage") {
61
+ localStorage.removeItem(this._clientTokenKey);
62
+ }
63
+ });
64
+ }
55
65
  }
56
66
  get id() {
57
67
  if (!this._id) {
@@ -102,6 +112,7 @@ export class KokimokiClient extends EventEmitter {
102
112
  if (this._connectPromise) {
103
113
  return await this._connectPromise;
104
114
  }
115
+ // Set up the WebSocket connection
105
116
  this._ws = new WebSocket(`${this._wsUrl}/apps/${this.appId}?clientVersion=${KOKIMOKI_APP_VERSION}`);
106
117
  this._ws.binaryType = "arraybuffer";
107
118
  // Close previous connection in hot-reload scenarios
@@ -118,7 +129,7 @@ export class KokimokiClient extends EventEmitter {
118
129
  // Wait for connection
119
130
  this._connectPromise = new Promise((onInit) => {
120
131
  // Fetch the auth token
121
- let clientToken = localStorage.getItem("KM_TOKEN");
132
+ let clientToken = localStorage.getItem(this._clientTokenKey);
122
133
  // Send the app token on first connect
123
134
  this.ws.onopen = () => {
124
135
  this.ws.send(JSON.stringify({ type: "auth", code: this.code, token: clientToken }));
@@ -184,7 +195,7 @@ export class KokimokiClient extends EventEmitter {
184
195
  this.emit("connected");
185
196
  }
186
197
  handleInitMessage(message) {
187
- localStorage.setItem("KM_TOKEN", message.clientToken);
198
+ localStorage.setItem(this._clientTokenKey, message.clientToken);
188
199
  this._id = message.clientId;
189
200
  this._connectionId = message.id;
190
201
  this._token = message.appToken;
@@ -343,6 +343,7 @@ declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
343
343
  private _autoReconnect;
344
344
  private _reconnectTimeout;
345
345
  private _pingInterval;
346
+ private _clientTokenKey;
346
347
  constructor(host: string, appId: string, code?: string);
347
348
  get id(): string;
348
349
  get connectionId(): string;
@@ -634,7 +634,7 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
634
634
  var eventsExports = events.exports;
635
635
  var EventEmitter$1 = /*@__PURE__*/getDefaultExportFromCjs(eventsExports);
636
636
 
637
- const KOKIMOKI_APP_VERSION = "1.4.0";
637
+ const KOKIMOKI_APP_VERSION = "1.4.1";
638
638
 
639
639
  /**
640
640
  * Utility module to work with key-value stores.
@@ -12247,6 +12247,7 @@ class KokimokiClient extends EventEmitter$1 {
12247
12247
  _autoReconnect = true;
12248
12248
  _reconnectTimeout = 0;
12249
12249
  _pingInterval;
12250
+ _clientTokenKey = "KM_TOKEN";
12250
12251
  constructor(host, appId, code = "") {
12251
12252
  super();
12252
12253
  this.host = host;
@@ -12265,6 +12266,15 @@ class KokimokiClient extends EventEmitter$1 {
12265
12266
  this.ws.send(pingBuffer);
12266
12267
  }
12267
12268
  }, 5000);
12269
+ // Detect devtools
12270
+ if (window.top && frameElement) {
12271
+ this._clientTokenKey = `KM_TOKEN/${frameElement.id}`;
12272
+ window.addEventListener("message", (e) => {
12273
+ if (e.data === "km:clearStorage") {
12274
+ localStorage.removeItem(this._clientTokenKey);
12275
+ }
12276
+ });
12277
+ }
12268
12278
  }
12269
12279
  get id() {
12270
12280
  if (!this._id) {
@@ -12315,6 +12325,7 @@ class KokimokiClient extends EventEmitter$1 {
12315
12325
  if (this._connectPromise) {
12316
12326
  return await this._connectPromise;
12317
12327
  }
12328
+ // Set up the WebSocket connection
12318
12329
  this._ws = new WebSocket(`${this._wsUrl}/apps/${this.appId}?clientVersion=${KOKIMOKI_APP_VERSION}`);
12319
12330
  this._ws.binaryType = "arraybuffer";
12320
12331
  // Close previous connection in hot-reload scenarios
@@ -12331,7 +12342,7 @@ class KokimokiClient extends EventEmitter$1 {
12331
12342
  // Wait for connection
12332
12343
  this._connectPromise = new Promise((onInit) => {
12333
12344
  // Fetch the auth token
12334
- let clientToken = localStorage.getItem("KM_TOKEN");
12345
+ let clientToken = localStorage.getItem(this._clientTokenKey);
12335
12346
  // Send the app token on first connect
12336
12347
  this.ws.onopen = () => {
12337
12348
  this.ws.send(JSON.stringify({ type: "auth", code: this.code, token: clientToken }));
@@ -12397,7 +12408,7 @@ class KokimokiClient extends EventEmitter$1 {
12397
12408
  this.emit("connected");
12398
12409
  }
12399
12410
  handleInitMessage(message) {
12400
- localStorage.setItem("KM_TOKEN", message.clientToken);
12411
+ localStorage.setItem(this._clientTokenKey, message.clientToken);
12401
12412
  this._id = message.clientId;
12402
12413
  this._connectionId = message.id;
12403
12414
  this._token = message.appToken;