static WebSocketManager webSocketManager; sclass WebSocketManager { Set webSockets = synchroHashSet(); *() { replaceCollection(webSockets, subBot_getMyWebSockets()); ifdef WebSocketManager_debug print("Have " + n2(webSockets, "web socket") + "."); endifdef } void onNewWebSocket(O ws, S uri) { ifdef WebSocketManager_debug print("New web socket!"); endifdef webSockets.add(ws); } void onWebSocketMessage(O ws, S msg) { ifdef WebSocketManager_debug print("Got message: " + msg); endifdef } void onWebSocketClosed(O ws) { ifdef WebSocketManager_debug print("Closed web socket"); endifdef webSockets.remove(ws); } void sendToAllWebSockets(S msg) { for (O ws : webSockets) pcall(ws, 'send, msg); } Collection webSockets() { ret cloneList(webSockets); } bool isEmpty() { ret empty(webSockets); } void close(O ws) { call(ws, 'close); } } static void onNewWebSocket(O ws, S uri) { if (webSocketManager != null) webSocketManager.onNewWebSocket(ws, uri); } static void onWebSocketMessage(O ws, S msg) { if (webSocketManager != null) webSocketManager.onWebSocketMessage(ws, msg); } static void onWebSocketClosed(O ws) { if (webSocketManager != null) webSocketManager.onWebSocketClosed(ws); }