class ConsoleWebsocketCfPlugin::Plugin

Public Instance Methods

console() click to toggle source
# File lib/console-websocket-cf-plugin/plugin.rb, line 48
def console

  app = input[:app]

  app_version = app.manifest[:entity][:version]
  guid = "#{app_version}/#{input[:instance]}"
  ws_url = "wss://#{app.url}:4443/#{guid}"

  puts "Starting connection to #{ws_url}"

  start_connection(app, guid, ws_url)

end
precondition() click to toggle source
# File lib/console-websocket-cf-plugin/plugin.rb, line 38
def precondition
  # skip all default preconditions
end

Private Instance Methods

start_connection(app, guid, ws_url) click to toggle source
# File lib/console-websocket-cf-plugin/plugin.rb, line 64
    def start_connection(app, guid, ws_url)
      
      EM.run {

        Faye::WebSocket::Client.class_eval <<-BYTES_IN
          attr_accessor :lines_in
        BYTES_IN

        ws = Faye::WebSocket::Client.new(ws_url, nil, { :headers => { 'Origin' => "http://#{app.url}:4443" }})
        ws.lines_in = ['']

        ws.on :error do |event|
          p [:error]
          p ws.status
        end

        ws.on :message do |event|
          msg = event.data

          msg = msg[(ws.lines_in.last.length)..(msg.length - 1)].lstrip if msg.start_with?(ws.lines_in.last)
          print msg
        end

        ws.on :close do |event|
          ws = nil
          EM.stop
        end
        
        EM.open_keyboard(KeyboardHandler, ws, guid)
      }

    end