Simplify on connect (#11176)

This commit is contained in:
Nicolas Mowen 2024-04-30 07:27:39 -06:00 committed by GitHub
parent 461442b399
commit 90bdb07463
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View File

@ -50,10 +50,6 @@ class WebSocketClient(Communicator): # type: ignore[misc]
class _WebSocketHandler(WebSocket): # type: ignore[misc]
receiver = self._dispatcher
def opened(self) -> None:
"""A new websocket is opened, we need to send an update message"""
threading.Timer(1.0, self.receiver, ("onConnect", "")).start()
def received_message(self, message: WebSocket.received_message) -> None:
try:
json_message = json.loads(message.data.decode("utf-8"))

View File

@ -65,7 +65,13 @@ function useValue(): useValueReturn {
setWsState({ ...wsState, [data.topic]: data.payload });
}
},
onOpen: () => {},
onOpen: () => {
sendJsonMessage({
topic: "onConnect",
message: "",
retain: false,
});
},
shouldReconnect: () => true,
});