diff options
author | metamuffin <metamuffin@disroot.org> | 2022-10-05 20:07:27 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-10-05 20:07:27 +0200 |
commit | 0e8a807309bb65091b4170ba9da1768dbd109bc1 (patch) | |
tree | 949c1bef601e778930de99c3ba92de604ed6a8f2 | |
parent | 2449d977f1c0fe98bf022ce5608972ae3aef0bce (diff) | |
download | keks-meet-0e8a807309bb65091b4170ba9da1768dbd109bc1.tar keks-meet-0e8a807309bb65091b4170ba9da1768dbd109bc1.tar.bz2 keks-meet-0e8a807309bb65091b4170ba9da1768dbd109bc1.tar.zst |
protocol .d.ts uses sum types now
-rw-r--r-- | common/packets.d.ts | 55 | ||||
-rw-r--r-- | readme.md | 1 |
2 files changed, 28 insertions, 28 deletions
diff --git a/common/packets.d.ts b/common/packets.d.ts index cd7fb02..369d221 100644 --- a/common/packets.d.ts +++ b/common/packets.d.ts @@ -6,45 +6,46 @@ // copy pasted from dom.lib.d.ts because it can not be referenced in the server. type Sdp = string -interface F_RTCIceCandidateInit { candidate?: string; sdpMLineIndex?: number | null; sdpMid?: string | null; usernameFragment?: string | null; } - -export interface /* enum */ ClientboundPacket { - init?: { your_id: number, version: string }, - client_join?: { id: number }, - client_leave?: { id: number }, - message?: { sender: number, message: string /* encrypted RelayMessageWrapper */ }, +interface F_RTCIceCandidateInit { + candidate?: string + sdpMLineIndex?: number | null + sdpMid?: string | null + usernameFragment?: string | null } -export interface /* enum */ ServerboundPacket { - ping?: null, - relay?: { recipient?: number, message: string /* encrypted RelayMessageWrapper */ }, -} +export type ClientboundPacket = + { init: { your_id: number, version: string } } + | { client_join: { id: number } } // join: more like "appear" - also sent when you join for others that were there before you. + | { client_leave: { id: number } } + | { message: { sender: number, message: string /* encrypted RelayMessageWrapper */ } } + +export type ServerboundPacket = + { ping: null } + | { relay: { recipient?: number, message: string /* encrypted RelayMessageWrapper */ } } export interface RelayMessageWrapper { - sender: number, // redundant, but ensures the server didnt cheat + sender: number, // redundancy to ensure the server didn't cheat inner: RelayMessage } -export interface /* enum */ RelayMessage { - chat?: ChatMessage, - identify?: { username: string } +export type RelayMessage = + { chat: ChatMessage } + | { identify: { username: string } } + | { provide: ProvideInfo } + | { request: { id: string } } + | { provide_stop: { id: string } } + | { request_stop: { id: string } } + | { offer: Sdp } + | { answer: Sdp } + | { ice_candidate: F_RTCIceCandidateInit } - provide?: ProvideInfo - request?: { id: string } - provide_stop?: { id: string } - request_stop?: { id: string } - - offer?: Sdp, - answer?: Sdp, - ice_candidate?: F_RTCIceCandidateInit, -} export interface ChatMessage { text?: string, image?: string } export type ResourceKind = "track" | "file" export type TrackKind = "audio" | "video" export interface ProvideInfo { - id: string, // for datachannels this is `label`, for tracks this will be the `id` of the only associated stream. + id: string // for datachannels this is `label`, for tracks this will be the `id` of the only associated stream. kind: ResourceKind - track_kind?: TrackKind + track_kind?: TrackKind // used to indicate a/v for tracks only label?: string - size?: number + size?: number // size for file transfers } @@ -130,7 +130,6 @@ system works as follows: - Prevent join notification bypass by not identifying - Tray icon for native - Pin js by bookmarking data:text/html loader page -- convert protocol enums to `A | B | C` - add "contributing" stuff to readme - download files in a streaming manner. - workaround using service worker |