diff options
| author | AAGaming <aa@mail.catvibers.me> | 2023-08-05 01:11:43 -0400 |
|---|---|---|
| committer | marios8543 <marios8543@gmail.com> | 2023-11-14 00:04:56 +0200 |
| commit | 34d1a34b10f4386865f3c241c5ae4026d2bfd8bd (patch) | |
| tree | d9560bceecd2cb3d0a2b89d9f75bc29a7dfdc3dd /frontend/src/wsrouter.ts | |
| parent | cfb6fe69e3f111de0d75a9d90e570bac392e1ee3 (diff) | |
| download | decky-loader-34d1a34b10f4386865f3c241c5ae4026d2bfd8bd.tar.gz decky-loader-34d1a34b10f4386865f3c241c5ae4026d2bfd8bd.zip | |
Migrate most of frontend callServerMethod usage over to websocket
Diffstat (limited to 'frontend/src/wsrouter.ts')
| -rw-r--r-- | frontend/src/wsrouter.ts | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/frontend/src/wsrouter.ts b/frontend/src/wsrouter.ts index 3a36b5b0..e50b06a7 100644 --- a/frontend/src/wsrouter.ts +++ b/frontend/src/wsrouter.ts @@ -1,5 +1,11 @@ import Logger from './logger'; +declare global { + interface Window { + DeckyBackend: WSRouter; + } +} + enum MessageType { // Call-reply CALL, @@ -94,7 +100,6 @@ export class WSRouter extends Logger { } async onMessage(msg: MessageEvent) { - this.debug('WS Message', msg); try { const data = JSON.parse(msg.data) as Message; switch (data.type) { @@ -108,7 +113,7 @@ export class WSRouter extends Logger { await this.write({ type: MessageType.ERROR, id: data.id, error: (e as Error)?.stack || e }); } } else { - await this.write({ type: MessageType.ERROR, id: data.id, error: 'Route does not exist.' }); + await this.write({ type: MessageType.ERROR, id: data.id, error: `Route ${data.route} does not exist.` }); } break; @@ -152,6 +157,10 @@ export class WSRouter extends Logger { return resolver.promise; } + callable<Args extends any[] = any[], Return = void>(route: string): (...args: Args) => Promise<Return> { + return (...args) => this.call<Args, Return>(route, ...args); + } + async onError(error: any) { this.error('WS DISCONNECTED', error); await this.connect(); |
