Class: ChannelHandler
- Defined in:
- lib/volt/server/channel_handler.rb
Class Method Summary collapse
-
.dispatcher=(val) ⇒ Object
Create one instance of the dispatcher.
-
.send_message_all(skip_channel = nil, *args) ⇒ Object
Sends a message to all, optionally skipping a users channel.
Instance Method Summary collapse
- #closed ⇒ Object
-
#initialize(session, *args) ⇒ ChannelHandler
constructor
A new instance of ChannelHandler.
- #process_message(message) ⇒ Object
- #send_message(*args) ⇒ Object
Constructor Details
#initialize(session, *args) ⇒ ChannelHandler
Returns a new instance of ChannelHandler.
22 23 24 25 26 27 28 29 |
# File 'lib/volt/server/channel_handler.rb', line 22 def initialize(session, *args) @session = session @@channels ||= [] @@channels << self super end |
Class Method Details
.dispatcher=(val) ⇒ Object
Create one instance of the dispatcher
7 8 9 |
# File 'lib/volt/server/channel_handler.rb', line 7 def self.dispatcher=(val) @@dispatcher = val end |
.send_message_all(skip_channel = nil, *args) ⇒ Object
Sends a message to all, optionally skipping a users channel
12 13 14 15 16 17 18 19 20 |
# File 'lib/volt/server/channel_handler.rb', line 12 def self.(skip_channel=nil, *args) @@channels.each do |channel| if skip_channel && channel == skip_channel next end channel.(*args) end end |
Instance Method Details
#closed ⇒ Object
46 47 48 49 |
# File 'lib/volt/server/channel_handler.rb', line 46 def closed # Remove ourself from the available channels @@channels.delete(self) end |
#process_message(message) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/volt/server/channel_handler.rb', line 31 def () # self.class.message_all(message) # Messages are json and wrapped in an array = JSON.parse().first puts "GOT: #{.inspect}" @@dispatcher.dispatch(self, ) end |
#send_message(*args) ⇒ Object
40 41 42 43 44 |
# File 'lib/volt/server/channel_handler.rb', line 40 def (*args) str = JSON.dump([*args]) send(str) end |