summaryrefslogtreecommitdiff
path: root/extensions/broadcast_channel/lib.deno_broadcast_channel.d.ts
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2021-05-22 18:08:24 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2021-05-23 15:16:42 +0200
commit8cf7f966f24d0fb996b41d92b04ad9647337a8f6 (patch)
tree306f60a892186dc14e06f65f7dd5c7b7dbfad147 /extensions/broadcast_channel/lib.deno_broadcast_channel.d.ts
parent5f0d91497b03795250c55340c7e7c7de66d4607b (diff)
feat(extensions): add BroadcastChannel
Co-Authored-By: Ben Noordhuis <info@bnoordhuis.nl> Fixes: #10354
Diffstat (limited to 'extensions/broadcast_channel/lib.deno_broadcast_channel.d.ts')
-rw-r--r--extensions/broadcast_channel/lib.deno_broadcast_channel.d.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/extensions/broadcast_channel/lib.deno_broadcast_channel.d.ts b/extensions/broadcast_channel/lib.deno_broadcast_channel.d.ts
new file mode 100644
index 000000000..c8efef778
--- /dev/null
+++ b/extensions/broadcast_channel/lib.deno_broadcast_channel.d.ts
@@ -0,0 +1,55 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+
+// deno-lint-ignore-file no-explicit-any
+
+/// <reference no-default-lib="true" />
+/// <reference lib="esnext" />
+
+interface BroadcastChannelEventMap {
+ "message": MessageEvent;
+ "messageerror": MessageEvent;
+}
+
+interface BroadcastChannel extends EventTarget {
+ /**
+ * Returns the channel name (as passed to the constructor).
+ */
+ readonly name: string;
+ onmessage: ((this: BroadcastChannel, ev: MessageEvent) => any) | null;
+ onmessageerror: ((this: BroadcastChannel, ev: MessageEvent) => any) | null;
+ /**
+ * Closes the BroadcastChannel object, opening it up to garbage collection.
+ */
+ close(): void;
+ /**
+ * Sends the given message to other BroadcastChannel objects set up for
+ * this channel. Messages can be structured objects, e.g. nested objects
+ * and arrays.
+ */
+ postMessage(message: any): void;
+ addEventListener<K extends keyof BroadcastChannelEventMap>(
+ type: K,
+ listener: (this: BroadcastChannel, ev: BroadcastChannelEventMap[K]) => any,
+ options?: boolean | AddEventListenerOptions,
+ ): void;
+ addEventListener(
+ type: string,
+ listener: EventListenerOrEventListenerObject,
+ options?: boolean | AddEventListenerOptions,
+ ): void;
+ removeEventListener<K extends keyof BroadcastChannelEventMap>(
+ type: K,
+ listener: (this: BroadcastChannel, ev: BroadcastChannelEventMap[K]) => any,
+ options?: boolean | EventListenerOptions,
+ ): void;
+ removeEventListener(
+ type: string,
+ listener: EventListenerOrEventListenerObject,
+ options?: boolean | EventListenerOptions,
+ ): void;
+}
+
+declare var BroadcastChannel: {
+ prototype: BroadcastChannel;
+ new (name: string): BroadcastChannel;
+};