bare-ws 1.0.0 → 1.1.0

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 (2) hide show
  1. package/lib/server.js +8 -1
  2. package/package.json +1 -1
package/lib/server.js CHANGED
@@ -11,7 +11,12 @@ const EMPTY = Buffer.alloc(0)
11
11
  const KEY = /^[+/0-9A-Za-z]{22}==$/
12
12
 
13
13
  module.exports = exports = class WebSocketServer extends EventEmitter {
14
- constructor (opts = {}) {
14
+ constructor (opts = {}, onconnection) {
15
+ if (typeof opts === 'function') {
16
+ onconnection = opts
17
+ opts = {}
18
+ }
19
+
15
20
  super()
16
21
 
17
22
  const createServer = opts.secure ? https.createServer : http.createServer
@@ -23,6 +28,8 @@ module.exports = exports = class WebSocketServer extends EventEmitter {
23
28
  this._server = server
24
29
 
25
30
  this._server.on('upgrade', this._onupgrade.bind(this))
31
+
32
+ if (onconnection) this.on('connection', onconnection)
26
33
  }
27
34
 
28
35
  get listening () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-ws",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "WebSocket library for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",