mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Updated ProxyData exceptions to include previous exception to finish stacktrace
Updated LiveUserData.Request to throw an IllegalArgumentException when a null or blank username is provided Updated HttpClientSettings to use setProxyClientSettings instead of direct access Fixed ProxyRotation bug starting at index 1 instead of 0 and made methods default to synchronized in case concurrency is used in implementors code Changed HttpClient#toUrl to toUri Added @Getter to HttpClientFactory for liveClientSettings Added consumer to TikTokLive#requests so that way proxies can be used when calling the fetch methods Changed LiveUserData.Response#startTime to clarify the variable name
This commit is contained in:
@@ -23,12 +23,14 @@
|
||||
package io.github.jwdeveloper.tiktok;
|
||||
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftsManager;
|
||||
import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
|
||||
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
||||
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TikTokLive {
|
||||
|
||||
@@ -82,13 +84,22 @@ public class TikTokLive {
|
||||
return CompletableFuture.supplyAsync(() -> isHostNameValid(hostName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use to get some data from TikTok about users are lives
|
||||
*
|
||||
* @return LiveHttpClient
|
||||
*/
|
||||
public static LiveHttpClient requests(Consumer<LiveClientSettings> consumer) {
|
||||
return new TikTokLiveHttpClient(consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use to get some data from TikTok about users are lives
|
||||
*
|
||||
* @return LiveHttpClient
|
||||
*/
|
||||
public static LiveHttpClient requests() {
|
||||
return new TikTokLiveHttpClient();
|
||||
return requests(liveClientSettings -> {});
|
||||
}
|
||||
|
||||
private static GiftsManager giftsManager;
|
||||
|
||||
@@ -125,7 +125,7 @@ public class TikTokLiveClient implements LiveClient {
|
||||
tikTokEventHandler.publish(this, new TikTokConnectingEvent());
|
||||
var userDataRequest = new LiveUserData.Request(liveRoomInfo.getHostName());
|
||||
var userData = httpClient.fetchLiveUserData(userDataRequest);
|
||||
liveRoomInfo.setStartTime(userData.getStartedAtTimeStamp());
|
||||
liveRoomInfo.setStartTime(userData.getStartTime());
|
||||
liveRoomInfo.setRoomId(userData.getRoomId());
|
||||
|
||||
if (clientSettings.isFetchGifts())
|
||||
|
||||
@@ -117,11 +117,9 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
||||
|
||||
var listenerManager = new TikTokListenersManager(listeners, eventHandler);
|
||||
|
||||
var httpClientFactory = new HttpClientFactory(clientSettings);
|
||||
|
||||
var liveHttpClient = clientSettings.isOffline() ?
|
||||
new TikTokLiveHttpOfflineClient() :
|
||||
new TikTokLiveHttpClient(httpClientFactory, clientSettings);
|
||||
new TikTokLiveHttpClient(new HttpClientFactory(clientSettings));
|
||||
|
||||
var eventsMapper = createMapper(giftsManager, tiktokRoomInfo);
|
||||
var messageHandler = new TikTokLiveMessageHandler(eventHandler, eventsMapper);
|
||||
|
||||
@@ -32,6 +32,7 @@ import io.github.jwdeveloper.tiktok.http.mappers.*;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class TikTokLiveHttpClient implements LiveHttpClient
|
||||
@@ -53,17 +54,18 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
||||
private final GiftsDataMapper giftsDataMapper;
|
||||
private final Logger logger;
|
||||
|
||||
public TikTokLiveHttpClient(HttpClientFactory factory, LiveClientSettings settings) {
|
||||
public TikTokLiveHttpClient(HttpClientFactory factory) {
|
||||
this.httpFactory = factory;
|
||||
this.clientSettings = settings;
|
||||
this.clientSettings = factory.getLiveClientSettings();
|
||||
this.logger = LoggerFactory.create("HttpClient-"+hashCode(), clientSettings);
|
||||
liveUserDataMapper = new LiveUserDataMapper();
|
||||
liveDataMapper = new LiveDataMapper();
|
||||
giftsDataMapper = new GiftsDataMapper();
|
||||
}
|
||||
|
||||
public TikTokLiveHttpClient() {
|
||||
this(new HttpClientFactory(LiveClientSettings.createDefault()), LiveClientSettings.createDefault());
|
||||
public TikTokLiveHttpClient(Consumer<LiveClientSettings> consumer) {
|
||||
this(new HttpClientFactory(LiveClientSettings.createDefault()));
|
||||
consumer.accept(clientSettings);
|
||||
}
|
||||
|
||||
public GiftsData.Response fetchRoomGiftsData(String room_id) {
|
||||
@@ -191,7 +193,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
||||
.withParam("internal_ext", webcastResponse.getInternalExt())
|
||||
.withParams(webcastResponse.getRouteParamsMapMap())
|
||||
.build()
|
||||
.toUrl();
|
||||
.toUri();
|
||||
|
||||
return new LiveConnectionData.Response(websocketCookie, webSocketUrl, webcastResponse);
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
|
||||
@@ -90,14 +90,14 @@ public class HttpClient {
|
||||
return toResponse().map(HttpResponse::body);
|
||||
}
|
||||
|
||||
public URI toUrl() {
|
||||
public URI toUri() {
|
||||
var stringUrl = prepareUrlWithParameters(url, httpClientSettings.getParams());
|
||||
return URI.create(stringUrl);
|
||||
}
|
||||
|
||||
protected HttpRequest prepareGetRequest() {
|
||||
var requestBuilder = HttpRequest.newBuilder().GET();
|
||||
requestBuilder.uri(toUrl());
|
||||
requestBuilder.uri(toUri());
|
||||
requestBuilder.timeout(httpClientSettings.getTimeout());
|
||||
httpClientSettings.getHeaders().forEach(requestBuilder::setHeader);
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
package io.github.jwdeveloper.tiktok.http;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.settings.*;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class HttpClientFactory {
|
||||
private final LiveClientSettings liveClientSettings;
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ public class HttpProxyClient extends HttpClient {
|
||||
public X509Certificate[] getAcceptedIssuers() { return null; }
|
||||
}}, null);
|
||||
|
||||
URL url = toUrl().toURL();
|
||||
URL url = toUri().toURL();
|
||||
|
||||
if (proxySettings.hasNext()) {
|
||||
try {
|
||||
@@ -117,7 +117,7 @@ public class HttpProxyClient extends HttpClient {
|
||||
|
||||
var responseInfo = createResponseInfo(socksConnection.getResponseCode(), headers);
|
||||
|
||||
var response = createHttpResponse(body, toUrl(), responseInfo);
|
||||
var response = createHttpResponse(body, toUri(), responseInfo);
|
||||
|
||||
return ActionResult.success(response);
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user