Manager: better SocketIO error checking & logging
This commit is contained in:
parent
5e5fa57fa4
commit
c875745bd4
@ -32,31 +32,49 @@ func socketIOServer() *gosocketio.Server {
|
||||
sio := gosocketio.NewServer(transport.GetDefaultWebsocketTransport())
|
||||
log.Info().Msg("initialising SocketIO")
|
||||
|
||||
var err error
|
||||
|
||||
// socket connection
|
||||
sio.On(gosocketio.OnConnection, func(c *gosocketio.Channel) {
|
||||
log.Info().Str("clientID", c.Id()).Msg("connected")
|
||||
c.Join("Room")
|
||||
err = sio.On(gosocketio.OnConnection, func(c *gosocketio.Channel) {
|
||||
log.Debug().Str("clientID", c.Id()).Msg("socketIO: connected")
|
||||
if err := c.Join("Room"); err != nil {
|
||||
log.Warn().Err(err).Str("clientID", c.Id()).Msg("socketIO: unable to make client join broadcast message room")
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("socketIO: unable to register OnConnection handler")
|
||||
}
|
||||
|
||||
// socket disconnection
|
||||
sio.On(gosocketio.OnDisconnection, func(c *gosocketio.Channel) {
|
||||
log.Info().Str("clientID", c.Id()).Msg("disconnected")
|
||||
c.Leave("Room")
|
||||
err = sio.On(gosocketio.OnDisconnection, func(c *gosocketio.Channel) {
|
||||
log.Debug().Str("clientID", c.Id()).Msg("socketIO: disconnected")
|
||||
if err := c.Leave("Room"); err != nil {
|
||||
log.Warn().Err(err).Str("clientID", c.Id()).Msg("socketIO: unable to make client leave broadcast message room")
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("socketIO: unable to register OnDisconnection handler")
|
||||
}
|
||||
|
||||
sio.On(gosocketio.OnError, func(c *gosocketio.Channel) {
|
||||
log.Warn().Interface("c", c).Msg("socketio error")
|
||||
err = sio.On(gosocketio.OnError, func(c *gosocketio.Channel) {
|
||||
log.Warn().Interface("c", c).Msg("socketIO: socketio error")
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("socketIO: unable to register OnError handler")
|
||||
}
|
||||
|
||||
// chat socket
|
||||
sio.On("/chat", func(c *gosocketio.Channel, message Message) string {
|
||||
err = sio.On("/chat", func(c *gosocketio.Channel, message Message) string {
|
||||
log.Info().Str("clientID", c.Id()).
|
||||
Str("text", message.Text).
|
||||
Str("name", message.Name).
|
||||
Msg("message received")
|
||||
Msg("socketIO: message received")
|
||||
c.BroadcastTo("Room", "/message", message.Text)
|
||||
return "message sent successfully."
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("socketIO: unable to register /chat handler")
|
||||
}
|
||||
|
||||
return sio
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user