How to use the createWebSocketStream function from ws
Find comprehensive JavaScript ws.createWebSocketStream code examples handpicked from public code repositorys.
4 5 6 7 8 9 10 11 12 13
To open a stream with `ws` on localhost:8099, just write: ```js const WebSocket = require('ws') const ws = new WebSocket('ws://localhost:8099') const stream = WebSocket.createWebSocketStream(ws) ``` The readme for `ws` has more info if you're curious about how to write the server side code: https://github.com/websockets/ws
326
0
50
+ 5 other calls in file
GitHub: samirkumardas/jmuxer
21 22 23 24 25 26 27 28 29 30
wss = new WebSocket.Server({ port: PORT }); console.log('Server ready on port '+ PORT); wss.on('connection', function connection(ws) { console.log('Socket connected. sending data...'); const wsstream = WebSocket.createWebSocketStream(ws); //lets pipe into jmuxer stream, then websocket mp4Reader.pipe(jmuxer.createStream()).pipe(wsstream); ws.on('error', function error(error) {
99
434
15
125 126 127 128 129 130 131 132 133 134
}); } ws.on('open', () => { logger.debug(`ws bind`); this._connectionCount = 0; const wsStream = WebSocket.createWebSocketStream(ws, {}); let bh = bind(wsStream, tcpConn); }); ws.on('close', (code, reason) => { logger.debug(`ws closed - ${code}`);
53
65
13
GitHub: web3os-org/kernel
1 2 3 4 5 6 7 8 9 10
const { WebSocketServer, createWebSocketStream } = require('ws') const wss = new WebSocketServer({ port: 30104 }) wss.on('connection', (ws, req) => { console.log('Connected:', req.socket.remoteAddress) const stream = createWebSocketStream(ws, { encoding: 'utf8' }) repl.start('<3os># ', stream) stream.pipe(process.stdout) process.stdin.pipe(stream) })
10
13
2
5 6 7 8 9 10 11 12 13 14
ws.on('close', () => process.exit(1)) ws.on('open', () => { if (program.pipe) { // Pipe var duplex = WebSocket.createWebSocketStream(ws) program.in.pipe(duplex) duplex.pipe(program.out) } else {
1
7
1
201 202 203 204 205 206 207 208 209
```js 'use strict'; const WebSocket = module.require('ws'); const ws = new WebSocket('ws://localhost:8099'); const stream = WebSocket.createWebSocketStream(ws); stream.pipe(process.stdout); stream.write("hello\n"); ```
0
0
2
45 46 47 48 49 50 51 52 53 54
headers: { 'x-auth-password': config['journal-token'] }, }); ws.on('open', () => { console.log(config['journal-fqdn'], 'websocket opened'); const stream = WebSocket.createWebSocketStream(ws). pipe(new ParseJournalStream()). pipe(new FilterJournalDockerStream()); stream.pause(); resolve(stream);
0
0
5
GitHub: Skilsar/Node.js
32 33 34 35 36 37 38 39 40 41
webSocketStream.pipe(file); } module.exports.ex3 = function () { const ws = new webSocket('ws://localhost:4000/'); const duplex = webSocket.createWebSocketStream(ws, { encoding: 'utf-8' }); duplex.pipe(process.stdout);
0
0
1
7 8 9 10 11 12 13 14 15 16
function on_wss_connection(wss){ const socket = new net.Socket(); const duplex = WebSocket.createWebSocketStream(wss); socket.connect(config["remote-port"], config["remote-host"]); socket.pipe(duplex); duplex.pipe(socket);
0
0
2
GitHub: l-Korrra-l/NodeJS_5sem
2 3 4 5 6 7 8 9 10
const ws = new WebSocket('ws://localhost:4000'); let k = 0; ws.on('open', ()=>{ const duplex = WebSocket.createWebSocketStream(ws, {encoding: 'utf8'}); let wfile = fs.createWriteStream(`./${++k}.txt`); duplex.pipe(wfile); });
0
0
1
2 3 4 5 6 7 8 9 10
const port = 4000; new webSocket.Server({port}, () => { console.log(`WS started on port ${port}...`) }).on('connection', ws => { const webSocketStream = webSocket.createWebSocketStream(ws); const file = fs.createWriteStream(`../upload/fileFromClient.txt`); webSocketStream.pipe(file); });
0
0
1