angelia.io 2.4.73 → 2.4.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "angelia.io",
3
- "version": "2.4.73",
3
+ "version": "2.4.74",
4
4
  "description": "WebSockets Server and Client API for node.js and the browser, with rooms support.",
5
5
  "homepage": "https://github.com/titoBouzout/angelia.io",
6
6
  "repository": {
package/readme.md CHANGED
@@ -90,6 +90,7 @@ Server.listen({
90
90
  | `cert` | String | '' | path to the cert file for using https fullchain.pem |
91
91
  | `key` | String | '' | path to the key file for using https privkey.pem |
92
92
  | `http` | node server | null | in case you want to use your own server. Else one will be created, as in `require('http(s)').createServer()` |
93
+ | `timeout` | Number | 60000 | time in milliseconds after a socket is considered gone, minimun value is 10000 |
93
94
 
94
95
  ### Server Object
95
96
 
package/server/Server.js CHANGED
@@ -97,12 +97,14 @@ class ServerSingleton {
97
97
 
98
98
  since: Date.now(),
99
99
  now: Date.now(),
100
+ timeout: +options.timeout >= 10000 ? +options.timeout : this.timeout,
100
101
  })
102
+ this.timeoutCheck = this.timeout / 2
101
103
 
102
104
  this.ensureFastProperties()
103
105
 
104
106
  // updates ping and checks for disconnections
105
- setInterval(this.ping, 30 * 1000)
107
+ setInterval(this.ping, this.timeoutCheck)
106
108
  setInterval(this.updateNow, 500)
107
109
 
108
110
  // fires the server
@@ -217,8 +219,6 @@ class ServerSingleton {
217
219
 
218
220
  // PRIVATE API
219
221
  onconnect(socket, request) {
220
- this.updateNow()
221
-
222
222
  socket = new this.Socket(socket, this)
223
223
 
224
224
  // set the ip, userAgent and params
@@ -305,8 +305,18 @@ class ServerSingleton {
305
305
  socket.timedout = true
306
306
  this.events.timeout && this.events.timeout(socket.proxy, delay)
307
307
  socket.io.terminate()
308
- } else {
309
- // ping
308
+ } else if (delay > this.timeoutCheck - 5000) {
309
+ /*
310
+ in an example:
311
+ if timeout is set to 60 seeconds
312
+ then we check for timed out sockets every 30 seconds
313
+ if the socket was last seen 29 seconds ago
314
+ then the next check will be in another 30 seconds
315
+ that means that if the socket doesnt sends any message
316
+ then the last seen will be 59 seconds the next time
317
+ this gives very little amount of time to check
318
+ for this reason we remove 5 seconds on the condition
319
+ */
310
320
  this.pingSocket(socket)
311
321
  }
312
322
  }