@softmila/adonisjs-socketio
TypeScript icon, indicating that this package has built-in type declarations

1.6.3 • Public • Published

@softmila/adonisjs-socketio


npm-image license-image

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.

Package Sidebar

Install

npm i @softmila/adonisjs-socketio

Weekly Downloads

543

Version

1.6.3

License

MIT

Unpacked Size

15.1 kB

Total Files

29

Last publish

Collaborators

  • tsiresy