summaryrefslogtreecommitdiff
path: root/js/dispatch.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/dispatch.ts')
-rw-r--r--js/dispatch.ts29
1 files changed, 0 insertions, 29 deletions
diff --git a/js/dispatch.ts b/js/dispatch.ts
deleted file mode 100644
index eeb00f38e..000000000
--- a/js/dispatch.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2018 the Deno authors. All rights reserved. MIT license.
-import { typedArrayToArrayBuffer } from "./util";
-import { deno as fbs } from "./msg_generated";
-
-export type MessageCallback = (msg: Uint8Array) => void;
-//type MessageStructCallback = (msg: pb.IMsg) => void;
-
-const channels = new Map<string, MessageCallback[]>();
-
-export function sub(channel: string, cb: MessageCallback): void {
- let subscribers = channels.get(channel);
- if (!subscribers) {
- subscribers = [];
- channels.set(channel, subscribers);
- }
- subscribers.push(cb);
-}
-
-deno.recv((channel: string, ab: ArrayBuffer) => {
- const subscribers = channels.get(channel);
- if (subscribers == null) {
- throw Error(`No subscribers for channel "${channel}".`);
- }
-
- const ui8 = new Uint8Array(ab);
- for (const subscriber of subscribers) {
- subscriber(ui8);
- }
-});