Class: Google::Chrome::ExtensionPorts
- Inherits:
-
Object
- Object
- Google::Chrome::ExtensionPorts
- Defined in:
- lib/google/chrome/client.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect(port) ⇒ Object
-
#initialize(client, id) ⇒ ExtensionPorts
constructor
A new instance of ExtensionPorts.
- #post(port, data) ⇒ Object
Constructor Details
#initialize(client, id) ⇒ ExtensionPorts
Returns a new instance of ExtensionPorts.
152 153 154 155 |
# File 'lib/google/chrome/client.rb', line 152 def initialize(client, id) @client = client @id = id end |
Instance Method Details
#connect ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/google/chrome/client.rb', line 157 def connect h, r = @client.request({ 'Tool' => 'ExtensionPorts' }, { 'command' => 'connect', 'data' => { 'extensionId' => @id } }) port = r['data']['portId'].to_i if block_given? begin yield(port) ensure disconnect(port) end else return port end end |
#disconnect(port) ⇒ Object
174 175 176 177 |
# File 'lib/google/chrome/client.rb', line 174 def disconnect(port) @client.request({ 'Tool' => 'ExtensionPorts', 'Destination' => port }, { 'command' => 'disconnect' }) end |
#post(port, data) ⇒ Object
179 180 181 182 183 |
# File 'lib/google/chrome/client.rb', line 179 def post(port, data) @client.request({ 'Tool' => 'ExtensionPorts', 'Destination' => port }, { 'command' => 'postMessage', 'data' => data }) end |