func (s *Socket) onMessage(event js.Value) {
	jsMessage := event.Get("data")
	messageJSON := jsMessage.String()
	var m message.Message
	err := json.Unmarshal([]byte(messageJSON), &m)
	if err != nil {
		s.log.Error("unmarshalling message: " + err.Error())
		return
	}
	switch m.Type {
	case message.LeaveGame:
		s.handleGameLeave(m)
	case message.GameInfos:
		s.lobby.SetGameInfos(m.Games, s.user.Username())
	case message.PlayerRemove:
		s.handlePlayerRemove(m)
	case message.JoinGame, message.ChangeGameStatus, message.ChangeGameTiles, message.RefreshGameBoard:
		s.handleInfo(m)
	case message.SocketError:
		s.log.Error(m.Info)
	case message.SocketWarning:
		s.log.Warning(m.Info)
	case message.SocketHTTPPing:
		s.httpPing()
	case message.GameChat:
		s.log.Chat(m.Info)
	default:
		s.log.Error("unknown message type received")
	}
}
// onMessage is called when the websocket receives a message.
onMessage is called when the websocket receives a message.
// onMessage is called when the websocket receives a message .
func (s *Socket) onMessage(event js.Value) {
	jsMessage := event.Get("data")
	messageJSON := jsMessage.String()
	var m message.Message
	err := json.Unmarshal([]byte(messageJSON), &m)
	if err != nil {
		s.log.Error("unmarshalling message: " + err.Error())
		return
	}
	switch m.Type {
	case message.LeaveGame:
		s.handleGameLeave(m)
	case message.GameInfos:
		s.lobby.SetGameInfos(m.Games, s.user.Username())
	case message.PlayerRemove:
		s.handlePlayerRemove(m)
	case message.JoinGame, message.ChangeGameStatus, message.ChangeGameTiles, message.RefreshGameBoard:
		s.handleInfo(m)
	case message.SocketError:
		s.log.Error(m.Info)
	case message.SocketWarning:
		s.log.Warning(m.Info)
	case message.SocketHTTPPing:
		s.httpPing()
	case message.GameChat:
		s.log.Chat(m.Info)
	default:
		s.log.Error("unknown message type received")
	}
}
func ( s * Socket ) onMessage ( event js . Value ) { jsMessage := event . Get ( " " ) messageJSON := jsMessage . String ( ) var m message . Message err := json . Unmarshal ( [ ] byte ( messageJSON ) , & m ) if err != nil { s . log . Error ( " " + err . Error ( ) ) return } switch m . Type { case message . LeaveGame : s . handleGameLeave ( m ) case message . GameInfos : s . lobby . SetGameInfos ( m . Games , s . user . Username ( ) ) case message . PlayerRemove : s . handlePlayerRemove ( m ) case message . JoinGame , message . ChangeGameStatus , message . ChangeGameTiles , message . RefreshGameBoard : s . handleInfo ( m ) case message . SocketError : s . log . Error ( m . Info ) case message . SocketWarning : s . log . Warning ( m . Info ) case message . SocketHTTPPing : s . httpPing ( ) case message . GameChat : s . log . Chat ( m . Info ) default : s . log . Error ( " " ) } }
onMessage is called when the websocket receives a message.
onMessage is called when the websocket receives a message .