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:, headers:) ⇒ WebSocketClient
65
66
67
68
69
70
71
72
73
|
# File 'lib/playwright/web_socket_client.rb', line 65
def initialize(url:, max_payload_size:, headers:)
@impl = DriverImpl.new(url)
@driver = ::WebSocket::Driver.client(@impl, max_length: max_payload_size)
.each do |key, value|
@driver.(key, value)
end
setup
end
|
Instance Method Details
#close(code: 1000, reason: "") ⇒ Object
121
122
123
124
125
|
# File 'lib/playwright/web_socket_client.rb', line 121
def close(code: 1000, reason: "")
return if @ready_state >= STATE_CLOSING
@ready_state = STATE_CLOSING
@driver.close(reason, code)
end
|
#on_close(&block) ⇒ Object
132
133
134
|
# File 'lib/playwright/web_socket_client.rb', line 132
def on_close(&block)
@on_close = block
end
|
#on_error(&block) ⇒ Object
137
138
139
|
# File 'lib/playwright/web_socket_client.rb', line 137
def on_error(&block)
@on_error = block
end
|
#on_message(&block) ⇒ Object
141
142
143
|
# File 'lib/playwright/web_socket_client.rb', line 141
def on_message(&block)
@on_message = block
end
|
#on_open(&block) ⇒ Object
127
128
129
|
# File 'lib/playwright/web_socket_client.rb', line 127
def on_open(&block)
@on_open = block
end
|
#send_text(message) ⇒ Object
116
117
118
119
|
# File 'lib/playwright/web_socket_client.rb', line 116
def send_text(message)
return if @ready_state >= STATE_CLOSING
@driver.text(message)
end
|
#start ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/playwright/web_socket_client.rb', line 101
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
|