MCPcopy Create free account
hub / github.com/JoaoLopesF/RemoteDebug / webSocketEvent

Function webSocketEvent

src/RemoteDebugWS.cpp:231–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229/////// WebSocket to comunicate with RemoteDebugApp
230
231void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t payloadlength) { // When a WebSocket message is received
232
233 int blk_count = 0;
234 char ipaddr[26];
235 IPAddress localip;
236
237 switch (type) {
238 case WStype_DISCONNECTED: // if the websocket is disconnected
239
240 D("[%u] Disconnected!", num);
241
242 // Disconnected
243
244 _webSocketConnected = WS_NOT_CONNECTED;
245
246 // Callback
247
248 if (_callbacks) {
249 _callbacks->onDisconnect();
250 }
251
252 break;
253 case WStype_CONNECTED: // if a new websocket connection is established
254 {
255#ifdef D // serial debug
256 IPAddress ip = WebSocketServer.remoteIP(num);
257 D("[%u] Connected from %d.%d.%d.%d url: %s", num, ip[0], ip[1], ip[2], ip[3],
258 payload);
259#endif
260
261 // Have in another connection
262 // One connection to reduce overheads
263
264 if (num != _webSocketConnected) {
265
266 WebSocketServer.sendTXT(_webSocketConnected, "* Closing client connection ...");
267 WebSocketServer.disconnect(_webSocketConnected);
268
269 }
270
271 // Set as connected
272
273 _webSocketConnected = num;
274
275 // Send initial message
276
277 WebSocketServer.sendTXT(_webSocketConnected, "$app:I");
278
279 // Callback
280
281 if (_callbacks) {
282 _callbacks->onConnect();
283 }
284 }
285 break;
286
287 case WStype_TEXT: // if new text data is received
288 {

Callers

nothing calls this directly

Calls 6

onDisconnectMethod · 0.80
remoteIPMethod · 0.80
onConnectMethod · 0.80
onReceiveMethod · 0.80
sendTXTMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected