Class: Volt::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.
27 28 29 30 31 32 33 34 |
# File 'lib/volt/server/socket_connection_handler.rb', line 27 def initialize(session, *args) @session = session @@channels ||= [] @@channels << self super end |
Class Method Details
.dispatcher ⇒ Object
13 14 15 |
# File 'lib/volt/server/socket_connection_handler.rb', line 13 def self.dispatcher @@dispatcher end |
.dispatcher=(val) ⇒ Object
Create one instance of the dispatcher
9 10 11 |
# File 'lib/volt/server/socket_connection_handler.rb', line 9 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
18 19 20 21 22 23 24 25 |
# File 'lib/volt/server/socket_connection_handler.rb', line 18 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
57 58 59 60 61 62 |
# File 'lib/volt/server/socket_connection_handler.rb', line 57 def closed # Remove ourself from the available channels @@channels.delete(self) QueryTasks.new(self).close! end |
#inspect ⇒ Object
64 65 66 |
# File 'lib/volt/server/socket_connection_handler.rb', line 64 def inspect "<#{self.class}:#{object_id}>" end |
#process_message(message) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/volt/server/socket_connection_handler.rb', line 36 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
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/volt/server/socket_connection_handler.rb', line 44 def (*args) str = JSON.dump([*args]) begin send(str) rescue MetaState::WrongStateError => e puts "Tried to send to closed connection: #{e.inspect}" # Mark this channel as closed closed end end |