Module: Kame::App

Defined in:
lib/kame/app.rb

Class Method Summary collapse

Class Method Details

.start(context = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/kame/app.rb', line 5

def self.start(context=nil)

  remote_object = nil

  app = Rack::Builder.app do
    server = Kame::Remocon::Server.new(host: 'localhost')

    remote_object = server.settings.remote_object

    map '/' do
      run server
    end

    map '/assets' do
      run Kame::Remocon::Server::OPAL.sprockets
    end
  end

  Thread.new do
    thin = Rack::Handler.get('thin')
    thin.run(DRb::WebSocket::RackApp.new(app), Host: "127.0.0.1", Port: 9292)
  end.run

  10.times do
    sleep 2
    if defined? Rack::Handler::Thin
      Launchy.open("http://localhost:9292")
      break
    end
  end

  @remote_object = remote_object

  print "Waiting for the client is up"

  100.times do
    if @remote_object.turtle
      puts
      commander = @remote_object.turtle.new_commander

      if context
        Commander::METHODS.each do |name|
          context.define_singleton_method(name) do |*args|
            commander.method_missing(name, *args)
          end
        end
      end

      break commander
    end
    print "."
    sleep(1)
  end
end