Commit 026e550b authored by Aron Carroll's avatar Aron Carroll

Streamer.onmessage now receives parsed JSON

parent 18569a70
......@@ -33,9 +33,10 @@ class AppController
annotator.deleteAnnotation(annotation)
streamer.onmessage = (msg) ->
data = JSON.parse(msg.data)
data = msg.data
unless data.type? and data.type is 'annotation-notification'
return
payload = data.payload
action = data.options.action
......
......@@ -59,7 +59,7 @@ class Streamer
setTimeout((-> self.open()), backoff(self._failCount, 10))
this._sock.onmessage = (msg) ->
self.onmessage(msg)
self.onmessage(JSON.parse(msg))
###*
# @ngdoc method
......
......@@ -106,3 +106,15 @@ describe 'streamer', ->
clock.tick(500)
assert.calledOnce(WebSocket)
it 'calls the onmessage handler when the socket recieves a message', ->
streamer.onmessage = sinon.spy()
streamer.open()
fakeSock.onmessage(JSON.stringify({animal: 'baboon'}))
assert.called(streamer.onmessage)
it 'calls the onmessage handler with parsed JSON', ->
streamer.onmessage = sinon.spy()
streamer.open()
fakeSock.onmessage(JSON.stringify({animal: 'baboon'}))
assert.calledWith(streamer.onmessage, {animal: 'baboon'})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment