File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * @typedef {string | object } Spec
3+ */
14
25export class WebSocketClient extends EventTarget {
36 /** @type {WebSocket } */
47 client ;
58
69 constructor (
10+ /** @type {String } */
711 url
812 ) {
913 super ( ) ;
1014 this . client = new WebSocket ( url ) ;
1115 this . client . addEventListener ( "message" , this . #messageHandler. bind ( this ) ) ;
16+
17+ /**
18+ * @type {{ search: (spec: Spec) => void, remove: (spec: Spec) => void } }
19+ */
1220 this . commands = {
1321 search : ( spec ) => this . send ( { commandName : "SEARCH" , spec } ) ,
1422 remove : ( spec ) => this . send ( { commandName : "REMOVE" , spec } )
@@ -20,11 +28,16 @@ export class WebSocketClient extends EventTarget {
2028 } ;
2129 }
2230
31+ /** @type {(data: Record<string, any>) => void } */
2332 send ( data ) {
2433 this . client . send ( JSON . stringify ( data ) ) ;
2534 }
2635
36+ /**
37+ * @param {MessageEvent } event
38+ */
2739 #messageHandler( event ) {
40+ /** @type {{ status: string, [key: string]: any } } */
2841 const data = JSON . parse ( event . data ) ;
2942 if ( ! data . status ) {
3043 console . warn (
You can’t perform that action at this time.
0 commit comments