From 9c3e96a80461d76ef42b8715e194427804a9f873 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Sun, 14 Aug 2022 17:49:31 -0500 Subject: [PATCH] feat: define makeAction --- src/react-app-env.d.ts | 32 +++++++++++++++++++------------ src/services/PeerRoom/PeerRoom.ts | 4 ++++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/react-app-env.d.ts b/src/react-app-env.d.ts index cfadd2d..cdd6063 100644 --- a/src/react-app-env.d.ts +++ b/src/react-app-env.d.ts @@ -25,21 +25,29 @@ declare module 'trystero' { export type RoomConfig = BaseRoomConfig & (BitTorrentRoomConfig | FirebaseRoomConfig | IpfsRoomConfig) + export type ActionSender = ( + data: T, + targetPeers?: string[], + metadata?: Record, + progress: (percent: number, peerId: string) => void + ) => void + + export type ActionReceiver = ( + data: T, + peerId: string, + metadata?: Record + ) => void + + export type ActionProgress = ( + percent: number, + peerId: string, + metadata?: Record + ) => void + export interface Room { makeAction: ( namespace: string - ) => [ - ( - data: T, - targetPeers?: string[], - metadata?: Record, - progress: (percent: number, peerId: string) => void - ) => void, - - (data: T, peerId: string, metadata?: Record) => void, - - (percent: number, peerId: string, metadata?: Record) => void - ] + ) => [ActionSender, ActionReceiver, ActionProgress] ping: (id: string) => Promise diff --git a/src/services/PeerRoom/PeerRoom.ts b/src/services/PeerRoom/PeerRoom.ts index 6cf9586..ea1a291 100644 --- a/src/services/PeerRoom/PeerRoom.ts +++ b/src/services/PeerRoom/PeerRoom.ts @@ -18,4 +18,8 @@ export class PeerRoom { this.room.leave() } } + + makeAction(namespace: string) { + return this.room?.makeAction(namespace) + } }