Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-ws

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-ws

Basic WebSocket support for Fastify built on the blazing fast ws and uws libraries.

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
344
increased by17.41%
Maintainers
1
Weekly downloads
 
Created
Source

fastify-ws

Build Status

WebSocket support for Fastify built on the blazing fast ws and uws libraries.

Example

In server.js:

'use strict'

const fastify = require('fastify')()

fastify.register(require('fastify-ws'), {
  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
})

fastify.ready(err => {
  if (err) throw err

  fastify.wsServer
    .on('connection', ws => {
      ws.on('message', msg => ws.send(msg)) // Creates an echo server
    })
})

fastify.listen(34567)

Then run node server.js and navigate to http://localhost:34567 in your browser. In the browser's JavaScript console, open a client-side WebSocket connection:

const host = location.origin.replace(/^http/, 'ws')
const ws = new WebSocket(host)
ws.onmessage = msg => console.log(msg.data)

Then, still in the browser console, send some messages to the server and watch as they're echoed back to you:

ws.send('WebSockets are awesome!')
// => undefined
// LOG: WebSockets are awesome!

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

  • Get TAP test suite to finish without resorting to process.exit()

License

Licensed under MIT.

Keywords

FAQs

Package last updated on 19 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc