seapig-client 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/seapig/client.rb +41 -7
- data/lib/seapig/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c85c9742df745b66c263c58793d7651c2e47f081
|
4
|
+
data.tar.gz: d8f5c63f05b55914e2a2514da60f4a66f64ac717
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a346602a2e0ac18c9a333685471d0c2125ffd603704a7e76059ec96dc207f0297536ece9acd36effd95a71218a23b8532bfa8a8364cbad470bf55a86853412da
|
7
|
+
data.tar.gz: e9321722d529bce9ede40dda180bcbafd5deeeee9839ed5c13905bd720770b79b4035b19a7aad4f4ea543aa9ef67c2c168f29d055affe0fe9a47e60f091af20e
|
data/lib/seapig/client.rb
CHANGED
@@ -13,8 +13,29 @@ class SeapigServer
|
|
13
13
|
@options = options
|
14
14
|
@slave_objects = {}
|
15
15
|
@master_objects = {}
|
16
|
+
|
17
|
+
connect
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def connect
|
22
|
+
|
23
|
+
if @socket
|
24
|
+
@socket.onclose {}
|
25
|
+
@socket.close
|
26
|
+
end
|
27
|
+
|
28
|
+
@timeout_timer ||= EM.add_periodic_timer(10) {
|
29
|
+
next if not @socket
|
30
|
+
next if Time.new.to_f - @last_communication_at < 20
|
31
|
+
puts "Seapig ping timeout, reconnecting"
|
32
|
+
connect
|
33
|
+
}
|
34
|
+
|
35
|
+
@connected = false
|
16
36
|
|
17
|
-
@
|
37
|
+
@last_communication_at = Time.new.to_f
|
38
|
+
@socket = WebSocket::EventMachine::Client.connect(uri: @uri)
|
18
39
|
|
19
40
|
@socket.onopen {
|
20
41
|
@connected = true
|
@@ -26,6 +47,7 @@ class SeapigServer
|
|
26
47
|
@socket.send JSON.dump(action: 'object-producer-register', pattern: object_id)
|
27
48
|
object.upload(0, {})
|
28
49
|
}
|
50
|
+
@last_communication_at = Time.new.to_f
|
29
51
|
}
|
30
52
|
|
31
53
|
@socket.onmessage { |message|
|
@@ -45,20 +67,32 @@ class SeapigServer
|
|
45
67
|
else
|
46
68
|
p :wtf, message
|
47
69
|
end
|
70
|
+
@last_communication_at = Time.new.to_f
|
48
71
|
}
|
49
72
|
|
50
73
|
@socket.onclose { |code, reason|
|
51
|
-
|
52
|
-
|
53
|
-
EM.stop
|
54
|
-
end
|
74
|
+
puts 'Seapig connection died unexpectedly, reconnecting'
|
75
|
+
connect
|
55
76
|
}
|
56
|
-
end
|
57
77
|
|
78
|
+
@socket.onping {
|
79
|
+
@last_communication_at = Time.new.to_f
|
80
|
+
}
|
81
|
+
|
82
|
+
end
|
83
|
+
|
58
84
|
|
59
85
|
def disconnect
|
60
86
|
@connected = false
|
61
|
-
@
|
87
|
+
if @timeout_timer
|
88
|
+
@timeout_timer.cancel
|
89
|
+
@timeout_timer = nil
|
90
|
+
end
|
91
|
+
if @socket
|
92
|
+
@socket.onclose {}
|
93
|
+
@socket.close
|
94
|
+
@socket = nil
|
95
|
+
end
|
62
96
|
end
|
63
97
|
|
64
98
|
|
data/lib/seapig/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seapig-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yunta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket-eventmachine-client
|