Class: DRb::WebSocket::ClientSide

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

Instance Method Summary collapse

Constructor Details

#initialize(uri, config, handler) ⇒ ClientSide

Returns a new instance of ClientSide.



75
76
77
78
79
80
81
82
83
# File 'lib/drb/websocket.rb', line 75

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

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/drb/websocket.rb', line 88

def alive?
  false
end

#closeObject



85
86
# File 'lib/drb/websocket.rb', line 85

def close
end

#recv_replyObject



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/drb/websocket.rb', line 102

def recv_reply
  Thread.start do
    @reply_stream = @handler.stream if @handler

    begin
      @msg.recv_reply(@reply_stream)
    rescue
      close
      raise $!
    end
  end
end

#send(uri, data) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/drb/websocket.rb', line 115

def send(uri, data)
  @reply_stream = StrStream.new
  it = URI.parse(uri)
  path = [(it.path=='' ? '/' : it.path), it.query].compact.join('?')

  EM.run do
    ws = Faye::WebSocket::Client.new(uri + path)

    ws.on :message do |event|
      sio = StrStream.new
      sio.write(event.data.pack('C*'))

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

      ws.close

      EM.stop
    end

    ws.send(data.bytes)
  end
end

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



92
93
94
95
96
97
98
99
100
# File 'lib/drb/websocket.rb', line 92

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