Class: Playwright::WebSocketClient
- Inherits:
-
Object
- Object
- Playwright::WebSocketClient
show all
- Defined in:
- lib/playwright/web_socket_client.rb
Defined Under Namespace
Classes: DriverImpl, SecureSocketFactory, TransportError
Constant Summary
collapse
- STATE_CONNECTING =
0
- STATE_OPENED =
1
- STATE_CLOSING =
2
- STATE_CLOSED =
3
Instance Method Summary
collapse
Constructor Details
#initialize(url:, max_payload_size:) ⇒ WebSocketClient
Returns a new instance of WebSocketClient.
65
66
67
68
69
70
|
# File 'lib/playwright/web_socket_client.rb', line 65
def initialize(url:, max_payload_size:)
@impl = DriverImpl.new(url)
@driver = ::WebSocket::Driver.client(@impl, max_length: max_payload_size)
setup
end
|
Instance Method Details
#close(code: 1000, reason: "") ⇒ Object
118
119
120
121
122
|
# File 'lib/playwright/web_socket_client.rb', line 118
def close(code: 1000, reason: "")
return if @ready_state >= STATE_CLOSING
@ready_state = STATE_CLOSING
@driver.close(reason, code)
end
|
#on_close(&block) ⇒ Object
129
130
131
|
# File 'lib/playwright/web_socket_client.rb', line 129
def on_close(&block)
@on_close = block
end
|
#on_error(&block) ⇒ Object
134
135
136
|
# File 'lib/playwright/web_socket_client.rb', line 134
def on_error(&block)
@on_error = block
end
|
#on_message(&block) ⇒ Object
138
139
140
|
# File 'lib/playwright/web_socket_client.rb', line 138
def on_message(&block)
@on_message = block
end
|
#on_open(&block) ⇒ Object
124
125
126
|
# File 'lib/playwright/web_socket_client.rb', line 124
def on_open(&block)
@on_open = block
end
|
#send_text(message) ⇒ Object
113
114
115
116
|
# File 'lib/playwright/web_socket_client.rb', line 113
def send_text(message)
return if @ready_state >= STATE_CLOSING
@driver.text(message)
end
|
#start ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/playwright/web_socket_client.rb', line 98
def start
@driver.start
Thread.new do
wait_for_data until @ready_state >= STATE_CLOSING
rescue EOFError
if @ready_state < STATE_CLOSING
handle_on_close(reason: 'Going Away', code: 1001)
end
end
end
|