Receive messages from server

This commit is contained in:
Pierre HUBERT 2020-03-30 14:52:43 +02:00
parent 4c5a608531
commit 45b2bcda9c

View File

@ -29,6 +29,11 @@ class UserWebSocket {
this.ws.addEventListener("error", (e) => this.Error(e)) this.ws.addEventListener("error", (e) => this.Error(e))
this.ws.addEventListener("close", (e) => this.Closed(e)); this.ws.addEventListener("close", (e) => this.Closed(e));
// Handle incoming messages
this.ws.addEventListener("message", (e) => {
this.ProcessMessage(JSON.parse(e.data));
})
} catch(e) { } catch(e) {
this.Error(e); this.Error(e);
} }
@ -74,4 +79,13 @@ class UserWebSocket {
delete this.ws delete this.ws
} }
} }
/**
* Process an incoming message
*
* @param {any} msg The incoming message
*/
static async ProcessMessage(msg) {
console.error("WS message", msg)
}
} }