2022-01-17 22:49:35 +00:00
|
|
|
//@ts-check
|
|
|
|
|
2022-01-28 15:59:33 +00:00
|
|
|
type SendingStatusUpdate<T> = {
|
2022-01-17 22:49:35 +00:00
|
|
|
/** 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, short text, shown beside app icon;
|
|
|
|
* it is recommended to use some aggregated value,
|
|
|
|
* eg. "8 votes", "Highscore: 123" */
|
|
|
|
summary?: string;
|
|
|
|
};
|
|
|
|
|
2022-01-28 15:59:33 +00:00
|
|
|
type ReceivedStatusUpdate<T> = {
|
2022-01-17 22:49:35 +00:00
|
|
|
/** the payload, deserialized json */
|
|
|
|
payload: T;
|
2022-02-22 18:58:37 +00:00
|
|
|
/** 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;
|
2022-01-17 22:49:35 +00:00
|
|
|
};
|
|
|
|
|
2022-01-28 15:59:33 +00:00
|
|
|
interface Webxdc<T> {
|
2022-01-17 22:49:35 +00:00
|
|
|
/** 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. */
|
2022-01-28 15:49:24 +00:00
|
|
|
selfAddr: string;
|
2022-01-17 22:49:35 +00:00
|
|
|
/** 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. */
|
2022-01-28 15:49:24 +00:00
|
|
|
selfName: string;
|
2022-01-17 22:49:35 +00:00
|
|
|
/**
|
2022-02-22 18:58:37 +00:00
|
|
|
* 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
|
2022-01-17 22:49:35 +00:00
|
|
|
* */
|
2022-02-22 18:58:37 +00:00
|
|
|
setUpdateListener(cb: (statusUpdate: ReceivedStatusUpdate<T>) => void, serial: number): void;
|
2022-01-17 22:49:35 +00:00
|
|
|
/**
|
2022-02-22 18:58:37 +00:00
|
|
|
* WARNING! This function is deprecated, see setUpdateListener().
|
2022-01-17 22:49:35 +00:00
|
|
|
*/
|
2022-01-28 15:59:33 +00:00
|
|
|
getAllUpdates(): Promise<ReceivedStatusUpdate<T>[]>;
|
2022-01-17 22:49:35 +00:00
|
|
|
/**
|
2022-01-28 15:59:33 +00:00
|
|
|
* Webxdc apps 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
|
2022-01-17 22:49:35 +00:00
|
|
|
* @param description short, human-readable description what this update is about. this is shown eg. as a fallback text in an email program.
|
|
|
|
*/
|
2022-01-28 15:59:33 +00:00
|
|
|
sendUpdate(update: SendingStatusUpdate<T>, description: string): void;
|
2022-01-17 22:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////// ANCHOR: global
|
|
|
|
declare global {
|
|
|
|
interface Window {
|
2022-01-28 15:59:33 +00:00
|
|
|
webxdc: Webxdc<any>;
|
2022-01-17 22:49:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
////////// ANCHOR_END: global
|
|
|
|
|
2022-01-28 15:59:33 +00:00
|
|
|
export { SendingStatusUpdate, ReceivedStatusUpdate, Webxdc };
|
2022-01-17 22:49:35 +00:00
|
|
|
|
|
|
|
/* Types for the Simulator */
|
|
|
|
declare global {
|
|
|
|
interface Window {
|
|
|
|
addXdcPeer: () => void;
|
|
|
|
clearXdcStorage: () => void;
|
|
|
|
alterXdcApp: () => void;
|
|
|
|
}
|
|
|
|
}
|