fastify-ws
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -6,3 +6,7 @@ 'use strict' | ||
module.exports = fp((fastify, opts, next) => { | ||
const WebSocketServer = require('ws').Server | ||
const wsLib = opts.wsLibrary || 'ws' | ||
if (wsLib !== 'ws' && wsLib !== 'uws') return next(new Error('Invalid "wsLibrary" option')) | ||
const WebSocketServer = require(wsLib).Server | ||
const wss = new WebSocketServer({ | ||
@@ -20,3 +24,3 @@ server: fastify.server | ||
const pingInterval = opts.pingInterval || 30000 | ||
const pingInterval = Number.parseInt(opts.pingInterval, 10) || 30000 | ||
@@ -23,0 +27,0 @@ setInterval(() => wss.clients.forEach(ws => { |
{ | ||
"name": "fastify-ws", | ||
"version": "0.1.0", | ||
"description": "Basic WebSocket support for Fastify built on the blazing fast ws library.", | ||
"version": "0.1.1", | ||
"description": "Basic WebSocket support for Fastify built on the blazing fast ws and uws libraries.", | ||
"main": "index.js", | ||
@@ -35,4 +35,5 @@ "scripts": { | ||
"utf-8-validate": "^3.0.3", | ||
"uws": "^8.14.1", | ||
"ws": "^3.2.0" | ||
} | ||
} |
@@ -5,3 +5,3 @@ # fastify-ws | ||
WebSocket support for [Fastify](https://github.com/fastify/fastify) built on the blazing fast [ws](http://npm.im/websocket-stream) library. | ||
WebSocket support for [Fastify](https://github.com/fastify/fastify) built on the blazing fast [ws](http://npm.im/ws) and [uws](http://npm.im/uws) libraries. | ||
@@ -16,3 +16,4 @@ ## Example | ||
fastify.register(require('fastify-ws'), { | ||
pingInterval: 10000 // Keep the connection alive by sending ping every 10 seconds (default: 30 seconds) | ||
pingInterval: 10000, // Keep the connection alive by sending pings every 10 seconds (default: 30 seconds) | ||
wsLibrary: 'uws' // Use the uws library instead of the default ws library | ||
}) | ||
@@ -46,2 +47,5 @@ | ||
## Notes | ||
If you choose to use `uws` as your WebSocket library, ensure that you have configured your system properly and understand that the API is a slightly reduced subset of `ws`'s. | ||
## TODO | ||
@@ -48,0 +52,0 @@ |
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
5416
283
57
55
5
1
+ Addeduws@^8.14.1
+ Addeduws@8.14.1(transitive)