Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
780ab36f
Commit
780ab36f
authored
Dec 15, 2014
by
Nick Stenning
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1804 from hypothesis/parse-streamer-json
Clean up Streamer.onmessage
parents
18569a70
8e097758
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
15 deletions
+21
-15
controllers.coffee
h/static/scripts/controllers.coffee
+8
-14
streamer-service.coffee
h/static/scripts/streamer-service.coffee
+1
-1
streamer-service-test.coffee
tests/js/streamer-service-test.coffee
+12
-0
No files found.
h/static/scripts/controllers.coffee
View file @
780ab36f
...
...
@@ -17,7 +17,7 @@ class AppController
isFirstRun
=
$location
.
search
().
hasOwnProperty
(
'firstrun'
)
applyUpdates
=
(
action
,
data
)
->
"""Update the application with new data from the websocket."""
# Update the application with new data from the websocket.
return
unless
data
?
.
length
if
action
==
'past'
action
=
'create'
...
...
@@ -32,27 +32,21 @@ class AppController
plugins
.
Store
?
.
unregisterAnnotation
(
annotation
)
annotator
.
deleteAnnotation
(
annotation
)
streamer
.
onmessage
=
(
msg
)
->
data
=
JSON
.
parse
(
msg
.
data
)
unless
data
.
type
?
and
data
.
type
is
'annotation-notification'
streamer
.
onmessage
=
(
data
)
->
if
!
data
or
data
.
type
!=
'annotation-notification'
return
payload
=
data
.
payload
action
=
data
.
options
.
action
unless
payload
instanceof
Array
then
payload
=
[
payload
]
p
=
auth
.
user
user
=
if
p
?
then
"acct:"
+
p
.
username
+
"@"
+
p
.
provider
else
''
unless
payload
instanceof
Array
then
payload
=
[
payload
]
action
=
data
.
options
.
action
payload
=
data
.
payload
if
$scope
.
socialView
.
name
is
'single-player'
payload
=
payload
.
filter
(
d
)
->
d
.
user
is
user
payload
=
payload
.
filter
(
ann
)
->
ann
.
user
is
auth
.
user
applyUpdates
action
,
payload
applyUpdates
(
action
,
payload
)
$scope
.
$digest
()
initStore
=
->
"""Initialize the storage component."""
# Initialize the storage component.
Store
=
plugins
.
Store
delete
plugins
.
Store
...
...
h/static/scripts/streamer-service.coffee
View file @
780ab36f
...
...
@@ -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.data)
)
###
*
# @ngdoc method
...
...
tests/js/streamer-service-test.coffee
View file @
780ab36f
...
...
@@ -106,3 +106,15 @@ describe 'streamer', ->
clock
.
tick
(
500
)
assert
.
calledOnce
(
WebSocket
)
it
'calls the onmessage handler when the socket receives a message'
,
->
streamer
.
onmessage
=
sinon
.
spy
()
streamer
.
open
()
fakeSock
.
onmessage
(
data
:
JSON
.
stringify
({
animal
:
'baboon'
}))
assert
.
called
(
streamer
.
onmessage
)
it
'calls the onmessage handler with parsed JSON'
,
->
streamer
.
onmessage
=
sinon
.
spy
()
streamer
.
open
()
fakeSock
.
onmessage
(
data
:
JSON
.
stringify
({
animal
:
'baboon'
}))
assert
.
calledWith
(
streamer
.
onmessage
,
{
animal
:
'baboon'
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment