iframe-pubsub 1.0.13 → 1.0.14
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 +11 -5
- package/dist/index.mjs +11 -5
- 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,13 @@ 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);
|
41
|
+
window.addEventListener("message", (event) => {
|
42
|
+
console.info("I am still live: ", event);
|
43
|
+
});
|
40
44
|
}
|
41
45
|
static getInstance() {
|
42
46
|
if (!_PubSub.instance) {
|
@@ -161,17 +165,19 @@ var Client = class {
|
|
161
165
|
__publicField(this, "callback");
|
162
166
|
__publicField(this, "pubsub");
|
163
167
|
__publicField(this, "isIframe");
|
168
|
+
__publicField(this, "boundHandleMessage");
|
164
169
|
this.pageId = pageId;
|
165
170
|
this.pubsub = PubSub.getInstance();
|
166
171
|
this.isIframe = window !== window.parent;
|
172
|
+
this.boundHandleMessage = this.handleMessage.bind(this);
|
167
173
|
if (this.isIframe) {
|
168
174
|
window.parent.postMessage({
|
169
175
|
type: "REGISTER",
|
170
176
|
pageId: this.pageId
|
171
177
|
}, "*");
|
172
|
-
window.addEventListener("message", this.
|
178
|
+
window.addEventListener("message", this.boundHandleMessage);
|
173
179
|
} else {
|
174
|
-
this.pubsub.register(pageId, this.
|
180
|
+
this.pubsub.register(pageId, this.boundHandleMessage);
|
175
181
|
}
|
176
182
|
}
|
177
183
|
/**
|
@@ -196,7 +202,7 @@ var Client = class {
|
|
196
202
|
if (this.isIframe) {
|
197
203
|
throw new Error("You are not allowed to clean up aichat from iframe.");
|
198
204
|
}
|
199
|
-
window.removeEventListener("message", this.
|
205
|
+
window.removeEventListener("message", this.boundHandleMessage);
|
200
206
|
return this.pubsub.unregister("aichat" /* AI_CHAT_CLIENT_ID */);
|
201
207
|
}
|
202
208
|
/**
|
package/dist/index.mjs
CHANGED
@@ -7,9 +7,13 @@ 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);
|
14
|
+
window.addEventListener("message", (event) => {
|
15
|
+
console.info("I am still live: ", event);
|
16
|
+
});
|
13
17
|
}
|
14
18
|
static getInstance() {
|
15
19
|
if (!_PubSub.instance) {
|
@@ -134,17 +138,19 @@ var Client = class {
|
|
134
138
|
__publicField(this, "callback");
|
135
139
|
__publicField(this, "pubsub");
|
136
140
|
__publicField(this, "isIframe");
|
141
|
+
__publicField(this, "boundHandleMessage");
|
137
142
|
this.pageId = pageId;
|
138
143
|
this.pubsub = PubSub.getInstance();
|
139
144
|
this.isIframe = window !== window.parent;
|
145
|
+
this.boundHandleMessage = this.handleMessage.bind(this);
|
140
146
|
if (this.isIframe) {
|
141
147
|
window.parent.postMessage({
|
142
148
|
type: "REGISTER",
|
143
149
|
pageId: this.pageId
|
144
150
|
}, "*");
|
145
|
-
window.addEventListener("message", this.
|
151
|
+
window.addEventListener("message", this.boundHandleMessage);
|
146
152
|
} else {
|
147
|
-
this.pubsub.register(pageId, this.
|
153
|
+
this.pubsub.register(pageId, this.boundHandleMessage);
|
148
154
|
}
|
149
155
|
}
|
150
156
|
/**
|
@@ -169,7 +175,7 @@ var Client = class {
|
|
169
175
|
if (this.isIframe) {
|
170
176
|
throw new Error("You are not allowed to clean up aichat from iframe.");
|
171
177
|
}
|
172
|
-
window.removeEventListener("message", this.
|
178
|
+
window.removeEventListener("message", this.boundHandleMessage);
|
173
179
|
return this.pubsub.unregister("aichat" /* AI_CHAT_CLIENT_ID */);
|
174
180
|
}
|
175
181
|
/**
|