Class: SocketConnectionHandler
- Defined in:
- lib/volt/server/socket_connection_handler.rb
Class Method Summary collapse
- .dispatcher ⇒ Object
-
.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) ⇒ SocketConnectionHandler
constructor
A new instance of SocketConnectionHandler.
- #inspect ⇒ Object
- #process_message(message) ⇒ Object
- #send_message(*args) ⇒ Object
Constructor Details
#initialize(session, *args) ⇒ SocketConnectionHandler
Returns a new instance of SocketConnectionHandler.
26 27 28 29 30 31 32 33 |
# File 'lib/volt/server/socket_connection_handler.rb', line 26 def initialize(session, *args) @session = session @@channels ||= [] @@channels << self super end |
Class Method Details
.dispatcher ⇒ Object
11 12 13 |
# File 'lib/volt/server/socket_connection_handler.rb', line 11 def self.dispatcher @@dispatcher end |
.dispatcher=(val) ⇒ Object
Create one instance of the dispatcher
7 8 9 |
# File 'lib/volt/server/socket_connection_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
16 17 18 19 20 21 22 23 24 |
# File 'lib/volt/server/socket_connection_handler.rb', line 16 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
49 50 51 52 53 54 55 |
# File 'lib/volt/server/socket_connection_handler.rb', line 49 def closed puts "CHANNEL CLOSED: #{self.inspect}" # Remove ourself from the available channels @@channels.delete(self) QueryTasks.new(self).close! end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/volt/server/socket_connection_handler.rb', line 57 def inspect "<#{self.class.to_s}:#{object_id}>" end |
#process_message(message) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/volt/server/socket_connection_handler.rb', line 35 def () # self.class.message_all(message) # Messages are json and wrapped in an array = JSON.parse().first @@dispatcher.dispatch(self, ) end |
#send_message(*args) ⇒ Object
43 44 45 46 47 |
# File 'lib/volt/server/socket_connection_handler.rb', line 43 def (*args) str = JSON.dump([*args]) send(str) end |