| 285 | } |
| 286 | |
| 287 | static parseUrl(url) { |
| 288 | const match = url.match(/^(https?):\/\/([^/:]+)(?::(\d+))?((?:\/.*)?)/); |
| 289 | if (!match) throw new Error('Invalid URL'); |
| 290 | const [, protocol, host, port, path] = match; |
| 291 | const wsProtocol = protocol === 'https' ? 'wss' : 'ws'; |
| 292 | const wsPort = port || (protocol === 'https' ? '443' : '80'); |
| 293 | const wsPath = (path || '').replace(/\/$/, ''); |
| 294 | return `${wsProtocol}://${host}:${wsPort}${wsPath}/centrallinkws/`; |
| 295 | } |
| 296 | |
| 297 | async connect(gatewayUrl) { |
| 298 | const url = GatewayClient.parseUrl(gatewayUrl); |