From 56751f4c230b4ba82584801d34c4e543909a5936 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Sun, 14 Aug 2022 13:18:27 -0500 Subject: [PATCH] chore: define trystero types --- src/react-app-env.d.ts | 68 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/src/react-app-env.d.ts b/src/react-app-env.d.ts index 69ee57a..5f86bb0 100644 --- a/src/react-app-env.d.ts +++ b/src/react-app-env.d.ts @@ -1,5 +1,71 @@ /// +// TODO: Contribute this to DefinitelyTyped declare module 'trystero' { - export function joinRoom(config: any, ns: any): any + export interface RoomConfig {} + + export type PeerActionData = any + + export interface Room { + makeAction: ( + namespace: string + ) => [ + ( + data: PeerActionData, + targetPeers?: string[], + metadata?: Record, + progress: (percent: number, peerId: string) => void + ) => void, + + (data: PeerActionData, peerId: string, metadata?: Record) => void, + + (percent: number, peerId: string, metadata?: Record) => void + ] + + ping: (id: string) => Promise + + leave: () => void + + getPeers: () => string[] + + addStream: ( + stream: MediaStream, + peerId?: string, + metadata?: Record + ) => Promise[] + + removeStream: (stream: MediaStream, peerId?: string) => void + + addTrack: ( + track: MediaStreamTrack, + stream: MediaStream, + peerId?: string, + metadata?: Record + ) => Promise[] + + removeTrack: ( + track: MediaStreamTrack, + stream: MediaStream, + peerId?: string + ) => void + + replaceTrack: ( + oldTrack: MediaStreamTrack, + newTrack: MediaStreamTrack, + stream: MediaStream, + peerId?: string + ) => Promise[] + + onPeerJoin: (fn: (peerId: string) => void) => void + + onPeerLeave: (fn: (peerId: string) => void) => void + + onPeerStream: (fn: (stream: MediaStream, peerId: string) => void) => void + + onPeerTrack: ( + fn: (track: MediaStreamTrack, stream: MediaStream, peerId: string) => void + ) => void + } + + export function joinRoom(config: RoomConfig, roomId: string): Room }