iframe-pubsub 1.0.13 → 1.0.15
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 +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -8
- package/dist/index.mjs +8 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -27,6 +27,7 @@ declare class Client {
|
|
27
27
|
private callback?;
|
28
28
|
private pubsub;
|
29
29
|
private isIframe;
|
30
|
+
private boundHandleMessage;
|
30
31
|
/**
|
31
32
|
* Create a new client instance.
|
32
33
|
*
|
@@ -181,6 +182,7 @@ declare class PubSub {
|
|
181
182
|
private static instance;
|
182
183
|
private subscribers;
|
183
184
|
private mainCallback?;
|
185
|
+
private boundHandleMessage;
|
184
186
|
private constructor();
|
185
187
|
static getInstance(): PubSub;
|
186
188
|
onMessage(callback: MessageCallback): void;
|
package/dist/index.d.ts
CHANGED
@@ -27,6 +27,7 @@ declare class Client {
|
|
27
27
|
private callback?;
|
28
28
|
private pubsub;
|
29
29
|
private isIframe;
|
30
|
+
private boundHandleMessage;
|
30
31
|
/**
|
31
32
|
* Create a new client instance.
|
32
33
|
*
|
@@ -181,6 +182,7 @@ declare class PubSub {
|
|
181
182
|
private static instance;
|
182
183
|
private subscribers;
|
183
184
|
private mainCallback?;
|
185
|
+
private boundHandleMessage;
|
184
186
|
private constructor();
|
185
187
|
static getInstance(): PubSub;
|
186
188
|
onMessage(callback: MessageCallback): void;
|
package/dist/index.js
CHANGED
@@ -34,9 +34,10 @@ var _PubSub = class _PubSub {
|
|
34
34
|
constructor() {
|
35
35
|
__publicField(this, "subscribers");
|
36
36
|
__publicField(this, "mainCallback");
|
37
|
+
__publicField(this, "boundHandleMessage");
|
37
38
|
this.subscribers = /* @__PURE__ */ new Map();
|
38
|
-
this.
|
39
|
-
window.addEventListener("message", this.
|
39
|
+
this.boundHandleMessage = this.handleMessage.bind(this);
|
40
|
+
window.addEventListener("message", this.boundHandleMessage);
|
40
41
|
}
|
41
42
|
static getInstance() {
|
42
43
|
if (!_PubSub.instance) {
|
@@ -97,7 +98,6 @@ var _PubSub = class _PubSub {
|
|
97
98
|
}
|
98
99
|
}
|
99
100
|
handleMessage(event) {
|
100
|
-
console.log("Pubsub Received message:", event);
|
101
101
|
const data = event.data;
|
102
102
|
const source = event.source;
|
103
103
|
if (data?.type === "REGISTER") {
|
@@ -161,17 +161,19 @@ var Client = class {
|
|
161
161
|
__publicField(this, "callback");
|
162
162
|
__publicField(this, "pubsub");
|
163
163
|
__publicField(this, "isIframe");
|
164
|
+
__publicField(this, "boundHandleMessage");
|
164
165
|
this.pageId = pageId;
|
165
166
|
this.pubsub = PubSub.getInstance();
|
166
167
|
this.isIframe = window !== window.parent;
|
168
|
+
this.boundHandleMessage = this.handleMessage.bind(this);
|
167
169
|
if (this.isIframe) {
|
168
170
|
window.parent.postMessage({
|
169
171
|
type: "REGISTER",
|
170
172
|
pageId: this.pageId
|
171
173
|
}, "*");
|
172
|
-
window.addEventListener("message", this.
|
174
|
+
window.addEventListener("message", this.boundHandleMessage);
|
173
175
|
} else {
|
174
|
-
this.pubsub.register(pageId, this.
|
176
|
+
this.pubsub.register(pageId, this.boundHandleMessage);
|
175
177
|
}
|
176
178
|
}
|
177
179
|
/**
|
@@ -196,7 +198,7 @@ var Client = class {
|
|
196
198
|
if (this.isIframe) {
|
197
199
|
throw new Error("You are not allowed to clean up aichat from iframe.");
|
198
200
|
}
|
199
|
-
window.removeEventListener("message", this.
|
201
|
+
window.removeEventListener("message", this.boundHandleMessage);
|
200
202
|
return this.pubsub.unregister("aichat" /* AI_CHAT_CLIENT_ID */);
|
201
203
|
}
|
202
204
|
/**
|
@@ -205,7 +207,6 @@ var Client = class {
|
|
205
207
|
* @param callback The callback function to register.
|
206
208
|
*/
|
207
209
|
onMessage(callback) {
|
208
|
-
console.info("Register new onMessage callback for", this.pageId, callback);
|
209
210
|
this.callback = callback;
|
210
211
|
}
|
211
212
|
/**
|
@@ -292,7 +293,6 @@ var Client = class {
|
|
292
293
|
});
|
293
294
|
}
|
294
295
|
handleMessage(event) {
|
295
|
-
console.log("Client Received message:", event);
|
296
296
|
let message;
|
297
297
|
if (event.data) {
|
298
298
|
const evt = event;
|
package/dist/index.mjs
CHANGED
@@ -7,9 +7,10 @@ var _PubSub = class _PubSub {
|
|
7
7
|
constructor() {
|
8
8
|
__publicField(this, "subscribers");
|
9
9
|
__publicField(this, "mainCallback");
|
10
|
+
__publicField(this, "boundHandleMessage");
|
10
11
|
this.subscribers = /* @__PURE__ */ new Map();
|
11
|
-
this.
|
12
|
-
window.addEventListener("message", this.
|
12
|
+
this.boundHandleMessage = this.handleMessage.bind(this);
|
13
|
+
window.addEventListener("message", this.boundHandleMessage);
|
13
14
|
}
|
14
15
|
static getInstance() {
|
15
16
|
if (!_PubSub.instance) {
|
@@ -70,7 +71,6 @@ var _PubSub = class _PubSub {
|
|
70
71
|
}
|
71
72
|
}
|
72
73
|
handleMessage(event) {
|
73
|
-
console.log("Pubsub Received message:", event);
|
74
74
|
const data = event.data;
|
75
75
|
const source = event.source;
|
76
76
|
if (data?.type === "REGISTER") {
|
@@ -134,17 +134,19 @@ var Client = class {
|
|
134
134
|
__publicField(this, "callback");
|
135
135
|
__publicField(this, "pubsub");
|
136
136
|
__publicField(this, "isIframe");
|
137
|
+
__publicField(this, "boundHandleMessage");
|
137
138
|
this.pageId = pageId;
|
138
139
|
this.pubsub = PubSub.getInstance();
|
139
140
|
this.isIframe = window !== window.parent;
|
141
|
+
this.boundHandleMessage = this.handleMessage.bind(this);
|
140
142
|
if (this.isIframe) {
|
141
143
|
window.parent.postMessage({
|
142
144
|
type: "REGISTER",
|
143
145
|
pageId: this.pageId
|
144
146
|
}, "*");
|
145
|
-
window.addEventListener("message", this.
|
147
|
+
window.addEventListener("message", this.boundHandleMessage);
|
146
148
|
} else {
|
147
|
-
this.pubsub.register(pageId, this.
|
149
|
+
this.pubsub.register(pageId, this.boundHandleMessage);
|
148
150
|
}
|
149
151
|
}
|
150
152
|
/**
|
@@ -169,7 +171,7 @@ var Client = class {
|
|
169
171
|
if (this.isIframe) {
|
170
172
|
throw new Error("You are not allowed to clean up aichat from iframe.");
|
171
173
|
}
|
172
|
-
window.removeEventListener("message", this.
|
174
|
+
window.removeEventListener("message", this.boundHandleMessage);
|
173
175
|
return this.pubsub.unregister("aichat" /* AI_CHAT_CLIENT_ID */);
|
174
176
|
}
|
175
177
|
/**
|
@@ -178,7 +180,6 @@ var Client = class {
|
|
178
180
|
* @param callback The callback function to register.
|
179
181
|
*/
|
180
182
|
onMessage(callback) {
|
181
|
-
console.info("Register new onMessage callback for", this.pageId, callback);
|
182
183
|
this.callback = callback;
|
183
184
|
}
|
184
185
|
/**
|
@@ -265,7 +266,6 @@ var Client = class {
|
|
265
266
|
});
|
266
267
|
}
|
267
268
|
handleMessage(event) {
|
268
|
-
console.log("Client Received message:", event);
|
269
269
|
let message;
|
270
270
|
if (event.data) {
|
271
271
|
const evt = event;
|