angelia.io 2.4.71 → 2.4.72

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/readme.md +35 -31
  3. package/server/Server.js +21 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "angelia.io",
3
- "version": "2.4.71",
3
+ "version": "2.4.72",
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
@@ -81,14 +81,15 @@ Server.listen({
81
81
 
82
82
  ### `Server` Options
83
83
 
84
- | name | kind | default | description |
85
- | -------------------- | ------- | ------- | --------------------------------------------------- |
86
- | `hostname` | String | '' | the hostname if any |
87
- | `port` | Number | 3001 | the port to use for this server |
88
- | `maxMessageSize` | Number | 5 | max size in mb of a message received |
89
- | `skipUTF8Validation` | Boolean | false | allows to skip utf8 validation |
90
- | `cert` | String | '' | path to the cert file for using https fullchain.pem |
91
- | `key` | String | '' | path to the key file for using https privkey.pem |
84
+ | name | kind | default | description |
85
+ | -------------------- | ----------- | ------- | ------------------------------------------------------------------------------------------------------------ |
86
+ | `hostname` | String | '' | the hostname if any |
87
+ | `port` | Number | 3001 | the port to use for this server |
88
+ | `maxMessageSize` | Number | 5 | max size in mb of a message received |
89
+ | `skipUTF8Validation` | Boolean | false | allows to skip utf8 validation |
90
+ | `cert` | String | '' | path to the cert file for using https fullchain.pem |
91
+ | `key` | String | '' | path to the key file for using https privkey.pem |
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()` |
92
93
 
93
94
  ### Server Object
94
95
 
@@ -115,29 +116,32 @@ Server.listen({
115
116
  <details>
116
117
  <summary><b>Expand</b></summary>
117
118
 
118
- | signature | kind | description |
119
- | ------------------------------------- | -------- | ---------------------------------------------------------------------------------------------- |
120
- | `since` | Number | timestamp of initialization |
121
- | `port` | Number | port used by this server |
122
- | `maxMessageSize` | Number | maximum message size in mb |
123
- | `timeout` | Number | after how long the socket is considered gone, in ms |
124
- | `connections` | Number | count of sockets connected |
125
- | `served` | Number | count of sockets ever connected |
126
- | `bytesSent` | Number | sum of bytes sent by the server |
127
- | `bytesReceived` | Number | sum of bytes the server has ever received |
128
- | `messagesSent` | Number | count of messages ever sent |
129
- | `messagesReceived` | Number | count of messages ever received |
130
- | `events` | Object | ref to events, ex: server.events.typing() to dispatch typing to anyone listening to it |
131
- | `listeners` | Array | for debbuging: array of listeners as strings |
132
- | `on(Class)` | Function | attaches all methods of a `Class` as listeners |
133
- | `on(Function)` | Function | attaches a named `Function` as a listener |
134
- | `on(Object)` | Function | attaches all properties of an object that are of the type `Function` as listeners |
135
- | `on(key, Function)` | Function | attaches a `Function` as a listener for `key` |
136
- | `emit(key, [value])` | Function | emits to all connected sockets |
137
- | `once(key, [value])` | Function | emits to the sockets and replace if exists a pending message with the same `key` |
138
- | `broadcast(sender, key, [value])` | Function | emits to all connected sockets except sender |
139
- | `broadcastOnce(sender, key, [value])` | Function | emits to the sockets except sender and replace if exists a pending message with the same `key` |
140
- | `sockets` | Set | a Set() with all the current connected sockets |
119
+ | signature | kind | description |
120
+ | ------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------- |
121
+ | `since` | Number | timestamp of initialization |
122
+ | `now` | Number | timestamp that updates every half a second |
123
+ | `port` | Number | port used by this server |
124
+ | `hostname` | String | the hostname if any |
125
+ | `maxMessageSize` | Number | maximum message size in mb |
126
+ | `timeout` | Number | after how long the socket is considered gone, in ms |
127
+ | `connections` | Number | count of sockets connected |
128
+ | `served` | Number | count of sockets ever connected |
129
+ | `bytesSent` | Number | sum of bytes sent by the server |
130
+ | `bytesReceived` | Number | sum of bytes the server has ever received |
131
+ | `messagesSent` | Number | count of messages ever sent |
132
+ | `messagesReceived` | Number | count of messages ever received |
133
+ | `events` | Object | ref to events, ex: server.events.typing() to dispatch typing to anyone listening to it |
134
+ | `listeners` | Array | for debbuging: array of listeners as strings |
135
+ | `on(Class)` | Function | attaches all methods of a `Class` as listeners |
136
+ | `on(Function)` | Function | attaches a named `Function` as a listener |
137
+ | `on(Object)` | Function | attaches all properties of an object that are of the type `Function` as listeners |
138
+ | `on(key, Function)` | Function | attaches a `Function` as a listener for `key` |
139
+ | `emit(key, [value])` | Function | emits to all connected sockets |
140
+ | `once(key, [value])` | Function | emits to the sockets and replace if exists a pending message with the same `key` |
141
+ | `broadcast(sender, key, [value])` | Function | emits to all connected sockets except sender |
142
+ | `broadcastOnce(sender, key, [value])` | Function | emits to the sockets except sender and replace if exists a pending message with the same `key` |
143
+ | `sockets` | Set | a Set() with all the current connected sockets |
144
+ | `http` | node server | the underlying http(s) server |
141
145
 
142
146
  </details>
143
147
 
package/server/Server.js CHANGED
@@ -17,6 +17,7 @@ class ServerSingleton {
17
17
 
18
18
  cert: '',
19
19
  key: '',
20
+ http: null,
20
21
 
21
22
  queue: [],
22
23
 
@@ -92,6 +93,7 @@ class ServerSingleton {
92
93
  maxMessageSize: +options.maxMessageSize > 0 ? +options.maxMessageSize : this.maxMessageSize,
93
94
  cert: options.cert || this.cert,
94
95
  key: options.key || this.key,
96
+ http: options.http || this.http,
95
97
 
96
98
  since: Date.now(),
97
99
  now: Date.now(),
@@ -104,26 +106,27 @@ class ServerSingleton {
104
106
  setInterval(this.updateNow, 500)
105
107
 
106
108
  // fires the server
107
- let server
108
- function handle(req, res) {
109
- res.writeHead(200, { 'Content-Type': 'text/plain' })
110
- res.end()
111
- }
112
- if (this.cert && this.key) {
113
- let fs = require('fs')
114
- server = require('https').createServer(
115
- {
116
- cert: fs.readFileSync(this.cert), // fullchain.pem
117
- key: fs.readFileSync(this.key), // privkey.pem
118
- },
119
- handle,
120
- )
121
- } else {
122
- server = require('http').createServer(handle)
109
+ if (!this.http) {
110
+ function handle(req, res) {
111
+ res.writeHead(200, { 'Content-Type': 'text/plain' })
112
+ res.end()
113
+ }
114
+ if (this.cert && this.key) {
115
+ let fs = require('fs')
116
+ this.http = require('https').createServer(
117
+ {
118
+ cert: fs.readFileSync(this.cert), // fullchain.pem
119
+ key: fs.readFileSync(this.key), // privkey.pem
120
+ },
121
+ handle,
122
+ )
123
+ } else {
124
+ this.http = require('http').createServer(handle)
125
+ }
123
126
  }
124
127
 
125
128
  let io = new this.WebSocket.Server({
126
- server: server,
129
+ server: this.http,
127
130
  perMessageDeflate: false,
128
131
  maxPayload: this.maxMessageSize * 1024 * 1024,
129
132
  clientTracking: false,
@@ -135,7 +138,7 @@ class ServerSingleton {
135
138
  io.on('connection', this.onconnect)
136
139
  io.on('error', this.onerror)
137
140
 
138
- server.listen(this.port, this.hostname || null)
141
+ this.http.listen(this.port, this.hostname || null)
139
142
 
140
143
  for (let m of ['RESTART', 'SIGINT', 'SIGTERM', 'SIGBREAK']) {
141
144
  process.on(m, () => {
@@ -156,8 +159,6 @@ class ServerSingleton {
156
159
 
157
160
  console.log('Socket Server Started Listening On Port ', this.port)
158
161
  this.events.listen && this.events.listen()
159
-
160
- return this
161
162
  }
162
163
 
163
164
  // count of connections