Closed vnaki closed 2 years ago
chat
package ws import ( "context" "fmt" "github.com/kataras/iris/v12/websocket" "time" ) type BuildService struct { *websocket.NSConn `stateless:"true"` *room websocket.Room } func NewBuildService() *BuildService { return new(BuildService) } func (w *BuildService) Namespace() string { return "ws.build" } func (w *BuildService) OnNamespaceConnected(_ websocket.Message) error { // join room 'chat' room, err := w.JoinRoom(context.Background(), "chat") if err != nil { return err } w.room = room return nil } func (w *BuildService) OnNamespaceDisconnect(_ websocket.Message) error { if w.room != nil { if err := w.room.Leave(context.Background()); err != nil { return err } } return nil } // receive client message func (w *BuildService) OnMessage(m websocket.Message) error { // reply client message w.Room("chat").Emit("OnMessage", m.Body) return nil }
map[string]*Room
map[string][] *Room
type NSConn struct { ... rooms map[string]*Room ... }
each room should have many connections! am I right ?
Can you provide some room detail usage
1. I expect incoming connections to join room
chat
, but it doesn't seem so:2. Why rooms is
map[string]*Room
, notmap[string][] *Room
?each room should have many connections! am I right ?
Can you provide some room detail usage