Class: Conveyor::Websocket

Inherits:
Object
  • Object
show all
Defined in:
lib/conveyor/websocket.rb

Class Method Summary collapse

Class Method Details

.configObject



32
33
34
# File 'lib/conveyor/websocket.rb', line 32

def config
  fm.config[:websocket]
end

.fmObject



28
29
30
# File 'lib/conveyor/websocket.rb', line 28

def fm
  Conveyor::Foreman.instance
end

.startObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/conveyor/websocket.rb', line 4

def start
  if config[:disable]
    fm.info "Websocket disabled"
    return
  end

  fm.info "Starting websocket on #{config[:host]}:#{config[:port]}", :color => :green
  
  EventMachine::start_server(config[:host], config[:port],
    EventMachine::WebSocket::Connection, config) do |ws|
    ws.onopen {
      sid = fm.channel.subscribe { |type,msg| ws.send msg }
      fm.info "#{sid} connected to websocket!"
      ws.onclose {
        fm.channel.unsubscribe(sid)
      }
    }
  end
end

.stopObject



24
25
26
# File 'lib/conveyor/websocket.rb', line 24

def stop
  # EM::WebSocket.stop unless config[:disable]
end