增加晶全app静态页面
This commit is contained in:
8
node_modules/websocket-stream/LICENSE
generated
vendored
Normal file
8
node_modules/websocket-stream/LICENSE
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
Copyright (c) 2013, Max Ogden
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
11
node_modules/websocket-stream/collaborators.md
generated
vendored
Normal file
11
node_modules/websocket-stream/collaborators.md
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
## Collaborators
|
||||
|
||||
websocket-stream is only possible due to the excellent work of the following collaborators:
|
||||
|
||||
<table><tbody><tr><th align="left">gst</th><td><a href="https://github.com/gst">GitHub/gst</a></td></tr>
|
||||
<tr><th align="left">maxogden</th><td><a href="https://github.com/maxogden">GitHub/maxogden</a></td></tr>
|
||||
<tr><th align="left">deanlandolt</th><td><a href="https://github.com/deanlandolt">GitHub/deanlandolt</a></td></tr>
|
||||
<tr><th align="left">mcollina</th><td><a href="https://github.com/mcollina">GitHub/mcollina</a></td></tr>
|
||||
<tr><th align="left">jnordberg</th><td><a href="https://github.com/jnordberg">GitHub/jnordberg</a></td></tr>
|
||||
<tr><th align="left">mafintosh</th><td><a href="https://github.com/mafintosh">GitHub/mafintosh</a></td></tr>
|
||||
</tbody></table>
|
||||
51
node_modules/websocket-stream/echo-server.js
generated
vendored
Normal file
51
node_modules/websocket-stream/echo-server.js
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
'use strict'
|
||||
|
||||
var http = require('http')
|
||||
var websocket = require('./')
|
||||
var server = null
|
||||
|
||||
var port = module.exports.port = 8343
|
||||
var url = module.exports.url = 'ws://localhost:' + module.exports.port
|
||||
|
||||
module.exports.start = function(opts, cb) {
|
||||
if (server) {
|
||||
cb(new Error('already started'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof opts == 'function') {
|
||||
cb = opts;
|
||||
opts = {};
|
||||
}
|
||||
|
||||
server = http.createServer()
|
||||
opts.server = server
|
||||
|
||||
websocket.createServer(opts, echo)
|
||||
|
||||
server.listen(port, cb)
|
||||
|
||||
function echo(stream) {
|
||||
stream.pipe(stream)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.stop = function(cb) {
|
||||
if (!server) {
|
||||
cb(new Error('not started'))
|
||||
return
|
||||
}
|
||||
|
||||
server.close(cb)
|
||||
server = null
|
||||
}
|
||||
|
||||
if (!module.parent) {
|
||||
module.exports.start(function(err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
console.log('Echo server started on port ' + port);
|
||||
});
|
||||
}
|
||||
27
node_modules/websocket-stream/index.d.ts
generated
vendored
Normal file
27
node_modules/websocket-stream/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
// Type definitions for websocket-stream 5.3
|
||||
// Project: https://github.com/maxogden/websocket-stream#readme
|
||||
// Original definitions by: Ben Burns <https://github.com/benjamincburns>
|
||||
|
||||
import * as WebSocket from 'ws';
|
||||
import { Duplex } from 'stream';
|
||||
import * as http from 'http';
|
||||
|
||||
declare namespace WebSocketStream {
|
||||
type WebSocketDuplex = Duplex & { socket: WebSocket };
|
||||
|
||||
class Server extends WebSocket.Server {
|
||||
on(event: 'connection', cb: (this: WebSocket, socket: WebSocket, request: http.IncomingMessage) => void): this;
|
||||
on(event: 'error', cb: (this: WebSocket, error: Error) => void): this;
|
||||
on(event: 'headers', cb: (this: WebSocket, headers: string[], request: http.IncomingMessage) => void): this;
|
||||
on(event: 'listening', cb: (this: WebSocket) => void): this;
|
||||
on(event: 'stream', cb: (this: WebSocket, stream: WebSocketDuplex, request: http.IncomingMessage) => void): this;
|
||||
on(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
|
||||
}
|
||||
|
||||
function createServer(opts?: WebSocket.ServerOptions, callback?: () => void): Server;
|
||||
}
|
||||
|
||||
declare function WebSocketStream(target: string | WebSocket, options?: WebSocket.ClientOptions): WebSocketStream.WebSocketDuplex;
|
||||
declare function WebSocketStream(target: string | WebSocket, protocols?: string | string[], options?: WebSocket.ClientOptions): WebSocketStream.WebSocketDuplex;
|
||||
|
||||
export = WebSocketStream;
|
||||
6
node_modules/websocket-stream/index.js
generated
vendored
Normal file
6
node_modules/websocket-stream/index.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
var server = require('./server.js')
|
||||
|
||||
module.exports = require('./stream.js')
|
||||
module.exports.Server = server.Server
|
||||
module.exports.createServer = server.createServer
|
||||
79
node_modules/websocket-stream/package.json
generated
vendored
Normal file
79
node_modules/websocket-stream/package.json
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
{
|
||||
"_from": "websocket-stream@^5.1.2",
|
||||
"_id": "websocket-stream@5.5.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-8z49MKIHbGk3C4HtuHWDtYX8mYej1wWabjthC/RupM9ngeukU4IWoM46dgth1UOS/T4/IqgEdCDJuMe2039OQQ==",
|
||||
"_location": "/websocket-stream",
|
||||
"_npmUser": {
|
||||
"name": "maxogden",
|
||||
"email": "max@maxogden.com"
|
||||
},
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "websocket-stream@^5.1.2",
|
||||
"name": "websocket-stream",
|
||||
"escapedName": "websocket-stream",
|
||||
"rawSpec": "^5.1.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^5.1.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/mqtt"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/websocket-stream/-/websocket-stream-5.5.2.tgz",
|
||||
"_shasum": "49d87083d96839f0648f5513bbddd581f496b8a2",
|
||||
"_spec": "websocket-stream@^5.1.2",
|
||||
"_where": "E:\\gitee\\fys\\fys\\app\\JingQuan\\node_modules\\mqtt",
|
||||
"author": "",
|
||||
"browser": {
|
||||
"./echo-server.js": "./fake-server.js",
|
||||
"./index.js": "./stream.js",
|
||||
"ws": "./ws-fallback.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/maxogden/websocket-stream/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"duplexify": "^3.5.1",
|
||||
"inherits": "^2.0.1",
|
||||
"readable-stream": "^2.3.3",
|
||||
"safe-buffer": "^5.1.2",
|
||||
"ws": "^3.2.0",
|
||||
"xtend": "^4.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Use websockets with the node streams API. Works in browser and node",
|
||||
"devDependencies": {
|
||||
"@types/node": "^11.13.4",
|
||||
"@types/ws": "^6.0.1",
|
||||
"beefy": "^2.1.8",
|
||||
"browserify": "^16.2.3",
|
||||
"concat-stream": "^1.6.2",
|
||||
"tape": "^4.9.1",
|
||||
"typescript": "^3.4.3"
|
||||
},
|
||||
"homepage": "https://github.com/maxogden/websocket-stream#readme",
|
||||
"keywords": [
|
||||
"websocket",
|
||||
"websockets",
|
||||
"stream",
|
||||
"streams",
|
||||
"realtime"
|
||||
],
|
||||
"license": "BSD-2-Clause",
|
||||
"main": "index.js",
|
||||
"name": "websocket-stream",
|
||||
"optionalDependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/maxogden/websocket-stream.git"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "beefy test-client.js",
|
||||
"test": "node test.js"
|
||||
},
|
||||
"version": "5.5.2"
|
||||
}
|
||||
148
node_modules/websocket-stream/readme.md
generated
vendored
Normal file
148
node_modules/websocket-stream/readme.md
generated
vendored
Normal file
@ -0,0 +1,148 @@
|
||||
# websocket-stream
|
||||
|
||||
[](https://nodei.co/npm/websocket-stream/)
|
||||
|
||||
Use HTML5 [websockets](https://developer.mozilla.org/en-US/docs/WebSockets) using the Node Streams API.
|
||||
|
||||
### Usage
|
||||
|
||||
This module works in Node or in Browsers that support WebSockets. You can use [browserify](http://github.com/substack/node-browserify) to package this module for browser use.
|
||||
|
||||
```javascript
|
||||
var websocket = require('websocket-stream')
|
||||
var ws = websocket('ws://echo.websocket.org')
|
||||
process.stdin.pipe(ws)
|
||||
ws.pipe(process.stdout)
|
||||
```
|
||||
|
||||
In the example above `ws` is a duplex stream. That means you can pipe output to anything that accepts streams. You can also pipe data into streams (such as a webcam feed or audio data).
|
||||
|
||||
The underlying `WebSocket` instance is available as `ws.socket`.
|
||||
|
||||
#### Options
|
||||
|
||||
The available options differs depending on if you use this module in the browser or with node.js. Options can be passed in as the third or second argument - `WebSocket(address, [protocols], [options])`.
|
||||
|
||||
##### `options.browserBufferSize`
|
||||
|
||||
How much to allow the [socket.bufferedAmount](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket#Attributes) to grow before starting to throttle writes. This option has no effect in node.js.
|
||||
|
||||
Default: `1024 * 512` (512KiB)
|
||||
|
||||
##### `options.browserBufferTimeout`
|
||||
|
||||
How long to wait before checking if the socket buffer has drained sufficently for another write. This option has no effect in node.js.
|
||||
|
||||
Default: `1000` (1 second)
|
||||
|
||||
##### `options.objectMode`
|
||||
|
||||
Send each chunk on its own, and do not try to pack them in a single
|
||||
websocket frame.
|
||||
|
||||
Default: `false`
|
||||
|
||||
##### `options.binary`
|
||||
|
||||
Always convert to `Buffer` in Node.js before sending.
|
||||
Forces `options.objectMode` to `false`.
|
||||
|
||||
Default: `true`
|
||||
|
||||
##### `options.perMessageDeflate`
|
||||
|
||||
We recommend disabling the [per message deflate
|
||||
extension](https://tools.ietf.org/html/rfc7692) to achieve the best
|
||||
throughput.
|
||||
|
||||
Default: `true` on the client, `false` on the server.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var websocket = require('websocket-stream')
|
||||
var ws = websocket('ws://realtimecats.com', {
|
||||
perMessageDeflate: false
|
||||
})
|
||||
```
|
||||
|
||||
Beware that this option is ignored by browser clients. To make sure that permessage-deflate is never used, disable it on the server.
|
||||
|
||||
##### Other options
|
||||
|
||||
When used in node.js see the [ws.WebSocket documentation](https://github.com/websockets/ws/blob/master/doc/ws.md#class-wswebsocket)
|
||||
|
||||
### On the server
|
||||
|
||||
Using the [`ws`](http://npmjs.org/ws) module you can make a websocket server and use this module to get websocket streams on the server:
|
||||
|
||||
```javascript
|
||||
var websocket = require('websocket-stream')
|
||||
var wss = websocket.createServer({server: someHTTPServer}, handle)
|
||||
|
||||
function handle(stream, request) {
|
||||
// `request` is the upgrade request sent by the client.
|
||||
fs.createReadStream('bigdata.json').pipe(stream)
|
||||
}
|
||||
```
|
||||
|
||||
We recommend disabling the [per message deflate
|
||||
extension](https://tools.ietf.org/html/rfc7692) to achieve the best
|
||||
throughput:
|
||||
|
||||
```javascript
|
||||
var websocket = require('websocket-stream')
|
||||
var wss = websocket.createServer({
|
||||
perMessageDeflate: false,
|
||||
server: someHTTPServer
|
||||
}, handle)
|
||||
|
||||
function handle(stream) {
|
||||
fs.createReadStream('bigdata.json').pipe(stream)
|
||||
}
|
||||
```
|
||||
|
||||
You can even use it on express.js with the [express-ws](https://www.npmjs.com/package/express-ws) library:
|
||||
|
||||
```js
|
||||
const express = require('express');
|
||||
const expressWebSocket = require('express-ws');
|
||||
const websocketStream = require('websocket-stream/stream');
|
||||
const app = express();
|
||||
|
||||
// extend express app with app.ws()
|
||||
expressWebSocket(app, null, {
|
||||
// ws options here
|
||||
perMessageDeflate: false,
|
||||
});
|
||||
|
||||
app.ws('/bigdata.json', function(ws, req) {
|
||||
// convert ws instance to stream
|
||||
const stream = websocketStream(ws, {
|
||||
// websocket-stream options here
|
||||
binary: true,
|
||||
});
|
||||
|
||||
fs.createReadStream('bigdata.json').pipe(stream);
|
||||
});
|
||||
|
||||
app.listen(3000);
|
||||
```
|
||||
|
||||
## Run the tests
|
||||
|
||||
### Server-side tests
|
||||
|
||||
```
|
||||
npm test
|
||||
```
|
||||
|
||||
### Client-side tests
|
||||
|
||||
First start the echo server by running `node test-server.js`
|
||||
|
||||
Then run `npm start` and open `localhost:9966` in your browser and open the Dev Tools console to see test output.
|
||||
|
||||
## license
|
||||
|
||||
BSD LICENSE
|
||||
29
node_modules/websocket-stream/server.js
generated
vendored
Normal file
29
node_modules/websocket-stream/server.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
'use strict'
|
||||
|
||||
var WebSocketServer = require('ws').Server
|
||||
var stream = require('./stream')
|
||||
|
||||
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, req) {
|
||||
this.emit('stream', stream(conn, opts), req)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
if (cb) {
|
||||
this.on('stream', cb)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.Server = Server
|
||||
module.exports.createServer = function(opts, cb) {
|
||||
return new Server(opts, cb)
|
||||
}
|
||||
189
node_modules/websocket-stream/stream.js
generated
vendored
Normal file
189
node_modules/websocket-stream/stream.js
generated
vendored
Normal file
@ -0,0 +1,189 @@
|
||||
'use strict'
|
||||
|
||||
var Transform = require('readable-stream').Transform
|
||||
var duplexify = require('duplexify')
|
||||
var WS = require('ws')
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
|
||||
module.exports = WebSocketStream
|
||||
|
||||
function buildProxy (options, socketWrite, socketEnd) {
|
||||
var proxy = new Transform({
|
||||
objectMode: options.objectMode
|
||||
})
|
||||
|
||||
proxy._write = socketWrite
|
||||
proxy._flush = socketEnd
|
||||
|
||||
return proxy
|
||||
}
|
||||
|
||||
function WebSocketStream(target, protocols, options) {
|
||||
var stream, socket
|
||||
|
||||
var isBrowser = process.title === 'browser'
|
||||
var isNative = !!global.WebSocket
|
||||
var socketWrite = isBrowser ? socketWriteBrowser : socketWriteNode
|
||||
|
||||
if (protocols && !Array.isArray(protocols) && 'object' === typeof protocols) {
|
||||
// accept the "options" Object as the 2nd argument
|
||||
options = protocols
|
||||
protocols = null
|
||||
|
||||
if (typeof options.protocol === 'string' || Array.isArray(options.protocol)) {
|
||||
protocols = options.protocol;
|
||||
}
|
||||
}
|
||||
|
||||
if (!options) options = {}
|
||||
|
||||
if (options.objectMode === undefined) {
|
||||
options.objectMode = !(options.binary === true || options.binary === undefined)
|
||||
}
|
||||
|
||||
var proxy = buildProxy(options, socketWrite, socketEnd)
|
||||
|
||||
if (!options.objectMode) {
|
||||
proxy._writev = writev
|
||||
}
|
||||
|
||||
// browser only: sets the maximum socket buffer size before throttling
|
||||
var bufferSize = options.browserBufferSize || 1024 * 512
|
||||
|
||||
// browser only: how long to wait when throttling
|
||||
var bufferTimeout = options.browserBufferTimeout || 1000
|
||||
|
||||
// use existing WebSocket object that was passed in
|
||||
if (typeof target === 'object') {
|
||||
socket = target
|
||||
// otherwise make a new one
|
||||
} else {
|
||||
// special constructor treatment for native websockets in browsers, see
|
||||
// https://github.com/maxogden/websocket-stream/issues/82
|
||||
if (isNative && isBrowser) {
|
||||
socket = new WS(target, protocols)
|
||||
} else {
|
||||
socket = new WS(target, protocols, options)
|
||||
}
|
||||
|
||||
socket.binaryType = 'arraybuffer'
|
||||
}
|
||||
|
||||
// according to https://github.com/baygeldin/ws-streamify/issues/1
|
||||
// Nodejs WebSocketServer cause memory leak
|
||||
// Handlers like onerror, onclose, onmessage and onopen are accessible via setter/getter
|
||||
// And setter first of all fires removeAllListeners, that doesnt make inner array of clients on WebSocketServer cleared ever
|
||||
var eventListenerSupport = ('undefined' === typeof socket.addEventListener)
|
||||
|
||||
// was already open when passed in
|
||||
if (socket.readyState === socket.OPEN) {
|
||||
stream = proxy
|
||||
} else {
|
||||
stream = stream = duplexify(undefined, undefined, options)
|
||||
if (!options.objectMode) {
|
||||
stream._writev = writev
|
||||
}
|
||||
|
||||
if (eventListenerSupport) {
|
||||
socket.addEventListener('open', onopen)
|
||||
} else {
|
||||
socket.onopen = onopen
|
||||
}
|
||||
}
|
||||
|
||||
stream.socket = socket
|
||||
|
||||
if (eventListenerSupport) {
|
||||
socket.addEventListener('close', onclose)
|
||||
socket.addEventListener('error', onerror)
|
||||
socket.addEventListener('message', onmessage)
|
||||
} else {
|
||||
socket.onclose = onclose
|
||||
socket.onerror = onerror
|
||||
socket.onmessage = onmessage
|
||||
}
|
||||
|
||||
proxy.on('close', destroy)
|
||||
|
||||
var coerceToBuffer = !options.objectMode
|
||||
|
||||
function socketWriteNode(chunk, enc, next) {
|
||||
// avoid errors, this never happens unless
|
||||
// destroy() is called
|
||||
if (socket.readyState !== socket.OPEN) {
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
if (coerceToBuffer && typeof chunk === 'string') {
|
||||
chunk = Buffer.from(chunk, 'utf8')
|
||||
}
|
||||
socket.send(chunk, next)
|
||||
}
|
||||
|
||||
function socketWriteBrowser(chunk, enc, next) {
|
||||
if (socket.bufferedAmount > bufferSize) {
|
||||
setTimeout(socketWriteBrowser, bufferTimeout, chunk, enc, next)
|
||||
return
|
||||
}
|
||||
|
||||
if (coerceToBuffer && typeof chunk === 'string') {
|
||||
chunk = Buffer.from(chunk, 'utf8')
|
||||
}
|
||||
|
||||
try {
|
||||
socket.send(chunk)
|
||||
} catch(err) {
|
||||
return next(err)
|
||||
}
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
function socketEnd(done) {
|
||||
socket.close()
|
||||
done()
|
||||
}
|
||||
|
||||
function onopen() {
|
||||
stream.setReadable(proxy)
|
||||
stream.setWritable(proxy)
|
||||
stream.emit('connect')
|
||||
}
|
||||
|
||||
function onclose() {
|
||||
stream.end()
|
||||
stream.destroy()
|
||||
}
|
||||
|
||||
function onerror(err) {
|
||||
stream.destroy(err)
|
||||
}
|
||||
|
||||
function onmessage(event) {
|
||||
var data = event.data
|
||||
if (data instanceof ArrayBuffer) data = Buffer.from(data)
|
||||
else data = Buffer.from(data, 'utf8')
|
||||
proxy.push(data)
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
socket.close()
|
||||
}
|
||||
|
||||
// this is to be enabled only if objectMode is false
|
||||
function writev (chunks, cb) {
|
||||
var buffers = new Array(chunks.length)
|
||||
for (var i = 0; i < chunks.length; i++) {
|
||||
if (typeof chunks[i].chunk === 'string') {
|
||||
buffers[i] = Buffer.from(chunks[i], 'utf8')
|
||||
} else {
|
||||
buffers[i] = chunks[i].chunk
|
||||
}
|
||||
}
|
||||
|
||||
this._write(Buffer.concat(buffers), 'binary', cb)
|
||||
}
|
||||
|
||||
return stream
|
||||
}
|
||||
74
node_modules/websocket-stream/test-client.js
generated
vendored
Normal file
74
node_modules/websocket-stream/test-client.js
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
var ws = require('./')
|
||||
var test = require('tape')
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
|
||||
test('echo works', function(t) {
|
||||
var stream = ws('ws://localhost:8343')
|
||||
stream.on('data', function(o) {
|
||||
t.ok(Buffer.isBuffer(o), 'is buffer')
|
||||
t.equal(o.toString(), 'hello', 'got hello back')
|
||||
stream.destroy()
|
||||
t.end()
|
||||
})
|
||||
stream.write(Buffer.from('hello'))
|
||||
})
|
||||
|
||||
test('echo works two times', function(t) {
|
||||
var stream = ws('ws://localhost:8343')
|
||||
stream.once('data', function(o) {
|
||||
t.equal(o.toString(), 'hello', 'got first hello back')
|
||||
stream.write(Buffer.from('hello'))
|
||||
stream.once('data', function(o) {
|
||||
t.equal(o.toString(), 'hello', 'got second hello back')
|
||||
stream.destroy()
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
stream.write(Buffer.from('hello'))
|
||||
})
|
||||
|
||||
test('with bare WebSocket, strings as strings', function (t) {
|
||||
var socket = new WebSocket('ws://localhost:8344')
|
||||
|
||||
socket.onmessage = function (e) {
|
||||
var data = e.data
|
||||
t.ok(typeof data === 'string', 'data must be a string')
|
||||
socket.close()
|
||||
t.end()
|
||||
}
|
||||
})
|
||||
|
||||
test('with bare WebSocket, binary only', function (t) {
|
||||
var socket = new WebSocket('ws://localhost:8345')
|
||||
|
||||
socket.onmessage = function (e) {
|
||||
var data = e.data
|
||||
t.notOk(typeof data === 'string', 'data must not be a string')
|
||||
socket.close()
|
||||
t.end()
|
||||
}
|
||||
})
|
||||
|
||||
test('coerce client data as binary', function(t) {
|
||||
var stream = ws('ws://localhost:8346', { binary: true })
|
||||
stream.on('data', function(o) {
|
||||
t.ok(Buffer.isBuffer(o), 'is buffer')
|
||||
t.equal(o.toString(), 'success', 'success!')
|
||||
stream.destroy()
|
||||
t.end()
|
||||
})
|
||||
stream.write('hello')
|
||||
})
|
||||
test('cork logic test', function (t) {
|
||||
var stream = ws('ws://localhost:8343', { binary: true })
|
||||
stream.on('data', function(o) {
|
||||
t.equal(o.toString(), 'hello', 'success!')
|
||||
stream.destroy()
|
||||
t.end()
|
||||
})
|
||||
stream.cork()
|
||||
stream.write('he')
|
||||
stream.write('l')
|
||||
stream.write('lo')
|
||||
stream.uncork()
|
||||
})
|
||||
56
node_modules/websocket-stream/test-server.js
generated
vendored
Normal file
56
node_modules/websocket-stream/test-server.js
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
var http = require('http')
|
||||
var websocket = require('./')
|
||||
var echo = require('./echo-server.js')
|
||||
var WebSocketServer = require('ws').Server
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
|
||||
echo.start(function(){
|
||||
console.log('echo server is running')
|
||||
})
|
||||
|
||||
function forBare (opts) {
|
||||
var server = http.createServer()
|
||||
|
||||
websocket.createServer({
|
||||
server: server,
|
||||
binary: opts.binary
|
||||
}, sendString)
|
||||
|
||||
server.listen(opts.port)
|
||||
|
||||
function sendString (stream) {
|
||||
stream.write('hello world')
|
||||
}
|
||||
}
|
||||
|
||||
forBare({
|
||||
port: 8344,
|
||||
binary: false
|
||||
})
|
||||
|
||||
forBare({
|
||||
port: 8345
|
||||
})
|
||||
|
||||
function checkIfDataIsBinary () {
|
||||
var server = http.createServer()
|
||||
var wss = new WebSocketServer({
|
||||
server: server
|
||||
})
|
||||
|
||||
server.listen(8346)
|
||||
|
||||
wss.on('connection', waitFor)
|
||||
|
||||
function waitFor (ws) {
|
||||
ws.on('message', function (data) {
|
||||
if (!Buffer.isBuffer(data)) {
|
||||
ws.send(Buffer.from('fail'))
|
||||
} else {
|
||||
ws.send(Buffer.from('success'))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
checkIfDataIsBinary()
|
||||
338
node_modules/websocket-stream/test.js
generated
vendored
Normal file
338
node_modules/websocket-stream/test.js
generated
vendored
Normal file
@ -0,0 +1,338 @@
|
||||
var test = require('tape')
|
||||
var websocket = require('./')
|
||||
var echo = require("./echo-server")
|
||||
var WebSocketServer = require('ws').Server
|
||||
var http = require('http')
|
||||
var concat = require('concat-stream')
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
var ts = require('typescript')
|
||||
|
||||
test('echo server', function(t) {
|
||||
|
||||
echo.start(function() {
|
||||
var client = websocket(echo.url)
|
||||
|
||||
client.on('error', console.error)
|
||||
|
||||
client.on('data', function(data) {
|
||||
t.ok(Buffer.isBuffer(data), 'is a buffer')
|
||||
t.equal(data.toString(), 'hello world')
|
||||
client.end()
|
||||
echo.stop(function() {
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
client.write('hello world')
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
test('emitting not connected errors', function(t) {
|
||||
|
||||
echo.start(function() {
|
||||
var client = websocket(echo.url)
|
||||
|
||||
client.on('error', function() {
|
||||
echo.stop(function() {
|
||||
t.true(true, 'should emit error')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
client.once('data', function(data) {
|
||||
client.end()
|
||||
client.write('abcde')
|
||||
})
|
||||
|
||||
client.write('hello world')
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
test('passes options to websocket constructor', function(t) {
|
||||
t.plan(3)
|
||||
|
||||
opts = {
|
||||
verifyClient: function verifyClient(info) {
|
||||
t.equal(info.req.headers['x-custom-header'], 'Custom Value')
|
||||
return true
|
||||
}
|
||||
}
|
||||
echo.start(opts, function() {
|
||||
var options = {headers: {'x-custom-header': 'Custom Value'}}
|
||||
var client = websocket(echo.url, options)
|
||||
|
||||
client.on('error', console.error)
|
||||
|
||||
client.on('data', function(data) {
|
||||
t.ok(Buffer.isBuffer(data), 'is a buffer')
|
||||
t.equal(data.toString(), 'hello world')
|
||||
client.end()
|
||||
echo.stop(function() {})
|
||||
})
|
||||
|
||||
client.write('hello world')
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
test('destroy', function(t) {
|
||||
t.plan(1)
|
||||
|
||||
echo.start(function() {
|
||||
var client = websocket(echo.url, echo.options)
|
||||
|
||||
client.on('close', function() {
|
||||
echo.stop(function() {
|
||||
t.pass('destroyed')
|
||||
})
|
||||
})
|
||||
|
||||
setTimeout(function() {
|
||||
client.destroy()
|
||||
}, 200)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
test('drain', function(t) {
|
||||
t.plan(1)
|
||||
|
||||
echo.start(function() {
|
||||
var client = websocket(echo.url, echo.options)
|
||||
|
||||
client.on('drain', function() {
|
||||
client.destroy()
|
||||
echo.stop(function() {
|
||||
t.pass('drained')
|
||||
})
|
||||
})
|
||||
|
||||
// write until buffer is full
|
||||
while (client.write('foobar')) {}
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
test('emit sending errors if the socket is closed by the other party', function(t) {
|
||||
|
||||
var server = http.createServer()
|
||||
var wss = new WebSocketServer({ server: server })
|
||||
|
||||
server.listen(8344, function() {
|
||||
var client = websocket('ws://localhost:8344')
|
||||
|
||||
wss.on('connection', function(ws) {
|
||||
var stream = websocket(ws)
|
||||
|
||||
client.destroy()
|
||||
|
||||
setTimeout(function() {
|
||||
stream.write('hello world')
|
||||
}, 50)
|
||||
|
||||
stream.on('error', function(err) {
|
||||
t.ok(err, 'client errors')
|
||||
server.close(t.end.bind(t))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('destroy client pipe should close server pipe', function(t) {
|
||||
t.plan(1)
|
||||
|
||||
var clientDestroy = function() {
|
||||
var client = websocket(echo.url, echo.options)
|
||||
client.on('data', function(o) {
|
||||
client.destroy()
|
||||
})
|
||||
client.write(Buffer.from('hello'))
|
||||
}
|
||||
|
||||
var opts = {}
|
||||
var server = http.createServer()
|
||||
opts.server = server
|
||||
var wss = new WebSocketServer(opts)
|
||||
wss.on('connection', function(ws) {
|
||||
var stream = websocket(ws)
|
||||
stream.on('close', function() {
|
||||
server.close(function() {
|
||||
t.pass('close is called')
|
||||
})
|
||||
})
|
||||
stream.pipe(stream)
|
||||
})
|
||||
server.listen(echo.port, clientDestroy)
|
||||
})
|
||||
|
||||
|
||||
test('error on socket should forward it to pipe', function(t) {
|
||||
t.plan(1)
|
||||
|
||||
var clientConnect = function() {
|
||||
websocket(echo.url, echo.options)
|
||||
}
|
||||
|
||||
var opts = {}
|
||||
var server = http.createServer()
|
||||
opts.server = server
|
||||
var wss = new WebSocketServer(opts)
|
||||
wss.on('connection', function(ws) {
|
||||
var stream = websocket(ws)
|
||||
stream.on('error', function() {
|
||||
server.close(function() {
|
||||
t.pass('error is called')
|
||||
})
|
||||
})
|
||||
stream.socket.emit('error', new Error('Fake error'))
|
||||
})
|
||||
server.listen(echo.port, clientConnect)
|
||||
})
|
||||
|
||||
test('stream end', function(t) {
|
||||
t.plan(1)
|
||||
|
||||
var server = http.createServer()
|
||||
websocket.createServer({ server: server }, handle)
|
||||
|
||||
function handle (stream) {
|
||||
stream.pipe(concat(function (body) {
|
||||
t.equal(body.toString(), 'pizza cats\n')
|
||||
server.close()
|
||||
}))
|
||||
}
|
||||
server.listen(0, function () {
|
||||
var w = websocket('ws://localhost:' + server.address().port)
|
||||
w.end('pizza cats\n')
|
||||
})
|
||||
})
|
||||
|
||||
test('stream handlers should fire once per connection', function(t) {
|
||||
t.plan(2)
|
||||
|
||||
var server = http.createServer()
|
||||
var wss = websocket.createServer({ server: server }, function() {
|
||||
server.close(function() {
|
||||
t.equal(m, 1)
|
||||
})
|
||||
})
|
||||
|
||||
var m = 0
|
||||
wss.on('stream', function(stream, request) {
|
||||
t.ok(request instanceof http.IncomingMessage)
|
||||
m++
|
||||
})
|
||||
server.listen(0, function() {
|
||||
var w = websocket('ws://localhost:' + server.address().port)
|
||||
w.end('pizza cats\n')
|
||||
})
|
||||
})
|
||||
|
||||
test('client with writev', function(t) {
|
||||
var server = http.createServer()
|
||||
|
||||
var str = ''
|
||||
var wss = websocket.createServer({
|
||||
server: server
|
||||
}, function (stream) {
|
||||
stream.once('data', function(data) {
|
||||
t.ok(Buffer.isBuffer(data), 'is a buffer')
|
||||
t.equal(data.toString(), 'hello world')
|
||||
|
||||
stream.once('data', function(data) {
|
||||
t.ok(Buffer.isBuffer(data), 'is a buffer')
|
||||
t.equal(data.toString(), str)
|
||||
stream.end()
|
||||
server.close()
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
server.listen(8352, function () {
|
||||
var client = websocket('ws://localhost:8352', {
|
||||
objectMode: false
|
||||
})
|
||||
|
||||
client.on('error', console.error)
|
||||
|
||||
client.once('connect', function () {
|
||||
client.cork()
|
||||
do {
|
||||
str += 'foobar'
|
||||
} while (client.write('foobar'))
|
||||
client.uncork()
|
||||
})
|
||||
|
||||
client.write('hello world')
|
||||
})
|
||||
})
|
||||
|
||||
test('server with writev', function(t) {
|
||||
var server = http.createServer()
|
||||
|
||||
var str = ''
|
||||
var wss = websocket.createServer({
|
||||
server: server,
|
||||
objectMode: false
|
||||
}, function (stream) {
|
||||
stream.cork()
|
||||
do {
|
||||
str += 'foobar'
|
||||
} while (stream.write('foobar'))
|
||||
stream.uncork()
|
||||
})
|
||||
|
||||
server.listen(8352, function () {
|
||||
var client = websocket('ws://localhost:8352')
|
||||
|
||||
client.on('error', console.error)
|
||||
|
||||
client.once('data', function(data) {
|
||||
t.ok(Buffer.isBuffer(data), 'is a buffer')
|
||||
t.equal(data.toString(), str)
|
||||
client.end()
|
||||
server.close()
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('stop echo', function(t) {
|
||||
echo.stop(function() {
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
test('typescript compilation', function(t) {
|
||||
function compile(fileNames, options) {
|
||||
const program = ts.createProgram(fileNames, options)
|
||||
const emitResult = program.emit()
|
||||
|
||||
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics)
|
||||
|
||||
return allDiagnostics.map(diagnostic => {
|
||||
if (diagnostic.file) {
|
||||
let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start)
|
||||
let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")
|
||||
return `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`
|
||||
} else {
|
||||
return `${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const messages = compile(['./ts-tests.ts'], {
|
||||
noEmit: true,
|
||||
noImplicitAny: true,
|
||||
target: ts.ScriptTarget.ES5,
|
||||
module: ts.ModuleKind.CommonJS
|
||||
})
|
||||
|
||||
t.equal(messages.length, 0, 'no errors emitted')
|
||||
t.end()
|
||||
})
|
||||
|
||||
69
node_modules/websocket-stream/ts-tests.ts
generated
vendored
Normal file
69
node_modules/websocket-stream/ts-tests.ts
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
import * as WebSocket from 'ws';
|
||||
import * as WebSocketStream from './';
|
||||
|
||||
{
|
||||
let ws = new WebSocket('ws://www.host.com/path');
|
||||
const stream = WebSocketStream(ws);
|
||||
ws = stream.socket;
|
||||
|
||||
stream.setEncoding("utf8");
|
||||
stream.write("hello world");
|
||||
|
||||
const message = stream.read(10);
|
||||
const message2 = stream.read();
|
||||
}
|
||||
|
||||
{
|
||||
const stream = WebSocketStream('ws://www.host.com/path');
|
||||
}
|
||||
|
||||
{
|
||||
// stream - url target with subprotocol
|
||||
const stream = WebSocketStream('ws://www.host.com/path', 'appProtocol-v1');
|
||||
}
|
||||
|
||||
{
|
||||
// stream - url target with subprotocols, no options
|
||||
const stream = WebSocketStream('ws://www.host.com/path', ['appProtocol-v1', 'appProtocol-v2']);
|
||||
}
|
||||
|
||||
{
|
||||
// stream - url target with options, no subprotocols
|
||||
const stream = WebSocketStream('ws://www.host.com/path', { maxPayload: 1024 });
|
||||
}
|
||||
|
||||
{
|
||||
// stream - url target with subprotocol and options
|
||||
const stream = WebSocketStream(
|
||||
'ws://www.host.com/path',
|
||||
['appProtocol-v1', 'appProtocol-v2'],
|
||||
{ maxPayload: 1024 },
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
// stream - url target with subprotocols and options
|
||||
const stream = WebSocketStream(
|
||||
'ws://www.host.com/path',
|
||||
['appProtocol-v1', 'appProtocol-v2'],
|
||||
{ maxPayload: 1024 },
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
// dot server
|
||||
const wss = new WebSocketStream.Server({port: 8081});
|
||||
wss.on('stream', (stream, req) => {
|
||||
stream.write(stream.read());
|
||||
stream.end();
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
// dot createServer
|
||||
const wss = WebSocketStream.createServer({port: 8081});
|
||||
wss.on('stream', (stream, req) => {
|
||||
stream.write(stream.read());
|
||||
stream.end(); // closes underlying socket
|
||||
});
|
||||
}
|
||||
12
node_modules/websocket-stream/ws-fallback.js
generated
vendored
Normal file
12
node_modules/websocket-stream/ws-fallback.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
var ws = null
|
||||
|
||||
if (typeof WebSocket !== 'undefined') {
|
||||
ws = WebSocket
|
||||
} else if (typeof MozWebSocket !== 'undefined') {
|
||||
ws = MozWebSocket
|
||||
} else if (typeof window !== 'undefined') {
|
||||
ws = window.WebSocket || window.MozWebSocket
|
||||
}
|
||||
|
||||
module.exports = ws
|
||||
Reference in New Issue
Block a user