Transpiled version (3104L) is out of date.
1 | sS hInitSecondaryWebSocket(O... _) { |
2 | optPar S wsVar = "ws2"; |
3 | optPar S url; |
4 | if (empty(url)) fail("Need URL for secondary websocket"); |
5 | optPar S onOpen; |
6 | optPar S onMessage; |
7 | optPar S readyMsg = "WebSocket 2 ready!"; |
8 | ret hreconnectingWebSockets() |
9 | + hscript([[ |
10 | var ws2Ready = false; |
11 | var ws2InitialMsgs = []; |
12 | var ws2Verbose = false; |
13 | var ]] + wsVar + [[ = new ReconnectingWebSocket(]] + jsQuote(url) + [[); |
14 | |
15 | ]] + wsVar + [[.onopen = function(event) { |
16 | ws2Ready = true; |
17 | console.log(]] + jsQuote(readyMsg) + [[); |
18 | ws2InitialMsgs.forEach(function(msg) { |
19 | if (ws2Verbose) console.log("Sending initial msg to websocket 2: " + msg); |
20 | ws2.send(msg); |
21 | }); |
22 | ]] + jsDropTrailingComments(onOpen) + [[ }; |
23 | |
24 | ]] + wsVar + [[.onmessage = function(event) { |
25 | ]] + unnull(onMessage) + [[ |
26 | }; |
27 | |
28 | // add an initial message to send when websocket opens |
29 | // also send it now if ws is open already |
30 | function ws2InitialMsg(msg) { |
31 | ws2InitialMsgs.push(msg); |
32 | if (ws2Ready) { |
33 | if (ws2Verbose) console.log("Sending initial msg to websocket 2: " + msg); |
34 | ws2.send(msg); |
35 | } |
36 | } |
37 | ]]); |
38 | } |
Began life as a copy of #1029959
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030367 |
Snippet name: | hInitSecondaryWebSocket |
Eternal ID of this version: | #1030367/4 |
Text MD5: | 3ccafa24dd2b733d65869a724abfe7d6 |
Author: | stefan |
Category: | javax / html |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-12-09 18:26:37 |
Source code size: | 1285 bytes / 38 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 174 / 254 |
Version history: | 3 change(s) |
Referenced in: | [show references] |