@mercuryworkshop/scramjet-controller 0.0.3 → 0.0.4

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.
@@ -1,308 +1,2 @@
1
- var $scramjetController;
2
- (() => { // webpackBootstrap
3
- var __webpack_modules__ = ({
4
- "./packages/scramjet/packages/rpc/index.ts":
5
- /*!*************************************************!*\
6
- !*** ./packages/scramjet/packages/rpc/index.ts ***!
7
- \*************************************************/
8
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
9
- __webpack_require__.r(__webpack_exports__);
10
- __webpack_require__.d(__webpack_exports__, {
11
- RpcHelper: () => (RpcHelper)
12
- });
13
- class RpcHelper {
14
- methods;
15
- id;
16
- sendRaw;
17
- counter = 0;
18
- promiseCallbacks = new Map();
19
- constructor(methods, id, sendRaw){
20
- this.methods = methods;
21
- this.id = id;
22
- this.sendRaw = sendRaw;
23
- }
24
- recieve(data) {
25
- if (data === undefined || data === null || typeof data !== "object") return;
26
- const dt = data[this.id];
27
- if (dt === undefined || dt === null || typeof dt !== "object") return;
28
- const type = dt.$type;
29
- if (type === "response") {
30
- const token = dt.$token;
31
- const data = dt.$data;
32
- const error = dt.$error;
33
- const cb = this.promiseCallbacks.get(token);
34
- if (!cb) return;
35
- this.promiseCallbacks.delete(token);
36
- if (error !== undefined) {
37
- cb.reject(new Error(error));
38
- } else {
39
- cb.resolve(data);
40
- }
41
- } else if (type === "request") {
42
- const method = dt.$method;
43
- const args = dt.$args;
44
- this.methods[method](args).then((r)=>{
45
- this.sendRaw({
46
- [this.id]: {
47
- $type: "response",
48
- $token: dt.$token,
49
- $data: r?.[0]
50
- }
51
- }, r?.[1]);
52
- }).catch((err)=>{
53
- console.error(err);
54
- this.sendRaw({
55
- [this.id]: {
56
- $type: "response",
57
- $token: dt.$token,
58
- $error: err?.toString() || "Unknown error"
59
- }
60
- }, []);
61
- });
62
- }
63
- }
64
- call(method, args, transfer = []) {
65
- let token = this.counter++;
66
- return new Promise((resolve, reject)=>{
67
- this.promiseCallbacks.set(token, {
68
- resolve,
69
- reject
70
- });
71
- this.sendRaw({
72
- [this.id]: {
73
- $type: "request",
74
- $method: method,
75
- $args: args,
76
- $token: token
77
- }
78
- }, transfer);
79
- });
80
- }
81
- }
82
-
83
-
84
- }),
85
-
86
- });
87
- /************************************************************************/
88
- // The module cache
89
- var __webpack_module_cache__ = {};
90
-
91
- // The require function
92
- function __webpack_require__(moduleId) {
93
-
94
- // Check if module is in cache
95
- var cachedModule = __webpack_module_cache__[moduleId];
96
- if (cachedModule !== undefined) {
97
- return cachedModule.exports;
98
- }
99
- // Create a new module (and put it into the cache)
100
- var module = (__webpack_module_cache__[moduleId] = {
101
- exports: {}
102
- });
103
- // Execute the module function
104
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
105
-
106
- // Return the exports of the module
107
- return module.exports;
108
-
109
- }
110
-
111
- /************************************************************************/
112
- // webpack/runtime/define_property_getters
113
- (() => {
114
- __webpack_require__.d = (exports, definition) => {
115
- for(var key in definition) {
116
- if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
117
- Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
118
- }
119
- }
120
- };
121
- })();
122
- // webpack/runtime/has_own_property
123
- (() => {
124
- __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
125
- })();
126
- // webpack/runtime/make_namespace_object
127
- (() => {
128
- // define __esModule on exports
129
- __webpack_require__.r = (exports) => {
130
- if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
131
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
132
- }
133
- Object.defineProperty(exports, '__esModule', { value: true });
134
- };
135
- })();
136
- /************************************************************************/
137
- var __webpack_exports__ = {};
138
- // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
139
- (() => {
140
-
141
- /*!*************************************************************!*\
142
- !*** ./packages/scramjet/packages/controller/src/inject.ts ***!
143
- \*************************************************************/
144
- __webpack_require__.r(__webpack_exports__);
145
- __webpack_require__.d(__webpack_exports__, {
146
- load: () => (load)
147
- });
148
- /* ESM import */var _mercuryworkshop_rpc__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @mercuryworkshop/rpc */ "./packages/scramjet/packages/rpc/index.ts");
149
-
150
- const MessagePort_postMessage = MessagePort.prototype.postMessage;
151
- const postMessage = (port, data, transfer)=>{
152
- MessagePort_postMessage.call(port, data, transfer);
153
- };
154
- class RemoteTransport {
155
- port;
156
- readyResolve;
157
- readyPromise = new Promise((resolve)=>{
158
- this.readyResolve = resolve;
159
- });
160
- ready = false;
161
- async init() {
162
- await this.readyPromise;
163
- this.ready = true;
164
- }
165
- rpc;
166
- constructor(port){
167
- this.port = port;
168
- this.rpc = new _mercuryworkshop_rpc__WEBPACK_IMPORTED_MODULE_0__.RpcHelper({
169
- ready: async ()=>{
170
- this.readyResolve();
171
- }
172
- }, "transport", (data, transfer)=>{
173
- postMessage(port, data, transfer);
174
- });
175
- port.onmessageerror = (ev)=>{
176
- console.error("onmessageerror (this should never happen!)", ev);
177
- };
178
- port.onmessage = (ev)=>{
179
- this.rpc.recieve(ev.data);
180
- };
181
- port.start();
182
- }
183
- connect(url, protocols, requestHeaders, onopen, onmessage, onclose, onerror) {
184
- const channel = new MessageChannel();
185
- let port = channel.port1;
186
- console.warn("connecting");
187
- this.rpc.call("connect", {
188
- url: url.href,
189
- protocols,
190
- requestHeaders,
191
- port: channel.port2
192
- }, [
193
- channel.port2
194
- ]).then((response)=>{
195
- console.log(response);
196
- if (response.result === "success") {
197
- onopen(response.protocol, response.extensions);
198
- } else {
199
- onerror(response.error);
200
- }
201
- });
202
- port.onmessage = (ev)=>{
203
- const message = ev.data;
204
- if (message.type === "data") {
205
- onmessage(message.data);
206
- } else if (message.type === "close") {
207
- onclose(message.code, message.reason);
208
- }
209
- };
210
- port.onmessageerror = (ev)=>{
211
- console.error("onmessageerror (this should never happen!)", ev);
212
- onerror("Message error in transport port");
213
- };
214
- return [
215
- (data)=>{
216
- postMessage(port, {
217
- type: "data",
218
- data: data
219
- }, data instanceof ArrayBuffer ? [
220
- data
221
- ] : []);
222
- },
223
- (code)=>{
224
- postMessage(port, {
225
- type: "close",
226
- code: code
227
- });
228
- }
229
- ];
230
- }
231
- async request(remote, method, body, headers, signal) {
232
- return await this.rpc.call("request", {
233
- remote: remote.href,
234
- method,
235
- body,
236
- headers
237
- });
238
- }
239
- meta() {
240
- return {};
241
- }
242
- }
243
- const sw = navigator.serviceWorker.controller;
244
- const { SCRAMJETCLIENT, ScramjetClient, CookieJar, setWasm } = $scramjet;
245
- function load({ config, sjconfig, cookies, prefix, yieldGetInjectScripts, codecEncode, codecDecode }) {
246
- let client;
247
- if (SCRAMJETCLIENT in globalThis) {
248
- client = globalThis[SCRAMJETCLIENT];
249
- } else {
250
- setWasm(Uint8Array.from(atob(self.WASM), (c)=>c.charCodeAt(0)));
251
- delete self.WASM;
252
- const channel = new MessageChannel();
253
- const transport = new RemoteTransport(channel.port1);
254
- sw?.postMessage({
255
- $sw$initRemoteTransport: {
256
- port: channel.port2,
257
- prefix: prefix.href
258
- }
259
- }, [
260
- channel.port2
261
- ]);
262
- const cookieJar = new CookieJar();
263
- cookieJar.load(cookies);
264
- const context = {
265
- interface: {
266
- getInjectScripts: yieldGetInjectScripts(cookieJar, config, sjconfig, prefix),
267
- codecEncode,
268
- codecDecode
269
- },
270
- prefix,
271
- cookieJar,
272
- config: sjconfig
273
- };
274
- function createFrameId() {
275
- return `${Array(8).fill(0).map(()=>Math.floor(Math.random() * 36).toString(36)).join("")}`;
276
- }
277
- const frame = globalThis.frameElement;
278
- if (frame && !frame.name) {
279
- frame.name = createFrameId();
280
- }
281
- client = new ScramjetClient(globalThis, {
282
- context,
283
- transport,
284
- sendSetCookie: async (url, cookie)=>{
285
- // sw.postMessage({
286
- // $controller$setCookie: {
287
- // url,
288
- // cookie
289
- // }
290
- // });
291
- },
292
- shouldPassthroughWebsocket: (url)=>{
293
- return url === "wss://anura.pro/";
294
- },
295
- shouldBlockMessageEvent (i) {
296
- return false;
297
- }
298
- });
299
- client.hook();
300
- }
301
- }
302
-
303
- })();
304
-
305
- $scramjetController = __webpack_exports__;
306
- })()
307
- ;
1
+ var $scramjetController;(()=>{var e={470:function(e,r,t){t.d(r,{C:()=>o});class o{methods;id;sendRaw;counter=0;promiseCallbacks=new Map;constructor(e,r,t){this.methods=e,this.id=r,this.sendRaw=t}recieve(e){if(null==e||"object"!=typeof e)return;let r=e[this.id];if(null==r||"object"!=typeof r)return;let t=r.$type;if("response"===t){let e=r.$token,t=r.$data,o=r.$error,s=this.promiseCallbacks.get(e);if(!s)return;this.promiseCallbacks.delete(e),void 0!==o?s.reject(Error(o)):s.resolve(t)}else if("request"===t){let e=r.$method,t=r.$args;this.methods[e](t).then(e=>{this.sendRaw({[this.id]:{$type:"response",$token:r.$token,$data:e?.[0]}},e?.[1])}).catch(e=>{console.error(e),this.sendRaw({[this.id]:{$type:"response",$token:r.$token,$error:e?.toString()||"Unknown error"}},[])})}}call(e,r,t=[]){let o=this.counter++;return new Promise((s,a)=>{this.promiseCallbacks.set(o,{resolve:s,reject:a}),this.sendRaw({[this.id]:{$type:"request",$method:e,$args:r,$token:o}},t)})}}}},r={};function t(o){var s=r[o];if(void 0!==s)return s.exports;var a=r[o]={exports:{}};return e[o](a,a.exports,t),a.exports}t.d=(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{t.r(o),t.d(o,{load:()=>d});var e=t(470);let r=MessagePort.prototype.postMessage,s=(e,t,o)=>{r.call(e,t,o)};class a{port;readyResolve;readyPromise=new Promise(e=>{this.readyResolve=e});ready=!1;async init(){await this.readyPromise,this.ready=!0}rpc;constructor(r){this.port=r,this.rpc=new e.C({ready:async()=>{this.readyResolve()}},"transport",(e,t)=>{s(r,e,t)}),r.onmessageerror=e=>{console.error("onmessageerror (this should never happen!)",e)},r.onmessage=e=>{this.rpc.recieve(e.data)},r.start()}connect(e,r,t,o,a,n,l){let i=new MessageChannel,c=i.port1;return console.warn("connecting"),this.rpc.call("connect",{url:e.href,protocols:r,requestHeaders:t,port:i.port2},[i.port2]).then(e=>{console.log(e),"success"===e.result?o(e.protocol,e.extensions):l(e.error)}),c.onmessage=e=>{let r=e.data;"data"===r.type?a(r.data):"close"===r.type&&n(r.code,r.reason)},c.onmessageerror=e=>{console.error("onmessageerror (this should never happen!)",e),l("Message error in transport port")},[e=>{s(c,{type:"data",data:e},e instanceof ArrayBuffer?[e]:[])},e=>{s(c,{type:"close",code:e})}]}async request(e,r,t,o,s){return await this.rpc.call("request",{remote:e.href,method:r,body:t,headers:o})}meta(){return{}}}let n=navigator.serviceWorker.controller,{SCRAMJETCLIENT:l,ScramjetClient:i,CookieJar:c,setWasm:p}=$scramjet;function d({config:e,sjconfig:r,cookies:t,prefix:o,yieldGetInjectScripts:s,codecEncode:d,codecDecode:h}){if(l in globalThis)globalThis[l];else{p(Uint8Array.from(atob(self.WASM),e=>e.charCodeAt(0))),delete self.WASM;let l=new MessageChannel,u=new a(l.port1);n?.postMessage({$sw$initRemoteTransport:{port:l.port2,prefix:o.href}},[l.port2]);let m=new c;m.load(t);let y={interface:{getInjectScripts:s(m,e,r,o),codecEncode:d,codecDecode:h},prefix:o,cookieJar:m,config:r},f=globalThis.frameElement;f&&!f.name&&(f.name=`${Array(8).fill(0).map(()=>Math.floor(36*Math.random()).toString(36)).join("")}`),new i(globalThis,{context:y,transport:u,sendSetCookie:async(e,r)=>{},shouldPassthroughWebsocket:e=>"wss://anura.pro/"===e,shouldBlockMessageEvent:e=>!1}).hook()}}})(),$scramjetController=o})();
308
2
  //# sourceMappingURL=controller.inject.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"controller.inject.js","sources":["webpack://$scramjetController/./packages/scramjet/packages/rpc/index.ts","webpack://$scramjetController/webpack/runtime/define_property_getters","webpack://$scramjetController/webpack/runtime/has_own_property","webpack://$scramjetController/webpack/runtime/make_namespace_object","webpack://$scramjetController/./packages/scramjet/packages/controller/src/inject.ts"],"sourcesContent":["type Serverbound = {\n\tmethod1: [{ paramA: string; paramB: number }, boolean];\n\tmethod2: [string, number];\n};\n\ntype Clientbound = {\n\tmethod1: [number];\n\tmethod2: [boolean, string];\n};\n\nexport type RpcDescription = {\n\t[method: string]: [args: any, returnType: any] | [args: any] | [];\n};\n\nexport type MethodsDefinition<Description extends RpcDescription> = {\n\t[Method in keyof Description]: (\n\t\t...args: Description[Method] extends [infer A, ...any[]] ? [A] : []\n\t) => Description[Method] extends [any, infer R]\n\t\t? Promise<[R, Transferable[]]>\n\t\t: Promise<void>;\n};\n\nexport class RpcHelper<\n\tLocal extends RpcDescription,\n\tRemote extends RpcDescription,\n> {\n\tcounter: number = 0;\n\tpromiseCallbacks: Map<\n\t\tnumber,\n\t\t{ resolve: (value: any) => void; reject: (reason?: any) => void }\n\t> = new Map();\n\tconstructor(\n\t\tprivate methods: MethodsDefinition<Local>,\n\t\tprivate id: string,\n\t\tprivate sendRaw: (data: any, transfer: Transferable[]) => void\n\t) {}\n\n\trecieve(data: any) {\n\t\tif (data === undefined || data === null || typeof data !== \"object\") return;\n\t\tconst dt = data[this.id];\n\t\tif (dt === undefined || dt === null || typeof dt !== \"object\") return;\n\n\t\tconst type = dt.$type;\n\n\t\tif (type === \"response\") {\n\t\t\tconst token = dt.$token;\n\t\t\tconst data = dt.$data;\n\t\t\tconst error = dt.$error;\n\t\t\tconst cb = this.promiseCallbacks.get(token);\n\t\t\tif (!cb) return;\n\t\t\tthis.promiseCallbacks.delete(token);\n\t\t\tif (error !== undefined) {\n\t\t\t\tcb.reject(new Error(error));\n\t\t\t} else {\n\t\t\t\tcb.resolve(data);\n\t\t\t}\n\t\t} else if (type === \"request\") {\n\t\t\tconst method = dt.$method as keyof Local;\n\t\t\tconst args = dt.$args as Local[typeof method][0];\n\t\t\t(this.methods[method] as any)(args)\n\t\t\t\t.then((r: any) => {\n\t\t\t\t\tthis.sendRaw(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[this.id]: {\n\t\t\t\t\t\t\t\t$type: \"response\",\n\t\t\t\t\t\t\t\t$token: dt.$token,\n\t\t\t\t\t\t\t\t$data: r?.[0],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tr?.[1]\n\t\t\t\t\t);\n\t\t\t\t})\n\t\t\t\t.catch((err: any) => {\n\t\t\t\t\tconsole.error(err);\n\t\t\t\t\tthis.sendRaw(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[this.id]: {\n\t\t\t\t\t\t\t\t$type: \"response\",\n\t\t\t\t\t\t\t\t$token: dt.$token,\n\t\t\t\t\t\t\t\t$error: err?.toString() || \"Unknown error\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[]\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t}\n\t}\n\n\tcall<Method extends keyof Remote>(\n\t\tmethod: Method,\n\t\targs: Remote[Method][0],\n\t\ttransfer: Transferable[] = []\n\t): Promise<Remote[Method][1]> {\n\t\tlet token = this.counter++;\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.promiseCallbacks.set(token, { resolve, reject });\n\t\t\tthis.sendRaw(\n\t\t\t\t{\n\t\t\t\t\t[this.id]: {\n\t\t\t\t\t\t$type: \"request\",\n\t\t\t\t\t\t$method: method,\n\t\t\t\t\t\t$args: args,\n\t\t\t\t\t\t$token: token,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\ttransfer\n\t\t\t);\n\t\t});\n\t}\n}\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { CookieJar, ScramjetConfig } from \"@mercuryworkshop/scramjet\";\nimport type * as ScramjetGlobal from \"@mercuryworkshop/scramjet\";\ndeclare const $scramjet: typeof ScramjetGlobal;\n\nimport type {\n\tRawHeaders,\n\tProxyTransport,\n\tTransferrableResponse,\n} from \"@mercuryworkshop/proxy-transports\";\n\nimport { RpcHelper } from \"@mercuryworkshop/rpc\";\nimport type {\n\tControllerToTransport,\n\tTransportToController,\n\tWebSocketData,\n\tWebSocketMessage,\n} from \"./types\";\n\nconst MessagePort_postMessage = MessagePort.prototype.postMessage;\nconst postMessage = (\n\tport: MessagePort,\n\tdata: any,\n\ttransfer?: Transferable[]\n) => {\n\tMessagePort_postMessage.call(port, data, transfer as any);\n};\n\nclass RemoteTransport implements ProxyTransport {\n\tprivate readyResolve!: () => void;\n\tprivate readyPromise: Promise<void> = new Promise((resolve) => {\n\t\tthis.readyResolve = resolve;\n\t});\n\n\tpublic ready = false;\n\tasync init() {\n\t\tawait this.readyPromise;\n\t\tthis.ready = true;\n\t}\n\n\tprivate rpc: RpcHelper<ControllerToTransport, TransportToController>;\n\tconstructor(public port: MessagePort) {\n\t\tthis.rpc = new RpcHelper<ControllerToTransport, TransportToController>(\n\t\t\t{\n\t\t\t\tready: async () => {\n\t\t\t\t\tthis.readyResolve();\n\t\t\t\t},\n\t\t\t},\n\t\t\t\"transport\",\n\t\t\t(data, transfer) => {\n\t\t\t\tpostMessage(port, data, transfer);\n\t\t\t}\n\t\t);\n\t\tport.onmessageerror = (ev) => {\n\t\t\tconsole.error(\"onmessageerror (this should never happen!)\", ev);\n\t\t};\n\t\tport.onmessage = (ev) => {\n\t\t\tthis.rpc.recieve(ev.data);\n\t\t};\n\t\tport.start();\n\t}\n\tconnect(\n\t\turl: URL,\n\t\tprotocols: string[],\n\t\trequestHeaders: RawHeaders,\n\t\tonopen: (protocol: string, extensions: string) => void,\n\t\tonmessage: (data: Blob | ArrayBuffer | string) => void,\n\t\tonclose: (code: number, reason: string) => void,\n\t\tonerror: (error: string) => void\n\t): [\n\t\t(data: Blob | ArrayBuffer | string) => void,\n\t\t(code: number, reason: string) => void,\n\t] {\n\t\tconst channel = new MessageChannel();\n\t\tlet port = channel.port1;\n\t\tconsole.warn(\"connecting\");\n\t\tthis.rpc\n\t\t\t.call(\n\t\t\t\t\"connect\",\n\t\t\t\t{\n\t\t\t\t\turl: url.href,\n\t\t\t\t\tprotocols,\n\t\t\t\t\trequestHeaders,\n\t\t\t\t\tport: channel.port2,\n\t\t\t\t},\n\t\t\t\t[channel.port2]\n\t\t\t)\n\t\t\t.then((response) => {\n\t\t\t\tconsole.log(response);\n\t\t\t\tif (response.result === \"success\") {\n\t\t\t\t\tonopen(response.protocol, response.extensions);\n\t\t\t\t} else {\n\t\t\t\t\tonerror(response.error);\n\t\t\t\t}\n\t\t\t});\n\t\tport.onmessage = (ev) => {\n\t\t\tconst message = ev.data as WebSocketMessage;\n\t\t\tif (message.type === \"data\") {\n\t\t\t\tonmessage(message.data);\n\t\t\t} else if (message.type === \"close\") {\n\t\t\t\tonclose(message.code, message.reason);\n\t\t\t}\n\t\t};\n\t\tport.onmessageerror = (ev) => {\n\t\t\tconsole.error(\"onmessageerror (this should never happen!)\", ev);\n\t\t\tonerror(\"Message error in transport port\");\n\t\t};\n\n\t\treturn [\n\t\t\t(data) => {\n\t\t\t\tpostMessage(\n\t\t\t\t\tport,\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"data\",\n\t\t\t\t\t\tdata: data,\n\t\t\t\t\t},\n\t\t\t\t\tdata instanceof ArrayBuffer ? [data] : []\n\t\t\t\t);\n\t\t\t},\n\t\t\t(code) => {\n\t\t\t\tpostMessage(port, {\n\t\t\t\t\ttype: \"close\",\n\t\t\t\t\tcode: code,\n\t\t\t\t});\n\t\t\t},\n\t\t];\n\t}\n\n\tasync request(\n\t\tremote: URL,\n\t\tmethod: string,\n\t\tbody: BodyInit | null,\n\t\theaders: RawHeaders,\n\t\tsignal: AbortSignal | undefined\n\t): Promise<TransferrableResponse> {\n\t\treturn await this.rpc.call(\"request\", {\n\t\t\tremote: remote.href,\n\t\t\tmethod,\n\t\t\tbody,\n\t\t\theaders,\n\t\t});\n\t}\n\n\tmeta() {\n\t\treturn {};\n\t}\n}\n\nconst sw = navigator.serviceWorker.controller;\nconst { SCRAMJETCLIENT, ScramjetClient, CookieJar, setWasm } = $scramjet;\n\ntype Config = any;\ntype Init = {\n\tconfig: Config;\n\tsjconfig: ScramjetConfig;\n\tcookies: string;\n\tprefix: URL;\n\tyieldGetInjectScripts: (\n\t\tcookieJar: CookieJar,\n\t\tconfig: Config,\n\t\tsjconfig: ScramjetConfig,\n\t\tprefix: URL\n\t) => any;\n\tcodecEncode: (input: string) => string;\n\tcodecDecode: (input: string) => string;\n};\n\nexport function load({\n\tconfig,\n\tsjconfig,\n\tcookies,\n\tprefix,\n\tyieldGetInjectScripts,\n\tcodecEncode,\n\tcodecDecode,\n}: Init) {\n\tlet client;\n\tif (SCRAMJETCLIENT in globalThis) {\n\t\tclient = globalThis[SCRAMJETCLIENT];\n\t} else {\n\t\tsetWasm(Uint8Array.from(atob(self.WASM), (c) => c.charCodeAt(0)));\n\t\tdelete self.WASM;\n\n\t\tconst channel = new MessageChannel();\n\t\tconst transport = new RemoteTransport(channel.port1);\n\t\tsw?.postMessage(\n\t\t\t{\n\t\t\t\t$sw$initRemoteTransport: {\n\t\t\t\t\tport: channel.port2,\n\t\t\t\t\tprefix: prefix.href,\n\t\t\t\t},\n\t\t\t},\n\t\t\t[channel.port2]\n\t\t);\n\n\t\tconst cookieJar = new CookieJar();\n\t\tcookieJar.load(cookies);\n\n\t\tconst context = {\n\t\t\tinterface: {\n\t\t\t\tgetInjectScripts: yieldGetInjectScripts(\n\t\t\t\t\tcookieJar,\n\t\t\t\t\tconfig,\n\t\t\t\t\tsjconfig,\n\t\t\t\t\tprefix\n\t\t\t\t),\n\t\t\t\tcodecEncode,\n\t\t\t\tcodecDecode,\n\t\t\t},\n\t\t\tprefix,\n\t\t\tcookieJar,\n\t\t\tconfig: sjconfig,\n\t\t};\n\t\tfunction createFrameId() {\n\t\t\treturn `${Array(8)\n\t\t\t\t.fill(0)\n\t\t\t\t.map(() => Math.floor(Math.random() * 36).toString(36))\n\t\t\t\t.join(\"\")}`;\n\t\t}\n\n\t\tconst frame = globalThis.frameElement as HTMLIFrameElement | null;\n\t\tif (frame && !frame.name) {\n\t\t\tframe.name = createFrameId();\n\t\t}\n\n\t\tclient = new ScramjetClient(globalThis, {\n\t\t\tcontext,\n\t\t\ttransport,\n\t\t\tsendSetCookie: async (url, cookie) => {\n\t\t\t\t// sw.postMessage({\n\t\t\t\t// \t$controller$setCookie: {\n\t\t\t\t// \t\turl,\n\t\t\t\t// \t\tcookie\n\t\t\t\t// \t}\n\t\t\t\t// });\n\t\t\t},\n\t\t\tshouldPassthroughWebsocket: (url) => {\n\t\t\t\treturn url === \"wss://anura.pro/\";\n\t\t\t},\n\t\t\tshouldBlockMessageEvent(i) {\n\t\t\t\treturn false;\n\t\t\t},\n\t\t});\n\n\t\tclient.hook();\n\t}\n}\n"],"names":["RpcHelper","Map","methods","id","sendRaw","data","undefined","dt","type","token","error","cb","Error","method","args","r","err","console","transfer","Promise","resolve","reject","MessagePort_postMessage","MessagePort","postMessage","port","RemoteTransport","ev","url","protocols","requestHeaders","onopen","onmessage","onclose","onerror","channel","MessageChannel","response","message","ArrayBuffer","code","remote","body","headers","signal","sw","navigator","SCRAMJETCLIENT","ScramjetClient","CookieJar","setWasm","$scramjet","load","config","sjconfig","cookies","prefix","yieldGetInjectScripts","codecEncode","codecDecode","client","globalThis","Uint8Array","atob","self","c","transport","cookieJar","context","createFrameId","Array","Math","frame","cookie","i"],"mappings":";;;;;;;;;;;;AAsBO,MAAMA;;;;IAIZ,UAAkB,EAAE;IACpB,mBAGI,IAAIC,MAAM;IACd,YACSC,OAAiC,EACjCC,EAAU,EACVC,OAAsD,CAC7D;aAHOF,UAAAA;aACAC,KAAAA;aACAC,UAAAA;IACN;IAEH,QAAQC,IAAS,EAAE;QAClB,IAAIA,SAASC,aAAaD,SAAS,QAAQ,OAAOA,SAAS,UAAU;QACrE,MAAME,KAAKF,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,IAAIE,OAAOD,aAAaC,OAAO,QAAQ,OAAOA,OAAO,UAAU;QAE/D,MAAMC,OAAOD,GAAG,KAAK;QAErB,IAAIC,SAAS,YAAY;YACxB,MAAMC,QAAQF,GAAG,MAAM;YACvB,MAAMF,OAAOE,GAAG,KAAK;YACrB,MAAMG,QAAQH,GAAG,MAAM;YACvB,MAAMI,KAAK,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAACF;YACrC,IAAI,CAACE,IAAI;YACT,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAACF;YAC7B,IAAIC,UAAUJ,WAAW;gBACxBK,GAAG,MAAM,CAAC,IAAIC,MAAMF;YACrB,OAAO;gBACNC,GAAG,OAAO,CAACN;YACZ;QACD,OAAO,IAAIG,SAAS,WAAW;YAC9B,MAAMK,SAASN,GAAG,OAAO;YACzB,MAAMO,OAAOP,GAAG,KAAK;YACpB,IAAI,CAAC,OAAO,CAACM,OAAO,CAASC,MAC5B,IAAI,CAAC,CAACC;gBACN,IAAI,CAAC,OAAO,CACX;oBACC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;wBACV,OAAO;wBACP,QAAQR,GAAG,MAAM;wBACjB,OAAOQ,GAAG,CAAC,EAAE;oBACd;gBACD,GACAA,GAAG,CAAC,EAAE;YAER,GACC,KAAK,CAAC,CA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GACd,IAAI,CAAC,GACL,GAAG,CAAC,IAAMC,KAAK,KAAK,CAACA,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,KAClD,IAAI,CAAC,KAAK;QACb;QAEA,MAAMC,QAAQX,WAAW,YAAY;QACrC,IAAIW,SAAS,CAACA,MAAM,IAAI,EAAE;YACzBA,MAAM,IAAI,GAAGH;QACd;QAEAT,SAAS,IAAIZ,eAAea,YAAY;YACvCO;YACAF;YACA,eAAe,OAAOtC,KAAK6C;YAC1B,mBAAmB;YACnB,4BAA4B;YAC5B,SAAS;YACT,WAAW;YACX,KAAK;YACL,MAAM;YACP;YACA,4BAA4B,CAAC7C;gBAC5B,OAAOA,QAAQ;YAChB;YACA,yBAAwB8C,CAAC;gBACxB,OAAO;YACR;QACD;QAEAd,OAAO,IAAI;IACZ;AACD"}
1
+ {"version":3,"file":"controller.inject.js","sources":["webpack://$scramjetController/./packages/rpc/index.ts","webpack://$scramjetController/webpack/runtime/define_property_getters","webpack://$scramjetController/webpack/runtime/has_own_property","webpack://$scramjetController/webpack/runtime/make_namespace_object","webpack://$scramjetController/./packages/controller/src/inject.ts"],"sourcesContent":["type Serverbound = {\n\tmethod1: [{ paramA: string; paramB: number }, boolean];\n\tmethod2: [string, number];\n};\n\ntype Clientbound = {\n\tmethod1: [number];\n\tmethod2: [boolean, string];\n};\n\nexport type RpcDescription = {\n\t[method: string]: [args: any, returnType: any] | [args: any] | [];\n};\n\nexport type MethodsDefinition<Description extends RpcDescription> = {\n\t[Method in keyof Description]: (\n\t\t...args: Description[Method] extends [infer A, ...any[]] ? [A] : []\n\t) => Description[Method] extends [any, infer R]\n\t\t? Promise<[R, Transferable[]]>\n\t\t: Promise<void>;\n};\n\nexport class RpcHelper<\n\tLocal extends RpcDescription,\n\tRemote extends RpcDescription,\n> {\n\tcounter: number = 0;\n\tpromiseCallbacks: Map<\n\t\tnumber,\n\t\t{ resolve: (value: any) => void; reject: (reason?: any) => void }\n\t> = new Map();\n\tconstructor(\n\t\tprivate methods: MethodsDefinition<Local>,\n\t\tprivate id: string,\n\t\tprivate sendRaw: (data: any, transfer: Transferable[]) => void\n\t) {}\n\n\trecieve(data: any) {\n\t\tif (data === undefined || data === null || typeof data !== \"object\") return;\n\t\tconst dt = data[this.id];\n\t\tif (dt === undefined || dt === null || typeof dt !== \"object\") return;\n\n\t\tconst type = dt.$type;\n\n\t\tif (type === \"response\") {\n\t\t\tconst token = dt.$token;\n\t\t\tconst data = dt.$data;\n\t\t\tconst error = dt.$error;\n\t\t\tconst cb = this.promiseCallbacks.get(token);\n\t\t\tif (!cb) return;\n\t\t\tthis.promiseCallbacks.delete(token);\n\t\t\tif (error !== undefined) {\n\t\t\t\tcb.reject(new Error(error));\n\t\t\t} else {\n\t\t\t\tcb.resolve(data);\n\t\t\t}\n\t\t} else if (type === \"request\") {\n\t\t\tconst method = dt.$method as keyof Local;\n\t\t\tconst args = dt.$args as Local[typeof method][0];\n\t\t\t(this.methods[method] as any)(args)\n\t\t\t\t.then((r: any) => {\n\t\t\t\t\tthis.sendRaw(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[this.id]: {\n\t\t\t\t\t\t\t\t$type: \"response\",\n\t\t\t\t\t\t\t\t$token: dt.$token,\n\t\t\t\t\t\t\t\t$data: r?.[0],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tr?.[1]\n\t\t\t\t\t);\n\t\t\t\t})\n\t\t\t\t.catch((err: any) => {\n\t\t\t\t\tconsole.error(err);\n\t\t\t\t\tthis.sendRaw(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[this.id]: {\n\t\t\t\t\t\t\t\t$type: \"response\",\n\t\t\t\t\t\t\t\t$token: dt.$token,\n\t\t\t\t\t\t\t\t$error: err?.toString() || \"Unknown error\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[]\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t}\n\t}\n\n\tcall<Method extends keyof Remote>(\n\t\tmethod: Method,\n\t\targs: Remote[Method][0],\n\t\ttransfer: Transferable[] = []\n\t): Promise<Remote[Method][1]> {\n\t\tlet token = this.counter++;\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.promiseCallbacks.set(token, { resolve, reject });\n\t\t\tthis.sendRaw(\n\t\t\t\t{\n\t\t\t\t\t[this.id]: {\n\t\t\t\t\t\t$type: \"request\",\n\t\t\t\t\t\t$method: method,\n\t\t\t\t\t\t$args: args,\n\t\t\t\t\t\t$token: token,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\ttransfer\n\t\t\t);\n\t\t});\n\t}\n}\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { CookieJar, ScramjetConfig } from \"@mercuryworkshop/scramjet\";\nimport type * as ScramjetGlobal from \"@mercuryworkshop/scramjet\";\ndeclare const $scramjet: typeof ScramjetGlobal;\n\nimport type {\n\tRawHeaders,\n\tProxyTransport,\n\tTransferrableResponse,\n} from \"@mercuryworkshop/proxy-transports\";\n\nimport { RpcHelper } from \"@mercuryworkshop/rpc\";\nimport type {\n\tControllerToTransport,\n\tTransportToController,\n\tWebSocketData,\n\tWebSocketMessage,\n} from \"./types\";\n\nconst MessagePort_postMessage = MessagePort.prototype.postMessage;\nconst postMessage = (\n\tport: MessagePort,\n\tdata: any,\n\ttransfer?: Transferable[]\n) => {\n\tMessagePort_postMessage.call(port, data, transfer as any);\n};\n\nclass RemoteTransport implements ProxyTransport {\n\tprivate readyResolve!: () => void;\n\tprivate readyPromise: Promise<void> = new Promise((resolve) => {\n\t\tthis.readyResolve = resolve;\n\t});\n\n\tpublic ready = false;\n\tasync init() {\n\t\tawait this.readyPromise;\n\t\tthis.ready = true;\n\t}\n\n\tprivate rpc: RpcHelper<ControllerToTransport, TransportToController>;\n\tconstructor(public port: MessagePort) {\n\t\tthis.rpc = new RpcHelper<ControllerToTransport, TransportToController>(\n\t\t\t{\n\t\t\t\tready: async () => {\n\t\t\t\t\tthis.readyResolve();\n\t\t\t\t},\n\t\t\t},\n\t\t\t\"transport\",\n\t\t\t(data, transfer) => {\n\t\t\t\tpostMessage(port, data, transfer);\n\t\t\t}\n\t\t);\n\t\tport.onmessageerror = (ev) => {\n\t\t\tconsole.error(\"onmessageerror (this should never happen!)\", ev);\n\t\t};\n\t\tport.onmessage = (ev) => {\n\t\t\tthis.rpc.recieve(ev.data);\n\t\t};\n\t\tport.start();\n\t}\n\tconnect(\n\t\turl: URL,\n\t\tprotocols: string[],\n\t\trequestHeaders: RawHeaders,\n\t\tonopen: (protocol: string, extensions: string) => void,\n\t\tonmessage: (data: Blob | ArrayBuffer | string) => void,\n\t\tonclose: (code: number, reason: string) => void,\n\t\tonerror: (error: string) => void\n\t): [\n\t\t(data: Blob | ArrayBuffer | string) => void,\n\t\t(code: number, reason: string) => void,\n\t] {\n\t\tconst channel = new MessageChannel();\n\t\tlet port = channel.port1;\n\t\tconsole.warn(\"connecting\");\n\t\tthis.rpc\n\t\t\t.call(\n\t\t\t\t\"connect\",\n\t\t\t\t{\n\t\t\t\t\turl: url.href,\n\t\t\t\t\tprotocols,\n\t\t\t\t\trequestHeaders,\n\t\t\t\t\tport: channel.port2,\n\t\t\t\t},\n\t\t\t\t[channel.port2]\n\t\t\t)\n\t\t\t.then((response) => {\n\t\t\t\tconsole.log(response);\n\t\t\t\tif (response.result === \"success\") {\n\t\t\t\t\tonopen(response.protocol, response.extensions);\n\t\t\t\t} else {\n\t\t\t\t\tonerror(response.error);\n\t\t\t\t}\n\t\t\t});\n\t\tport.onmessage = (ev) => {\n\t\t\tconst message = ev.data as WebSocketMessage;\n\t\t\tif (message.type === \"data\") {\n\t\t\t\tonmessage(message.data);\n\t\t\t} else if (message.type === \"close\") {\n\t\t\t\tonclose(message.code, message.reason);\n\t\t\t}\n\t\t};\n\t\tport.onmessageerror = (ev) => {\n\t\t\tconsole.error(\"onmessageerror (this should never happen!)\", ev);\n\t\t\tonerror(\"Message error in transport port\");\n\t\t};\n\n\t\treturn [\n\t\t\t(data) => {\n\t\t\t\tpostMessage(\n\t\t\t\t\tport,\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"data\",\n\t\t\t\t\t\tdata: data,\n\t\t\t\t\t},\n\t\t\t\t\tdata instanceof ArrayBuffer ? [data] : []\n\t\t\t\t);\n\t\t\t},\n\t\t\t(code) => {\n\t\t\t\tpostMessage(port, {\n\t\t\t\t\ttype: \"close\",\n\t\t\t\t\tcode: code,\n\t\t\t\t});\n\t\t\t},\n\t\t];\n\t}\n\n\tasync request(\n\t\tremote: URL,\n\t\tmethod: string,\n\t\tbody: BodyInit | null,\n\t\theaders: RawHeaders,\n\t\tsignal: AbortSignal | undefined\n\t): Promise<TransferrableResponse> {\n\t\treturn await this.rpc.call(\"request\", {\n\t\t\tremote: remote.href,\n\t\t\tmethod,\n\t\t\tbody,\n\t\t\theaders,\n\t\t});\n\t}\n\n\tmeta() {\n\t\treturn {};\n\t}\n}\n\nconst sw = navigator.serviceWorker.controller;\nconst { SCRAMJETCLIENT, ScramjetClient, CookieJar, setWasm } = $scramjet;\n\ntype Config = any;\ntype Init = {\n\tconfig: Config;\n\tsjconfig: ScramjetConfig;\n\tcookies: string;\n\tprefix: URL;\n\tyieldGetInjectScripts: (\n\t\tcookieJar: CookieJar,\n\t\tconfig: Config,\n\t\tsjconfig: ScramjetConfig,\n\t\tprefix: URL\n\t) => any;\n\tcodecEncode: (input: string) => string;\n\tcodecDecode: (input: string) => string;\n};\n\nexport function load({\n\tconfig,\n\tsjconfig,\n\tcookies,\n\tprefix,\n\tyieldGetInjectScripts,\n\tcodecEncode,\n\tcodecDecode,\n}: Init) {\n\tlet client;\n\tif (SCRAMJETCLIENT in globalThis) {\n\t\tclient = globalThis[SCRAMJETCLIENT];\n\t} else {\n\t\tsetWasm(Uint8Array.from(atob(self.WASM), (c) => c.charCodeAt(0)));\n\t\tdelete self.WASM;\n\n\t\tconst channel = new MessageChannel();\n\t\tconst transport = new RemoteTransport(channel.port1);\n\t\tsw?.postMessage(\n\t\t\t{\n\t\t\t\t$sw$initRemoteTransport: {\n\t\t\t\t\tport: channel.port2,\n\t\t\t\t\tprefix: prefix.href,\n\t\t\t\t},\n\t\t\t},\n\t\t\t[channel.port2]\n\t\t);\n\n\t\tconst cookieJar = new CookieJar();\n\t\tcookieJar.load(cookies);\n\n\t\tconst context = {\n\t\t\tinterface: {\n\t\t\t\tgetInjectScripts: yieldGetInjectScripts(\n\t\t\t\t\tcookieJar,\n\t\t\t\t\tconfig,\n\t\t\t\t\tsjconfig,\n\t\t\t\t\tprefix\n\t\t\t\t),\n\t\t\t\tcodecEncode,\n\t\t\t\tcodecDecode,\n\t\t\t},\n\t\t\tprefix,\n\t\t\tcookieJar,\n\t\t\tconfig: sjconfig,\n\t\t};\n\t\tfunction createFrameId() {\n\t\t\treturn `${Array(8)\n\t\t\t\t.fill(0)\n\t\t\t\t.map(() => Math.floor(Math.random() * 36).toString(36))\n\t\t\t\t.join(\"\")}`;\n\t\t}\n\n\t\tconst frame = globalThis.frameElement as HTMLIFrameElement | null;\n\t\tif (frame && !frame.name) {\n\t\t\tframe.name = createFrameId();\n\t\t}\n\n\t\tclient = new ScramjetClient(globalThis, {\n\t\t\tcontext,\n\t\t\ttransport,\n\t\t\tsendSetCookie: async (url, cookie) => {\n\t\t\t\t// sw.postMessage({\n\t\t\t\t// \t$controller$setCookie: {\n\t\t\t\t// \t\turl,\n\t\t\t\t// \t\tcookie\n\t\t\t\t// \t}\n\t\t\t\t// });\n\t\t\t},\n\t\t\tshouldPassthroughWebsocket: (url) => {\n\t\t\t\treturn url === \"wss://anura.pro/\";\n\t\t\t},\n\t\t\tshouldBlockMessageEvent(i) {\n\t\t\t\treturn false;\n\t\t\t},\n\t\t});\n\n\t\tclient.hook();\n\t}\n}\n"],"names":["RpcHelper","Map","methods","id","sendRaw","data","dt","type","token","error","cb","undefined","Error","method","args","r","err","console","transfer","Promise","resolve","reject","e","Object","Symbol","MessagePort_postMessage","MessagePort","postMessage","port","RemoteTransport","ev","url","protocols","requestHeaders","onopen","onmessage","onclose","onerror","channel","MessageChannel","response","message","ArrayBuffer","code","remote","body","headers","signal","sw","navigator","SCRAMJETCLIENT","ScramjetClient","CookieJar","setWasm","$scramjet","load","config","sjconfig","cookies","prefix","yieldGetInjectScripts","codecEncode","codecDecode","globalThis","Uint8Array","atob","self","c","transport","cookieJar","context","frame","Array","Math","client","cookie","i"],"mappings":"yEAsBO,OAAMA,E,kBAIZ,SAAkB,CAAE,AACpB,kBAGI,IAAIC,GAAM,AACd,aACSC,CAAiC,CACjCC,CAAU,CACVC,CAAsD,CAC7D,C,KAHOF,OAAO,CAAPA,E,KACAC,EAAE,CAAFA,E,KACAC,OAAO,CAAPA,CACN,CAEH,QAAQC,CAAS,CAAE,CAClB,GAAIA,MAAAA,GAAuC,AAAgB,UAAhB,OAAOA,EAAmB,OACrE,IAAMC,EAAKD,CAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CACxB,GAAIC,MAAAA,GAAmC,AAAc,UAAd,OAAOA,EAAiB,OAE/D,IAAMC,EAAOD,EAAG,KAAK,CAErB,GAAIC,AAAS,aAATA,EAAqB,CACxB,IAAMC,EAAQF,EAAG,MAAM,CACjBD,EAAOC,EAAG,KAAK,CACfG,EAAQH,EAAG,MAAM,CACjBI,EAAK,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAACF,GACrC,GAAI,CAACE,EAAI,OACT,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAACF,GACz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1,2 @@
1
- var $scramjetController;
2
- (() => { // webpackBootstrap
3
- var __webpack_modules__ = ({
4
- "./packages/scramjet/packages/rpc/index.ts":
5
- /*!*************************************************!*\
6
- !*** ./packages/scramjet/packages/rpc/index.ts ***!
7
- \*************************************************/
8
- (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
9
- __webpack_require__.r(__webpack_exports__);
10
- __webpack_require__.d(__webpack_exports__, {
11
- RpcHelper: () => (RpcHelper)
12
- });
13
- class RpcHelper {
14
- methods;
15
- id;
16
- sendRaw;
17
- counter = 0;
18
- promiseCallbacks = new Map();
19
- constructor(methods, id, sendRaw){
20
- this.methods = methods;
21
- this.id = id;
22
- this.sendRaw = sendRaw;
23
- }
24
- recieve(data) {
25
- if (data === undefined || data === null || typeof data !== "object") return;
26
- const dt = data[this.id];
27
- if (dt === undefined || dt === null || typeof dt !== "object") return;
28
- const type = dt.$type;
29
- if (type === "response") {
30
- const token = dt.$token;
31
- const data = dt.$data;
32
- const error = dt.$error;
33
- const cb = this.promiseCallbacks.get(token);
34
- if (!cb) return;
35
- this.promiseCallbacks.delete(token);
36
- if (error !== undefined) {
37
- cb.reject(new Error(error));
38
- } else {
39
- cb.resolve(data);
40
- }
41
- } else if (type === "request") {
42
- const method = dt.$method;
43
- const args = dt.$args;
44
- this.methods[method](args).then((r)=>{
45
- this.sendRaw({
46
- [this.id]: {
47
- $type: "response",
48
- $token: dt.$token,
49
- $data: r?.[0]
50
- }
51
- }, r?.[1]);
52
- }).catch((err)=>{
53
- console.error(err);
54
- this.sendRaw({
55
- [this.id]: {
56
- $type: "response",
57
- $token: dt.$token,
58
- $error: err?.toString() || "Unknown error"
59
- }
60
- }, []);
61
- });
62
- }
63
- }
64
- call(method, args, transfer = []) {
65
- let token = this.counter++;
66
- return new Promise((resolve, reject)=>{
67
- this.promiseCallbacks.set(token, {
68
- resolve,
69
- reject
70
- });
71
- this.sendRaw({
72
- [this.id]: {
73
- $type: "request",
74
- $method: method,
75
- $args: args,
76
- $token: token
77
- }
78
- }, transfer);
79
- });
80
- }
81
- }
82
-
83
-
84
- }),
85
-
86
- });
87
- /************************************************************************/
88
- // The module cache
89
- var __webpack_module_cache__ = {};
90
-
91
- // The require function
92
- function __webpack_require__(moduleId) {
93
-
94
- // Check if module is in cache
95
- var cachedModule = __webpack_module_cache__[moduleId];
96
- if (cachedModule !== undefined) {
97
- return cachedModule.exports;
98
- }
99
- // Create a new module (and put it into the cache)
100
- var module = (__webpack_module_cache__[moduleId] = {
101
- exports: {}
102
- });
103
- // Execute the module function
104
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
105
-
106
- // Return the exports of the module
107
- return module.exports;
108
-
109
- }
110
-
111
- /************************************************************************/
112
- // webpack/runtime/define_property_getters
113
- (() => {
114
- __webpack_require__.d = (exports, definition) => {
115
- for(var key in definition) {
116
- if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
117
- Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
118
- }
119
- }
120
- };
121
- })();
122
- // webpack/runtime/has_own_property
123
- (() => {
124
- __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
125
- })();
126
- // webpack/runtime/make_namespace_object
127
- (() => {
128
- // define __esModule on exports
129
- __webpack_require__.r = (exports) => {
130
- if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
131
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
132
- }
133
- Object.defineProperty(exports, '__esModule', { value: true });
134
- };
135
- })();
136
- /************************************************************************/
137
- var __webpack_exports__ = {};
138
- // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
139
- (() => {
140
-
141
- /*!*********************************************************!*\
142
- !*** ./packages/scramjet/packages/controller/src/sw.ts ***!
143
- \*********************************************************/
144
- __webpack_require__.r(__webpack_exports__);
145
- __webpack_require__.d(__webpack_exports__, {
146
- route: () => (route),
147
- shouldRoute: () => (shouldRoute)
148
- });
149
- /* ESM import */var _mercuryworkshop_rpc__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @mercuryworkshop/rpc */ "./packages/scramjet/packages/rpc/index.ts");
150
-
151
- function makeId() {
152
- return Math.random().toString(36).substring(2, 10);
153
- }
154
- let cookieResolvers = {};
155
- addEventListener("message", (e)=>{
156
- if (!e.data) return;
157
- if (typeof e.data != "object") return;
158
- if (e.data.$sw$setCookieDone && typeof e.data.$sw$setCookieDone == "object") {
159
- const done = e.data.$sw$setCookieDone;
160
- const resolver = cookieResolvers[done.id];
161
- if (resolver) {
162
- resolver();
163
- delete cookieResolvers[done.id];
164
- }
165
- }
166
- if (e.data.$sw$initRemoteTransport && typeof e.data.$sw$initRemoteTransport == "object") {
167
- const { port, prefix } = e.data.$sw$initRemoteTransport;
168
- console.error(prefix, tabs);
169
- const relevantcontroller = tabs.find((tab)=>new URL(prefix).pathname.startsWith(tab.prefix));
170
- if (!relevantcontroller) {
171
- console.error("No relevant controller found for transport init");
172
- return;
173
- }
174
- relevantcontroller.rpc.call("initRemoteTransport", port, [
175
- port
176
- ]);
177
- }
178
- });
179
- class ControllerReference {
180
- prefix;
181
- id;
182
- rpc;
183
- constructor(prefix, id, port){
184
- this.prefix = prefix;
185
- this.id = id;
186
- this.rpc = new _mercuryworkshop_rpc__WEBPACK_IMPORTED_MODULE_0__.RpcHelper({
187
- sendSetCookie: async ({ url, cookie })=>{
188
- let clients1 = await self.clients.matchAll();
189
- let promises = [];
190
- for (const client of clients1){
191
- let id = makeId();
192
- client.postMessage({
193
- $controller$setCookie: {
194
- url,
195
- cookie,
196
- id
197
- }
198
- });
199
- promises.push(new Promise((resolve)=>{
200
- cookieResolvers[id] = resolve;
201
- }));
202
- }
203
- await Promise.race([
204
- new Promise((resolve)=>setTimeout(()=>{
205
- console.error("timed out waiting for set cookie response (deadlock?)");
206
- resolve();
207
- }, 1000)),
208
- promises
209
- ]);
210
- }
211
- }, "tabchannel-" + id, (data, transfer)=>{
212
- port.postMessage(data, transfer);
213
- });
214
- port.addEventListener("message", (e)=>{
215
- this.rpc.recieve(e.data);
216
- });
217
- port.onmessageerror = console.error;
218
- this.rpc.call("ready", null);
219
- }
220
- }
221
- const tabs = [];
222
- addEventListener("message", (e)=>{
223
- if (!e.data) return;
224
- if (typeof e.data != "object") return;
225
- if (!e.data.$controller$init) return;
226
- if (typeof e.data.$controller$init != "object") return;
227
- const init = e.data.$controller$init;
228
- tabs.push(new ControllerReference(init.prefix, init.id, e.ports[0]));
229
- });
230
- function shouldRoute(event) {
231
- const url = new URL(event.request.url);
232
- const tab = tabs.find((tab)=>url.pathname.startsWith(tab.prefix));
233
- return tab !== undefined;
234
- }
235
- async function route(event) {
236
- try {
237
- const url = new URL(event.request.url);
238
- const tab = tabs.find((tab)=>url.pathname.startsWith(tab.prefix));
239
- const client = await clients.get(event.clientId);
240
- const rawheaders = [
241
- ...event.request.headers
242
- ];
243
- const response = await tab.rpc.call("request", {
244
- rawUrl: event.request.url,
245
- destination: event.request.destination,
246
- mode: event.request.mode,
247
- referrer: event.request.referrer,
248
- method: event.request.method,
249
- body: event.request.body,
250
- cache: event.request.cache,
251
- forceCrossOriginIsolated: false,
252
- initialHeaders: rawheaders,
253
- rawClientUrl: client ? client.url : undefined
254
- }, event.request.body instanceof ReadableStream || // @ts-expect-error the types for fetchevent are messed up
255
- event.request.body instanceof ArrayBuffer ? [
256
- event.request.body
257
- ] : undefined);
258
- return new Response(response.body, {
259
- status: response.status,
260
- statusText: response.statusText,
261
- headers: response.headers
262
- });
263
- } catch (e) {
264
- console.error("Service Worker error:", e);
265
- return new Response("Internal Service Worker Error: " + e.message, {
266
- status: 500
267
- });
268
- }
269
- }
270
-
271
- })();
272
-
273
- $scramjetController = __webpack_exports__;
274
- })()
275
- ;
1
+ var $scramjetController;(()=>{var e={470:function(e,t,r){r.d(t,{C:()=>o});class o{methods;id;sendRaw;counter=0;promiseCallbacks=new Map;constructor(e,t,r){this.methods=e,this.id=t,this.sendRaw=r}recieve(e){if(null==e||"object"!=typeof e)return;let t=e[this.id];if(null==t||"object"!=typeof t)return;let r=t.$type;if("response"===r){let e=t.$token,r=t.$data,o=t.$error,s=this.promiseCallbacks.get(e);if(!s)return;this.promiseCallbacks.delete(e),void 0!==o?s.reject(Error(o)):s.resolve(r)}else if("request"===r){let e=t.$method,r=t.$args;this.methods[e](r).then(e=>{this.sendRaw({[this.id]:{$type:"response",$token:t.$token,$data:e?.[0]}},e?.[1])}).catch(e=>{console.error(e),this.sendRaw({[this.id]:{$type:"response",$token:t.$token,$error:e?.toString()||"Unknown error"}},[])})}}call(e,t,r=[]){let o=this.counter++;return new Promise((s,a)=>{this.promiseCallbacks.set(o,{resolve:s,reject:a}),this.sendRaw({[this.id]:{$type:"request",$method:e,$args:t,$token:o}},r)})}}}},t={};function r(o){var s=t[o];if(void 0!==s)return s.exports;var a=t[o]={exports:{}};return e[o](a,a.exports,r),a.exports}r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{r.r(o),r.d(o,{route:()=>i,shouldRoute:()=>n});var e=r(470);let t={};addEventListener("message",e=>{if(e.data&&"object"==typeof e.data){if(e.data.$sw$setCookieDone&&"object"==typeof e.data.$sw$setCookieDone){let r=e.data.$sw$setCookieDone,o=t[r.id];o&&(o(),delete t[r.id])}if(e.data.$sw$initRemoteTransport&&"object"==typeof e.data.$sw$initRemoteTransport){let{port:t,prefix:r}=e.data.$sw$initRemoteTransport;console.error(r,a);let o=a.find(e=>new URL(r).pathname.startsWith(e.prefix));if(!o)return void console.error("No relevant controller found for transport init");o.rpc.call("initRemoteTransport",t,[t])}}});class s{prefix;id;rpc;constructor(r,o,s){this.prefix=r,this.id=o,this.rpc=new e.C({sendSetCookie:async({url:e,cookie:r})=>{let o=await self.clients.matchAll(),s=[];for(let a of o){let o=Math.random().toString(36).substring(2,10);a.postMessage({$controller$setCookie:{url:e,cookie:r,id:o}}),s.push(new Promise(e=>{t[o]=e}))}await Promise.race([new Promise(e=>setTimeout(()=>{console.error("timed out waiting for set cookie response (deadlock?)"),e()},1e3)),s])}},"tabchannel-"+o,(e,t)=>{s.postMessage(e,t)}),s.addEventListener("message",e=>{this.rpc.recieve(e.data)}),s.onmessageerror=console.error,this.rpc.call("ready",null)}}let a=[];function n(e){let t=new URL(e.request.url);return void 0!==a.find(e=>t.pathname.startsWith(e.prefix))}async function i(e){try{let t=new URL(e.request.url),r=a.find(e=>t.pathname.startsWith(e.prefix)),o=await clients.get(e.clientId),s=[...e.request.headers],n=await r.rpc.call("request",{rawUrl:e.request.url,destination:e.request.destination,mode:e.request.mode,referrer:e.request.referrer,method:e.request.method,body:e.request.body,cache:e.request.cache,forceCrossOriginIsolated:!1,initialHeaders:s,rawClientUrl:o?o.url:void 0},e.request.body instanceof ReadableStream||e.request.body instanceof ArrayBuffer?[e.request.body]:void 0);return new Response(n.body,{status:n.status,statusText:n.statusText,headers:n.headers})}catch(e){return console.error("Service Worker error:",e),new Response("Internal Service Worker Error: "+e.message,{status:500})}}addEventListener("message",e=>{if(!e.data||"object"!=typeof e.data||!e.data.$controller$init||"object"!=typeof e.data.$controller$init)return;let t=e.data.$controller$init;a.push(new s(t.prefix,t.id,e.ports[0]))})})(),$scramjetController=o})();
276
2
  //# sourceMappingURL=controller.sw.js.map