forked from Shiloh/remnantchat
feat: define makeAction
This commit is contained in:
parent
2ec8c52f7c
commit
9c3e96a804
32
src/react-app-env.d.ts
vendored
32
src/react-app-env.d.ts
vendored
@ -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>
|
||||||
|
|
||||||
|
@ -18,4 +18,8 @@ export class PeerRoom {
|
|||||||
this.room.leave()
|
this.room.leave()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
makeAction<T>(namespace: string) {
|
||||||
|
return this.room?.makeAction<T>(namespace)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user