feat: define makeAction

This commit is contained in:
Jeremy Kahn 2022-08-14 17:49:31 -05:00
parent 2ec8c52f7c
commit 9c3e96a804
2 changed files with 24 additions and 12 deletions

View File

@ -25,21 +25,29 @@ declare module 'trystero' {
export type RoomConfig = BaseRoomConfig & export type RoomConfig = BaseRoomConfig &
(BitTorrentRoomConfig | FirebaseRoomConfig | IpfsRoomConfig) (BitTorrentRoomConfig | FirebaseRoomConfig | IpfsRoomConfig)
export type ActionSender = <T>(
data: T,
targetPeers?: string[],
metadata?: Record,
progress: (percent: number, peerId: string) => void
) => void
export type ActionReceiver = <T>(
data: T,
peerId: string,
metadata?: Record
) => void
export type ActionProgress = (
percent: number,
peerId: string,
metadata?: Record
) => void
export interface Room { export interface Room {
makeAction: <T>( makeAction: <T>(
namespace: string namespace: string
) => [ ) => [ActionSender<T>, ActionReceiver<T>, ActionProgress]
(
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
]
ping: (id: string) => Promise<number> ping: (id: string) => Promise<number>

View File

@ -18,4 +18,8 @@ export class PeerRoom {
this.room.leave() this.room.leave()
} }
} }
makeAction<T>(namespace: string) {
return this.room?.makeAction<T>(namespace)
}
} }