Class: WebsocketRails::ChannelManager

Inherits:
Object
  • Object
show all
Defined in:
lib/websocket_rails/channel_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChannelManager

Returns a new instance of ChannelManager.



29
30
31
32
# File 'lib/websocket_rails/channel_manager.rb', line 29

def initialize
  @channels = {}.with_indifferent_access
  @filtered_channels = {}.with_indifferent_access
end

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



27
28
29
# File 'lib/websocket_rails/channel_manager.rb', line 27

def channels
  @channels
end

#filtered_channelsObject (readonly)

Returns the value of attribute filtered_channels.



27
28
29
# File 'lib/websocket_rails/channel_manager.rb', line 27

def filtered_channels
  @filtered_channels
end

Instance Method Details

#[](channel) ⇒ Object



44
45
46
# File 'lib/websocket_rails/channel_manager.rb', line 44

def [](channel)
  @channels[channel] ||= Channel.new channel
end

#channel_tokensObject



34
35
36
37
38
39
40
41
42
# File 'lib/websocket_rails/channel_manager.rb', line 34

def channel_tokens
  @channel_tokens ||= begin
    if WebsocketRails.synchronize?
      ::Redis::HashKey.new('websocket_rails.channel_tokens', Synchronization.redis)
    else
      {}
    end
  end
end

#unsubscribe(connection) ⇒ Object



48
49
50
51
52
# File 'lib/websocket_rails/channel_manager.rb', line 48

def unsubscribe(connection)
  @channels.each do |channel_name, channel|
    channel.unsubscribe(connection)
  end
end