MCPcopy Index your code
hub / github.com/ducktors/fastify-socket.io

github.com/ducktors/fastify-socket.io @v5.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v5.1.0 ↗ · + Follow
5 symbols 22 edges 6 files 0 documented · 0% 2 cross-repo links updated 2mo agov5.1.0 · 2024-08-12★ 1077 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

fastify-socket.io

CI Test npm Coverage Status Maintainability OpenSSF Scorecard

fastify-socket.io enables the use of Socket.io in a Fastify application.

Supports Fastify versions 4.x Supports socket.io version 4.x

Install

npm i fastify-socket.io socket.io

Usage

Require fastify-socket.io and register it as any other plugin, it will add a io decorator.

const fastify = require("fastify")();

fastify.register(require("fastify-socket.io"), {
  // put your options here
});

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

fastify.listen({ port: 3000 });

For more details see examples

You can use it as is without passing any option, or you can configure it as explained by Socket.io doc.

Hooks

By default the plugin will add a preClose hook that disconnects all the local sockets in order to close correctly the fastify server. In order to change this behaviour you can use preClose option:

await fastify.register(require('fastify-socket.io'), {
  preClose: (done) => {
    // do other things
    fastify.io.local.disconnectSockets(true);
    done();
  }
})

The plugin also adds an onClose hook which closes the socket server when the fastify instance is closed.

Typescript

The io decorator is NOT typed.

This is necessary to allow, eventually, the developer to be able to define custom types and make use of the socket.io new types system (doc).

For more info see the example

Acknowledgements

The code is a port for Fastify of socket.io.

License

Licensed under MIT.

socket.io license

Extension points exported contracts — how you extend this code

FastifyInstance (Interface)
(no doc)
examples/typescript-example/server.ts

Core symbols most depended-on inside this repo

defaultPreClose
called by 1
src/index.ts

Shape

Class 2
Function 1
Interface 1
Method 1

Languages

TypeScript100%

Modules by API surface

test/index.test.ts3 symbols
src/index.ts1 symbols
examples/typescript-example/server.ts1 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add fastify-socket.io \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page