| 6 | private callbacks: Map<string, (data: VscodeMessagePayload) => void>; |
| 7 | |
| 8 | private constructor(url: string) { |
| 9 | this.ws = new WebSocket(url); |
| 10 | this.callbacks = new Map(); |
| 11 | this.ws.onmessage = (event) => { |
| 12 | const { callbackId, ...data } = JSON.parse(event.data); |
| 13 | const callback = this.callbacks.get(callbackId); |
| 14 | if (callback) { |
| 15 | callback(data); |
| 16 | } |
| 17 | }; |
| 18 | |
| 19 | this.ws.onopen = () => { |
| 20 | this.send(JSON.stringify({ |
| 21 | event: "api_subscribe", |
| 22 | })); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | static getInstance() { |
| 27 | if (!RelayWebsocket.instance) { |