mqtt-sub_handler 0.1.1 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eea6058ba5750daeebbf41696765e1702b60495a
4
- data.tar.gz: 3dbea34eea6371096173df3cccf2468d682e0786
3
+ metadata.gz: 7e09d59deb9258997fe1da980c6829a8a8a46bdc
4
+ data.tar.gz: a1c0f844c2c1091264b76ce512ce7c3ec0d2208c
5
5
  SHA512:
6
- metadata.gz: 9cda8aadc97990675ca7d3b443fa69f82dfb253a4c67eddad0f0bc7a769b24012d30947cd8e7d72df417eea919981590a17e3166e7aa31f9a7deb6bde58d9478
7
- data.tar.gz: 1cf6cd63dde250ad6da0d09dbea8b0610cbd375db61305df229d31951961902d26d789fe476b77b9d9be932f9ffcf779474d70372b8a2c30bbbee84d8582534b
6
+ metadata.gz: d9a99a82f2d2f83c088ddf25230db211796a1b6f435f976052fc6f5075d79eadf3ccbc4d6bf78b797a388ecd6f8aece4cde3e88152d40b50f1d897d8f65166e3
7
+ data.tar.gz: d0412d540d2b44a00879b1965b9bc46301d2d716135229fb43d5fbf84565d664488993ec9177836b5ad2b23ca8160f22dceeda23b8f6749809d45707101ca290
@@ -0,0 +1,73 @@
1
+
2
+ require 'json'
3
+
4
+ require_relative 'sub_handler.rb'
5
+
6
+ module MQTT
7
+ class TXHash
8
+ attr_reader :hash
9
+
10
+ def publish_layer(currentHash = nil, currentList = nil)
11
+ currentHash ||= @hash;
12
+ currentList ||= Array.new();
13
+
14
+ status = catch(:halt) do
15
+ loop do
16
+ throw :halt, :publish_layer if currentList[-1] == "+"
17
+ throw :halt, :publish_all_layered if currentList[-1] == "#"
18
+ throw :halt, :publish_hash if currentList.length == @topicList.length
19
+
20
+ currentList << @topicList[currentList.length]
21
+ end
22
+ end
23
+
24
+ case status
25
+ when :publish_hash
26
+ @mqtt.publish_to currentList.join("/"), currentHash.to_json, retain: true
27
+
28
+ when :publish_layer
29
+ if(currentHash.is_a? Hash) then
30
+ currentHash.each do |key, val|
31
+ newList = currentList.clone();
32
+ newList[-1] = key;
33
+ publish_layer(val, newList);
34
+ end
35
+ else
36
+ @mqtt.publish_to currentList.join("/"), currentHash.to_json, retain: true
37
+ end
38
+
39
+ when :publish_all_layered
40
+ if(currentHash.is_a? Hash) then
41
+ currentHash.each do |key, val|
42
+ publish_layer(val, (currentList.clone[-1] = key)<<"#");
43
+ end
44
+ else
45
+ @mqtt.publish_to currentList.join("/"), currentHash.to_json, retain: true
46
+ end
47
+ end
48
+ end
49
+ alias update_hash publish_layer
50
+ private :update_hash
51
+
52
+ def initialize(mqtt, topic, startHash: Hash.new)
53
+ @mqtt = mqtt;
54
+ @topicList = MQTT::SubHandler.get_topic_split(topic);
55
+
56
+ @hash = startHash;
57
+ end
58
+
59
+ def hash=(newHash)
60
+ @hash = newHash;
61
+ update_hash
62
+ end
63
+
64
+ def [](key)
65
+ return @hash[key]
66
+ end
67
+
68
+ def []=(key, val)
69
+ @hash[key]= val
70
+ update_hash
71
+ end
72
+ end
73
+ end
@@ -67,7 +67,9 @@ class SubHandler
67
67
  @callbackList.each do |h|
68
68
  tMatch = SubHandler.getTopicMatch(topic, h.topic_split);
69
69
  if tMatch
70
- h.offer(tMatch, data)
70
+ Timeout.timeout(3) {
71
+ h.offer(tMatch, data)
72
+ }
71
73
  topicHasReceivers = true;
72
74
  end
73
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mqtt-sub_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xasin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-23 00:00:00.000000000 Z
11
+ date: 2019-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mqtt
@@ -89,6 +89,7 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - README.md
91
91
  - lib/mqtt/Waitpoint.rb
92
+ - lib/mqtt/mqtt_hash.rb
92
93
  - lib/mqtt/persistence.rb
93
94
  - lib/mqtt/persistence_extensions.rb
94
95
  - lib/mqtt/sub_handler.rb