Socket
Socket
Sign inDemoInstall

fastify-websocket-server

Package Overview
Dependencies
4
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fastify-websocket-server

Fastify plugin that adds websockets support


Version published
Weekly downloads
3
decreased by-25%
Maintainers
1
Install size
202 kB
Created
Weekly downloads
 

Changelog

Source

1.0.2 (2019-01-23)

<a name="1.0.1"></a>

Readme

Source

fastify-websocket-server

Fastify plugin that creates websocket server on your fastify instance.

NPM Version Downloads Count Vunerabilities Count Build Status Coverage Status License

ToC

Why not use fastify-ws?

  • It doesn't support all ws options in it's constructor.
  • It doesn't expose types and doesn't support typescript out of the box.

Getting started

Installation

npm i fastify-websocket-server

Usage

const fastify = require('fastify')()
const websocketPlugin = require('fastify-websocket-server');
 
fastify.register(websocketPlugin, {
  // The same options that `ws` supports
}).after((err) => {
  if (err) { throw err; }
  fastify.wss
    .on('connection', (ws) => {
      ws.on('message', (msg) => {
        socket.send(msg)); // echo message
      }
    })
})
fastify.listen(3000);

Docs

Docs available via link.

Roadmap

Any ideas or PR welcome

Support for "typed" websockets

Allow setting message types via query param or some header. This will set default message mode.

Better support for JSON messages

The idea is if websocket message type is set to JSON to add following:

  • support JSON message validation against schema, just like Fastify does.
  • use fast-json-stringify module to serialize messages with schemas

Keywords

FAQs

Last updated on 24 Jan 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc