@@ -15,27 +15,27 @@ export interface SocketOptions {
15
15
/**
16
16
* The host that we're connecting to. Set from the URI passed when connecting
17
17
*/
18
- host : string ;
18
+ host ? : string ;
19
19
20
20
/**
21
21
* The hostname for our connection. Set from the URI passed when connecting
22
22
*/
23
- hostname : string ;
23
+ hostname ? : string ;
24
24
25
25
/**
26
26
* If this is a secure connection. Set from the URI passed when connecting
27
27
*/
28
- secure : boolean ;
28
+ secure ? : boolean ;
29
29
30
30
/**
31
31
* The port for our connection. Set from the URI passed when connecting
32
32
*/
33
- port : string | number ;
33
+ port ? : string | number ;
34
34
35
35
/**
36
36
* Any query parameters in our uri. Set from the URI passed when connecting
37
37
*/
38
- query : { [ key : string ] : any } ;
38
+ query ? : { [ key : string ] : any } ;
39
39
40
40
/**
41
41
* `http.Agent` to use, defaults to `false` (NodeJS only)
@@ -44,35 +44,35 @@ export interface SocketOptions {
44
44
*
45
45
* @see https://nodejs.org/api/http.html#httprequestoptions-callback
46
46
*/
47
- agent : string | boolean ;
47
+ agent ? : string | boolean ;
48
48
49
49
/**
50
50
* Whether the client should try to upgrade the transport from
51
51
* long-polling to something better.
52
52
* @default true
53
53
*/
54
- upgrade : boolean ;
54
+ upgrade ? : boolean ;
55
55
56
56
/**
57
57
* Forces base 64 encoding for polling transport even when XHR2
58
58
* responseType is available and WebSocket even if the used standard
59
59
* supports binary.
60
60
*/
61
- forceBase64 : boolean ;
61
+ forceBase64 ? : boolean ;
62
62
63
63
/**
64
64
* The param name to use as our timestamp key
65
65
* @default 't'
66
66
*/
67
- timestampParam : string ;
67
+ timestampParam ? : string ;
68
68
69
69
/**
70
70
* Whether to add the timestamp with each transport request. Note: this
71
71
* is ignored if the browser is IE or Android, in which case requests
72
72
* are always stamped
73
73
* @default false
74
74
*/
75
- timestampRequests : boolean ;
75
+ timestampRequests ? : boolean ;
76
76
77
77
/**
78
78
* A list of transports to try (in order). Engine.io always attempts to
@@ -81,7 +81,7 @@ export interface SocketOptions {
81
81
*
82
82
* @default ['polling','websocket', 'webtransport']
83
83
*/
84
- transports : string [ ] ;
84
+ transports ? : string [ ] ;
85
85
86
86
/**
87
87
* If true and if the previous websocket connection to the server succeeded,
@@ -92,50 +92,50 @@ export interface SocketOptions {
92
92
* not block websockets.
93
93
* @default false
94
94
*/
95
- rememberUpgrade : boolean ;
95
+ rememberUpgrade ? : boolean ;
96
96
97
97
/**
98
98
* Timeout for xhr-polling requests in milliseconds (0) (only for polling transport)
99
99
*/
100
- requestTimeout : number ;
100
+ requestTimeout ? : number ;
101
101
102
102
/**
103
103
* Transport options for Node.js client (headers etc)
104
104
*/
105
- transportOptions : Object ;
105
+ transportOptions ? : Object ;
106
106
107
107
/**
108
108
* (SSL) Certificate, Private key and CA certificates to use for SSL.
109
109
* Can be used in Node.js client environment to manually specify
110
110
* certificate information.
111
111
*/
112
- pfx : string ;
112
+ pfx ? : string ;
113
113
114
114
/**
115
115
* (SSL) Private key to use for SSL. Can be used in Node.js client
116
116
* environment to manually specify certificate information.
117
117
*/
118
- key : string ;
118
+ key ? : string ;
119
119
120
120
/**
121
121
* (SSL) A string or passphrase for the private key or pfx. Can be
122
122
* used in Node.js client environment to manually specify certificate
123
123
* information.
124
124
*/
125
- passphrase : string ;
125
+ passphrase ? : string ;
126
126
127
127
/**
128
128
* (SSL) Public x509 certificate to use. Can be used in Node.js client
129
129
* environment to manually specify certificate information.
130
130
*/
131
- cert : string ;
131
+ cert ? : string ;
132
132
133
133
/**
134
134
* (SSL) An authority certificate or array of authority certificates to
135
135
* check the remote host against.. Can be used in Node.js client
136
136
* environment to manually specify certificate information.
137
137
*/
138
- ca : string | string [ ] ;
138
+ ca ? : string | string [ ] ;
139
139
140
140
/**
141
141
* (SSL) A string describing the ciphers to use or exclude. Consult the
@@ -144,7 +144,7 @@ export interface SocketOptions {
144
144
* details on the format.. Can be used in Node.js client environment to
145
145
* manually specify certificate information.
146
146
*/
147
- ciphers : string ;
147
+ ciphers ? : string ;
148
148
149
149
/**
150
150
* (SSL) If true, the server certificate is verified against the list of
@@ -153,7 +153,7 @@ export interface SocketOptions {
153
153
* is sent. Can be used in Node.js client environment to manually specify
154
154
* certificate information.
155
155
*/
156
- rejectUnauthorized : boolean ;
156
+ rejectUnauthorized ? : boolean ;
157
157
158
158
/**
159
159
* Headers that will be passed for each request to the server (via xhr-polling and via websockets).
@@ -166,56 +166,56 @@ export interface SocketOptions {
166
166
* client certificates, etc.) with cross-origin XHR polling requests
167
167
* @default false
168
168
*/
169
- withCredentials : boolean ;
169
+ withCredentials ? : boolean ;
170
170
171
171
/**
172
172
* Whether to automatically close the connection whenever the beforeunload event is received.
173
173
* @default false
174
174
*/
175
- closeOnBeforeunload : boolean ;
175
+ closeOnBeforeunload ? : boolean ;
176
176
177
177
/**
178
178
* Whether to always use the native timeouts. This allows the client to
179
179
* reconnect when the native timeout functions are overridden, such as when
180
180
* mock clocks are installed.
181
181
* @default false
182
182
*/
183
- useNativeTimers : boolean ;
183
+ useNativeTimers ? : boolean ;
184
184
185
185
/**
186
186
* Whether the heartbeat timer should be unref'ed, in order not to keep the Node.js event loop active.
187
187
*
188
188
* @see https://nodejs.org/api/timers.html#timeoutunref
189
189
* @default false
190
190
*/
191
- autoUnref : boolean ;
191
+ autoUnref ? : boolean ;
192
192
193
193
/**
194
194
* parameters of the WebSocket permessage-deflate extension (see ws module api docs). Set to false to disable.
195
195
* @default false
196
196
*/
197
- perMessageDeflate : { threshold : number } ;
197
+ perMessageDeflate ? : { threshold : number } ;
198
198
199
199
/**
200
200
* The path to get our client file from, in the case of the server
201
201
* serving it
202
202
* @default '/engine.io'
203
203
*/
204
- path : string ;
204
+ path ? : string ;
205
205
206
206
/**
207
207
* Whether we should add a trailing slash to the request path.
208
208
* @default true
209
209
*/
210
- addTrailingSlash : boolean ;
210
+ addTrailingSlash ? : boolean ;
211
211
212
212
/**
213
213
* Either a single protocol string or an array of protocol strings. These strings are used to indicate sub-protocols,
214
214
* so that a single server can implement multiple WebSocket sub-protocols (for example, you might want one server to
215
215
* be able to handle different types of interactions depending on the specified protocol)
216
216
* @default []
217
217
*/
218
- protocols : string | string [ ] ;
218
+ protocols ? : string | string [ ] ;
219
219
}
220
220
221
221
interface HandshakeData {
@@ -285,7 +285,9 @@ export class Socket extends Emitter<
285
285
* @param {String|Object } uri - uri or options
286
286
* @param {Object } opts - options
287
287
*/
288
- constructor ( uri , opts : Partial < SocketOptions > = { } ) {
288
+ constructor ( uri ?: string , opts ?: SocketOptions ) ;
289
+ constructor ( opts : SocketOptions ) ;
290
+ constructor ( uri ?: string | SocketOptions , opts : SocketOptions = { } ) {
289
291
super ( ) ;
290
292
291
293
if ( uri && "object" === typeof uri ) {
@@ -294,11 +296,12 @@ export class Socket extends Emitter<
294
296
}
295
297
296
298
if ( uri ) {
297
- uri = parse ( uri ) ;
298
- opts . hostname = uri . host ;
299
- opts . secure = uri . protocol === "https" || uri . protocol === "wss" ;
300
- opts . port = uri . port ;
301
- if ( uri . query ) opts . query = uri . query ;
299
+ const parsedUri = parse ( uri as string ) ;
300
+ opts . hostname = parsedUri . host ;
301
+ opts . secure =
302
+ parsedUri . protocol === "https" || parsedUri . protocol === "wss" ;
303
+ opts . port = parsedUri . port ;
304
+ if ( parsedUri . query ) opts . query = parsedUri . query ;
302
305
} else if ( opts . host ) {
303
306
opts . hostname = parse ( opts . host ) . host ;
304
307
}
0 commit comments