O'Reilly logo

Building Applications with Scala by Diego Pacheco

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working on the UI

Now, it is time to code on the UI on both the HTML layout and the WebSocket code in JavaScript. We will need to create a new file, located at ReactiveWebStore/app/views.

Your chat_index.scala.html file should look something like this:

 @()(implicit flash:Flash) @main("Chat"){ <!DOCTYPE html> <meta charset="utf-8" /> <title>Chat Room</title> <script type="text/javascript"> var output; var websocket = new WebSocket("ws://localhost:9000/chat/ws"); function init(){ output = document.getElementById("output"); websocket.onmessage = function(evt) { writeToScreen('<span style="color:blue;">' + evt.data+ '</span>'); }; websocket.onerror = function(evt) { writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data); }; } function ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required