nali 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,12 @@
1
1
  Nali.extend Application:
2
2
 
3
- domEngine: jBone.noConflict()
4
- wsServer: 'ws://' + window.location.host
5
- defaultUrl: ''
6
- notFoundUrl: ''
7
- htmlContainer: 'body'
8
- title: 'Application'
3
+ domEngine: jBone.noConflict()
4
+ wsServer: 'ws://' + window.location.host
5
+ defaultUrl: ''
6
+ notFoundUrl: ''
7
+ htmlContainer: 'body'
8
+ title: 'Application'
9
+ keepAliveDelay: 20
9
10
 
10
11
  run: ( options ) ->
11
12
  @::starting()
@@ -10,22 +10,42 @@ Nali.extend Connection:
10
10
  @dispatcher.onopen = ( event ) => @onOpen event
11
11
  @dispatcher.onclose = ( event ) => @onClose event
12
12
  @dispatcher.onmessage = ( event ) => @onMessage JSON.parse event.data
13
-
14
- journal: []
13
+ @keepAlive()
14
+ @
15
+
16
+ connected: false
17
+ keepAliveTimer: null
18
+ journal: []
15
19
 
16
20
  onOpen: ( event ) ->
21
+ @connected = true
17
22
  @trigger 'open'
18
23
 
19
24
  onMessage: ( message ) ->
20
25
  @[ message.action ] message
21
26
 
22
27
  onClose: ( event ) ->
28
+ @connected = false
23
29
  @trigger 'close'
24
30
 
25
31
  send: ( msg ) ->
32
+ @open() unless @connected
26
33
  @dispatcher.send JSON.stringify msg
27
34
  @
28
-
35
+
36
+ keepAlive: ->
37
+ clearTimeout @keepAliveTimer if @keepAliveTimer
38
+ if @Application.keepAliveDelay
39
+ @keepAliveTimer = setTimeout =>
40
+ @keepAliveTimer = null
41
+ @send ping: true
42
+ , @Application.keepAliveDelay * 1000
43
+ @
44
+
45
+ pong: ->
46
+ @keepAlive()
47
+ @
48
+
29
49
  sync: ( message ) ->
30
50
  @Model.sync message.params
31
51
  @
data/lib/nali/clients.rb CHANGED
@@ -12,13 +12,17 @@ module Nali
12
12
  end
13
13
 
14
14
  def self.on_received_message( client, message )
15
- if controller = Object.const_get( message[ :controller ].capitalize + 'Controller' )
16
- controller = controller.new( client, message )
17
- if controller.methods.include?( action = message[ :action ].to_sym )
18
- controller.send action
19
- else puts "Action #{ action } not exists in #{ controller }" end
20
- else puts "Controller #{ controller } not exists" end
21
- on_message client, message
15
+ if message[ :ping ]
16
+ client.send_json action: :pong
17
+ else
18
+ if controller = Object.const_get( message[ :controller ].capitalize + 'Controller' )
19
+ controller = controller.new( client, message )
20
+ if controller.methods.include?( action = message[ :action ].to_sym )
21
+ controller.send action
22
+ else puts "Action #{ action } not exists in #{ controller }" end
23
+ else puts "Controller #{ controller } not exists" end
24
+ on_message client, message
25
+ end
22
26
  end
23
27
 
24
28
  def self.on_client_disconnected( client )
@@ -63,7 +63,7 @@ module EventMachine
63
63
  if not params.empty? and ( watch_time( model ) < model.updated_at.to_f or model.destroyed? )
64
64
  watch_time_up model
65
65
  relations.each { |relation| sync relation }
66
- send_json action: 'sync', params: params
66
+ send_json action: :sync, params: params
67
67
  end
68
68
  end
69
69
 
data/lib/nali/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Nali
2
2
 
3
- VERSION = '0.1.6'
3
+ VERSION = '0.1.7'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nali
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: