OkHttpHelper.java 725 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
package chat.rocket.android.helper;


import com.facebook.stetho.okhttp3.StethoInterceptor;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

10 11 12
/**
 * Helper class for OkHttp client.
 */
13 14 15
public class OkHttpHelper {
    private static OkHttpClient sHttpClientForWS;

16 17 18 19 20
    /**
     * acquire OkHttpClient instance for WebSocket connection.
     */
    public static OkHttpClient getClientForWebSocket() {
        if (sHttpClientForWS == null) {
21 22 23 24 25 26 27 28
            sHttpClientForWS = new OkHttpClient.Builder()
                    .readTimeout(0, TimeUnit.NANOSECONDS)
                    .addNetworkInterceptor(new StethoInterceptor())
                    .build();
        }
        return sHttpClientForWS;
    }
}