fastify-socket.io-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

fastify-socket.io-plugin

Version

socket.io for fastify

Installation

yarn add fastify-socket.io-plugin
or
npm install fastify-socket.io-plugin

Usage

Register plugin

import fastifySocketIO from "fastify-socket.io-plugin";

fastify.register(fastifySocketIO);

If you use with TypeScript , you have to give this type to avoid error

import Fastify, { FastifyInstance } from "fastify";

const fastify: FastifyInstance = Fastify();

Socket.io options are available and you can edit them and more socket.io

fastify.register(fastifySocketIO, {...});

Example

fastify.io.on("connect", (socket) => {
  console.log("someone has connected");
});

Use with fastify decorate

fastify.get("/", (request, reply) => {
  fastify.io.emit("hello");
});

Use with request decorate

fastify.get("/", (request, reply) => {
  request.io.emit("hello");
});

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Package Sidebar

Install

npm i fastify-socket.io-plugin

Weekly Downloads

4

Version

1.0.3

License

MIT

Unpacked Size

13.3 kB

Total Files

10

Last publish

Collaborators

  • urdux