Class: ChromeRemote::Client
- Inherits:
-
Object
- Object
- ChromeRemote::Client
- Defined in:
- lib/chrome_remote/client.rb
Instance Attribute Summary collapse
-
#handlers ⇒ Object
readonly
Returns the value of attribute handlers.
-
#ws ⇒ Object
readonly
Returns the value of attribute ws.
Instance Method Summary collapse
-
#initialize(ws_url) ⇒ Client
constructor
A new instance of Client.
- #listen ⇒ Object
- #listen_until(&block) ⇒ Object
- #on(event_name, &block) ⇒ Object
- #send_cmd(command, params = {}) ⇒ Object
- #wait_for(event_name) ⇒ Object
Constructor Details
#initialize(ws_url) ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/chrome_remote/client.rb', line 7 def initialize(ws_url) @ws = WebSocketClient.new(ws_url) @handlers = Hash.new {|hash, key| hash[key] = [] } end |
Instance Attribute Details
#handlers ⇒ Object (readonly)
Returns the value of attribute handlers.
5 6 7 |
# File 'lib/chrome_remote/client.rb', line 5 def handlers @handlers end |
#ws ⇒ Object (readonly)
Returns the value of attribute ws.
5 6 7 |
# File 'lib/chrome_remote/client.rb', line 5 def ws @ws end |
Instance Method Details
#listen ⇒ Object
29 30 31 |
# File 'lib/chrome_remote/client.rb', line 29 def listen read_until { false } end |
#listen_until(&block) ⇒ Object
25 26 27 |
# File 'lib/chrome_remote/client.rb', line 25 def listen_until(&block) read_until { block.call } end |
#on(event_name, &block) ⇒ Object
21 22 23 |
# File 'lib/chrome_remote/client.rb', line 21 def on(event_name, &block) handlers[event_name] << block end |
#send_cmd(command, params = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/chrome_remote/client.rb', line 12 def send_cmd(command, params = {}) msg_id = generate_unique_id ws.send_msg({method: command, params: params, id: msg_id}.to_json) msg = read_until { |msg| msg["id"] == msg_id } msg["result"] end |
#wait_for(event_name) ⇒ Object
33 34 35 36 |
# File 'lib/chrome_remote/client.rb', line 33 def wait_for(event_name) msg = read_until { |msg| msg["method"] == event_name } msg["params"] end |