Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/balcieren/fastify-socket.io-plugin
Socket.io for fastify
https://github.com/balcieren/fastify-socket.io-plugin
fastify fastify-plugin nodejs socket socket-io
Last synced: 28 days ago
JSON representation
Socket.io for fastify
- Host: GitHub
- URL: https://github.com/balcieren/fastify-socket.io-plugin
- Owner: balcieren
- License: mit
- Created: 2021-08-15T13:30:51.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-08-31T08:16:55.000Z (over 3 years ago)
- Last Synced: 2024-11-15T03:41:58.186Z (about 2 months ago)
- Topics: fastify, fastify-plugin, nodejs, socket, socket-io
- Language: TypeScript
- Homepage:
- Size: 9.77 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# fastify-socket.io-plugin
[![Version](https://img.shields.io/npm/v/fastify-socket.io-plugin.svg)](https://www.npmjs.com/package/fastify-socket.io-plugin)
socket.io for fastify
## Installation
```bash
yarn add fastify-socket.io-plugin
or
npm install fastify-socket.io-plugin
```## Usage
Register plugin
```js
import fastifySocketIO from "fastify-socket.io-plugin";fastify.register(fastifySocketIO);
```If you use with TypeScript , you have to give this type to avoid error
```js
import Fastify, { FastifyInstance } from "fastify";const fastify: FastifyInstance = Fastify();
```Socket.io options are available and you can edit them and more [socket.io](https://socket.io/)
```js
fastify.register(fastifySocketIO, {...});
```Example
```js
fastify.io.on("connect", (socket) => {
console.log("someone has connected");
});
```Use with fastify decorate
```js
fastify.get("/", (request, reply) => {
fastify.io.emit("hello");
});
```Use with request decorate
```js
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](https://choosealicense.com/licenses/mit/)