-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathNativeWebSocketClient.ts
More file actions
55 lines (48 loc) · 1.54 KB
/
NativeWebSocketClient.ts
File metadata and controls
55 lines (48 loc) · 1.54 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
import { type TurboModule, TurboModuleRegistry } from "react-native";
import type {
Double,
Int32,
UnsafeObject,
} from "react-native/Libraries/Types/CodegenTypes";
type ClientP12Configuration = Readonly<{
path: string;
password?: string;
}>;
type WebSocketClientConfiguration = Readonly<{
headers?: UnsafeObject;
timeoutInterval?: Double;
enableCompression?: boolean;
clientP12Configuration?: ClientP12Configuration;
trustSelfSignedServerCertificate?: boolean;
}>;
export enum WebSocketEvents {
OPEN_EVENT = "WebSocketClient-Open",
CLOSE_EVENT = "WebSocketClient-Close",
ERROR_EVENT = "WebSocketClient-Error",
MESSAGE_EVENT = "WebSocketClient-Message",
READY_STATE_EVENT = "WebSocketClient-ReadyState",
}
export enum WebSocketReadyState {
CONNECTING,
OPEN,
CLOSING,
CLOSED,
}
export interface Spec extends TurboModule {
addListener: (eventType: string) => void;
removeListeners: (count: Int32) => void;
ensureClientFor: (
url: string,
config?: WebSocketClientConfiguration,
) => Promise<void>;
createClientFor: (
url: string,
config?: WebSocketClientConfiguration,
) => Promise<void>;
connectFor: (url: string) => Promise<void>;
disconnectFor(url: string): Promise<void>;
sendDataFor(url: string, data: string): Promise<void>;
sendBinaryDataFor(url: string, data: string): Promise<void>;
invalidateClientFor(url: string): Promise<void>;
}
export default TurboModuleRegistry.get<Spec>("WebSocketClient") as Spec;