1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| 'use strict'
|
| var WebSocketServer = require('ws').Server
| var stream = require('./stream')
|
| class Server extends WebSocketServer{
| constructor(opts, cb) {
| super(opts)
|
| var proxied = false
| this.on('newListener', function(event) {
| if (!proxied && event === 'stream') {
| proxied = true
| this.on('connection', function(conn, req) {
| this.emit('stream', stream(conn, opts), req)
| })
| }
| })
|
| if (cb) {
| this.on('stream', cb)
| }
| }
| }
|
| module.exports.Server = Server
| module.exports.createServer = function(opts, cb) {
| return new Server(opts, cb)
| }
|
|