(type: 'ps' | 'net', interval = 3000, initialDelay = 0)
| 238 | }; |
| 239 | |
| 240 | const startPolling = (type: 'ps' | 'net', interval = 3000, initialDelay = 0) => { |
| 241 | stopPolling(); |
| 242 | activePollingType.value = type; |
| 243 | |
| 244 | const sendInitial = () => { |
| 245 | if (type === 'ps') { |
| 246 | sendPsMessage(); |
| 247 | } else { |
| 248 | sendNetMessage(); |
| 249 | } |
| 250 | }; |
| 251 | |
| 252 | const scheduleInitialFetch = () => { |
| 253 | if (initialDelay > 0) { |
| 254 | setTimeout(sendInitial, initialDelay); |
| 255 | } else { |
| 256 | sendInitial(); |
| 257 | } |
| 258 | }; |
| 259 | |
| 260 | if (isWsOpen()) { |
| 261 | scheduleInitialFetch(); |
| 262 | } else { |
| 263 | const checkConnection = setInterval(() => { |
| 264 | if (isWsOpen()) { |
| 265 | clearInterval(checkConnection); |
| 266 | scheduleInitialFetch(); |
| 267 | } |
| 268 | }, 100); |
| 269 | setTimeout(() => clearInterval(checkConnection), 5000); |
| 270 | } |
| 271 | |
| 272 | pollingTimer = setInterval(() => { |
| 273 | if (type === 'ps') { |
| 274 | sendPsMessage(); |
| 275 | } else { |
| 276 | sendNetMessage(); |
| 277 | } |
| 278 | }, interval); |
| 279 | }; |
| 280 | |
| 281 | const stopPolling = () => { |
| 282 | if (pollingTimer) { |
nothing calls this directly
no test coverage detected