-
Notifications
You must be signed in to change notification settings - Fork 2
/
discontinuity.ts
62 lines (53 loc) · 1.78 KB
/
discontinuity.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
import * as Ably from 'ably';
import EventEmitter from './utils/event-emitter.js';
/**
* Represents an object that has a channel and therefore may care about discontinuities.
*/
export interface HandlesDiscontinuity {
/**
* A channel that this object is associated with.
*/
get channel(): Ably.RealtimeChannel;
/**
* Called when a discontinuity is detected on the channel.
* @param reason The error that caused the discontinuity.
*/
discontinuityDetected(reason?: Ably.ErrorInfo): void;
}
/**
* A response to subscribing to discontinuity events that allows control of the subscription.
*/
export interface OnDiscontinuitySubscriptionResponse {
/**
* Unsubscribe from discontinuity events.
*/
off: () => void;
}
/**
* A listener that can be registered for discontinuity events.
* @param reason The error that caused the discontinuity.
*/
export type DiscontinuityListener = (reason?: Ably.ErrorInfo) => void;
/**
* An interface to be implemented by objects that can emit discontinuities to listeners.
*/
export interface EmitsDiscontinuities {
/**
* Register a listener to be called when a discontinuity is detected.
* @param listener The listener to be called when a discontinuity is detected.
* @returns A response that allows control of the subscription.
*/
onDiscontinuity(listener: DiscontinuityListener): OnDiscontinuitySubscriptionResponse;
}
interface DiscontinuityEventMap {
['discontinuity']: Ably.ErrorInfo | undefined;
}
/**
* An event emitter specialization for discontinuity events.
*/
export type DiscontinuityEmitter = EventEmitter<DiscontinuityEventMap>;
/**
* Creates a new discontinuity emitter.
* @returns A new discontinuity emitter.
*/
export const newDiscontinuityEmitter = (): DiscontinuityEmitter => new EventEmitter();