socket.io client question
Closed this issue · 4 comments
zkcrescent commented
from official documents, web side socket.io client can connect to special namespace, how to handle the connection event on server side ?
client side:
import { Socket, io } from "socket.io-client"
const socket = io("/admin")
server side:
skio := socket.NewServer( types.NewWebServer(nil), nil)
skio.On("/admin", func(clis ...any){})
not works.
zkcrescent commented
when useing
skio := socket.NewServer( types.NewWebServer(nil), nil)
skio.On("connection", func(clis ...any){})
it does not catch the io("/admin")
connection event
zishang520 commented
By default, skio
listens to the root (/
) event. You need to listen to the connection
event after Of
:
skio.Of("/admin", nil).On("connection", func(clis ...any){})
zishang520 commented
If you need dynamic namespace you can use regexp expression:
skio.Of(regexp.MustCompile(`/\w+`), nil).On("connection", func(clis ...any){})
zkcrescent commented
thanks for your help. Another question is that I want to wrap (echo)[github.com/labstack/echo/v4] context when on connection, how can I do for this.