Saturday, 10 September 2022

How to use socket globally in hapi js?

I am using hapijs in my MERN project and this is my socket.js file

import Emitter from '../config/emitter'

exports.register = (server, options, next) => {
  const io = require('socket.io')(server.listener)
  io.on('connection', (socket) => {
    // Subscribe this socket to `action` events
    socket.emit('action', action)
  })
  next()
}

exports.register.attributes = {
  name: 'socket'
}

I want to use this socket object globally anywhere in project(file) so that I can emit the event from there. How can I do that?



from How to use socket globally in hapi js?

No comments:

Post a Comment