blob: 3621b4a3115a904267c4fe11e371fff3d566bfb6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package triad
import spray.json._
import ApiProtocol._
import scalajs.js
import org.scalajs.dom
import org.scalajs.dom.html
@js.annotation.JSExport
object Main {
@js.annotation.JSExport
def main(root: html.Element): Unit = {
val source = new dom.EventSource("live")
source.onmessage = (e: dom.MessageEvent) => {
val str = e.data.asInstanceOf[String]
if (str.nonEmpty) { // ignore empty strings on heartbeats
println(str)
val message = str.parseJson.convertTo[Message]
val template = JsTemplates.message(message)
root.appendChild(template.render)
dom.window
.scrollTo(0, dom.document.body.scrollHeight) // scroll to bottom
}
}
}
}
|