@softmila/adonisjs-socketio
v1.7.1
Published
Socket.io package for AdonisJS
Downloads
14
Readme
@softmila/adonisjs-socketio
Introduction
AdonisJS-SocketIO provides JavaScript API to implementation socketio in AdonisJS applications.
Installation
node ace add @softmila/adonisjs-socketio
Usage
Create a service to handle event from socketio
// SocketIoServiceHandler.ts
import { OnMessage, OnceMessage, OnAnyMessage} from '@softmila/adonisjs-socketio'
export default class SocketIoServiceHandler {
@OnMessage('on_message')
async onMessageHandler(socket: Socket, data: any){
console.log('Data:::', data)
const io = await app.container.make('io')
socket.emit('on_response', {data "ok"})
}
@OnceMessage('once_message')
async onceMessageHandler(socket: Socket, data: any){
console.log('Data:', data)
}
@OnAnyMessage()
async onAnyMessageHandler(socket: Socket, data: any){
console.log('Data:', data)
}
}
io is avalaible in HttpContext and ContainerBindings .
Note: Services that handle socketio event can't inject dependency that depends HttpContext.
License
Adonisjs-SocketIO is open-sourced software licensed under the MIT license.