That is what I get in browser console:
WS-PARSER: received {"eventPhase":2,"origin":"","bubbles":false,"defaultPrevented":false,"srcElement":{"binaryType":"blob","extensions":"","url":"ws://localhost:9000/map-socket/a@a.com","bufferedAmount":0,"readyState":1,"onerror":null,"onopen":null,"onclose":null,"protocol":"","URL":"ws://localhost:9000/map-socket/a@a.com"},"type":"message","returnValue":true,"target":{"binaryType":"blob","extensions":"","url":"ws://localhost:9000/map-socket/a@a.com","bufferedAmount":0,"readyState":1,"onerror":null,"onopen":null,"onclose":null,"protocol":"","URL":"ws://localhost:9000/map-socket/a@a.com"},"source":null,"cancelable":false,"currentTarget":{"binaryType":"blob","extensions":"","url":"ws://localhost:9000/map-socket/a@a.com","bufferedAmount":0,"readyState":1,"onerror":null,"onopen":null,"onclose":null,"protocol":"","URL":"ws://localhost:9000/map-socket/a@a.com"},"ports":[],"timeStamp":1341430631884,"lastEventId":"","cancelBubble":false,"data":"{\"stars\":[{\"x\":\"0.0\",\"y\":\"0.0\",\"own\":\"-1\",\"id\":\"0\",\"units\":\"0\"},{\"x\":\"0.0\",\"y\":\"0.0\",\"own\":\"-1\",\"id\":\"1\",\"units\":\"0\"},{\"x\":\"0.0\",\"y\":\"0.0\",\"own\":\"0\",\"id\":\"2\",\"units\":\"0\"}]}"}
I have 2 questions:
1) Why does the first part of the message (automatic) has that many header repetitions? Is this ok, should I leave it like that or can I somehow reduce the amount of the boilerplate?
2) Why are all the quotes in the second part of the message (my payload) escaped?
Here is the code that formulates the JSON:
val stars = strs.getAll.map(_.asJsValue).toSeq
Json.toJson(
Map(
"stars" -> stars
)
)
the asJsValue method:
def asJsValue = {
Json.toJson(
Map(
"id" -> id.toString,
"x" -> x.toString,
"y" -> y.toString,
"units" -> units.toString,
"own" -> getOwnerID.toString
)
)
}
and on the client side:
websocket.onmessage = receivedEvent
receiveEvent = (event) ->
console.log("WS-PARSER: received " + JSON.stringify(event))
datavalue is sent over the wire(disclaimer: not a play user)