MCPcopy
hub / github.com/webpack/webpack-dev-server / WebSocketClient

Class WebSocketClient

client-src/clients/WebSocketClient.js:8–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6 * @implements {CommunicationClient}
7 */
8export 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…