iframe-pubsub 1.0.11 → 1.0.12

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
@@ -42,7 +42,7 @@ declare class Client {
42
42
  *
43
43
  * Note: aichat itself does not know the iframe is removed then we have to clean up from parent
44
44
  */
45
- cleanAIChat(): void;
45
+ cleanAIChat(): boolean;
46
46
  /**
47
47
  * Listen for messages from the parent page with a callback.
48
48
  *
@@ -197,7 +197,7 @@ declare class PubSub {
197
197
  *
198
198
  * @param pageId The ID of the page or component to unregister from.
199
199
  */
200
- unregister(pageId: string): void;
200
+ unregister(pageId: string): boolean;
201
201
  sendMessage(message: IMessage): void;
202
202
  /**
203
203
  * Try to send a message to a client with retry logic.
package/dist/index.d.ts CHANGED
@@ -42,7 +42,7 @@ declare class Client {
42
42
  *
43
43
  * Note: aichat itself does not know the iframe is removed then we have to clean up from parent
44
44
  */
45
- cleanAIChat(): void;
45
+ cleanAIChat(): boolean;
46
46
  /**
47
47
  * Listen for messages from the parent page with a callback.
48
48
  *
@@ -197,7 +197,7 @@ declare class PubSub {
197
197
  *
198
198
  * @param pageId The ID of the page or component to unregister from.
199
199
  */
200
- unregister(pageId: string): void;
200
+ unregister(pageId: string): boolean;
201
201
  sendMessage(message: IMessage): void;
202
202
  /**
203
203
  * Try to send a message to a client with retry logic.
package/dist/index.js CHANGED
@@ -63,7 +63,7 @@ var _PubSub = class _PubSub {
63
63
  * @param pageId The ID of the page or component to unregister from.
64
64
  */
65
65
  unregister(pageId) {
66
- this.subscribers.delete(pageId);
66
+ return this.subscribers.delete(pageId);
67
67
  }
68
68
  sendMessage(message) {
69
69
  if (this.mainCallback) {
@@ -195,7 +195,8 @@ var Client = class {
195
195
  if (this.isIframe) {
196
196
  throw new Error("You are not allowed to clean up aichat from iframe.");
197
197
  }
198
- this.pubsub.unregister("aichat");
198
+ window.removeEventListener("message", this.handleMessage.bind(this));
199
+ return this.pubsub.unregister("aichat" /* AI_CHAT_CLIENT_ID */);
199
200
  }
200
201
  /**
201
202
  * Listen for messages from the parent page with a callback.
@@ -203,6 +204,7 @@ var Client = class {
203
204
  * @param callback The callback function to register.
204
205
  */
205
206
  onMessage(callback) {
207
+ console.info("Register new onMessage callback for", this.pageId, callback);
206
208
  this.callback = callback;
207
209
  }
208
210
  /**
package/dist/index.mjs CHANGED
@@ -36,7 +36,7 @@ var _PubSub = class _PubSub {
36
36
  * @param pageId The ID of the page or component to unregister from.
37
37
  */
38
38
  unregister(pageId) {
39
- this.subscribers.delete(pageId);
39
+ return this.subscribers.delete(pageId);
40
40
  }
41
41
  sendMessage(message) {
42
42
  if (this.mainCallback) {
@@ -168,7 +168,8 @@ var Client = class {
168
168
  if (this.isIframe) {
169
169
  throw new Error("You are not allowed to clean up aichat from iframe.");
170
170
  }
171
- this.pubsub.unregister("aichat");
171
+ window.removeEventListener("message", this.handleMessage.bind(this));
172
+ return this.pubsub.unregister("aichat" /* AI_CHAT_CLIENT_ID */);
172
173
  }
173
174
  /**
174
175
  * Listen for messages from the parent page with a callback.
@@ -176,6 +177,7 @@ var Client = class {
176
177
  * @param callback The callback function to register.
177
178
  */
178
179
  onMessage(callback) {
180
+ console.info("Register new onMessage callback for", this.pageId, callback);
179
181
  this.callback = callback;
180
182
  }
181
183
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iframe-pubsub",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "A PubSub library for iframe communication.",
5
5
  "author": "Lap Tran",
6
6
  "license": "ISC",