Class: Conveyor::Websocket

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

Class Method Summary collapse

Class Method Details

.configObject



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

def config
  fm.config[:websocket]
end

.fmObject



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

def fm
  Conveyor::Foreman.instance
end

.startObject



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

def start
  return if config[:disabled]

  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



21
22
23
# File 'lib/conveyor/websocket.rb', line 21

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