Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #926 from websockets/remove/factory-functions
Remove `WebSocket.createServer()` and `WebSocket.connect()`
- Loading branch information
Showing
1 changed file
with
6 additions
and
40 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,49 +1,15 @@ | ||
'use strict'; | ||
|
||
/*! | ||
* ws: a node.js websocket client | ||
* Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
var WS = module.exports = require('./lib/WebSocket'); | ||
|
||
WS.Server = require('./lib/WebSocketServer'); | ||
WS.Sender = require('./lib/Sender'); | ||
WS.Receiver = require('./lib/Receiver'); | ||
|
||
/** | ||
* Create a new WebSocket server. | ||
* | ||
* @param {Object} options Server options | ||
* @param {Function} fn Optional connection listener. | ||
* @returns {WS.Server} | ||
* @api public | ||
*/ | ||
WS.createServer = function createServer (options, fn) { | ||
var server = new WS.Server(options); | ||
|
||
if (typeof fn === 'function') { | ||
server.on('connection', fn); | ||
} | ||
|
||
return server; | ||
}; | ||
'use strict'; | ||
|
||
/** | ||
* Create a new WebSocket connection. | ||
* | ||
* @param {String} address The URL/address we need to connect to. | ||
* @param {Function} fn Open listener. | ||
* @returns {WS} | ||
* @api public | ||
*/ | ||
WS.connect = WS.createConnection = function connect (address, fn) { | ||
var client = new WS(address); | ||
const WebSocket = require('./lib/WebSocket'); | ||
|
||
if (typeof fn === 'function') { | ||
client.on('open', fn); | ||
} | ||
WebSocket.Server = require('./lib/WebSocketServer'); | ||
WebSocket.Receiver = require('./lib/Receiver'); | ||
WebSocket.Sender = require('./lib/Sender'); | ||
|
||
return client; | ||
}; | ||
module.exports = WebSocket; |