nali 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,12 @@
|
|
1
1
|
Nali.extend Application:
|
2
2
|
|
3
|
-
domEngine:
|
4
|
-
wsServer:
|
5
|
-
defaultUrl:
|
6
|
-
notFoundUrl:
|
7
|
-
htmlContainer:
|
8
|
-
title:
|
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
|
-
|
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
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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 )
|
data/lib/nali/connection.rb
CHANGED
@@ -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:
|
66
|
+
send_json action: :sync, params: params
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
data/lib/nali/version.rb
CHANGED