You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
590 B
32 lines
590 B
5 years ago
|
|
||
|
var inherits = require('inherits')
|
||
|
var WebSocketServer = require('ws').Server
|
||
|
var stream = require('./stream')
|
||
|
|
||
|
module.exports = Server
|
||
|
|
||
|
function Server(opts, cb) {
|
||
|
if (!(this instanceof Server)) {
|
||
|
return new Server(opts, cb)
|
||
|
}
|
||
|
|
||
|
WebSocketServer.call(this, opts)
|
||
|
|
||
|
var proxied = false
|
||
|
this.on('newListener', function(event) {
|
||
|
if (!proxied && event === 'stream') {
|
||
|
proxied = true
|
||
|
this.on('connection', function(conn) {
|
||
|
this.emit('stream', stream(conn))
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
|
||
|
if (cb) {
|
||
|
this.on('stream', cb)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
inherits(Server, WebSocketServer)
|
||
|
|