blob: 7aa1322d3b142dddbf91ee38376788ad8e0306f8 (
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
31
32
33
34
|
import org.scalajs.dom
import scalajs.js.annotation
@annotation.JSExportTopLevel("Main")
object Main {
object Templates extends Templates(scalatags.JsDom)
@annotation.JSExport
def main() = {
val container = dom.document.getElementById("conversation")
val address = {
val location = dom.window.location
val protocol = if (location.protocol == "https:") {
"wss"
} else {
"ws"
}
s"$protocol://${location.host}/feed"
}
val ws = new dom.WebSocket(address)
ws.onmessage = event => {
val msg = upickle.default.read[Message](
event.data.asInstanceOf[String])
container.appendChild(Templates.message(msg).render)
dom.window.scrollTo(0, dom.document.body.scrollHeight)
}
}
}
|