(currentNode: string)
| 134 | }; |
| 135 | |
| 136 | const initWebSocket = async (currentNode: string) => { |
| 137 | if (websocket || isConnecting.value) { |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | const token = ++initWebSocketToken; |
| 142 | isConnecting.value = true; |
| 143 | |
| 144 | const href = window.location.href; |
| 145 | const protocol = href.split('//')[0] === 'http:' ? 'ws' : 'wss'; |
| 146 | const ipLocal = href.split('//')[1].split('/')[0]; |
| 147 | |
| 148 | const url = `${protocol}://${ipLocal}/api/v2/process/ws?operateNode=${currentNode}`; |
| 149 | const authError = await checkStreamAuth(url, currentNode); |
| 150 | if (token !== initWebSocketToken || connectionRefCount === 0) { |
| 151 | if (token === initWebSocketToken) { |
| 152 | isConnecting.value = false; |
| 153 | } |
| 154 | return; |
| 155 | } |
| 156 | if (authError) { |
| 157 | MsgError(authError); |
| 158 | isConnecting.value = false; |
| 159 | return; |
| 160 | } |
| 161 | websocket = new WebSocket(url); |
| 162 | websocket.onopen = onOpen; |
| 163 | websocket.onmessage = onMessage; |
| 164 | websocket.onerror = onError; |
| 165 | websocket.onclose = onClose; |
| 166 | }; |
| 167 | |
| 168 | const closeWebSocket = () => { |
| 169 | initWebSocketToken++; |
no test coverage detected