Class: DRb::WebSocket::ClientSide

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

Instance Method Summary collapse

Constructor Details

#initialize(uri, config) ⇒ ClientSide

Returns a new instance of ClientSide.



256
257
258
259
260
261
262
# File 'lib/opal/drb/websocket.rb', line 256

def initialize(uri, config)
  @uri = uri
  @pool =  SocketPool.open(uri)
  @res = nil
  @config = config
  @msg = DRbMessage.new(@config)
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


264
265
266
# File 'lib/opal/drb/websocket.rb', line 264

def alive?
  !!@pool.ws && @pool.ws.open?
end

#closeObject



268
269
# File 'lib/opal/drb/websocket.rb', line 268

def close
end

#recv_reply(reply_stream) ⇒ Object



277
278
279
# File 'lib/opal/drb/websocket.rb', line 277

def recv_reply(reply_stream)
  @msg.recv_reply(reply_stream)
end

#send(uri, data) ⇒ Object



281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/opal/drb/websocket.rb', line 281

def send(uri, data)
  promise = Promise.new
  @pool.send(data) do |message|
    reply_stream = StrStream.new
    reply_stream.write(message.to_s)

    if @config[:load_limit] < reply_stream.buf.size
      raise TypeError, 'too large packet'
    end

    promise.resolve reply_stream
  end
  promise
end

#send_request(ref, msg_id, *arg, &b) ⇒ Object



271
272
273
274
275
# File 'lib/opal/drb/websocket.rb', line 271

def send_request(ref, msg_id, *arg, &b)
  stream = StrStream.new
  @msg.send_request(stream, ref, msg_id, *arg, &b)
  send(@uri, stream.buf)
end