Class: DRb::WebSocket::CallbackServer

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

Defined Under Namespace

Classes: ServerSide

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, config) ⇒ CallbackServer

Returns a new instance of CallbackServer.



6
7
8
9
10
11
# File 'lib/drb/websocket/callback_server.rb', line 6

def initialize(uri, config)
  @uri = uri
  @config = config
  @queue = Thread::Queue.new
  reconnect
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



4
5
6
# File 'lib/drb/websocket/callback_server.rb', line 4

def uri
  @uri
end

Instance Method Details

#acceptObject



30
31
32
33
34
35
# File 'lib/drb/websocket/callback_server.rb', line 30

def accept
  (sender_id, message) = @queue.pop
  server_side = ServerSide.new(@wsclient, sender_id, message, @config, @uri)
  reconnect
  server_side
end

#closeObject



23
24
25
26
27
28
# File 'lib/drb/websocket/callback_server.rb', line 23

def close
  EM.defer do
    @wsclient.close
    @wsclient = nil
  end
end

#reconnectObject



13
14
15
16
17
18
19
20
21
# File 'lib/drb/websocket/callback_server.rb', line 13

def reconnect
  @wsclient = WSClient.new(uri)

  @wsclient.on(:message) do |event|
    message = event.data
    sender_id = message.shift(36).pack('C*')
    @queue << [sender_id, message.pack('C*')]
  end
end