September 2018
Intermediate to advanced
398 pages
9h 43m
English
To add the web socket to the client, we are going to use the UIManager object, which is the entry point of the client. In Scala.js, WebSocket is part of the framework; edit the UIManager and add the web socket property to it, as follows:
val webSocket: WebSocket = getWebSocket
Some configuration is needed to create the WebSocket. We encapsulate all of the initializations into a function named getWebSocket, as follows:
private def getWebSocket: WebSocket = {
val ws = new WebSocket(getWebsocketUri(dom.document, "v1/cart/events")) ws.onopen = { (event: Event) ⇒ println(s"webSocket.onOpen '${event.`type`}'") event.preventDefault() } ws.onerror = { (event: Event) => System.err.println(s"webSocket.onError '${event.getClass}'") ...Read now
Unlock full access