fastify-ws
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -6,7 +6,7 @@ 'use strict' | ||
module.exports = fp((fastify, opts, next) => { | ||
const wsLib = opts.wsLibrary || 'ws' | ||
const lib = opts.library || 'ws' | ||
if (wsLib !== 'ws' && wsLib !== 'uws') return next(new Error('Invalid "wsLibrary" option')) | ||
if (lib !== 'ws' && lib !== 'uws') return next(new Error('Invalid "library" option')) | ||
const WebSocketServer = require(wsLib).Server | ||
const WebSocketServer = require(lib).Server | ||
const wss = new WebSocketServer({ | ||
@@ -16,5 +16,5 @@ server: fastify.server | ||
fastify.decorate('wsServer', wss) | ||
fastify.decorate('ws', wss) | ||
next() | ||
}) |
{ | ||
"name": "fastify-ws", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Basic WebSocket support for Fastify built on the blazing fast ws and uws libraries.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -15,3 +15,3 @@ # fastify-ws | ||
fastify.register(require('fastify-ws'), { | ||
wsLibrary: 'uws' // Use the uws library instead of the default ws library | ||
library: 'uws' // Use the uws library instead of the default ws library | ||
}) | ||
@@ -22,5 +22,5 @@ | ||
fastify.wsServer | ||
.on('connection', ws => { | ||
ws.on('message', msg => ws.send(msg)) // Creates an echo server | ||
fastify.ws | ||
.on('connection', socket => { | ||
socket.on('message', msg => socket.send(msg)) // Creates an echo server | ||
}) | ||
@@ -27,0 +27,0 @@ }) |
12
test.js
@@ -17,11 +17,11 @@ 'use strict' | ||
fastify.wsServer | ||
.on('connection', ws => { | ||
ws.send('hello client') | ||
fastify.ws | ||
.on('connection', socket => { | ||
socket.send('hello client') | ||
ws.on('message', msg => { | ||
socket.on('message', msg => { | ||
t.equal(msg, 'hello server') | ||
ws.terminate() | ||
fastify.wsServer.close(() => fastify.close()) | ||
socket.terminate() | ||
fastify.ws.close(() => fastify.close()) | ||
@@ -28,0 +28,0 @@ process.exit() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
4992