Initial commit
This commit is contained in:
54
node_modules/wss/index.js
generated
vendored
Normal file
54
node_modules/wss/index.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
const {Server} = require('ws')
|
||||
|
||||
Server.prototype.listening = false
|
||||
Server.prototype.listen = function (...args) {
|
||||
return this._server
|
||||
.listen(...args)
|
||||
.once('listening', () => {
|
||||
this.listening = true
|
||||
})
|
||||
}
|
||||
Server.prototype.close = function (fn = Function.prototype) {
|
||||
if (this.clients) {
|
||||
for (const client of this.clients) client.terminate()
|
||||
}
|
||||
this._ultron.destroy()
|
||||
this._ultron = null
|
||||
return this._server.close((...args) => {
|
||||
this.listening = false
|
||||
fn(...args)
|
||||
})
|
||||
}
|
||||
module.exports = Server // v 1
|
||||
module.exports.createServerFrom = createServerFrom
|
||||
module.exports.createServer = createServer
|
||||
function createServerFrom (server, connectionListener, options = {}) {
|
||||
if (typeof server === 'undefined') throw new Error('must provide server')
|
||||
const wss = new Server(Object.assign(options, {server}))
|
||||
return connectionListener
|
||||
? wss.on('connection', connectionListener)
|
||||
: wss
|
||||
}
|
||||
|
||||
function createServer (options = {}, connectionListener) {
|
||||
if (typeof options === 'function') {
|
||||
connectionListener = options
|
||||
options = {}
|
||||
}
|
||||
const server = createServerFor(options)
|
||||
return createServerFrom(server, connectionListener) // v 2
|
||||
function createServerFor (options) {
|
||||
return options.key && options.cert || options.pfx
|
||||
? require('https').createServer(options, requestListener)
|
||||
: require('http').createServer(requestListener)
|
||||
}
|
||||
|
||||
function requestListener (req, res) {
|
||||
const {STATUS_CODES: {'426': status}} = require('http')
|
||||
res.writeHead(426, {
|
||||
'content-length': status.length,
|
||||
'content-type': 'text/plain'
|
||||
})
|
||||
res.end(status)
|
||||
}
|
||||
}
|
||||
45
node_modules/wss/package.json
generated
vendored
Normal file
45
node_modules/wss/package.json
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "wss",
|
||||
"version": "3.3.4",
|
||||
"description": "wrapper built upon ws module that provides standard server api only.",
|
||||
"author": "Ivo von Putzer Reibegg <ivo.putzer@gmail.com> (https://github.com/ivoputzer)",
|
||||
"homepage": "https://github.com/ivoputzer/wss#readme",
|
||||
"keywords": [
|
||||
"Hixie",
|
||||
"HyBi",
|
||||
"Push",
|
||||
"RFC-6455",
|
||||
"WebSocket",
|
||||
"WebSocketServer",
|
||||
"real-time"
|
||||
],
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/ivoputzer/wss.git"
|
||||
},
|
||||
"scripts": {
|
||||
"version": "echo $npm_package_version",
|
||||
"test": "m.test",
|
||||
"pretest": "standard",
|
||||
"coverage": "node --require ./node_modules/m.test/global.js ./node_modules/istanbul/lib/cli.js cover --print detail test/.istanbul.js"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"istanbul": "^0.4.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"dependencies": {
|
||||
"ws": "^2.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"standard": "^8.6.0",
|
||||
"m.test": "0.0.57",
|
||||
"pem": "^1.9.4"
|
||||
},
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/ivoputzer/wss/issues"
|
||||
}
|
||||
}
|
||||
71
node_modules/wss/readme.md
generated
vendored
Normal file
71
node_modules/wss/readme.md
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
wss
|
||||
===
|
||||
[](https://travis-ci.org/ivoputzer/wss)
|
||||
[](package.json)
|
||||
[](http://standardjs.com/)
|
||||
[](https://coveralls.io/github/ivoputzer/wss?branch=master)
|
||||
[](https://nodejs.org/docs/v6.0.0/api)
|
||||
[](https://www.npmjs.com/package/wss)
|
||||
[](https://spdx.org/licenses/MIT)
|
||||
|
||||
wrapper built upon [ws](https://www.npmjs.org/package/ws) module that provides standard server api only.
|
||||
|
||||
#### usage with server creation
|
||||
|
||||
```javascript
|
||||
const {createServer} = require('wss')
|
||||
|
||||
createServer(function connectionListener (ws) {
|
||||
ws.send('welcome!')
|
||||
ws.on('message', (data) => {
|
||||
ws.send(data.toString()) // echo-server
|
||||
})
|
||||
})
|
||||
.listen(8080, function () {
|
||||
const {address, port} = this.address() // this is the http[s].Server
|
||||
console.log('listening on http://%s:%d (%s)', /::/.test(address) ? '0.0.0.0' : address, port)
|
||||
})
|
||||
```
|
||||
|
||||
#### usage with existent server
|
||||
```javascript
|
||||
const {createServer} = require('http')
|
||||
const {createServerFrom} = require('wss')
|
||||
|
||||
const http = createServer()
|
||||
createServerFrom(http, function connectionListener (ws) {
|
||||
ws.send('welcome!')
|
||||
ws.on('message', (data) => {
|
||||
ws.send(data.toString()) // echo-server
|
||||
})
|
||||
})
|
||||
http.listen(8080)
|
||||
```
|
||||
|
||||
### wss
|
||||
the `ws.Server` object is inherited from [ws](http://npmjs.org/ws)
|
||||
|
||||
### wss.prototype.close([callback])
|
||||
stops the server from accepting new connections.
|
||||
|
||||
### wss.prototype.listen(handle[, callback])
|
||||
the `handle` object can be set to either a server or socket (anything with an underlying _handle_ member), or a `{fd}` object. This function is asynchronous. callback will be added as a listener for the `listening` event.
|
||||
|
||||
### wss.prototype.listen(path[, callback])
|
||||
start a unix socket server listening for connections on the given path. this function is asynchronous. callback will be added as a listener for the `listening` event.
|
||||
|
||||
### wss.prototype.listen([port[, hostname[, backlog[, callback]]]])
|
||||
begin accepting connections on the specified port and hostname. if the hostname is omitted, the server will accept connections on any ipv6 address (::) when ipv6 is available, or any ipv4 address (0.0.0.0) otherwise. omit the port argument, or use a port value of 0, to have the operating system assign a random port, which can be retrieved by using server.address().port after the `listening` event has been emitted.
|
||||
|
||||
to listen to a unix socket, supply a filename instead of port and hostname.
|
||||
|
||||
backlog is the maximum length of the queue of pending connections. The actual length will be determined by your OS through sysctl settings such as `tcp_max_syn_backlog` and somaxconn on linux. The default value of this parameter is `511`. This function is asynchronous. `callback` will be added as a listener for the `listening` event.
|
||||
|
||||
Note: The server.listen() method may be called multiple times. Each subsequent call will re-open the server using the provided options.
|
||||
|
||||
### wss.createServerFrom(server=http.Server|https.Server)
|
||||
returns a new `ws.Server` based on given web server object.
|
||||
throws if no server is given.
|
||||
|
||||
### wss.createServer([options[, connectionListener]])
|
||||
returns a new `ws.Server` based on given options and connectionListener. underlaying `https` server is created when `tls` options have been provided as of`tls.createServer()`, otherwise it will fallback to a `http` implementation. the connectionListener is a function which is automatically added to the `connection` event.
|
||||
Reference in New Issue
Block a user