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); }
Began life as a copy of #1014671
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1014674 |
| Snippet name: | WebSocketManager |
| Eternal ID of this version: | #1014674/11 |
| Text MD5: | 6a8e91e52f1d073a1c80595b4ac19f3d |
| Author: | stefan |
| Category: | javax / websockets |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2018-06-23 19:47:14 |
| Source code size: | 1391 bytes / 60 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 684 / 1228 |
| Version history: | 10 change(s) |
| Referenced in: | [show references] |