-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
35 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use strict' | ||
|
||
var http = require('http') | ||
var websocket = require('./') | ||
var server = null | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
var Server = require('./server.js') | ||
var server = require('./server.js') | ||
|
||
module.exports = require('./stream.js') | ||
module.exports.Server = Server | ||
module.exports.createServer = Server | ||
module.exports.Server = server.Server | ||
module.exports.createServer = server.createServer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
'use strict' | ||
|
||
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, opts)) | ||
}) | ||
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) { | ||
this.emit('stream', stream(conn, opts)) | ||
}) | ||
} | ||
}) | ||
|
||
if (cb) { | ||
this.on('stream', cb) | ||
} | ||
}) | ||
|
||
if (cb) { | ||
this.on('stream', cb) | ||
} | ||
} | ||
|
||
inherits(Server, WebSocketServer) | ||
|
||
module.exports.Server = Server | ||
module.exports.createServer = function(opts, cb) { | ||
return new Server(opts, cb) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters