Refactor out global vars in Messaging class
parent
f11c66ca2a
commit
391808b796
|
@ -11,9 +11,6 @@ require_relative 'messagehandler.rb'
|
|||
# The Device class is temporarily inheriting from Tim's HardwareInterface.
|
||||
# Eventually, we should merge the two projects, but this is good enough for now.
|
||||
class Messaging
|
||||
|
||||
include Credentials, WebSocket
|
||||
|
||||
class << self
|
||||
attr_accessor :current
|
||||
|
||||
|
@ -25,6 +22,8 @@ class Messaging
|
|||
attr_accessor :socket, :uuid, :token, :identified, :confirmed,
|
||||
:confirmation_id
|
||||
|
||||
include Credentials, WebSocket
|
||||
|
||||
# On instantiation #new sets the @uuid, @token variables, connects to skynet
|
||||
def initialize
|
||||
identified = false
|
||||
|
@ -42,7 +41,7 @@ class Messaging
|
|||
end
|
||||
|
||||
def send_message(devices, message_hash )
|
||||
@socket.emit("message", devices: devices, message: message_hash})
|
||||
@socket.emit("message", devices: devices, message: message_hash)
|
||||
end
|
||||
|
||||
# Acts as the entry point for message traffic captured from MeshBlu.
|
||||
|
|
|
@ -13,24 +13,16 @@ module WebSocket
|
|||
#Handles self identification on skynet by responding to the :indentify with a
|
||||
#:identity event / credentials Hash.
|
||||
def create_identify_event
|
||||
Messaging.current.socket.on :identify do |data|
|
||||
self.emit :identity, {
|
||||
uuid: Messaging.current.uuid,
|
||||
token: Messaging.current.token,
|
||||
socketid: data['socketid']}
|
||||
Messaging.current.identified = true
|
||||
socket.on :identify do |data|
|
||||
auth_data = {uuid: uuid, token: token, socketid: data['socketid']}
|
||||
socket.emit :identity, auth_data
|
||||
identified = true
|
||||
end
|
||||
end
|
||||
|
||||
### Routes all skynet messages to handle_event() for interpretation.
|
||||
def create_message_event
|
||||
#@socket.on :message do |channel, message|
|
||||
# $skynet.handle_message(channel, message)
|
||||
#end
|
||||
|
||||
Messaging.current.socket.on :message do |message|
|
||||
Messaging.current.handle_message(message)
|
||||
end
|
||||
socket.on(:message) { |message| Messaging.current.handle_message(message) }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue