meshchat 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/meshchat.rb +2 -1
- data/lib/meshchat/debug.rb +8 -0
- data/lib/meshchat/network/incoming/request_processor.rb +2 -1
- data/lib/meshchat/network/local/connection.rb +2 -1
- data/lib/meshchat/network/local/server.rb +2 -1
- data/lib/meshchat/network/message/base.rb +2 -1
- data/lib/meshchat/network/message/node_list.rb +6 -3
- data/lib/meshchat/network/message/node_list_hash.rb +2 -1
- data/lib/meshchat/network/message/whisper.rb +2 -1
- data/lib/meshchat/network/remote/relay.rb +19 -7
- data/lib/meshchat/network/remote/relay_pool.rb +39 -12
- data/lib/meshchat/ui/cli/input_factory.rb +2 -1
- data/lib/meshchat/ui/cli/readline_input.rb +3 -11
- data/lib/meshchat/ui/command/help.rb +1 -1
- data/lib/meshchat/ui/command/node_finder.rb +4 -6
- data/lib/meshchat/ui/command/roll.rb +4 -5
- data/lib/meshchat/ui/command/whisper.rb +2 -1
- data/lib/meshchat/ui/notifier/lib_notify.rb +1 -0
- data/lib/meshchat/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56aa2cb171ad17cc1b7d19162c0bf720af173103
|
4
|
+
data.tar.gz: 6da9f9913dcd1b4cc59a7934582b77836c01bdf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9422fdcb2ad7a3b3ab943a9c37ba3a9af90e0c16da7c65c9db51eacab1c36360c7b5e0d6a77e1f991f94b94c6cf947dd79ea66cfd56fba70a32d8e0e49970911
|
7
|
+
data.tar.gz: af6d8c3895ae4659a9c0485296efc7078efacbb22f795c62960ae7cec0fd3e2332242433b37de97a91b8e12e4ea821c3592822209599337139dd223fab06ef2e
|
data/lib/meshchat.rb
CHANGED
data/lib/meshchat/debug.rb
CHANGED
@@ -31,6 +31,14 @@ module Meshchat
|
|
31
31
|
Display.debug('Subscribed to relay...')
|
32
32
|
end
|
33
33
|
|
34
|
+
def connected_to_relay
|
35
|
+
Display.debug('Connected to relay...')
|
36
|
+
end
|
37
|
+
|
38
|
+
def disconnected_from_relay
|
39
|
+
Display.debug('Disconnected from relay...')
|
40
|
+
end
|
41
|
+
|
34
42
|
def received_message_from_relay(message, relay_url)
|
35
43
|
Display.debug('RECEIVING on RELAY: ' + relay_url)
|
36
44
|
Display.debug('RECEIVING on RELAY: ')
|
@@ -11,7 +11,8 @@ module Meshchat
|
|
11
11
|
@_message_processor = MessageProcessor.new(
|
12
12
|
network: network,
|
13
13
|
message_dispatcher: message_dispatcher,
|
14
|
-
location: location
|
14
|
+
location: location
|
15
|
+
)
|
15
16
|
end
|
16
17
|
|
17
18
|
# @param [String] request_body - the encrypted message as a json string
|
@@ -19,7 +19,8 @@ module Meshchat
|
|
19
19
|
@_message_dispatcher = message_dispatcher
|
20
20
|
@_request_processor = Incoming::RequestProcessor.new(
|
21
21
|
network: NETWORK_LOCAL,
|
22
|
-
message_dispatcher: message_dispatcher
|
22
|
+
message_dispatcher: message_dispatcher
|
23
|
+
)
|
23
24
|
end
|
24
25
|
|
25
26
|
def process_http_request
|
@@ -48,11 +48,13 @@ module Meshchat
|
|
48
48
|
|
49
49
|
we_only_have_message = _message_factory.create(
|
50
50
|
NODE_LIST_DIFF,
|
51
|
-
data: { message: we_only_have }
|
51
|
+
data: { message: we_only_have }
|
52
|
+
)
|
52
53
|
|
53
54
|
they_only_have_message = _message_factory.create(
|
54
55
|
NODE_LIST_DIFF,
|
55
|
-
data: { message: they_only_have }
|
56
|
+
data: { message: they_only_have }
|
57
|
+
)
|
56
58
|
|
57
59
|
# give the sender our list
|
58
60
|
_message_dispatcher.send_message(
|
@@ -66,7 +68,8 @@ module Meshchat
|
|
66
68
|
Node.online.each do |node|
|
67
69
|
_message_dispatcher.send_message(
|
68
70
|
node: node,
|
69
|
-
message: they_only_have_message
|
71
|
+
message: they_only_have_message
|
72
|
+
)
|
70
73
|
end
|
71
74
|
end
|
72
75
|
end
|
@@ -9,26 +9,33 @@ module Meshchat
|
|
9
9
|
# https://github.com/NullVoxPopuli/mesh-relay/blob/master/app/channels/mesh_relay_channel.rb
|
10
10
|
CHANNEL = 'MeshRelayChannel'
|
11
11
|
|
12
|
-
attr_reader :_url, :_client, :_request_processor
|
12
|
+
attr_reader :_url, :_client, :_request_processor, :_message_queue
|
13
13
|
attr_accessor :_connected
|
14
|
+
|
14
15
|
delegate :perform, to: :_client
|
16
|
+
delegate :subscribed?, to: :_client
|
15
17
|
|
16
|
-
def initialize(url, message_dispatcher,
|
18
|
+
def initialize(url, message_dispatcher, subscribed_callback = nil)
|
17
19
|
@_url = url
|
20
|
+
@_message_queue = []
|
18
21
|
@_request_processor = Incoming::RequestProcessor.new(
|
19
22
|
network: NETWORK_RELAY,
|
20
23
|
location: url,
|
21
|
-
message_dispatcher: message_dispatcher
|
24
|
+
message_dispatcher: message_dispatcher
|
25
|
+
)
|
22
26
|
|
23
|
-
setup(
|
27
|
+
setup(subscribed_callback: subscribed_callback)
|
24
28
|
end
|
25
29
|
|
26
|
-
def setup(
|
30
|
+
def setup(subscribed_callback: nil)
|
27
31
|
path = "#{_url}?uid=#{APP_CONFIG.user['uid']}"
|
28
32
|
@_client = ActionCableClient.new(path, CHANNEL)
|
29
33
|
|
30
34
|
# don't output anything upon connecting
|
31
|
-
_client.connected
|
35
|
+
_client.connected do
|
36
|
+
Debug.connected_to_relay
|
37
|
+
self._connected = true
|
38
|
+
end
|
32
39
|
|
33
40
|
# If there are errors, report them!
|
34
41
|
_client.errored do |message|
|
@@ -37,7 +44,7 @@ module Meshchat
|
|
37
44
|
|
38
45
|
_client.subscribed do
|
39
46
|
Debug.subscribed_to_relay
|
40
|
-
|
47
|
+
subscribed_callback.call if subscribed_callback
|
41
48
|
end
|
42
49
|
|
43
50
|
# forward the encrypted messages to our RequestProcessor
|
@@ -47,12 +54,17 @@ module Meshchat
|
|
47
54
|
end
|
48
55
|
|
49
56
|
_client.disconnected do
|
57
|
+
Debug.disconnected_from_relay
|
50
58
|
self._connected = false
|
51
59
|
end
|
52
60
|
|
53
61
|
_client
|
54
62
|
end
|
55
63
|
|
64
|
+
def send_now(payload)
|
65
|
+
_client.perform('chat', payload)
|
66
|
+
end
|
67
|
+
|
56
68
|
def connected?
|
57
69
|
_connected
|
58
70
|
end
|
@@ -8,44 +8,71 @@ module Meshchat
|
|
8
8
|
CHANNEL = 'MeshRelayChannel'
|
9
9
|
|
10
10
|
attr_accessor :_message_dispatcher
|
11
|
-
attr_accessor :_active_relay
|
11
|
+
attr_accessor :_active_relay, :_waiting_for_subscription
|
12
12
|
attr_accessor :_known_relays, :_available_relays
|
13
|
+
attr_accessor :_message_queue
|
13
14
|
|
14
15
|
def initialize(message_dispatcher)
|
15
16
|
@_message_dispatcher = message_dispatcher
|
16
17
|
@_known_relays = APP_CONFIG.user['relays'] || []
|
17
18
|
@_available_relays = APP_CONFIG.user['relays'] || []
|
19
|
+
@_message_queue = []
|
18
20
|
|
19
21
|
find_initial_relay if @_known_relays.present?
|
22
|
+
|
23
|
+
EM.add_periodic_timer(5) { ensure_relay }
|
20
24
|
end
|
21
25
|
|
22
26
|
# TODO: add logic for just selecting the first available relay.
|
23
27
|
# we only need one connection.
|
24
28
|
# @return [Array] an array of action cable clients
|
25
|
-
def find_initial_relay
|
29
|
+
def find_initial_relay
|
26
30
|
url = _known_relays.first
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
self._waiting_for_subscription = true
|
32
|
+
@_active_relay = Relay.new(url, _message_dispatcher, lambda do
|
33
|
+
self._waiting_for_subscription = false
|
34
|
+
deplete_queue
|
35
|
+
end)
|
30
36
|
end
|
31
37
|
|
32
38
|
# @param [Hash] payload - the message payload
|
33
39
|
def send_payload(payload)
|
34
40
|
return if _active_relay.blank?
|
41
|
+
_message_queue << payload
|
42
|
+
ensure_connection do
|
43
|
+
deplete_queue
|
44
|
+
end
|
45
|
+
end
|
35
46
|
|
36
|
-
|
37
|
-
|
47
|
+
def deplete_queue
|
48
|
+
until _message_queue.empty?
|
49
|
+
if _active_relay.subscribed?
|
50
|
+
payload = _message_queue.pop
|
51
|
+
_active_relay.send_now(payload)
|
52
|
+
end
|
38
53
|
end
|
39
54
|
end
|
40
55
|
|
41
|
-
def
|
42
|
-
|
43
|
-
if !_active_relay.connected?
|
44
|
-
find_initial_relay(connected: block)
|
45
|
-
else
|
56
|
+
def ensure_connection
|
57
|
+
if _active_relay.connected? && _active_relay.subscribed?
|
46
58
|
yield
|
59
|
+
else
|
60
|
+
# if the relay isn't already connected,
|
61
|
+
# it'll be built with a callback to deplete the queue
|
62
|
+
ensure_relay
|
47
63
|
end
|
48
64
|
end
|
65
|
+
|
66
|
+
def ensure_relay
|
67
|
+
return if _waiting_for_subscription
|
68
|
+
return if _active_relay.subscribed?
|
69
|
+
return if _active_relay.connected?
|
70
|
+
|
71
|
+
# clear the previous node
|
72
|
+
_active_relay = nil
|
73
|
+
# re-connect
|
74
|
+
find_initial_relay
|
75
|
+
end
|
49
76
|
end
|
50
77
|
end
|
51
78
|
end
|
@@ -57,7 +57,8 @@ module Meshchat
|
|
57
57
|
|
58
58
|
def whisper_for_locked_target(input)
|
59
59
|
command = Command::Whisper.new(
|
60
|
-
input, _message_dispatcher, _message_factory, self
|
60
|
+
input, _message_dispatcher, _message_factory, self
|
61
|
+
)
|
61
62
|
|
62
63
|
command._target_node = _whisper_lock_target
|
63
64
|
command
|
@@ -13,7 +13,6 @@ module Meshchat
|
|
13
13
|
end
|
14
14
|
|
15
15
|
module Handler
|
16
|
-
|
17
16
|
def initialize
|
18
17
|
Readline.callback_handler_install('> ') do |line|
|
19
18
|
EventMachine.next_tick { handle_input(line) }
|
@@ -46,23 +45,18 @@ module Meshchat
|
|
46
45
|
def callback_on_next_tick=(callback)
|
47
46
|
@callback = callback
|
48
47
|
end
|
49
|
-
|
50
48
|
end
|
51
49
|
|
52
50
|
class << self
|
53
51
|
def autocompletes
|
54
52
|
commands = Meshchat::Ui::Command::COMMAND_MAP.map { |k, _v| "/#{k}" }
|
55
|
-
aliases = Meshchat::Node.all.map { |n|
|
53
|
+
aliases = Meshchat::Node.all.map { |n| n.alias_name.to_s }
|
56
54
|
commands + aliases
|
57
55
|
end
|
58
56
|
|
59
|
-
|
60
|
-
@input_handler
|
61
|
-
end
|
57
|
+
attr_reader :input_handler
|
62
58
|
|
63
|
-
|
64
|
-
@input_handler = handler
|
65
|
-
end
|
59
|
+
attr_writer :input_handler
|
66
60
|
end
|
67
61
|
|
68
62
|
def start
|
@@ -77,7 +71,6 @@ module Meshchat
|
|
77
71
|
Readline.completion_proc = completion
|
78
72
|
end
|
79
73
|
|
80
|
-
|
81
74
|
# def initialize(*args)
|
82
75
|
# super(args)
|
83
76
|
#
|
@@ -92,7 +85,6 @@ module Meshchat
|
|
92
85
|
#
|
93
86
|
# Readline.readline('> ', true)
|
94
87
|
# end
|
95
|
-
|
96
88
|
end
|
97
89
|
end
|
98
90
|
end
|
@@ -10,7 +10,7 @@ module Meshchat
|
|
10
10
|
def handle
|
11
11
|
Meshchat::Ui::Command::COMMAND_MAP.each do |key, klass|
|
12
12
|
if klass.respond_to?(:description)
|
13
|
-
line =
|
13
|
+
line = '/%-18s %s' % [key, klass.description]
|
14
14
|
Display.info line
|
15
15
|
end
|
16
16
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Meshchat
|
2
3
|
module Ui
|
3
4
|
module Command
|
@@ -7,11 +8,9 @@ module Meshchat
|
|
7
8
|
def find_by_target(string, &block)
|
8
9
|
search_key = string.start_with?('#') ? :uid : :alias_name
|
9
10
|
nodes = Node.where(search_key => string)
|
10
|
-
if nodes.
|
11
|
-
return Display.warning('No node by: ' + string)
|
12
|
-
end
|
11
|
+
return Display.warning('No node by: ' + string) if nodes.empty?
|
13
12
|
|
14
|
-
return
|
13
|
+
return yield(nodes.first) if nodes.length == 1
|
15
14
|
|
16
15
|
Display.warning I18n.t('node.multiple_with_alias', name: string)
|
17
16
|
ask_for_specification(nodes, block)
|
@@ -21,7 +20,6 @@ module Meshchat
|
|
21
20
|
# there are now more than 1 nodes
|
22
21
|
display_nodes(nodes)
|
23
22
|
|
24
|
-
|
25
23
|
# insert a callback into the input handler to run the next
|
26
24
|
# time a line is received
|
27
25
|
#
|
@@ -48,7 +46,7 @@ module Meshchat
|
|
48
46
|
alias_name = node.alias_name
|
49
47
|
uid = node.uid[0..5]
|
50
48
|
last_seen = node.updated_at&.strftime('%B %e, %Y %H:%M:%S') || 'never'
|
51
|
-
line =
|
49
|
+
line = '%-2s | %-15s %-8s %s' % [i, alias_name, uid, last_seen]
|
52
50
|
Display.info line
|
53
51
|
end
|
54
52
|
end
|
@@ -3,7 +3,7 @@ module Meshchat
|
|
3
3
|
module Ui
|
4
4
|
module Command
|
5
5
|
class Roll < Command::Chat
|
6
|
-
REGEX = /(\d+)d(\d+)(
|
6
|
+
REGEX = /(\d+)d(\d+)(([+-])(\d+))?/
|
7
7
|
|
8
8
|
def self.description
|
9
9
|
'rolls a die in the XdY+Z format'
|
@@ -11,12 +11,11 @@ module Meshchat
|
|
11
11
|
|
12
12
|
def initialize(input, message_dispatcher, message_factory, input_factory)
|
13
13
|
super
|
14
|
-
Display.debug input
|
15
14
|
# input, X, Y, +Z, Z
|
16
|
-
_, num, size,
|
15
|
+
_, num, size, modifier, _operator, number = REGEX.match(input).to_a
|
17
16
|
|
18
|
-
result = Array.new(num) { rand(size) + 1 }.inject(:+) + modifier
|
19
|
-
@_input = "rolls #{num}d#{size}#{modifier != 0 ?
|
17
|
+
result = Array.new(num.to_i) { rand(size.to_i) + 1 }.inject(:+) + modifier.to_i
|
18
|
+
@_input = "rolls #{num}d#{size}#{modifier != 0 ? modifier : ''} and gets #{result}"
|
20
19
|
end
|
21
20
|
|
22
21
|
def show_myself(message)
|
data/lib/meshchat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meshchat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- L. Preston Sego III
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 1.2
|
145
|
+
version: 1.3.2
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 1.2
|
152
|
+
version: 1.3.2
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: i18n
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -369,6 +369,6 @@ rubyforge_project:
|
|
369
369
|
rubygems_version: 2.5.1
|
370
370
|
signing_key:
|
371
371
|
specification_version: 4
|
372
|
-
summary: Meshchat-0.12.
|
372
|
+
summary: Meshchat-0.12.1
|
373
373
|
test_files: []
|
374
374
|
has_rdoc:
|