Sha256: 3d9077824b6a9abe050d8cdba63df26490286bea127b81e2b763e26d0c60155e

Contents?: true

Size: 863 Bytes

Versions: 10

Compression:

Stored size: 863 Bytes

Contents

module Conveyor
  class Websocket
    class << self
      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

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

      def fm
        Conveyor::Foreman.instance
      end

      def config
        fm.config[:websocket]
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gina-conveyor-0.2.4 lib/conveyor/websocket.rb
gina-conveyor-0.2.3 lib/conveyor/websocket.rb
gina-conveyor-0.2.2 lib/conveyor/websocket.rb
gina-conveyor-0.2.1 lib/conveyor/websocket.rb
gina-conveyor-0.2.0 lib/conveyor/websocket.rb
gina-conveyor-0.1.3 lib/conveyor/websocket.rb
gina-conveyor-0.1.2 lib/conveyor/websocket.rb
gina-conveyor-0.1.1 lib/conveyor/websocket.rb
gina-conveyor-0.1.0 lib/conveyor/websocket.rb
gina-conveyor-0.0.2 lib/conveyor/websocket.rb