-
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 8 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,27 @@ type SendOptions = | |
| text: string; | ||
| }; | ||
|
|
||
| interface Webxdc<T> { | ||
| /** | ||
| * A listener for realtime data. | ||
| */ | ||
| export class RealtimeListener { | ||
| listener: (data: Uint8Array) => void | ||
| active: boolean | ||
| trashed: boolean | ||
|
||
|
|
||
| /* Whether the realtime channel was left */ | ||
| is_trashed(): boolean | ||
| /* Receive data from the realtime channel */ | ||
| receive(data: Uint8Array): void | ||
| /* Set a listener for the realtime channel */ | ||
| setListener(listener: (data: Uint8Array) => void): void | ||
| /* Send data over the realtime channel */ | ||
| send(data: Uint8Array): void | ||
| /* Leave the realtime channel */ | ||
| leave(): void | ||
| } | ||
|
|
||
| interface Webxdc<StatusPayload> { | ||
| /** 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 +94,31 @@ 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>; | ||
|
|
||
| /** | ||
| * Join a realtime channel. | ||
| */ | ||
| joinRealtimeChannel(): RealtimeListener; | ||
Simon-Laux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * @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 realtime data. | ||
| */ | ||
| sendRealtimeData(payload: Uint8Array): void; | ||
|
|
||
| /** | ||
| * Send a message with file, text or both to a chat. | ||
| * Asks user to what Chat to send the message to. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.