@@ -29,19 +29,23 @@ type Transport = "polling" | "websocket";
29
29
30
30
interface EngineOptions {
31
31
/**
32
- * how many ms without a pong packet to consider the connection closed (5000)
32
+ * how many ms without a pong packet to consider the connection closed
33
+ * @default 5000
33
34
*/
34
35
pingTimeout : number ;
35
36
/**
36
- * how many ms before sending a new ping packet (25000)
37
+ * how many ms before sending a new ping packet
38
+ * @default 25000
37
39
*/
38
40
pingInterval : number ;
39
41
/**
40
- * how many ms before an uncompleted transport upgrade is cancelled (10000)
42
+ * how many ms before an uncompleted transport upgrade is cancelled
43
+ * @default 10000
41
44
*/
42
45
upgradeTimeout : number ;
43
46
/**
44
- * how many bytes or characters a message can be, before closing the session (to avoid DoS). Default value is 1E5.
47
+ * how many bytes or characters a message can be, before closing the session (to avoid DoS).
48
+ * @default 1e5 (100 KB)
45
49
*/
46
50
maxHttpBufferSize : number ;
47
51
/**
@@ -55,19 +59,23 @@ interface EngineOptions {
55
59
fn : ( err : string | null | undefined , success : boolean ) => void
56
60
) => void ;
57
61
/**
58
- * to allow connections to (['polling', 'websocket'])
62
+ * the low-level transports that are enabled
63
+ * @default ["polling", "websocket"]
59
64
*/
60
65
transports : Transport [ ] ;
61
66
/**
62
- * whether to allow transport upgrades (true)
67
+ * whether to allow transport upgrades
68
+ * @default true
63
69
*/
64
70
allowUpgrades : boolean ;
65
71
/**
66
- * parameters of the WebSocket permessage-deflate extension (see ws module api docs). Set to false to disable. (false)
72
+ * parameters of the WebSocket permessage-deflate extension (see ws module api docs). Set to false to disable.
73
+ * @default false
67
74
*/
68
75
perMessageDeflate : boolean | object ;
69
76
/**
70
- * parameters of the http compression for the polling transports (see zlib api docs). Set to false to disable. (true)
77
+ * parameters of the http compression for the polling transports (see zlib api docs). Set to false to disable.
78
+ * @default true
71
79
*/
72
80
httpCompression : boolean | object ;
73
81
/**
@@ -82,7 +90,8 @@ interface EngineOptions {
82
90
initialPacket : any ;
83
91
/**
84
92
* configuration of the cookie that contains the client sid to send as part of handshake response headers. This cookie
85
- * might be used for sticky-session. Defaults to not sending any cookie (false)
93
+ * might be used for sticky-session. Defaults to not sending any cookie.
94
+ * @default false
86
95
*/
87
96
cookie : CookieSerializeOptions | boolean ;
88
97
/**
@@ -93,15 +102,18 @@ interface EngineOptions {
93
102
94
103
interface AttachOptions {
95
104
/**
96
- * name of the path to capture (/engine.io).
105
+ * name of the path to capture
106
+ * @default "/engine.io"
97
107
*/
98
108
path : string ;
99
109
/**
100
- * destroy unhandled upgrade requests (true)
110
+ * destroy unhandled upgrade requests
111
+ * @default true
101
112
*/
102
113
destroyUpgrade : boolean ;
103
114
/**
104
- * milliseconds after which unhandled requests are ended (1000)
115
+ * milliseconds after which unhandled requests are ended
116
+ * @default 1000
105
117
*/
106
118
destroyUpgradeTimeout : number ;
107
119
}
@@ -110,21 +122,30 @@ interface EngineAttachOptions extends EngineOptions, AttachOptions {}
110
122
111
123
interface ServerOptions extends EngineAttachOptions {
112
124
/**
113
- * name of the path to capture (/socket.io)
125
+ * name of the path to capture
126
+ * @default "/socket.io"
114
127
*/
115
128
path : string ;
116
129
/**
117
- * whether to serve the client files (true)
130
+ * whether to serve the client files
131
+ * @default true
118
132
*/
119
133
serveClient : boolean ;
120
134
/**
121
- * the adapter to use. Defaults to an instance of the Adapter that ships with socket.io which is memory based.
135
+ * the adapter to use
136
+ * @default the in-memory adapter (https://github.com/socketio/socket.io-adapter)
122
137
*/
123
138
adapter : any ;
124
139
/**
125
- * the parser to use. Defaults to an instance of the Parser that ships with socket.io.
140
+ * the parser to use
141
+ * @default the default parser (https://github.com/socketio/socket.io-parser)
126
142
*/
127
143
parser : any ;
144
+ /**
145
+ * how many ms before a client without namespace is closed
146
+ * @default 45000
147
+ */
148
+ connectTimeout : number ;
128
149
}
129
150
130
151
export class Server extends EventEmitter {
@@ -154,6 +175,7 @@ export class Server extends EventEmitter {
154
175
private eio ;
155
176
private engine ;
156
177
private _path : string ;
178
+ private _connectTimeout : number ;
157
179
private httpServer : http . Server ;
158
180
159
181
/**
@@ -173,6 +195,7 @@ export class Server extends EventEmitter {
173
195
srv = null ;
174
196
}
175
197
this . path ( opts . path || "/socket.io" ) ;
198
+ this . connectTimeout ( opts . connectTimeout || 45000 ) ;
176
199
this . serveClient ( false !== opts . serveClient ) ;
177
200
this . _parser = opts . parser || parser ;
178
201
this . encoder = new this . _parser . Encoder ( ) ;
@@ -263,6 +286,19 @@ export class Server extends EventEmitter {
263
286
return this ;
264
287
}
265
288
289
+ /**
290
+ * Set the delay after which a client without namespace is closed
291
+ * @param v
292
+ * @public
293
+ */
294
+ public connectTimeout ( v : number ) : Server ;
295
+ public connectTimeout ( ) : number ;
296
+ public connectTimeout ( v ?: number ) : Server | number {
297
+ if ( v === undefined ) return this . _connectTimeout ;
298
+ this . _connectTimeout = v ;
299
+ return this ;
300
+ }
301
+
266
302
/**
267
303
* Sets the adapter for rooms.
268
304
*
0 commit comments