-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
sysend.d.ts
34 lines (31 loc) · 1.61 KB
/
sysend.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**@license
* sysend.js - send messages between browser windows/tabs version 1.17.5
*
* Copyright (C) 2014 Jakub T. Jankiewicz <https://jcubic.pl/me>
* Released under the MIT license
*
*/
type callback<T> = (message: T, event: string) => void;
interface Sysend {
id: string;
broadcast<T>(event: string, data?: T): void;
emit(event: string, data?: unknown): void;
on<T>(event: string, callback: callback<T>): void;
off<T>(event: string, callback?: callback<T>): void;
proxy(...args: string[]): void;
serializer<T>(to: (data: T) => string, from: (data: string) => T): void;
track(event: 'open', callback: (data: {id: string, count: number, primary: boolean}) => void): void;
track(event: 'close', callback: (data: {id: string, count: number, primary: boolean, self: boolean}) => void): void;
track(event: 'primary', callback: () => void): void;
track<T>(event: 'message', callback: (payload: {data: T, origin: string}) => void): void;
track(event: 'secondary', callback: () => void): void;
track(event: 'update', callback: (payload: Array<{ id: string, primary: boolean }>) => void): void;
untrack(event: 'open' | 'close' | 'primary' | 'secondary' | 'message' | 'update', fn?: (input?: unknown) => void): void;
list(): Promise<Array<{ id: string, primary: boolean }>>;
post<T>(target: string, data?: T): void;
channel(...domains: string[]): void;
isPrimary(): boolean;
rpc<T extends Array<unknown>, U>(object: Record<string, (...args: T) => U>): Promise<Record<string, (id: string, ...args: T) => Promise<U>>>
}
declare const sysend: Sysend;
export default sysend;