From c4e2146bd1d18a28965047239749d19a46690647 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Thu, 16 Jan 2025 08:37:38 +0000 Subject: [PATCH] websockets broadcast --- CommandDistributor.cpp | 4 ++- Release_Notes/websocketTester.html | 41 ++++++++++++++++++++++++++++++ Websockets.cpp | 3 +++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 Release_Notes/websocketTester.html diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index e32ff03..cdaecf5 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -45,6 +45,7 @@ template void CommandDistributor::broadcastReply(clientType t broadcastBufferWriter->flush(); StringFormatter::send(broadcastBufferWriter, msg...); broadcastToClients(type); + if (type==COMMAND_TYPE) broadcastToClients(WEBSOCKET_TYPE); } #else // on a single USB connection config, write direct to Serial and ignore flush/shove @@ -76,6 +77,7 @@ void CommandDistributor::parse(byte clientId,byte * buffer, RingStream * stream auto websock=Websockets::checkConnectionString(clientId,buffer,stream); if (websock) { clients[clientId]=WEBSOCK_CONNECTING_TYPE; + // websockets will have replied already return; } if (buffer[0] == '<') @@ -149,7 +151,7 @@ void CommandDistributor::broadcastToClients(clientType type) { for (byte clientId=0; clientIdmark(clientId); + ring->mark(clientId | (type==WEBSOCKET_TYPE? Websockets::WEBSOCK_CLIENT_MARKER : 0)); ring->print(broadcastBufferWriter->getString()); //DIAG(F("CD commit client %d"), clientId); ring->commit(); diff --git a/Release_Notes/websocketTester.html b/Release_Notes/websocketTester.html new file mode 100644 index 0000000..4dbd606 --- /dev/null +++ b/Release_Notes/websocketTester.html @@ -0,0 +1,41 @@ + + + + + + + This is a minimalist test page for the DCCEX websocket API. + It demonstrates the Websocket connection and how to send + or receive websocket traffic. + The connection string must be edited to address your command station + correctly.

+ + + + + +

+ + \ No newline at end of file diff --git a/Websockets.cpp b/Websockets.cpp index c9d964a..b15477a 100644 --- a/Websockets.cpp +++ b/Websockets.cpp @@ -28,6 +28,9 @@ CommandDistributor pass it to this code checkConnectionString() to check for an HTTP protocol GET requesting a change to websocket protocol. + [Note that the WifiInboundHandler has a shortcut to detecting this so that + it does not need to use up 500+ bytes of RAM just to get at the one parameter that + actually means something.] If that is found, the relevant answer is generated and queued and the CommandDistributor marks this client as a websocket client awaiting connection. Once the outbound handshake has completed, the CommandDistributor promotes the client