From 13579ef8dc7ec3b5e7505e9a8e010e51b0f914d3 Mon Sep 17 00:00:00 2001 From: Tomoaki Ichige <ichigetomoaki1207@gmail.com> Date: Sun, 1 Sep 2024 01:33:22 +0900 Subject: [PATCH] fix: add handling for received websocket ping in mqtt-client --- kmqtt-client/src/commonMain/kotlin/WebSocket.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kmqtt-client/src/commonMain/kotlin/WebSocket.kt b/kmqtt-client/src/commonMain/kotlin/WebSocket.kt index 15937f7..9d599bd 100644 --- a/kmqtt-client/src/commonMain/kotlin/WebSocket.kt +++ b/kmqtt-client/src/commonMain/kotlin/WebSocket.kt @@ -130,6 +130,11 @@ public class WebSocket(private val socket: SocketInterface, host: String, path: return null } + private fun decodePing(length: ULong): UByteArray? { + send(decodeBinary(length), 0xA) + return null + } + private fun decodePong(length: ULong): UByteArray? { decodeBinary(length) return null @@ -156,6 +161,7 @@ public class WebSocket(private val socket: SocketInterface, host: String, path: val decoded = when (opcode.toInt()) { 0x2 -> decodeBinary(length) 0x8 -> decodeClose(length) + 0x9 -> decodePing(length) 0xA -> decodePong(length) else -> { close() -- GitLab