-
Notifications
You must be signed in to change notification settings - Fork 1
feat: ephemeral peer channels #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
fdd3d5c
7593239
f331601
91eb01a
2dc25e1
04da65d
e3e13d7
5969503
175394a
6c4589d
98d5fdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { Webxdc } from "./webxdc"; | ||
| declare global { | ||
| interface Window { | ||
| webxdc: Webxdc<any>; | ||
| webxdc: Webxdc<any, any>; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| type SendingStatusUpdate<T> = { | ||
| type SendingStatusUpdate<PayloadType> = { | ||
| /** the payload, deserialized json: | ||
| * any javascript primitive, array or object. */ | ||
| payload: T; | ||
| payload: PayloadType; | ||
| /** 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, | ||
|
|
@@ -16,9 +16,9 @@ type SendingStatusUpdate<T> = { | |
| summary?: string; | ||
| }; | ||
|
|
||
| type ReceivedStatusUpdate<T> = { | ||
| type ReceivedStatusUpdate<PayloadType> = { | ||
| /** the payload, deserialized json */ | ||
| payload: T; | ||
| payload: PayloadType; | ||
| /** the serial number of this update. Serials are larger than 0 and newer serials have higher numbers */ | ||
| serial: number; | ||
| /** the maximum serial currently known */ | ||
|
|
@@ -60,7 +60,7 @@ type SendOptions = | |
| text: string; | ||
| }; | ||
|
|
||
| interface Webxdc<T> { | ||
| interface Webxdc<StatusPayload, EphemeralPayload = any> { | ||
| /** 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. */ | ||
|
|
@@ -74,19 +74,37 @@ interface Webxdc<T> { | |
| * @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, | ||
| cb: (statusUpdate: ReceivedStatusUpdate<StatusPayload>) => void, | ||
| serial?: number | ||
| ): Promise<void>; | ||
|
|
||
| /** | ||
| * Set a listener for _ephemeral_ status updates. | ||
| * Own status updates are not received. | ||
|
||
| * | ||
| * @returns Promise that is resolved when the there is atleast one peer connected | ||
| */ | ||
| setEphemeralUpdateListener(cb: (payload: EphemeralPayload) => void): Promise<void>; | ||
|
|
||
| /** | ||
| * @deprecated See {@link setUpdateListener|`setUpdateListener()`}. | ||
| */ | ||
| getAllUpdates(): Promise<ReceivedStatusUpdate<T>[]>; | ||
| getAllUpdates(): Promise<ReceivedStatusUpdate<StatusPayload>[]>; | ||
| /** | ||
| * 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; | ||
| sendUpdate(update: SendingStatusUpdate<StatusPayload>, description: string): void; | ||
|
|
||
| /** | ||
| * Send an ephemeral update to another peer. | ||
| * @param payload Data that can be serialized with `JSON.stringify`. | ||
| * | ||
| * @returns A promise that resolves when a peer connection is established. Ephemeral messages can then be sent with `sendEphemeral` | ||
|
||
| */ | ||
| sendEphemeralUpdate(payload: EphemeralPayload): Promise<void>; | ||
|
|
||
| /** | ||
| * Send a message with file, text or both to a chat. | ||
| * Asks user to what Chat to send the message to. | ||
|
|
@@ -116,4 +134,4 @@ interface Webxdc<T> { | |
| }): Promise<File[]>; | ||
| } | ||
|
|
||
| export { SendingStatusUpdate, ReceivedStatusUpdate, Webxdc, XDCFile }; | ||
| export { SendingStatusUpdate, ReceivedStatusUpdate, Webxdc, XDCFile }; | ||
Uh oh!
There was an error while loading. Please reload this page.