Class: Volt::SocketConnectionHandler
- Defined in:
- lib/volt/server/socket_connection_handler.rb
Instance Attribute Summary collapse
-
#user_id ⇒ Object
We track the connected user_id with the channel for use with permissions.
Class Method Summary collapse
- .dispatcher ⇒ Object
- .dispatcher=(val) ⇒ Object
-
.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.
13 14 15 16 17 18 |
# File 'lib/volt/server/socket_connection_handler.rb', line 13 def initialize(session, *args) @session = session @@channels ||= [] @@channels << self end |
Instance Attribute Details
#user_id ⇒ Object
We track the connected user_id with the channel for use with permissions. This may be changed as new listeners connect, which is fine.
10 11 12 |
# File 'lib/volt/server/socket_connection_handler.rb', line 10 def user_id @user_id end |
Class Method Details
.dispatcher ⇒ Object
24 25 26 |
# File 'lib/volt/server/socket_connection_handler.rb', line 24 def self.dispatcher @@dispatcher end |
.dispatcher=(val) ⇒ Object
20 21 22 |
# File 'lib/volt/server/socket_connection_handler.rb', line 20 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
29 30 31 32 33 34 35 |
# File 'lib/volt/server/socket_connection_handler.rb', line 29 def self.(skip_channel = nil, *args) return unless defined?(@@channels) @@channels.each do |channel| next if skip_channel && channel == skip_channel channel.(*args) end end |
Instance Method Details
#closed ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/volt/server/socket_connection_handler.rb', line 71 def closed unless @closed @closed = true # Remove ourself from the available channels @@channels.delete(self) begin @@dispatcher.close_channel(self) rescue DRb::DRbConnError => e # ignore drb read of @@dispatcher error if child has closed end else Volt.logger.error("Socket Error: Connection already closed\n#{inspect}") end end |
#inspect ⇒ Object
87 88 89 |
# File 'lib/volt/server/socket_connection_handler.rb', line 87 def inspect "<#{self.class}:#{object_id}>" end |
#process_message(message) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/volt/server/socket_connection_handler.rb', line 37 def () # Messages are json and wrapped in an array begin = EJSON.parse().first rescue JSON::ParserError => e Volt.logger.error("Unable to process task request message: #{.inspect}") end begin @@dispatcher.dispatch(self, ) rescue => e if defined?(DRb::DRbConnError) && e.is_a?(DRb::DRbConnError) # The child process was restarting, so drb failed to send else # re-raise the issue raise end end end |
#send_message(*args) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/volt/server/socket_connection_handler.rb', line 57 def (*args) str = EJSON.stringify([*args]) @session.send(str) if RUNNING_SERVER == 'thin' # This might seem strange, but it prevents a delay with outgoing # messages. # TODO: Figure out the cause of the issue and submit a fix upstream. EM.next_tick {} end end |