Class: DRb::WebSocket::Handler
- Inherits:
-
Object
- Object
- DRb::WebSocket::Handler
- Defined in:
- lib/drb/websocket/client.rb
Instance Method Summary collapse
-
#initialize(uri, config) ⇒ Handler
constructor
A new instance of Handler.
- #send(uri, data) ⇒ Object
- #stream(&block) ⇒ Object
Constructor Details
#initialize(uri, config) ⇒ Handler
Returns a new instance of Handler.
54 55 56 57 58 59 |
# File 'lib/drb/websocket/client.rb', line 54 def initialize(uri, config) @uri = uri @config = config @queue = Thread::Queue.new @sender_id = SecureRandom.uuid end |
Instance Method Details
#send(uri, data) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/drb/websocket/client.rb', line 65 def send(uri, data) @wsclient = WSClient.new(uri) @wsclient.on(:message) do |event| = event.data sender_id = .shift(36).pack('C*') next if sender_id != @sender_id sio = StrStream.new sio.write(.pack('C*')) @queue.push sio if @config[:load_limit] < sio.buf.size raise TypeError, 'too large packet' end @wsclient.close end @wsclient.on(:open) do @wsclient.send((@sender_id + data).bytes) end end |
#stream(&block) ⇒ Object
61 62 63 |
# File 'lib/drb/websocket/client.rb', line 61 def stream(&block) @queue.pop(&block) end |