Class: DRb::WebSocket::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, config) ⇒ Server

Returns a new instance of Server.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/drb/websocket/server.rb', line 25

def initialize(uri, config)
  @uri = uri
  @config = config
  @queue = Thread::Queue.new
  Faye::WebSocket.load_adapter('thin')

  u = URI.parse(uri)
  RackApp.register(uri, self)

  if RackApp.config.standalone
    Thread.new do
      app = RackApp.new(-> { [400, {}, []] })
      thin = Rack::Handler.get('thin')
      thin.run(app, Host: u.host, Port: u.port)
    end.run
  end
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



23
24
25
# File 'lib/drb/websocket/server.rb', line 23

def uri
  @uri
end

Instance Method Details

#acceptObject



46
47
48
49
# File 'lib/drb/websocket/server.rb', line 46

def accept
  ws = @queue.pop
  ServerSide.new(ws, @config, uri)
end

#closeObject



43
44
# File 'lib/drb/websocket/server.rb', line 43

def close
end

#on_message(data) ⇒ Object



51
52
# File 'lib/drb/websocket/server.rb', line 51

def on_message(data)
end

#on_session_start(ws) ⇒ Object



54
55
56
# File 'lib/drb/websocket/server.rb', line 54

def on_session_start(ws)
  @queue.push(ws)
end