nomo 0.0.45 → 0.0.46

Sign up to get free protection for your applications and to get access to all the features.
data/lib/nomo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nomo
2
- VERSION = "0.0.45"
2
+ VERSION = "0.0.46"
3
3
  end
@@ -5,37 +5,55 @@ $ ->
5
5
 
6
6
  nomoKey = null
7
7
  nomoLastModified = null
8
- connection = new WebSocket('ws://<%= Nomo.server ? Nomo.server : request.host %>', 'nomo')
8
+ connection = null
9
+ connectionOpen = false
9
10
 
10
- ##
11
- # WebSocket Connection
11
+ connect = ->
12
+ connection = new WebSocket('ws://<%= Nomo.server ? Nomo.server : request.host %>', 'nomo')
12
13
 
13
- connection.onopen = ->
14
+ ##
15
+ # WebSocket Connection
14
16
 
15
- # If there's already a nomoKey there could be updates we haven't received
16
- if nomoKey
17
- msgToServer = JSON.stringify({ key: nomoKey, lastModified: nomoLastModified })
17
+ connection.onopen = ->
18
+ connectionOpen = true
18
19
 
19
- console.log('(nomo) connected -- msg to server: ' + msgToServer)
20
- connection.send(msgToServer)
20
+ # If there's already a nomoKey there could be updates we haven't received
21
+ if nomoKey
22
+ msgToServer = JSON.stringify({ key: nomoKey, lastModified: nomoLastModified })
21
23
 
22
- # Else send a HEAD request so we can fetch the nomoKey
23
- else
24
- console.log('(nomo) connected')
25
- $.ajax
26
- type: 'HEAD',
27
- dataType: 'html',
28
- url: document.location.pathname
24
+ console.log('(nomo) connected -- msg to server: ' + msgToServer)
25
+ connection.send(msgToServer)
29
26
 
30
- ##
31
- # WebSocket Message
27
+ # Else send a HEAD request so we can fetch the nomoKey
28
+ else
29
+ console.log('(nomo) connected')
30
+ $.ajax
31
+ type: 'HEAD',
32
+ dataType: 'html',
33
+ url: document.location.pathname
34
+
35
+ ##
36
+ # WebSocket Message
37
+
38
+ connection.onmessage = (msg) ->
39
+ msg = JSON.parse(msg.data)
32
40
 
33
- connection.onmessage = (msg) ->
34
- msg = JSON.parse(msg.data)
41
+ if msg.event == 'update'
42
+ console.log('(nomo) nomo:update triggered')
43
+ $(document).trigger('nomo:update', [nomoKey, nomoLastModified])
35
44
 
36
- if msg.event == 'update'
37
- console.log('(nomo) nomo:update triggered')
38
- $(document).trigger('nomo:update', [nomoKey, nomoLastModified])
45
+ ##
46
+ # On connection close
47
+
48
+ connection.onclose = ->
49
+ connectionOpen = false
50
+ console.log '(nomo) connection closed, retrying in 5 seconds...'
51
+
52
+ setTimeout ->
53
+ connect() unless connectionOpen
54
+ , 5000
55
+
56
+ connect()
39
57
 
40
58
  ##
41
59
  # ajaxComplete
@@ -47,7 +65,9 @@ $ ->
47
65
  if nomoKeyHeader && (nomoKey != nomoKeyHeader)
48
66
  nomoKey = nomoKeyHeader
49
67
  nomoLastModified = nomoLastModifiedHeader
50
- msgToServer = JSON.stringify({ key: nomoKey })
51
68
 
52
- console.log('(nomo) page changed -- msg to server: ' + msgToServer)
53
- connection.send(msgToServer)
69
+ if connectionOpen
70
+ msgToServer = JSON.stringify({ key: nomoKey })
71
+
72
+ console.log('(nomo) page changed -- msg to server: ' + msgToServer)
73
+ connection.send(msgToServer)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nomo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.45
4
+ version: 0.0.46
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-30 00:00:00.000000000 Z
12
+ date: 2012-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &70271198519160 !ruby/object:Gem::Requirement
16
+ requirement: &70339260059220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70271198519160
24
+ version_requirements: *70339260059220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis-namespace
27
- requirement: &70271198518740 !ruby/object:Gem::Requirement
27
+ requirement: &70339260058800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70271198518740
35
+ version_requirements: *70339260058800
36
36
  description: 304 Not Modified Headers made easy.
37
37
  email:
38
38
  - sausman@stackd.com