mosca 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/mosca/client.rb +7 -1
- data/lib/mosca/version.rb +1 -1
- data/spec/mosca_spec.rb +3 -2
- 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: 15f35eb8f69221fc5b332d47f9a7d16d2bc89298
|
4
|
+
data.tar.gz: 0e69fc6153e88456cdb09a62e2e367fb2f9be624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a71f4cc939b000d437113a0c51b53e19fca2f8921e02ffaff04aa2f1459ac95225992b1f781c1fa9be0e597ef904dbf9e3f95ef23886899604ca9dc6785c6e1b
|
7
|
+
data.tar.gz: 8132b4d0bb719cb28ef9e28d2a39cc4afa38031361a1761532940842c34c7a1c2e9693665fda5137da3d06c060e97f4cc63ed0c63ee60cbfe12d2d2db1801693
|
data/Gemfile.lock
CHANGED
data/lib/mosca/client.rb
CHANGED
@@ -7,6 +7,9 @@ module Mosca
|
|
7
7
|
class Client
|
8
8
|
extend Forwardable
|
9
9
|
|
10
|
+
DEFAULT_KEEP_ALIVE = 10
|
11
|
+
KEEP_ALIVE_MARGIN = 5
|
12
|
+
|
10
13
|
class << self
|
11
14
|
attr_accessor :default_broker, :default_timeout
|
12
15
|
end
|
@@ -25,6 +28,7 @@ module Mosca
|
|
25
28
|
@topic_base = args[:topic_base] || ""
|
26
29
|
@broker = args[:broker] || ENV["MOSCA_BROKER"] || self.class.default_broker
|
27
30
|
@client = args[:client] || MQTT::Client
|
31
|
+
@keep_alive = args[:keep_alive] || DEFAULT_KEEP_ALIVE
|
28
32
|
end
|
29
33
|
|
30
34
|
def publish! message, params = {}
|
@@ -81,6 +85,8 @@ module Mosca
|
|
81
85
|
@connection
|
82
86
|
else
|
83
87
|
@connection = @client.connect(client_options)
|
88
|
+
@connection.keep_alive = @keep_alive
|
89
|
+
@connection
|
84
90
|
end
|
85
91
|
end
|
86
92
|
|
@@ -98,7 +104,7 @@ module Mosca
|
|
98
104
|
end
|
99
105
|
|
100
106
|
def is_alive?
|
101
|
-
( Time.now - @connection.last_ping_response ) <
|
107
|
+
( Time.now - @connection.last_ping_response ) < @keep_alive + KEEP_ALIVE_MARGIN
|
102
108
|
end
|
103
109
|
end
|
104
110
|
end
|
data/lib/mosca/version.rb
CHANGED
data/spec/mosca_spec.rb
CHANGED
@@ -4,13 +4,14 @@ describe Mosca::Client do
|
|
4
4
|
OUT = "out_topic"
|
5
5
|
IN = "in_topic"
|
6
6
|
MESSAGE = "test_message"
|
7
|
+
KEEP_ALIVE = 5
|
7
8
|
|
8
9
|
let (:client) {
|
9
10
|
ClientDouble.new
|
10
11
|
}
|
11
12
|
|
12
13
|
let (:mosca) {
|
13
|
-
mosca = Mosca::Client.new topic_out: OUT, topic_in: IN, client: client
|
14
|
+
mosca = Mosca::Client.new topic_out: OUT, topic_in: IN, client: client, keep_alive: KEEP_ALIVE
|
14
15
|
}
|
15
16
|
|
16
17
|
it "has a default broker" do
|
@@ -160,7 +161,7 @@ describe Mosca::Client do
|
|
160
161
|
end
|
161
162
|
|
162
163
|
it "is false when not alive (no ping response)" do
|
163
|
-
|
164
|
+
allow( client ).to receive( :last_ping_response ).and_return( Time.now - ( KEEP_ALIVE + 5 ) )
|
164
165
|
expect( mosca.connected? ).to be_falsey
|
165
166
|
end
|
166
167
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mosca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Armando Andini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11
|
11
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mqtt
|