Integrating socket.io with Adonis 4


#1

Hello ,
I want to use web socket in Adonis 4 but the official WS is under development.
So the only way for using it (at this time) is integrating socket.io with adonis 4 . I tried to use adonis-websocket and change it to work on 4th version but I could not find http.js .
How can I use adonis-websocket on adonis4? or maybe apply this “http://amanvirk.me/using-socket-io-with-adonis/” on adonis 4?

Kind Regards


#2

Create start/socket.js file and paste following code inside it.

const Server = use('Server')
const io = use('socket.io')(Server.getInstance())

io.on('connection', function (socket) {
  console.log(socket.id)
})

websocket with adonis 4
Authentication by session token in sockets
#3

Thanks @virk , It worked but now I want to connect adonis 4 to adonis-websocket (https://github.com/adonisjs/adonis-websocket) for using auth & … .
I change some parts (ex. some changes on requires and setting @adonis/… ) but now I have a problem:

TypeError: Class extends value #<SessionManager> is not a constructor or null
    at new Ws (/*********/node_modules/adonis-websocket/src/Ws/index.js:24:29)

I tried some online solutions but I could not solve the problem.
What can I do?

Kind Regards.


#4

adonis-websocket is not compatible with 4.0


#5

I know that . I want to make it compatible. now It works if I remove :

class WsSession extends Session {
}

from line 24-25 of Ws/index.js but if I remove it , Auth and session will not work.

Could you please help me to solve this issue and publish it?

Thanks,
Kind Regards


#6

Hi virk,
Have you news about websocket integration in Adonis 4? I am still work in new project and I have choose your framework and nuxt for the client.
My project is a “Registered Electronic Mail” organizer, multi tenant, multi mailbox and with user role permission. I think that when I finish I want publish a complete video lessons to bring Adonis and developer. Your project is great and before or after I support you on patreon. Best regards.


#7

Hi Virk, I follow but it does not run.


#8

Did you tried building the connection from the browser?


#9

Tks, i did it.
Now, I want to use in the ‘controller’ how?


#10

thanks , is webSocket going to be developed in near future ? it would be awesome if it was developed (i realy hate to go back on other frameworks like express (i’m Addicted tp adonis :smile: ) )


#11

Yes, it is.


#12

Theres a repo based on old adonis-websocket but works with adonis 4 https://github.com/NortonPerson/adonis-websocket