33import com .fastcomments .api .PublicApi ;
44import com .fastcomments .core .CommentWidgetConfig ;
55import com .fastcomments .invoker .ApiCallback ;
6+ import com .fastcomments .invoker .ApiClient ;
67import com .fastcomments .invoker .ApiException ;
78import com .fastcomments .model .*;
89import com .google .gson .Gson ;
@@ -30,6 +31,10 @@ public class LiveEventSubscriber {
3031 (JsonDeserializer <java .time .OffsetDateTime >) (json , type , ctx ) ->
3132 java .time .OffsetDateTime .parse (json .getAsString ()))
3233 .create ();
34+ private static final OkHttpClient httpClient = new OkHttpClient .Builder ()
35+ .connectionPool (new ConnectionPool (5 , 5 , TimeUnit .MINUTES ))
36+ .dispatcher (new Dispatcher ())
37+ .build ();
3338 private final OkHttpClient client ;
3439
3540 private final Map <String , Timer > debouncers = new ConcurrentHashMap <>();
@@ -41,6 +46,7 @@ private static OkHttpClient buildClient(long pingIntervalSeconds) {
4146 .pingInterval (pingIntervalSeconds , TimeUnit .SECONDS ) // protocol-level WebSocket ping to keep NATs alive (emulators, silly networks, etc)
4247 .protocols (Collections .singletonList (Protocol .HTTP_1_1 )) // just skip negotiating, server is 1.1, reduces latency
4348 .connectionPool (new ConnectionPool (5 , 5 , TimeUnit .MINUTES )) // create our own connection pool so it doesn't get shared w/ another okhttpclient config
49+ .dispatcher (new Dispatcher ())
4450 .build ();
4551 }
4652
@@ -325,8 +331,8 @@ private static void fetchEventLog(
325331 Consumer <List <LiveEvent >> callback
326332 ) {
327333 try {
328- // Create PublicApi instance
329- PublicApi publicApi = new PublicApi ();
334+ // Create PublicApi instance with its own HTTP client
335+ PublicApi publicApi = new PublicApi (new ApiClient ( httpClient ) );
330336
331337 // Create API request
332338 PublicApi .APIgetEventLogRequest request =
0 commit comments