module Mycroft::Messages
Public Instance Methods
broadcast(content)
click to toggle source
Sends a broadcast to the mycroft message board
# File lib/mycroft/messages.rb, line 83 def broadcast(content) message = { id: SecureRandom.uuid, content: content } send_message('MSG_BROADCAST', message) end
connect_to_mycroft()
click to toggle source
connects to mycroft aka starts tls if necessary
# 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()
click to toggle source
Sends app down to mycroft
# File lib/mycroft/messages.rb, line 43 def down send_message('APP_DOWN') end
in_use(priority)
click to toggle source
# File lib/mycroft/messages.rb, line 47 def in_use(priority) send_message('APP_IN_USE', {priority: (priority or 30)}) end
query(capability, action, data, priority = 30, instance_id = nil)
click to toggle source
Sends a query to mycroft
# File lib/mycroft/messages.rb, line 52 def query(capability, action, data, priority = 30, instance_id = nil) query_message = { id: SecureRandom.uuid, capability: capability, action: action, data: data, priority: priority, instanceId: [] } query_message[:instanceId] = instance_id unless instance_id.nil? send_message('MSG_QUERY', query_message) end
query_fail(id, message)
click to toggle source
# File lib/mycroft/messages.rb, line 74 def query_fail(id, message) query_fail_message = { id: id, message: message } send_message('MSG_QUERY_FAIL', query_fail_message) end
query_success(id, ret)
click to toggle source
# File lib/mycroft/messages.rb, line 66 def query_success(id, ret) query_success_message = { id: id, ret: ret } send_message('MSG_QUERY_SUCCESS', query_success_message) end
send_manifest()
click to toggle source
Sends the app manifest to mycroft
# 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 send_message('APP_MANIFEST', manifest) end
up()
click to toggle source
Sends app up to mycroft
# File lib/mycroft/messages.rb, line 38 def up send_message('APP_UP') end