Sha256: c1e4ae8d06c7130b6687b773f57e106597d166e716c4e1d32fa4992f89977b58

Contents?: true

Size: 864 Bytes

Versions: 2

Compression:

Stored size: 864 Bytes

Contents

Cramp::Websocket.backend = :thin

class Termvana::WebsocketAction < Cramp::Websocket
  self.transport = :websocket

  on_data :received_data
  on_start :opened_conn
  on_finish :closed_conn

  attr_accessor :environment

  def opened_conn
    @environment = Termvana::Environment.new(:env => {"HOME" => ENV['HOME']})
    @environment.messenger do |message|
      render message.to_s
    end
    render Termvana::Response.new(:message => "Welcome to Nirvana. Websocket connected.", :type => :on_connect).to_s
    # resulvt = Termvana::Runner.run ARGV
    # send(result) unless result.to_s.empty?
  end

  def received_data(data)
    command = Termvana::Request.new(data)
    callable = Termvana::CommandProcessor.parse(environment, command)
    callable.call
  end

  def closed_conn
    # Ripl.shell.after_loop
    STDERR.puts "Browser disconnecting."
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
termvana-0.2.0.beta2 lib/termvana/app/actions/websocket_action.rb
termvana-0.2.0.beta1 lib/termvana/app/actions/websocket_action.rb