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
...
@@ -17,7 +17,7 @@ class AppController
isFirstRun
=
$location
.
search
().
hasOwnProperty
(
'firstrun'
)
isFirstRun
=
$location
.
search
().
hasOwnProperty
(
'firstrun'
)
applyUpdates
=
(
action
,
data
)
->
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
return
unless
data
?
.
length
if
action
==
'past'
if
action
==
'past'
action
=
'create'
action
=
'create'
...
@@ -32,27 +32,21 @@ class AppController
...
@@ -32,27 +32,21 @@ class AppController
plugins
.
Store
?
.
unregisterAnnotation
(
annotation
)
plugins
.
Store
?
.
unregisterAnnotation
(
annotation
)
annotator
.
deleteAnnotation
(
annotation
)
annotator
.
deleteAnnotation
(
annotation
)
streamer
.
onmessage
=
(
msg
)
->
streamer
.
onmessage
=
(
data
)
->
data
=
JSON
.
parse
(
msg
.
data
)
if
!
data
or
data
.
type
!=
'annotation-notification'
unless
data
.
type
?
and
data
.
type
is
'annotation-notification'
return
return
payload
=
data
.
payload
action
=
data
.
options
.
action
unless
payload
instanceof
Array
then
payload
=
[
payload
]
p
=
auth
.
user
action
=
data
.
options
.
action
user
=
if
p
?
then
"acct:"
+
p
.
username
+
"@"
+
p
.
provider
else
''
payload
=
data
.
payload
unless
payload
instanceof
Array
then
payload
=
[
payload
]
if
$scope
.
socialView
.
name
is
'single-player'
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
()
$scope
.
$digest
()
initStore
=
->
initStore
=
->
"""Initialize the storage component."""
# Initialize the storage component.
Store
=
plugins
.
Store
Store
=
plugins
.
Store
delete
plugins
.
Store
delete
plugins
.
Store
...
...
h/static/scripts/streamer-service.coffee
View file @
780ab36f
...
@@ -59,7 +59,7 @@ class Streamer
...
@@ -59,7 +59,7 @@ class Streamer
setTimeout((-> self.open()), backoff(self._failCount, 10))
setTimeout((-> self.open()), backoff(self._failCount, 10))
this._sock.onmessage = (msg) ->
this._sock.onmessage = (msg) ->
self.onmessage(
msg
)
self.onmessage(
JSON.parse(msg.data)
)
###
*
###
*
# @ngdoc method
# @ngdoc method
...
...
tests/js/streamer-service-test.coffee
View file @
780ab36f
...
@@ -106,3 +106,15 @@ describe 'streamer', ->
...
@@ -106,3 +106,15 @@ describe 'streamer', ->
clock
.
tick
(
500
)
clock
.
tick
(
500
)
assert
.
calledOnce
(
WebSocket
)
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