Skip to content

Commit

Permalink
ignore ping messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tibroc committed Dec 5, 2024
1 parent 255aad3 commit 927769c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions room-hub/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
type MessageType string

const (
MessageTypePing MessageType = "Ping" // ping
MessageTypePairingPIN MessageType = "PairingPIN" // assign pin to room (server -> appliance)
MessageTypeRegisterRoom MessageType = "RegisterRoom" // appliance registers with room config (appliance -> server)
MessageTypePairingPINUserInput MessageType = "PairingPINUserInput" // connect to room (plugin -> server)
Expand All @@ -22,6 +23,10 @@ const (
)

// Messages
type PingMessage struct {
Type MessageType `json:"type" validate:"required"`
}

type RegisterRoomMessage struct {
Type MessageType `json:"type" validate:"required"`
RoomConfig RoomConfig `json:"roomConfig" validate:"required"`
Expand Down
16 changes: 12 additions & 4 deletions room-hub/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ func roomHandler(w http.ResponseWriter, r *http.Request) {

err = json.Unmarshal(msg, &registerRoomMessage)
if err != nil || registerRoomMessage.Type != MessageTypeRegisterRoom {
log.Printf("Error unmarshalling RegisterRoomMessage: %s", err)
if registerRoomMessage.Type != MessageTypePing {
log.Printf("Error unmarshalling RegisterRoomMessage: %s", err)
}
continue
}

Expand Down Expand Up @@ -266,7 +268,9 @@ func pluginHandler(w http.ResponseWriter, r *http.Request) {
var pairingPINUserInputMessage PairingPINUserInputMessage
err = json.Unmarshal(msg, &pairingPINUserInputMessage)
if err != nil || pairingPINUserInputMessage.Type != MessageTypePairingPINUserInput {
log.Printf("Error parsing PairingPINUserInputMessage: %s", msg)
if pairingPINUserInputMessage.Type != MessageTypePing {
log.Printf("Error parsing PairingPINUserInputMessage: %s", msg)
}
continue
}

Expand Down Expand Up @@ -324,7 +328,9 @@ func handleRoomLinksMessage(pluginConn *websocket.Conn, room *Room) bool {
var joinURLsMessage JoinURLsMessage
err = json.Unmarshal(msg, &joinURLsMessage)
if err != nil || joinURLsMessage.Type != MessageTypeJoinURLs {
log.Printf("Error parsing joinURLsMessage: %s", msg)
if joinURLsMessage.Type != MessageTypePing {
log.Printf("Error parsing joinURLsMessage: %s", msg)
}
continue
}

Expand Down Expand Up @@ -358,7 +364,9 @@ func handleVerificationResponse(roomConn *websocket.Conn) bool {
var verificationCodeResponseMessage VerificationCodeResponseMessage
err = json.Unmarshal(msg, &verificationCodeResponseMessage)
if err != nil || verificationCodeResponseMessage.Type != MessageTypeVerificationCodeResponse {
log.Printf("Error parsing VerificationCodeResponse: %s", err)
if verificationCodeResponseMessage.Type != MessageTypePing {
log.Printf("Error parsing VerificationCodeResponse: %s", err)
}
continue
}

Expand Down

0 comments on commit 927769c

Please sign in to comment.