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.
31 lines
590 B
31 lines
590 B
|
|
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) |
|
|
|
|