Skip to content

Commit

Permalink
Improve logging on pairing websocket error
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed Jan 10, 2025
1 parent 7cec9d1 commit 21861db
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,34 @@ class PairingWebSocket {

// Register the client and the sender callback that it's needed to deliver
// the message to the remote client
channel.registerClient(service, endpoint, session.id,(pairingMessage) -> {
log.trace "Sending message=${pairingMessage} - endpoint: ${endpoint} [sessionId: $session.id]"
session .sendAsync(pairingMessage)
channel.registerClient(service, endpoint, session.id,(msg) -> {
log.trace "Sending message=${msg} - endpoint: ${endpoint} [sessionId: $session.id]"
session
.sendAsync(msg)
.exceptionally(ex-> log.error("Failed to send message=${msg} - endpoint: ${endpoint} [sessionId: $session.id]"))
})

// acquire a pairing key and send it to the remote client
final resp = this.pairingService.acquirePairingKey(service, endpoint)
session.sendAsync(new PairingResponse(
final msg = new PairingResponse(
msgId: rndHex(),
pairingId: resp.pairingId,
publicKey: resp.publicKey
))
publicKey: resp.publicKey )
session
.sendAsync(msg)
.exceptionally(ex-> log.error("Failed to send message=${msg} - endpoint: ${endpoint} [sessionId: $session.id]"))
}

@OnMessage
void onMessage(String service, String token, String endpoint, PairingMessage message, WebSocketSession session) {
if( message instanceof PairingHeartbeat ) {
log.trace "Receiving heartbeat - endpoint: ${endpoint} [sessionId: $session.id]"
// send pong message
final pong = new PairingHeartbeat(msgId:rndHex())
session.sendAsync(pong)
final msg = new PairingHeartbeat(msgId:rndHex())
session
.sendAsync(msg)
.exceptionally(ex-> log.error("Failed to send message=${msg} - endpoint: ${endpoint} [sessionId: $session.id]"))

}
else {
// Collect a reply from the client and takes care to dispatch it
Expand Down

0 comments on commit 21861db

Please sign in to comment.