2

当我在 socket.io 中发出时如何调用控制器

我希望从客户端调用发出时,数据首先保存在数据库中,然后发送给它。

我的代码:

import SocketIO from '@ioc:Socket.IO'

SocketIO.afterStart(() => {

   const io = SocketIO.io()

     io.use((socket, next) => {
     //Middleware
     next()
   });

   io.on('connection', (socket) => {

   io.emit(`room.6`, {
     type: 'connected'
     //role: socket.handshake.query.user
   });

   socket.on('disconnect', () => {
     io.emit(`room.6`, {
       type: 'disconnected',
      //role: socket.handshake.query.user
    })
   });

   socket.on(`room.6`, (data) => {
     io.emit(`room.6`, //Here the controller should be called)
   });
 });
})
4

0 回答 0