class MaterialRaingular::Websocket::Emitter

Attributes

channel[RW]

Public Class Methods

[](channel) click to toggle source
# File lib/material_raingular/websocket/emitter.rb, line 5
def [](channel)
  new(channel)
end
new(channel=nil) click to toggle source
# File lib/material_raingular/websocket/emitter.rb, line 22
def initialize(channel=nil)
  self.channel = channel
end
publish(channel,action,data) click to toggle source
# File lib/material_raingular/websocket/emitter.rb, line 10
def publish(channel,action,data) new(channel).publish(action,data) end
redis() click to toggle source
# File lib/material_raingular/websocket/emitter.rb, line 8
def redis() new.redis end
token(channel) click to toggle source
# File lib/material_raingular/websocket/emitter.rb, line 9
def token(channel) new(channel).token end

Public Instance Methods

publish(action,data) click to toggle source
# File lib/material_raingular/websocket/emitter.rb, line 18
def publish(action,data)
  return unless token.present?
  redis.publish "websocket_rails.events", [action,{data: data,channel: channel, token: token}].to_json
end
redis() click to toggle source
# File lib/material_raingular/websocket/emitter.rb, line 12
def redis()
  @redis ||= Redis.new(WebsocketRails.config.redis_options.reject{|k,v| k.to_sym == :driver})
end
token() click to toggle source
# File lib/material_raingular/websocket/emitter.rb, line 15
def token
  @token ||= redis.hget "websocket_rails.channel_tokens", channel
end