Module: Mycroft::Messages
Instance Method Summary collapse
-
#broadcast(content) ⇒ Object
Sends a broadcast to the mycroft message board.
-
#connect_to_mycroft ⇒ Object
connects to mycroft aka starts tls if necessary.
-
#down ⇒ Object
Sends app down to mycroft.
- #in_use(priority) ⇒ Object
-
#query(capability, action, data, priority = 30, instance_id = nil) ⇒ Object
Sends a query to mycroft.
- #query_fail(id, message) ⇒ Object
- #query_success(id, ret) ⇒ Object
-
#send_manifest ⇒ Object
Sends the app manifest to mycroft.
-
#up ⇒ Object
Sends app up to mycroft.
Methods included from Helpers
#parse_message, #send_message, #update_dependencies
Instance Method Details
#broadcast(content) ⇒ Object
Sends a broadcast to the mycroft message board
83 84 85 86 87 88 89 90 |
# File 'lib/mycroft/messages.rb', line 83 def broadcast(content) = { id: SecureRandom.uuid, content: content } ('MSG_BROADCAST', ) end |
#connect_to_mycroft ⇒ Object
connects to mycroft aka starts tls if necessary
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mycroft/messages.rb', line 10 def connect_to_mycroft if ARGV.include?("--no-tls") @client = TCPSocket.open(@host, @port) else socket = TCPSocket.new(@host, @port) ssl_context = OpenSSL::SSL::SSLContext.new ssl_context.cert = OpenSSL::X509::Certificate.new(File.open(@cert)) ssl_context.key = OpenSSL::PKey::RSA.new(File.open(@key)) @client = OpenSSL::SSL::SSLSocket.new(socket, ssl_context) begin @client.connect rescue end end end |
#down ⇒ Object
Sends app down to mycroft
43 44 45 |
# File 'lib/mycroft/messages.rb', line 43 def down ('APP_DOWN') end |
#in_use(priority) ⇒ Object
47 48 49 |
# File 'lib/mycroft/messages.rb', line 47 def in_use(priority) ('APP_IN_USE', {priority: (priority or 30)}) end |
#query(capability, action, data, priority = 30, instance_id = nil) ⇒ Object
Sends a query to mycroft
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mycroft/messages.rb', line 52 def query(capability, action, data, priority = 30, instance_id = nil) = { id: SecureRandom.uuid, capability: capability, action: action, data: data, priority: priority, instanceId: [] } [:instanceId] = instance_id unless instance_id.nil? ('MSG_QUERY', ) end |
#query_fail(id, message) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/mycroft/messages.rb', line 74 def query_fail(id, ) = { id: id, message: } ('MSG_QUERY_FAIL', ) end |
#query_success(id, ret) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/mycroft/messages.rb', line 66 def query_success(id, ret) = { id: id, ret: ret } ('MSG_QUERY_SUCCESS', ) end |
#send_manifest ⇒ Object
Sends the app manifest to mycroft
27 28 29 30 31 32 33 34 35 |
# File 'lib/mycroft/messages.rb', line 27 def send_manifest begin manifest = JSON.parse(File.read(@manifest)) manifest['instanceId'] = "#{Socket.gethostname}_#{SecureRandom.uuid}" if @generate_instance_ids @instance_id = manifest['instanceId'] rescue end ('APP_MANIFEST', manifest) end |
#up ⇒ Object
Sends app up to mycroft
38 39 40 |
# File 'lib/mycroft/messages.rb', line 38 def up ('APP_UP') end |