...20import okhttp3.Response;21import okhttp3.WebSocketListener;22import org.openqa.selenium.remote.http.ClientConfig;23import org.openqa.selenium.remote.http.Filter;24import org.openqa.selenium.remote.http.HttpRequest;25import org.openqa.selenium.remote.http.HttpResponse;26import org.openqa.selenium.remote.http.WebSocket;27import java.util.Objects;28import java.util.concurrent.atomic.AtomicReference;29import java.util.function.BiFunction;30import java.util.function.Function;31class OkHttpWebSocket implements WebSocket {32 private final okhttp3.WebSocket socket;33 private OkHttpWebSocket(okhttp3.OkHttpClient client, okhttp3.Request request, Listener listener) {34 Objects.requireNonNull(client, "HTTP client to use must be set.");35 Objects.requireNonNull(request, "Request to send must be set.");36 Objects.requireNonNull(listener, "WebSocket listener must be set.");37 socket = client.newWebSocket(request, new WebSocketListener() {38 @Override39 public void onMessage(okhttp3.WebSocket webSocket, String text) {40 if (text != null) {41 listener.onText(text);42 }43 }44 @Override45 public void onClosed(okhttp3.WebSocket webSocket, int code, String reason) {46 listener.onClose(code, reason);47 }48 @Override49 public void onFailure(okhttp3.WebSocket webSocket, Throwable t, Response response) {50 listener.onError(t);51 }52 });53 }54 static BiFunction<HttpRequest, WebSocket.Listener, WebSocket> create(ClientConfig config) {55 Filter filter = config.filter();56 Function<HttpRequest, HttpRequest> filterRequest = req -> {57 AtomicReference<HttpRequest> ref = new AtomicReference<>();58 filter.andFinally(in -> {59 ref.set(in);60 return new HttpResponse();61 }).execute(req);62 return ref.get();63 };64 OkHttpClient client = new CreateOkClient().apply(config);65 return (req, listener) -> {66 HttpRequest filtered = filterRequest.apply(req);67 Request okReq = OkMessages.toOkHttpRequest(config.baseUri(), filtered);68 return new OkHttpWebSocket(client, okReq, listener);69 };70 }71 @Override72 public WebSocket sendText(CharSequence data) {73 socket.send(data.toString());74 return this;75 }76 @Override77 public void close() {78 socket.close(1000, "WebDriver closing socket");79 }80 @Override81 public void abort() {...