@kokimoki/app 1.4.1 → 1.4.3

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 _devMode;
37
38
  private _clientTokenKey;
38
39
  constructor(host: string, appId: string, code?: string);
39
40
  get id(): string;
@@ -34,6 +34,7 @@ export class KokimokiClient extends EventEmitter {
34
34
  _autoReconnect = true;
35
35
  _reconnectTimeout = 0;
36
36
  _pingInterval;
37
+ _devMode = false;
37
38
  _clientTokenKey = "KM_TOKEN";
38
39
  constructor(host, appId, code = "") {
39
40
  super();
@@ -53,12 +54,16 @@ export class KokimokiClient extends EventEmitter {
53
54
  this.ws.send(pingBuffer);
54
55
  }
55
56
  }, 5000);
56
- // Detect devtools
57
- if (window.top && frameElement) {
58
- this._clientTokenKey = `KM_TOKEN/${frameElement.id}`;
57
+ // Listen for devtools messages
58
+ if (window.top) {
59
59
  window.addEventListener("message", (e) => {
60
+ console.log(`[KM TOOLS] ${e.data}`);
60
61
  if (e.data === "km:clearStorage") {
61
62
  localStorage.removeItem(this._clientTokenKey);
63
+ window.location.reload();
64
+ }
65
+ else if (e.data === "km:reload") {
66
+ window.location.reload();
62
67
  }
63
68
  });
64
69
  }
@@ -112,6 +117,27 @@ export class KokimokiClient extends EventEmitter {
112
117
  if (this._connectPromise) {
113
118
  return await this._connectPromise;
114
119
  }
120
+ // Detect devtools
121
+ if (window.top) {
122
+ window.top.postMessage({ appId: this.appId }, "*");
123
+ await new Promise((resolve, reject) => {
124
+ // Wait up to 50ms for parent to respond
125
+ const timeout = setTimeout(() => {
126
+ window.removeEventListener("message", onMessage);
127
+ resolve();
128
+ }, 50);
129
+ // Listen for parent response
130
+ const onMessage = (e) => {
131
+ clearTimeout(timeout);
132
+ window.removeEventListener("message", onMessage);
133
+ if (e.data.clientKey) {
134
+ this._clientTokenKey = `KM_TOKEN/${e.data.clientKey}`;
135
+ }
136
+ resolve();
137
+ };
138
+ window.addEventListener("message", onMessage);
139
+ });
140
+ }
115
141
  // Set up the WebSocket connection
116
142
  this._ws = new WebSocket(`${this._wsUrl}/apps/${this.appId}?clientVersion=${KOKIMOKI_APP_VERSION}`);
117
143
  this._ws.binaryType = "arraybuffer";
@@ -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 _devMode;
346
347
  private _clientTokenKey;
347
348
  constructor(host: string, appId: string, code?: string);
348
349
  get id(): 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.1";
637
+ const KOKIMOKI_APP_VERSION = "1.4.3";
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
+ _devMode = false;
12250
12251
  _clientTokenKey = "KM_TOKEN";
12251
12252
  constructor(host, appId, code = "") {
12252
12253
  super();
@@ -12266,12 +12267,16 @@ class KokimokiClient extends EventEmitter$1 {
12266
12267
  this.ws.send(pingBuffer);
12267
12268
  }
12268
12269
  }, 5000);
12269
- // Detect devtools
12270
- if (window.top && frameElement) {
12271
- this._clientTokenKey = `KM_TOKEN/${frameElement.id}`;
12270
+ // Listen for devtools messages
12271
+ if (window.top) {
12272
12272
  window.addEventListener("message", (e) => {
12273
+ console.log(`[KM TOOLS] ${e.data}`);
12273
12274
  if (e.data === "km:clearStorage") {
12274
12275
  localStorage.removeItem(this._clientTokenKey);
12276
+ window.location.reload();
12277
+ }
12278
+ else if (e.data === "km:reload") {
12279
+ window.location.reload();
12275
12280
  }
12276
12281
  });
12277
12282
  }
@@ -12325,6 +12330,27 @@ class KokimokiClient extends EventEmitter$1 {
12325
12330
  if (this._connectPromise) {
12326
12331
  return await this._connectPromise;
12327
12332
  }
12333
+ // Detect devtools
12334
+ if (window.top) {
12335
+ window.top.postMessage({ appId: this.appId }, "*");
12336
+ await new Promise((resolve, reject) => {
12337
+ // Wait up to 50ms for parent to respond
12338
+ const timeout = setTimeout(() => {
12339
+ window.removeEventListener("message", onMessage);
12340
+ resolve();
12341
+ }, 50);
12342
+ // Listen for parent response
12343
+ const onMessage = (e) => {
12344
+ clearTimeout(timeout);
12345
+ window.removeEventListener("message", onMessage);
12346
+ if (e.data.clientKey) {
12347
+ this._clientTokenKey = `KM_TOKEN/${e.data.clientKey}`;
12348
+ }
12349
+ resolve();
12350
+ };
12351
+ window.addEventListener("message", onMessage);
12352
+ });
12353
+ }
12328
12354
  // Set up the WebSocket connection
12329
12355
  this._ws = new WebSocket(`${this._wsUrl}/apps/${this.appId}?clientVersion=${KOKIMOKI_APP_VERSION}`);
12330
12356
  this._ws.binaryType = "arraybuffer";