-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.d.ts
125 lines (103 loc) · 2.82 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { Unsubscribe } from 'nanoevents'
import {
Channel,
Message,
ChannelParamsMap,
Identifier,
ChannelEvents
} from '../channel/index.js'
import { Transport } from '../transport/index.js'
import { Protocol, ReasonError } from '../protocol/index.js'
import { Hub, HubOptions } from '../hub/index.js'
import { Encoder } from '../encoder/index.js'
import { Logger } from '../logger/index.js'
import { Monitor } from '../monitor/index.js'
type ConnectEvent = Partial<{
restored: boolean
reconnect: boolean
}>
export type InfoEvent = {
type: string
identifier?: Identifier
data?: object
}
export interface CableEvents {
connect: (event: ConnectEvent) => void
disconnect: (event: ReasonError) => void
close: (event?: ReasonError) => void
keepalive: (msg?: Message) => void
info: (event: InfoEvent) => void
}
export type CableOptions = {
transport: Transport
protocol: Protocol
encoder: Encoder
logger?: Logger
lazy?: boolean
hubOptions?: HubOptions
performFailures?: 'throw' | 'warn' | 'ignore'
}
export type CableState =
| 'idle'
| 'disconnected'
| 'connecting'
| 'connected'
| 'closed'
export class GhostChannel extends Channel {}
export const PUBSUB_CHANNEL: string
type PubSubChannelParams =
| { stream_name: string }
| { signed_stream_name: string }
export class PubSubChannel extends Channel<
PubSubChannelParams,
Message,
ChannelEvents<Message>,
never
> {}
export class Cable {
transport: Transport
hub: Hub
protocol: Protocol
encoder: Encoder
logger: Logger
monitor?: Monitor
readonly state: CableState
readonly sessionId: string | undefined
constructor(opts: CableOptions)
connect(): Promise<void>
subscribe<T extends Channel>(channel: T): T
unsubscribe(channel: Channel): void
perform(
identifier: Identifier,
action?: string,
payload?: object
): Promise<Message | void>
disconnect(): void
subscribeTo(channel: string, params?: ChannelParamsMap): GhostChannel
subscribeTo<P extends ChannelParamsMap, T extends Channel<P>>(
channel: {
new (...args: {} extends P ? [undefined?] : [P]): T
},
...args: {} extends P ? [undefined?] : [P]
): T
streamFrom(name: string): PubSubChannel
streamFromSigned(signedName: string): PubSubChannel
keepalive(msg?: Message): void
send(msg: object): void
on<E extends keyof CableEvents>(
event: E,
callback: CableEvents[E]
): Unsubscribe
once<E extends keyof CableEvents>(
event: E,
callback: CableEvents[E]
): Unsubscribe
connected(): void
restored(remoteIds: string[]): void
disconnected(reason?: ReasonError): void
closed(reason?: string | ReasonError): void
notify(event: string, data?: object): void
notify(event: string, identifier?: Identifier, data?: object): void
setSessionId(sid: string): void
}
export class NoConnectionError extends Error {}