1
1
/// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
2
import EventEmitter from "events" ;
5
3
import { Validator } from "./validator" ;
6
- import Queue from "./queue" ;
7
4
import WebSocket from "ws" ;
8
- import { ExponentialStrategy } from "backoff" ;
9
5
import EventBuffer from "./event-buffer" ;
10
6
export interface RPC_ClientOptions {
11
7
identity : string ;
@@ -41,43 +37,32 @@ export interface IHandlersOption {
41
37
}
42
38
type IHandlers = ( { params, reply, method, signal, messageId, } : IHandlersOption ) => Promise < Record < string , any > > ;
43
39
declare class RPC_Client extends EventEmitter {
44
- _identity ?: string ;
45
- _wildcardHandler : IHandlers | null ;
46
- _handlers : Map < string , IHandlers > ;
47
- _state : number ;
48
- _callQueue : Queue ;
49
- _ws ?: WebSocket ;
50
- _wsAbortController ?: AbortController ;
51
- _keepAliveAbortController ?: AbortController ;
52
- _pendingPingResponse : boolean ;
53
- _lastPingTime : number ;
54
- _closePromise ?: Promise < {
55
- code : number ;
56
- reason : string ;
57
- } > ;
58
- _protocolOptions : string [ ] ;
59
- _protocol ?: string ;
60
- _strictProtocols : string [ ] ;
61
- _strictValidators ?: Map < string , Validator > ;
62
- _pendingCalls : Map < string , Record < string , any > > ;
63
- _pendingResponses : Map < string , {
64
- abort : {
65
- ( reason ?: any ) : void ;
66
- ( reason ?: any ) : void ;
67
- } ;
68
- promise : Promise < any > ;
69
- } > ;
70
- _outboundMsgBuffer : string [ ] ;
71
- _connectedOnce : boolean ;
72
- _backoffStrategy ?: ExponentialStrategy ;
73
- _badMessagesCount : number ;
74
- _reconnectAttempt : number ;
75
- _options : RPC_ClientOptions ;
76
- _connectionUrl : string ;
77
- _connectPromise : Promise < {
78
- response : any ;
79
- } > ;
80
- _nextPingTimeout : NodeJS . Timeout ;
40
+ protected _identity ?: string ;
41
+ private _wildcardHandler ;
42
+ private _handlers ;
43
+ protected _state : number ;
44
+ private _callQueue ;
45
+ protected _ws ?: WebSocket ;
46
+ private _wsAbortController ?;
47
+ private _keepAliveAbortController ?;
48
+ private _pendingPingResponse ;
49
+ private _lastPingTime ;
50
+ private _closePromise ?;
51
+ private _protocolOptions ;
52
+ protected _protocol ?: string ;
53
+ private _strictProtocols ;
54
+ private _strictValidators ?;
55
+ private _pendingCalls ;
56
+ private _pendingResponses ;
57
+ private _outboundMsgBuffer ;
58
+ private _connectedOnce ;
59
+ private _backoffStrategy ?;
60
+ private _badMessagesCount ;
61
+ private _reconnectAttempt ;
62
+ protected _options : RPC_ClientOptions ;
63
+ private _connectionUrl ;
64
+ private _connectPromise ;
65
+ private _nextPingTimeout ;
81
66
static OPEN : number ;
82
67
static CONNECTING : number ;
83
68
static CLOSING : number ;
@@ -92,22 +77,17 @@ declare class RPC_Client extends EventEmitter {
92
77
* @returns {Promise<undefined> } Resolves when connected, rejects on failure
93
78
*/
94
79
connect ( ) : Promise < any > ;
95
- _keepAlive ( ) : Promise < void > ;
96
- _tryReconnect ( ) : Promise < void > ;
97
- _beginConnect ( ) : Promise < {
98
- response : any ;
99
- } > ;
80
+ private _keepAlive ;
81
+ private _tryReconnect ;
82
+ private _beginConnect ;
100
83
/**
101
84
* Start consuming from a WebSocket
102
85
* @param {WebSocket } ws - A WebSocket instance
103
86
* @param {EventBuffer } leadMsgBuffer - A buffer which traps all 'message' events
104
87
*/
105
- _attachWebsocket ( ws : WebSocket , leadMsgBuffer ?: EventBuffer ) : void ;
106
- _handleDisconnect ( { code, reason } : {
107
- code : number ;
108
- reason : Buffer ;
109
- } ) : void ;
110
- _rejectPendingCalls ( abortReason : string ) : void ;
88
+ protected _attachWebsocket ( ws : WebSocket , leadMsgBuffer ?: EventBuffer ) : void ;
89
+ private _handleDisconnect ;
90
+ private _rejectPendingCalls ;
111
91
/**
112
92
* Call a method on a remote RPCClient or RPCServerClient.
113
93
* @param {string } method - The RPC method to call.
@@ -119,7 +99,7 @@ declare class RPC_Client extends EventEmitter {
119
99
* @returns Promise<*> - Response value from the remote handler.
120
100
*/
121
101
call ( method : any , params ?: any , options ?: Record < string , any > ) : Promise < unknown > ;
122
- _call ( method : any , params : any , options ?: Record < string , any > ) : Promise < any > ;
102
+ private _call ;
123
103
/**
124
104
* Closes the RPCClient.
125
105
* @param {Object } options - Close options
@@ -139,12 +119,12 @@ declare class RPC_Client extends EventEmitter {
139
119
code : number | undefined ;
140
120
reason : string | undefined ;
141
121
} | undefined > ;
142
- _awaitUntilPendingSettled ( ) : Promise < PromiseSettledResult < any > [ ] > ;
143
- _deferNextPing ( ) : void ;
144
- _onMessage ( buffer : Buffer ) : void ;
145
- _onCall ( msgId : string , method : string , params : any ) : Promise < void > ;
146
- _onCallResult ( msgId : string , result : any ) : any ;
147
- _onCallError ( msgId : string , errorCode : string , errorDescription : string , errorDetails : Record < string , any > ) : void ;
122
+ private _awaitUntilPendingSettled ;
123
+ private _deferNextPing ;
124
+ private _onMessage ;
125
+ private _onCall ;
126
+ private _onCallResult ;
127
+ private _onCallError ;
148
128
/**
149
129
* Send a message to the RPCServer. While socket is connecting, the message is queued and send when open.
150
130
* @param {Buffer|String } message - String to send via websocket
0 commit comments