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.
31 32 33 34 35 36 |
# File 'lib/volt/server/socket_connection_handler.rb', line 31 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
16 17 18 |
# File 'lib/volt/server/socket_connection_handler.rb', line 16 def self.dispatcher @@dispatcher end |
.dispatcher=(val) ⇒ Object
12 13 14 |
# File 'lib/volt/server/socket_connection_handler.rb', line 12 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
21 22 23 24 25 26 27 28 29 |
# File 'lib/volt/server/socket_connection_handler.rb', line 21 def self.(skip_channel = nil, *args) return unless defined?(@@channels) @@channels.each do |channel| if skip_channel && channel == skip_channel next end channel.(*args) end end |
Instance Method Details
#closed ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/volt/server/socket_connection_handler.rb', line 52 def closed unless @closed @closed = true # Remove ourself from the available channels @@channels.delete(self) QueryTasks.new(self).close! else Volt.logger.error("Socket Error: Connection already closed\n#{inspect}") end 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
38 39 40 41 42 43 44 |
# File 'lib/volt/server/socket_connection_handler.rb', line 38 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
46 47 48 49 50 |
# File 'lib/volt/server/socket_connection_handler.rb', line 46 def (*args) str = JSON.dump([*args]) @session.send(str) end |