Class: SocketConnectionHandler

Inherits:
SockJS::Session
  • Object
show all
Defined in:
lib/volt/server/socket_connection_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.dispatcherObject



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.send_message_all(skip_channel=nil, *args)
  @@channels.each do |channel|
    if skip_channel && channel == skip_channel
      next
    end
    channel.send_message(*args)
  end
  
end

Instance Method Details

#closedObject



50
51
52
53
54
55
56
57
# File 'lib/volt/server/socket_connection_handler.rb', line 50

def closed
  puts "CHANNEL CLOSED"
  # Remove ourself from the available channels
  @@channels.delete(self)
  
  # Remove any listening channels
  ChannelTasks.new(self).close!
end

#process_message(message) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/volt/server/socket_connection_handler.rb', line 35

def process_message(message)
  # self.class.message_all(message)
  # Messages are json and wrapped in an array
  message = JSON.parse(message).first
  
  puts "GOT: #{message.inspect}"
  @@dispatcher.dispatch(self, message)
end

#send_message(*args) ⇒ Object



44
45
46
47
48
# File 'lib/volt/server/socket_connection_handler.rb', line 44

def send_message(*args)
  str = JSON.dump([*args])
  
  send(str)
end