| 6 | * @implements {CommunicationClient} |
| 7 | */ |
| 8 | export default class WebSocketClient { |
| 9 | /** |
| 10 | * @param {string} url url to connect |
| 11 | */ |
| 12 | constructor(url) { |
| 13 | this.client = new WebSocket(url); |
| 14 | this.client.onerror = (error) => { |
| 15 | log.error(error); |
| 16 | }; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * @param {(...args: EXPECTED_ANY[]) => void} fn function |
| 21 | */ |
| 22 | onOpen(fn) { |
| 23 | this.client.onopen = fn; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @param {(...args: EXPECTED_ANY[]) => void} fn function |
| 28 | */ |
| 29 | onClose(fn) { |
| 30 | this.client.onclose = fn; |
| 31 | } |
| 32 | |
| 33 | // call f with the message string as the first argument |
| 34 | /** |
| 35 | * @param {(...args: EXPECTED_ANY[]) => void} fn function |
| 36 | */ |
| 37 | onMessage(fn) { |
| 38 | this.client.onmessage = (err) => { |
| 39 | fn(err.data); |
| 40 | }; |
| 41 | } |
| 42 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…