-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathWebSocketClient.ts
More file actions
59 lines (49 loc) · 1.85 KB
/
WebSocketClient.ts
File metadata and controls
59 lines (49 loc) · 1.85 KB
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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import type { EmitterSubscription } from "react-native";
import type { ClientHeaders, ClientP12Configuration } from "./APIClient";
import type { WebSocketReadyState } from "../WebSocketClient/NativeWebSocketClient";
export type WebSocketClientConfiguration = {
headers?: ClientHeaders;
timeoutInterval?: number;
enableCompression?: boolean;
clientP12Configuration?: ClientP12Configuration;
trustSelfSignedServerCertificate?: boolean;
};
type WebSocketMessage =
| string
| WebSocketReadyState
| Record<string, string | number>;
export type WebSocketEvent = {
url: string;
message: WebSocketMessage;
};
export type WebSocketEventHandler = (event: WebSocketEvent) => void;
export type WebSocketClientErrorEventHandler = (
event: WebSocketClientErrorEvent,
) => void;
export interface WebSocketClientInterface {
url: string;
readyState: WebSocketReadyState;
onReadyStateSubscription: EmitterSubscription;
onWebSocketOpenSubscription?: EmitterSubscription;
onWebSocketCloseSubscription?: EmitterSubscription;
onWebSocketErrorSubscription?: EmitterSubscription;
onWebSocketMessageSubscription?: EmitterSubscription;
onWebSocketClientErrorSubscription?: EmitterSubscription;
send(data: string): void;
sendBinary?(data: string): void;
open(): void;
close(): void;
onOpen(callback: WebSocketEventHandler): void;
onClose(callback: WebSocketEventHandler): void;
onError(callback: WebSocketEventHandler): void;
onMessage(callback: WebSocketEventHandler): void;
onClientError(callback: WebSocketClientErrorEventHandler): void;
invalidate(): Promise<void>;
}
export type WebSocketClientErrorEvent = {
url: string;
errorCode: number;
errorDescription: string;
};