-
Notifications
You must be signed in to change notification settings - Fork 84
/
angular2-websocket.d.ts
95 lines (95 loc) · 2.87 KB
/
angular2-websocket.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
import { Observable, Subject } from 'rxjs';
export declare class $WebSocket {
private url;
private protocols;
private config;
private binaryType;
private static Helpers;
private reconnectAttempts;
private sendQueue;
private onOpenCallbacks;
private onMessageCallbacks;
private onErrorCallbacks;
private onCloseCallbacks;
private readyStateConstants;
private normalCloseCode;
private reconnectableStatusCodes;
private socket;
private dataStream;
private errorMessages;
private internalConnectionState;
constructor(url: string, protocols?: Array<string>, config?: WebSocketConfig, binaryType?: BinaryType);
connect(force?: boolean): void;
getErrorStream(): Subject<any>;
/**
* Run in Block Mode
* Return true when can send and false in socket closed
* @param data
* @returns {boolean}
*/
send4Direct(data: any, binary?: boolean): boolean;
/**
* Return Promise
* When can Send will resolve Promise
* When Socket closed will reject Promise
* @param data
* @returns {Promise<any>}
*/
send4Promise(data: any, binary?: boolean): Promise<any>;
/**
* Return cold Observable
* When can Send will complete observer
* When Socket closed will error observer
* @param data
* @returns {Observable<any>}
*/
send4Observable(data: any, binary?: boolean): Observable<any>;
private send4Mode;
/**
* Set send(data) function return mode
* @param mode
*/
setSend4Mode(mode: WebSocketSendMode): void;
/**
* Use {mode} mode to send {data} data
* If no specify, Default SendMode is Observable mode
* @param data
* @param mode
* @param binary
* @returns {any}
*/
send(data: any, mode?: WebSocketSendMode, binary?: boolean): any;
getDataStream(): Subject<any>;
onOpenHandler(event: Event): void;
notifyOpenCallbacks(event: any): void;
fireQueue(): void;
notifyCloseCallbacks(event: any): void;
notifyErrorCallbacks(event: any): void;
onOpen(cb: any): this;
onClose(cb: any): this;
onError(cb: any): this;
onMessage(callback: any, options?: any): this;
onMessageHandler(message: MessageEvent): void;
onCloseHandler(event: CloseEvent): void;
onErrorHandler(event: any): void;
reconnect(): this;
close(force?: boolean, keepReconnectIfNotNormalClose?: boolean): this;
getBackoffDelay(attempt: any): number;
setInternalState(state: any): void;
/**
* Could be -1 if not initzialized yet
* @returns {number}
*/
getReadyState(): number;
}
export interface WebSocketConfig {
initialTimeout?: number;
maxTimeout?: number;
reconnectIfNotNormalClose?: boolean;
}
export declare enum WebSocketSendMode {
Direct = 0,
Promise = 1,
Observable = 2,
}
export declare type BinaryType = "blob" | "arraybuffer";