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.



159
160
161
162
163
164
165
# File 'lib/opal/drb/websocket.rb', line 159

def initialize(uri, config)
  @uri = uri
  @res = nil
  @config = config
  @msg = DRbMessage.new(@config)
  @proxy = ENV['HTTP_PROXY']
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


170
171
172
# File 'lib/opal/drb/websocket.rb', line 170

def alive?
  false
end

#closeObject



167
168
# File 'lib/opal/drb/websocket.rb', line 167

def close
end

#recv_reply(reply_stream) ⇒ Object



180
181
182
183
# File 'lib/opal/drb/websocket.rb', line 180

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

#send(uri, data) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/opal/drb/websocket.rb', line 185

def send(uri, data)
  promise = Promise.new
  @ws = ::WebSocket.new(uri)
  @ws.onmessage do |event|
    reply_stream = StrStream.new
    reply_stream.write(event.data.to_s)

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

    promise.resolve reply_stream

    @ws.close
  end

  @ws.onopen do
    @ws.send(`new Uint8Array(#{data.bytes.each_slice(2).map(&:first)}).buffer`)
  end

  promise
end

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



174
175
176
177
178
# File 'lib/opal/drb/websocket.rb', line 174

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