Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #37 Add TypeScript type declarations #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
declare module 'bugout' {
type BugoutOpts = {
announce?: string[]
}

type SeenCallBack = (address: string) => void
type ServerCallback = (address: string) => void
type ConnectionsCallback = (count: number) => void
type MessageCallback = (address: string, message: Record<string, unknown>, packet: Record<string, unknown>) => void
type PingCallback = (address: string) => void
type LeftCallback = (address: string) => void
type TimeoutCallback = (address: string) => void
type RPCCallback = (address: string, callback: (...any) => void) => void
type RPCResponseCallBack = (address: string, none: string, response: Record<string, unknown>) => void

type EventCallbacks =
| SeenCallBack
| ServerCallback
| ConnectionsCallback
| MessageCallback
| PingCallback
| LeftCallback
| TimeoutCallback
| RPCCallback
| RPCResponseCallBack

class Bugout {
constructor(identifier: string, opts: BugoutOpts)
address(): string
register(callName: string, func: Function, docString: string): void
rpc(address: string, callName: string, args: Array<Record<string, unknown>>, callback: () => void)
send(address: string, message: string): void
send(message: string): void
heartbeat(milliseconds: number): void
destroy(callback?: () => void): void
on<CallbackType extends EventCallbacks>(eventName: string, callback: CallbackType)
}
export default Bugout
export {
Bugout,
BugoutOpts,
SeenCallBack,
ServerCallback,
ConnectionsCallback,
MessageCallback,
PingCallback,
LeftCallback,
TimeoutCallback,
RPCCallback,
RPCResponseCallBack,
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.11",
"description": "Backend web services over WebRTC.",
"main": "index.js",
"types": "index.d.ts",
"author": "Chris McCormick <[email protected]>",
"homepage": "https://github.com/chr15m/bugout",
"repository": {
Expand Down