fastify-socket.io-plugin
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.