Options for inject okhttp Call/WebSocket factory

This commit is contained in:
Yu-Hsuan Lin
2017-05-02 01:15:47 +08:00
parent 80535c6304
commit c817af5b22
9 changed files with 183 additions and 267 deletions

View File

@@ -94,14 +94,19 @@ socket.on(Socket.EVENT_OPEN, new Emitter.Listener() {
Use custom SSL settings:
```java
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.hostnameVerifier(myHostnameVerifier)
.sslSocketFactory(mySSLContext.getSocketFactory(), myX509TrustManager)
.build();
// default SSLContext for all sockets
Socket.setDefaultSSLContext(mySSLContext);
Socket.setDefaultHostnameVerifier(myHostnameVerifier);
Socket.setDefaultOkHttpWebSocketFactory(okHttpClient);
Socket.setDefaultOkHttpCallFactory(okHttpClient);
// set as an option
opts = new Socket.Options();
opts.sslContext = mySSLContext;
opts.hostnameVerifier = myHostnameVerifier;
opts.callFactory = okHttpClient;
opts.webSocketFactory = okHttpClient;
socket = new Socket(opts);
```