generated from Simon-Laux/webxdc-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webxdc.d.ts
80 lines (74 loc) · 3.13 KB
/
webxdc.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//@ts-check
type SendingStatusUpdate<T> = {
/** the payload, deserialized json:
* any javascript primitive, array or object. */
payload: T;
/** optional, short, informational message that will be added to the chat,
* eg. "Alice voted" or "Bob scored 123 in MyGame";
* usually only one line of text is shown,
* use this option sparingly to not spam the chat. */
info?: string;
/** optional, if the Webxdc creates a document, you can set this to the name of the document;
* do not set if the Webxdc does not create a document */
document?: string;
/** optional, short text, shown beside the icon;
* it is recommended to use some aggregated value,
* eg. "8 votes", "Highscore: 123" */
summary?: string;
};
type ReceivedStatusUpdate<T> = {
/** the payload, deserialized json */
payload: T;
/** the serial number of this update. Serials are larger than 0 and newer serials have higher numbers */
serial: number;
/** the maximum serial currently known */
max_serial: number;
/** optional, short, informational message. */
info?: string;
/** optional, if the Webxdc creates a document, this is the name of the document;
* not set if the Webxdc does not create a document */
document?: string;
/** optional, short text, shown beside the webxdc's icon. */
summary?: string;
};
interface Webxdc<T> {
/** Returns the peer's own address.
* This is esp. useful if you want to differ between different peers - just send the address along with the payload,
* and, if needed, compare the payload addresses against selfAddr() later on. */
selfAddr: string;
/** Returns the peer's own name. This is name chosen by the user in their settings, if there is nothing set, that defaults to the peer's address. */
selfName: string;
/**
* set a listener for new status updates.
* The "serial" specifies the last serial that you know about (defaults to 0).
* Note that own status updates, that you send with {@link sendUpdate}, also trigger this method
* @returns promise that resolves when the listener has processed all the update messages known at the time when `setUpdateListener` was called.
* */
setUpdateListener(cb: (statusUpdate: ReceivedStatusUpdate<T>) => void, serial?: number): Promise<void>;
/**
* WARNING! This function is deprecated, see setUpdateListener().
*/
getAllUpdates(): Promise<ReceivedStatusUpdate<T>[]>;
/**
* Webxdc are usually shared in a chat and run independently on each peer. To get a shared status, the peers use sendUpdate() to send updates to each other.
* @param update status update to send
* @param description short, human-readable description what this update is about. this is shown eg. as a fallback text in an email program.
*/
sendUpdate(update: SendingStatusUpdate<T>, description: string): void;
}
////////// ANCHOR: global
declare global {
interface Window {
webxdc: Webxdc<any>;
}
}
////////// ANCHOR_END: global
export { SendingStatusUpdate, ReceivedStatusUpdate, Webxdc };
/* Types for the Simulator */
declare global {
interface Window {
addXdcPeer: () => void;
clearXdcStorage: () => void;
alterXdcApp: () => void;
}
}