@stripchatdev/ext-helper 0.1.0 → 0.1.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.
- package/dist/ext-helper.js +148 -140
- package/package.json +1 -1
package/dist/ext-helper.js
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
const M = (r) => !!r && typeof r == "object" && "protocol" in r && r.protocol === "iframe_pubsub" && "version" in r && r.version === "1.0",
|
|
1
|
+
const M = (r) => !!r && typeof r == "object" && "protocol" in r && r.protocol === "iframe_pubsub" && "version" in r && r.version === "1.0", f = (r, e) => r, E = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
2
2
|
var u;
|
|
3
3
|
(function(r) {
|
|
4
4
|
r.Base32IncorrectEncoding = "B32_ENC_INVALID", r.DecodeTimeInvalidCharacter = "DEC_TIME_CHAR", r.DecodeTimeValueMalformed = "DEC_TIME_MALFORMED", r.EncodeTimeNegative = "ENC_TIME_NEG", r.EncodeTimeSizeExceeded = "ENC_TIME_SIZE_EXCEED", r.EncodeTimeValueMalformed = "ENC_TIME_MALFORMED", r.PRNGDetectFailure = "PRNG_DETECT", r.ULIDInvalid = "ULID_INVALID", r.Unexpected = "UNEXPECTED", r.UUIDInvalid = "UUID_INVALID";
|
|
5
5
|
})(u || (u = {}));
|
|
6
|
-
class
|
|
6
|
+
class d extends Error {
|
|
7
7
|
constructor(e, t) {
|
|
8
8
|
super(`${t} (${e})`), this.name = "ULIDError", this.code = e;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function m(r) {
|
|
12
12
|
const e = Math.floor(r() * 32) % 32;
|
|
13
|
-
return
|
|
13
|
+
return E.charAt(e);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const e =
|
|
15
|
+
function R(r) {
|
|
16
|
+
const e = y(), t = e && (e.crypto || e.msCrypto) || null;
|
|
17
17
|
if (typeof (t == null ? void 0 : t.getRandomValues) == "function")
|
|
18
18
|
return () => {
|
|
19
|
-
const
|
|
20
|
-
return t.getRandomValues(
|
|
19
|
+
const n = new Uint8Array(1);
|
|
20
|
+
return t.getRandomValues(n), n[0] / 255;
|
|
21
21
|
};
|
|
22
22
|
if (typeof (t == null ? void 0 : t.randomBytes) == "function")
|
|
23
23
|
return () => t.randomBytes(1).readUInt8() / 255;
|
|
24
|
-
throw new
|
|
24
|
+
throw new d(u.PRNGDetectFailure, "Failed to find a reliable PRNG");
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
return
|
|
26
|
+
function y() {
|
|
27
|
+
return I() ? self : typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : null;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function N(r, e) {
|
|
30
30
|
let t = "";
|
|
31
31
|
for (; r > 0; r--)
|
|
32
|
-
t =
|
|
32
|
+
t = m(e) + t;
|
|
33
33
|
return t;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function v(r, e = 10) {
|
|
36
36
|
if (isNaN(r))
|
|
37
|
-
throw new
|
|
37
|
+
throw new d(u.EncodeTimeValueMalformed, `Time must be a number: ${r}`);
|
|
38
38
|
if (r > 281474976710655)
|
|
39
|
-
throw new
|
|
39
|
+
throw new d(u.EncodeTimeSizeExceeded, `Cannot encode a time larger than ${281474976710655}: ${r}`);
|
|
40
40
|
if (r < 0)
|
|
41
|
-
throw new
|
|
41
|
+
throw new d(u.EncodeTimeNegative, `Time must be positive: ${r}`);
|
|
42
42
|
if (Number.isInteger(r) === !1)
|
|
43
|
-
throw new
|
|
44
|
-
let t,
|
|
45
|
-
for (let
|
|
46
|
-
t = r % 32,
|
|
47
|
-
return
|
|
43
|
+
throw new d(u.EncodeTimeValueMalformed, `Time must be an integer: ${r}`);
|
|
44
|
+
let t, n = "";
|
|
45
|
+
for (let s = e; s > 0; s--)
|
|
46
|
+
t = r % 32, n = E.charAt(t) + n, r = (r - t) / 32;
|
|
47
|
+
return n;
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function I() {
|
|
50
50
|
return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope;
|
|
51
51
|
}
|
|
52
|
-
function
|
|
53
|
-
const t =
|
|
54
|
-
return
|
|
52
|
+
function p(r, e) {
|
|
53
|
+
const t = R(), n = Date.now();
|
|
54
|
+
return v(n, 10) + N(16, t);
|
|
55
55
|
}
|
|
56
|
-
const
|
|
56
|
+
const _ = ({ seq: r, uniqId: e }) => (t) => ({
|
|
57
57
|
...{
|
|
58
58
|
protocol: "iframe_pubsub",
|
|
59
59
|
version: "1.0",
|
|
@@ -62,83 +62,83 @@ const T = ({ seq: r, uniqId: e }) => (t) => ({
|
|
|
62
62
|
timestamp: Date.now()
|
|
63
63
|
},
|
|
64
64
|
...t
|
|
65
|
-
}), b =
|
|
66
|
-
uniqId: () =>
|
|
67
|
-
seq: () =>
|
|
65
|
+
}), b = _({
|
|
66
|
+
uniqId: () => p(),
|
|
67
|
+
seq: () => p()
|
|
68
68
|
});
|
|
69
|
-
class
|
|
69
|
+
class T {
|
|
70
70
|
constructor(e) {
|
|
71
|
-
this.eventHandlerMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (
|
|
72
|
-
if (M(
|
|
73
|
-
if (
|
|
74
|
-
const { eventName:
|
|
75
|
-
if (!
|
|
71
|
+
this.eventHandlerMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (s, i) => {
|
|
72
|
+
if (M(s)) {
|
|
73
|
+
if (s.type === "event") {
|
|
74
|
+
const { eventName: a } = s, o = this.eventHandlerMap.get(a);
|
|
75
|
+
if (!o)
|
|
76
76
|
return;
|
|
77
|
-
|
|
77
|
+
o.forEach((c) => {
|
|
78
78
|
try {
|
|
79
|
-
|
|
80
|
-
} catch (
|
|
81
|
-
console.error("[PubSubSubscriber] globalMessageHandler: failed to handle income message",
|
|
79
|
+
c(s.data, i.id);
|
|
80
|
+
} catch (h) {
|
|
81
|
+
console.error("[PubSubSubscriber] globalMessageHandler: failed to handle income message", h);
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
|
-
console.error("[PubSubSubscriber] globalMessageHandler: unhandled message",
|
|
86
|
+
console.error("[PubSubSubscriber] globalMessageHandler: unhandled message", s);
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
|
-
const { brokerId: t, transport:
|
|
90
|
-
this.brokerId = t, this.transport =
|
|
89
|
+
const { brokerId: t, transport: n } = e;
|
|
90
|
+
this.brokerId = t, this.transport = n, this.transport.onMessage(this.globalMessageHandler);
|
|
91
91
|
}
|
|
92
92
|
subscribe(e, t) {
|
|
93
|
-
const
|
|
94
|
-
let
|
|
95
|
-
|
|
96
|
-
const
|
|
93
|
+
const n = f(e);
|
|
94
|
+
let s = this.eventHandlerMap.get(n);
|
|
95
|
+
s || (s = /* @__PURE__ */ new Set(), this.eventHandlerMap.set(n, s)), s.add(t);
|
|
96
|
+
const i = b({
|
|
97
97
|
type: "subscribe",
|
|
98
98
|
eventName: e
|
|
99
99
|
});
|
|
100
|
-
this.transport.send(this.brokerId,
|
|
100
|
+
this.transport.send(this.brokerId, i);
|
|
101
101
|
}
|
|
102
102
|
unsubscribe(e, t) {
|
|
103
|
-
const
|
|
104
|
-
let
|
|
105
|
-
if (!
|
|
103
|
+
const n = f(e);
|
|
104
|
+
let s = this.eventHandlerMap.get(n);
|
|
105
|
+
if (!s)
|
|
106
106
|
return;
|
|
107
|
-
t ?
|
|
108
|
-
const
|
|
107
|
+
t ? s.delete(t) : this.eventHandlerMap.delete(n);
|
|
108
|
+
const i = b({
|
|
109
109
|
type: "unsubscribe",
|
|
110
110
|
eventName: e
|
|
111
111
|
});
|
|
112
|
-
this.transport.send(this.brokerId,
|
|
112
|
+
this.transport.send(this.brokerId, i);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
const w = !!Error.captureStackTrace, P = "APP_ERROR";
|
|
116
|
-
class
|
|
116
|
+
class l extends Error {
|
|
117
117
|
constructor(e, t) {
|
|
118
118
|
super(e), this.name = new.target.name || P, this.cause = t, w && Error.captureStackTrace(this, this.constructor);
|
|
119
119
|
}
|
|
120
120
|
static getChainedMessage(e) {
|
|
121
121
|
let { message: t } = e;
|
|
122
|
-
return e instanceof
|
|
123
|
-
Caused by: ${
|
|
122
|
+
return e instanceof l && e.cause && (t += `
|
|
123
|
+
Caused by: ${l.getChainedMessage(e.cause)}`), t;
|
|
124
124
|
}
|
|
125
125
|
toJSON() {
|
|
126
126
|
return {
|
|
127
127
|
name: this.name,
|
|
128
128
|
message: this.message,
|
|
129
|
-
cause: this.cause ?
|
|
129
|
+
cause: this.cause ? l.getChainedMessage(this.cause) : void 0
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
const O = {
|
|
134
134
|
INTERNAL_ERROR: "INTERNAL_ERROR"
|
|
135
135
|
}, C = "RPC_ERROR";
|
|
136
|
-
class D extends
|
|
136
|
+
class D extends l {
|
|
137
137
|
constructor(e) {
|
|
138
138
|
super(e.message || "unknown rpc error"), this.name = C, this.code = (e == null ? void 0 : e.code) || O.INTERNAL_ERROR;
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
-
const A = (r) => !!r && typeof r == "object" && "protocol" in r && r.protocol === "iframe_rpc" && "version" in r && r.version === "1.0",
|
|
141
|
+
const A = (r) => !!r && typeof r == "object" && "protocol" in r && r.protocol === "iframe_rpc" && "version" in r && r.version === "1.0", H = ({ uniqId: r }) => (e) => ({
|
|
142
142
|
...{
|
|
143
143
|
protocol: "iframe_rpc",
|
|
144
144
|
version: "1.0",
|
|
@@ -146,90 +146,90 @@ const A = (r) => !!r && typeof r == "object" && "protocol" in r && r.protocol ==
|
|
|
146
146
|
timestamp: Date.now()
|
|
147
147
|
},
|
|
148
148
|
...e
|
|
149
|
-
}),
|
|
150
|
-
uniqId: () =>
|
|
149
|
+
}), S = H({
|
|
150
|
+
uniqId: () => p()
|
|
151
151
|
});
|
|
152
|
-
class
|
|
152
|
+
class L {
|
|
153
153
|
constructor(e) {
|
|
154
|
-
this.pendingEntryMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (
|
|
155
|
-
if (A(
|
|
156
|
-
if (
|
|
157
|
-
const
|
|
158
|
-
if (!
|
|
159
|
-
console.error("[RpcClient] globalMessageHandler: got success response without pending request",
|
|
154
|
+
this.pendingEntryMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (s) => {
|
|
155
|
+
if (A(s)) {
|
|
156
|
+
if (s.type === "response" && s.status === "ok") {
|
|
157
|
+
const i = s.id, a = this.pendingEntryMap.get(i);
|
|
158
|
+
if (!a) {
|
|
159
|
+
console.error("[RpcClient] globalMessageHandler: got success response without pending request", s);
|
|
160
160
|
return;
|
|
161
161
|
}
|
|
162
|
-
this.pendingEntryMap.delete(
|
|
162
|
+
this.pendingEntryMap.delete(i), a.resolve(s.result);
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
|
-
if (
|
|
166
|
-
const
|
|
167
|
-
if (!
|
|
168
|
-
console.error("[RpcClient] globalMessageHandler: got error response without pending request",
|
|
165
|
+
if (s.type === "response" && s.status === "error") {
|
|
166
|
+
const i = s.id, a = this.pendingEntryMap.get(i);
|
|
167
|
+
if (!a) {
|
|
168
|
+
console.error("[RpcClient] globalMessageHandler: got error response without pending request", s);
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
171
|
-
this.pendingEntryMap.delete(
|
|
171
|
+
this.pendingEntryMap.delete(i), a.reject(new D(s.error));
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
|
-
console.error("[RpcClient] globalMessageHandler: invalid message schema",
|
|
174
|
+
console.error("[RpcClient] globalMessageHandler: invalid message schema", s);
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
|
-
const { serverId: t, transport:
|
|
178
|
-
this.serverId = t, this.transport =
|
|
177
|
+
const { serverId: t, transport: n } = e;
|
|
178
|
+
this.serverId = t, this.transport = n, this.transport.onMessage(this.globalMessageHandler);
|
|
179
179
|
}
|
|
180
180
|
makeRequest(e, t) {
|
|
181
|
-
const
|
|
181
|
+
const n = S({
|
|
182
182
|
type: "request",
|
|
183
183
|
method: e,
|
|
184
184
|
params: t
|
|
185
|
-
}),
|
|
186
|
-
this.pendingEntryMap.set(
|
|
185
|
+
}), s = new Promise((i, a) => {
|
|
186
|
+
this.pendingEntryMap.set(n.id, {
|
|
187
187
|
method: e,
|
|
188
|
-
resolve: (
|
|
189
|
-
o
|
|
188
|
+
resolve: (o) => {
|
|
189
|
+
i(o);
|
|
190
190
|
},
|
|
191
|
-
reject: (
|
|
192
|
-
|
|
191
|
+
reject: (o) => {
|
|
192
|
+
a(o);
|
|
193
193
|
}
|
|
194
194
|
});
|
|
195
195
|
});
|
|
196
196
|
try {
|
|
197
|
-
this.transport.send(this.serverId,
|
|
198
|
-
} catch (
|
|
199
|
-
console.error("[RpcClient] makeRequest: failed to send rpc message",
|
|
200
|
-
const
|
|
201
|
-
|
|
197
|
+
this.transport.send(this.serverId, n);
|
|
198
|
+
} catch (i) {
|
|
199
|
+
console.error("[RpcClient] makeRequest: failed to send rpc message", i);
|
|
200
|
+
const a = this.pendingEntryMap.get(n.id);
|
|
201
|
+
a && (this.pendingEntryMap.delete(n.id), a.reject(i));
|
|
202
202
|
}
|
|
203
|
-
return
|
|
203
|
+
return s;
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
|
-
class
|
|
206
|
+
class k {
|
|
207
207
|
constructor(e) {
|
|
208
|
-
this.peers = /* @__PURE__ */ new Map(), this.onMessage = (
|
|
209
|
-
const
|
|
210
|
-
const { data:
|
|
211
|
-
if (!
|
|
208
|
+
this.peers = /* @__PURE__ */ new Map(), this.onMessage = (n) => {
|
|
209
|
+
const s = (i) => {
|
|
210
|
+
const { data: a, origin: o, source: c } = i;
|
|
211
|
+
if (!c) {
|
|
212
212
|
console.error("[PostMessageTransport] onMessage: source could not be empty");
|
|
213
213
|
return;
|
|
214
214
|
}
|
|
215
|
-
const
|
|
216
|
-
if (
|
|
215
|
+
const h = this.findPeer(c, o);
|
|
216
|
+
if (h)
|
|
217
217
|
try {
|
|
218
|
-
|
|
219
|
-
} catch (
|
|
220
|
-
console.error("[PostMessageTransport] onMessage: failed to call cb on message",
|
|
218
|
+
n(a, h);
|
|
219
|
+
} catch (g) {
|
|
220
|
+
console.error("[PostMessageTransport] onMessage: failed to call cb on message", g);
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
|
-
return this.localWindow.addEventListener("message",
|
|
224
|
-
this.localWindow.removeEventListener("message",
|
|
223
|
+
return this.localWindow.addEventListener("message", s), () => {
|
|
224
|
+
this.localWindow.removeEventListener("message", s);
|
|
225
225
|
};
|
|
226
226
|
};
|
|
227
227
|
const { localWindow: t } = e;
|
|
228
228
|
this.localWindow = t || window;
|
|
229
229
|
}
|
|
230
230
|
send(e, t) {
|
|
231
|
-
const
|
|
232
|
-
|
|
231
|
+
const n = this.peers.get(e);
|
|
232
|
+
n && n.source.postMessage(t, n.origin);
|
|
233
233
|
}
|
|
234
234
|
broadcast(e) {
|
|
235
235
|
this.peers.forEach((t) => {
|
|
@@ -237,8 +237,8 @@ class L {
|
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
239
|
broadcastGroup(e, t) {
|
|
240
|
-
e.forEach((
|
|
241
|
-
this.send(
|
|
240
|
+
e.forEach((n) => {
|
|
241
|
+
this.send(n, t);
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
244
|
addPeer(e) {
|
|
@@ -248,9 +248,9 @@ class L {
|
|
|
248
248
|
this.peers.delete(e);
|
|
249
249
|
}
|
|
250
250
|
findPeer(e, t) {
|
|
251
|
-
for (const [
|
|
252
|
-
if (
|
|
253
|
-
return
|
|
251
|
+
for (const [n, s] of this.peers)
|
|
252
|
+
if (s.source === e && s.origin === t)
|
|
253
|
+
return s;
|
|
254
254
|
return null;
|
|
255
255
|
}
|
|
256
256
|
}
|
|
@@ -258,21 +258,21 @@ class G {
|
|
|
258
258
|
constructor(e) {
|
|
259
259
|
const {
|
|
260
260
|
serverId: t,
|
|
261
|
-
serverOrigin:
|
|
262
|
-
serverSource:
|
|
263
|
-
theme:
|
|
264
|
-
} = e,
|
|
261
|
+
serverOrigin: n,
|
|
262
|
+
serverSource: s,
|
|
263
|
+
theme: i
|
|
264
|
+
} = e, a = {
|
|
265
265
|
id: t,
|
|
266
|
-
origin:
|
|
267
|
-
source:
|
|
268
|
-
},
|
|
269
|
-
|
|
270
|
-
transport:
|
|
266
|
+
origin: n,
|
|
267
|
+
source: s
|
|
268
|
+
}, o = new k({});
|
|
269
|
+
o.addPeer(a), this.rpcClient = new L({
|
|
270
|
+
transport: o,
|
|
271
271
|
serverId: t
|
|
272
|
-
}), this.subscriber = new
|
|
273
|
-
transport:
|
|
274
|
-
brokerId:
|
|
275
|
-
}), document.documentElement.dataset.theme =
|
|
272
|
+
}), this.subscriber = new T({
|
|
273
|
+
transport: o,
|
|
274
|
+
brokerId: a.id
|
|
275
|
+
}), document.documentElement.dataset.theme = i;
|
|
276
276
|
}
|
|
277
277
|
makeRequest(e, t) {
|
|
278
278
|
return this.rpcClient.makeRequest(e, t);
|
|
@@ -285,31 +285,39 @@ class G {
|
|
|
285
285
|
}
|
|
286
286
|
bootstrap() {
|
|
287
287
|
let e = { height: 0, width: 0 };
|
|
288
|
-
const t =
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
288
|
+
const t = () => {
|
|
289
|
+
const o = document.body;
|
|
290
|
+
return Math.max(
|
|
291
|
+
o.offsetHeight,
|
|
292
|
+
o.scrollHeight
|
|
293
|
+
);
|
|
294
|
+
}, n = () => {
|
|
295
|
+
const o = document.body;
|
|
296
|
+
return Math.max(
|
|
297
|
+
o.offsetWidth,
|
|
298
|
+
o.scrollWidth
|
|
299
|
+
);
|
|
300
|
+
}, s = () => {
|
|
301
|
+
const o = n(), c = t();
|
|
302
|
+
(e.height !== c || e.width !== o) && (e = { height: c, width: o }, this.makeRequest("v1.system.resize.notify", { height: c, width: o }));
|
|
297
303
|
};
|
|
298
|
-
(()
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
304
|
+
s(), new ResizeObserver(s).observe(document.body), new MutationObserver(s).observe(document.body, {
|
|
305
|
+
childList: !0,
|
|
306
|
+
subtree: !0,
|
|
307
|
+
attributes: !0,
|
|
308
|
+
attributeFilter: ["style", "class", "hidden", "open"]
|
|
309
|
+
});
|
|
302
310
|
}
|
|
303
311
|
}
|
|
304
|
-
const
|
|
305
|
-
const r = new URL(window.location.href), e = r.searchParams.get("origin") || "", t = r.searchParams.get("theme") || "dark",
|
|
312
|
+
const x = () => {
|
|
313
|
+
const r = new URL(window.location.href), e = r.searchParams.get("origin") || "", t = r.searchParams.get("theme") || "dark", n = new G({
|
|
306
314
|
serverId: "server",
|
|
307
315
|
serverOrigin: e || window.parent.origin,
|
|
308
316
|
serverSource: window.parent,
|
|
309
317
|
theme: t
|
|
310
318
|
});
|
|
311
|
-
return
|
|
319
|
+
return n.bootstrap(), n;
|
|
312
320
|
};
|
|
313
321
|
export {
|
|
314
|
-
|
|
322
|
+
x as createExtHelper
|
|
315
323
|
};
|