Module: Rfid::Translator
Constant Summary collapse
- @@channel =
nil
Instance Method Summary collapse
- #connected? ⇒ Boolean
- #redis ⇒ Object
- #send(message) ⇒ Object
- #start ⇒ Object
-
#web_log(type, socket_id, message = nil, data = nil) ⇒ Object
types: ‘socket_opened’ ‘socket_closed’ ‘channel_occupied’ ‘channel_vacated’ ‘channel_subscribed’ ‘channel_unsubscribed’ ‘api_message’ ‘client_message’ ‘presence_message’ ‘error’ ‘api_error’ ‘client_error’ ‘pipe_incoming_message’ ‘wsapi_message’.
Instance Method Details
#connected? ⇒ Boolean
22 23 24 |
# File 'lib/rfid/translator.rb', line 22 def connected? !self.channel.nil? end |
#redis ⇒ Object
11 12 13 |
# File 'lib/rfid/translator.rb', line 11 def redis @redis ||= EM::Hiredis.connect(Rfid.config.redis_url) end |
#send(message) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/rfid/translator.rb', line 26 def send() if connected? web_log('client_message', nil, "Message", ) self.channel.push() end end |
#start ⇒ Object
15 16 17 18 19 20 |
# File 'lib/rfid/translator.rb', line 15 def start redis.blpop(Rfid.config.redis_key, 0).callback do |list, data| send(data) EM.next_tick(&method(:start)) end end |
#web_log(type, socket_id, message = nil, data = nil) ⇒ Object
types: ‘socket_opened’ ‘socket_closed’ ‘channel_occupied’ ‘channel_vacated’ ‘channel_subscribed’ ‘channel_unsubscribed’ ‘api_message’ ‘client_message’ ‘presence_message’ ‘error’ ‘api_error’ ‘client_error’ ‘pipe_incoming_message’ ‘wsapi_message’
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rfid/translator.rb', line 49 def web_log(type, socket_id, = nil, data = nil) if connected? hash = { :event => 'log_message', :data => { :socket_id => socket_id, :message => , :date => Time.now.strftime("%H:%M:%S"), :type => type, :data => data, } } self.channel.push(hash.to_json) end Rfid.log(type, socket_id, , data) end |