mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Compare commits
13 Commits
1.11.3-Rel
...
1.11.9-Rel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
95e352908d | ||
|
|
3f00256634 | ||
|
|
089d8d6ed8 | ||
|
|
4be74c45ff | ||
|
|
db4d382e34 | ||
|
|
2590200205 | ||
|
|
4aefde8a0c | ||
|
|
6486519876 | ||
|
|
96cf28e5d5 | ||
|
|
cfdced9645 | ||
|
|
7589a2ac4a | ||
|
|
a0c445656c | ||
|
|
1e78fdda89 |
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.11.2-Release</version>
|
<version>1.11.8-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -39,11 +39,16 @@ public class TikTokGiftComboEvent extends TikTokGiftEvent {
|
|||||||
this.comboState = comboState;
|
this.comboState = comboState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TikTokGiftComboEvent(Gift gift, User host, User user, int combo, GiftComboStateType comboState) {
|
||||||
|
super(gift, user, host, combo);
|
||||||
|
this.comboState = comboState;
|
||||||
|
}
|
||||||
|
|
||||||
public static TikTokGiftComboEvent of(Gift gift, int combo, GiftComboStateType comboState) {
|
public static TikTokGiftComboEvent of(Gift gift, int combo, GiftComboStateType comboState) {
|
||||||
return new TikTokGiftComboEvent(
|
return new TikTokGiftComboEvent(gift, new User(0L, "Test", new Picture("")), WebcastGiftMessage.newBuilder().setComboCount(combo).build(), comboState);
|
||||||
gift,
|
}
|
||||||
new User(0L, "Test", new Picture("")),
|
|
||||||
WebcastGiftMessage.newBuilder().setComboCount(combo).build(),
|
public static TikTokGiftComboEvent of(Gift gift, User host, User user, int combo, GiftComboStateType comboState) {
|
||||||
comboState);
|
return new TikTokGiftComboEvent(gift, host, user, combo, comboState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,17 +49,25 @@ public class TikTokGiftEvent extends TikTokHeaderEvent {
|
|||||||
}
|
}
|
||||||
combo = msg.getComboCount();
|
combo = msg.getComboCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokGiftEvent(Gift gift) {
|
public TikTokGiftEvent(Gift gift, User user, User toUser, int combo) {
|
||||||
this.gift = gift;
|
this.gift = gift;
|
||||||
user = new User(0L, "sender", new Picture(""));
|
this.user = user;
|
||||||
toUser = new User(0L, "receiver", new Picture(""));
|
this.toUser = toUser;
|
||||||
combo = 1;
|
this.combo = combo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static TikTokGiftEvent of(Gift gift) {
|
public static TikTokGiftEvent of(Gift gift) {
|
||||||
return new TikTokGiftEvent(gift);
|
return new TikTokGiftEvent(
|
||||||
|
gift,
|
||||||
|
new User(0L, "sender", new Picture("")),
|
||||||
|
new User(0L, "reviever", new Picture("")),
|
||||||
|
1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TikTokGiftEvent of(Gift gift, User user, User toUser) {
|
||||||
|
return new TikTokGiftEvent(gift, user, toUser, 1) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TikTokGiftEvent of(String name, int id, int diamonds) {
|
public static TikTokGiftEvent of(String name, int id, int diamonds) {
|
||||||
|
|||||||
@@ -44,10 +44,20 @@ public class TikTokFollowEvent extends TikTokHeaderEvent {
|
|||||||
|
|
||||||
public static TikTokFollowEvent of(String userName) {
|
public static TikTokFollowEvent of(String userName) {
|
||||||
return new TikTokFollowEvent(WebcastSocialMessage.newBuilder()
|
return new TikTokFollowEvent(WebcastSocialMessage.newBuilder()
|
||||||
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
.setUsername(userName)
|
.setUsername(userName)
|
||||||
.setNickname(userName)
|
.setNickname(userName)
|
||||||
.build())
|
.build())
|
||||||
.build());
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TikTokFollowEvent of(User user) {
|
||||||
|
return new TikTokFollowEvent(WebcastSocialMessage.newBuilder()
|
||||||
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
|
.setUsername(user.getName())
|
||||||
|
.setNickname(user.getProfileName() != null ? user.getProfileName() : user.getName())
|
||||||
|
.setId(user.getId())
|
||||||
|
.build())
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,13 +48,22 @@ public class TikTokJoinEvent extends TikTokHeaderEvent {
|
|||||||
totalUsers = msg.getMemberCount();
|
totalUsers = msg.getMemberCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TikTokJoinEvent of(String userName)
|
public static TikTokJoinEvent of(String userName) {
|
||||||
{
|
|
||||||
return new TikTokJoinEvent(WebcastMemberMessage.newBuilder()
|
return new TikTokJoinEvent(WebcastMemberMessage.newBuilder()
|
||||||
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
.setUsername(userName)
|
.setUsername(userName)
|
||||||
.setNickname(userName)
|
.setNickname(userName)
|
||||||
.build())
|
.build())
|
||||||
.build());
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TikTokJoinEvent of(User user) {
|
||||||
|
return new TikTokJoinEvent(WebcastMemberMessage.newBuilder()
|
||||||
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
|
.setUsername(user.getName())
|
||||||
|
.setNickname(user.getProfileName())
|
||||||
|
.setId(user.getId())
|
||||||
|
.build())
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,15 +56,25 @@ public class TikTokLikeEvent extends TikTokHeaderEvent
|
|||||||
totalLikes = msg.getTotal();
|
totalLikes = msg.getTotal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TikTokLikeEvent of(String userName, int likes)
|
public static TikTokLikeEvent of(String userName, int likes) {
|
||||||
{
|
|
||||||
return new TikTokLikeEvent(WebcastLikeMessage.newBuilder()
|
return new TikTokLikeEvent(WebcastLikeMessage.newBuilder()
|
||||||
.setCount(likes)
|
.setCount(likes)
|
||||||
.setTotal(likes)
|
.setTotal(likes)
|
||||||
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
.setUsername(userName)
|
.setUsername(userName)
|
||||||
.setNickname(userName)
|
.setNickname(userName)
|
||||||
.build())
|
.build())
|
||||||
.build());
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TikTokLikeEvent of(User user, int likes) {
|
||||||
|
return new TikTokLikeEvent(WebcastLikeMessage.newBuilder()
|
||||||
|
.setCount(likes)
|
||||||
|
.setTotal(likes)
|
||||||
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
|
.setUsername(user.getName())
|
||||||
|
.setNickname(user.getProfileName())
|
||||||
|
.build())
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,10 +49,19 @@ public class TikTokShareEvent extends TikTokHeaderEvent {
|
|||||||
|
|
||||||
public static TikTokShareEvent of(String userName, int shaders) {
|
public static TikTokShareEvent of(String userName, int shaders) {
|
||||||
return new TikTokShareEvent(WebcastSocialMessage.newBuilder()
|
return new TikTokShareEvent(WebcastSocialMessage.newBuilder()
|
||||||
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
.setUsername(userName)
|
.setUsername(userName)
|
||||||
.setNickname(userName)
|
.setNickname(userName)
|
||||||
.build())
|
.build())
|
||||||
.build(), shaders);
|
.build(), shaders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TikTokShareEvent of(User user, int shaders) {
|
||||||
|
return new TikTokShareEvent(WebcastSocialMessage.newBuilder()
|
||||||
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
|
.setUsername(user.getName())
|
||||||
|
.setNickname(user.getProfileName())
|
||||||
|
.build())
|
||||||
|
.build(), shaders);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,6 +95,9 @@ public class ProxyClientSettings implements Iterator<ProxyData>, Iterable<ProxyD
|
|||||||
public ProxyClientSettings clone() {
|
public ProxyClientSettings clone() {
|
||||||
ProxyClientSettings settings = new ProxyClientSettings();
|
ProxyClientSettings settings = new ProxyClientSettings();
|
||||||
settings.setEnabled(enabled);
|
settings.setEnabled(enabled);
|
||||||
|
settings.setAutoDiscard(autoDiscard);
|
||||||
|
settings.setFallback(fallback);
|
||||||
|
settings.setAllowWebsocket(allowWebsocket);
|
||||||
settings.setRotation(rotation);
|
settings.setRotation(rotation);
|
||||||
settings.setIndex(index);
|
settings.setIndex(index);
|
||||||
settings.setType(type);
|
settings.setType(type);
|
||||||
|
|||||||
@@ -66,5 +66,5 @@ public interface LiveHttpClient
|
|||||||
|
|
||||||
LiveConnectionData.Response fetchLiveConnectionData(LiveConnectionData.Request request);
|
LiveConnectionData.Response fetchLiveConnectionData(LiveConnectionData.Request request);
|
||||||
|
|
||||||
boolean sendChat(LiveRoomInfo roomInfo, String content);
|
boolean sendChat(LiveRoomInfo roomInfo, String content, String sessionId, String ttTargetIdc);
|
||||||
}
|
}
|
||||||
@@ -102,4 +102,12 @@ public interface LiveClient {
|
|||||||
* <p>We cannot fix this as it is a TikTok issue, not a library issue.
|
* <p>We cannot fix this as it is a TikTok issue, not a library issue.
|
||||||
*/
|
*/
|
||||||
boolean sendChat(String content);
|
boolean sendChat(String content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a chat message to the connected room
|
||||||
|
* @return true if successful, otherwise false
|
||||||
|
* @apiNote This is known to return true on some sessionIds despite failing!
|
||||||
|
* <p>We cannot fix this as it is a TikTok issue, not a library issue.
|
||||||
|
*/
|
||||||
|
boolean sendChat(String content, String sessionId, String ttTargetIdc);
|
||||||
}
|
}
|
||||||
@@ -62,12 +62,11 @@ message Text {
|
|||||||
int32 type = 1;
|
int32 type = 1;
|
||||||
TextFormat format = 2;
|
TextFormat format = 2;
|
||||||
string stringValue = 11;
|
string stringValue = 11;
|
||||||
oneof textPieceType
|
TextPieceUser userValue = 21;
|
||||||
{
|
TextPieceGift giftValue = 22;
|
||||||
TextPieceUser userValue = 21;
|
TextPieceHeart heartValue = 23;
|
||||||
TextPieceGift giftValue = 22;
|
|
||||||
}
|
|
||||||
TextPiecePatternRef patternRefValue = 24;
|
TextPiecePatternRef patternRefValue = 24;
|
||||||
|
TextPieceImage imageValue = 25;
|
||||||
}
|
}
|
||||||
|
|
||||||
message TextFormat {
|
message TextFormat {
|
||||||
@@ -83,7 +82,7 @@ message Text {
|
|||||||
|
|
||||||
message TextPieceGift {
|
message TextPieceGift {
|
||||||
int32 giftId = 1;
|
int32 giftId = 1;
|
||||||
PatternRef nameRef = 2;
|
TextPiecePatternRef nameRef = 2;
|
||||||
ShowType showType = 3; // Enum
|
ShowType showType = 3; // Enum
|
||||||
int64 colorId = 4;
|
int64 colorId = 4;
|
||||||
}
|
}
|
||||||
@@ -98,16 +97,19 @@ message Text {
|
|||||||
bool withColon = 2;
|
bool withColon = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PatternRef {
|
|
||||||
string key = 1;
|
|
||||||
string default_pattern = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum ShowType {
|
enum ShowType {
|
||||||
SHOW_TYPE_NORMAL = 0;
|
SHOW_TYPE_NORMAL = 0;
|
||||||
SHOW_TYPE_FADE_IN_OUT = 1;
|
SHOW_TYPE_FADE_IN_OUT = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message TextPieceHeart {
|
||||||
|
string color = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message TextPieceImage {
|
||||||
|
Image image_model = 1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Image
|
// @Image
|
||||||
@@ -151,7 +153,7 @@ message BadgeStruct {
|
|||||||
bool is_customized = 24;
|
bool is_customized = 24;
|
||||||
|
|
||||||
message CombineBadge {
|
message CombineBadge {
|
||||||
int32 badge_display_type = 1;
|
BadgeDisplayType badge_display_type = 1;
|
||||||
Image icon = 2;
|
Image icon = 2;
|
||||||
TextBadge text = 3;
|
TextBadge text = 3;
|
||||||
string str = 4;
|
string str = 4;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.11.2-Release</version>
|
<version>1.11.8-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -199,7 +199,12 @@ public class TikTokLiveClient implements LiveClient
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean sendChat(String content) {
|
public boolean sendChat(String content) {
|
||||||
return httpClient.sendChat(roomInfo, content);
|
return sendChat(content, clientSettings.getSessionId(), clientSettings.getTtTargetIdc());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean sendChat(String content, String sessionId, String ttTargetIdc) {
|
||||||
|
return httpClient.sendChat(roomInfo, content, sessionId, ttTargetIdc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connectAsync(Consumer<LiveClient> onConnection) {
|
public void connectAsync(Consumer<LiveClient> onConnection) {
|
||||||
|
|||||||
@@ -182,23 +182,23 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean sendChat(LiveRoomInfo roomInfo, String content) {
|
public boolean sendChat(LiveRoomInfo roomInfo, String content, String sessionId, String ttTargetIdc) {
|
||||||
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
||||||
if (proxyClientSettings.isEnabled()) {
|
if (proxyClientSettings.isEnabled()) {
|
||||||
while (proxyClientSettings.hasNext()) {
|
while (proxyClientSettings.hasNext()) {
|
||||||
try {
|
try {
|
||||||
return requestSendChat(roomInfo, content);
|
return requestSendChat(roomInfo, content, sessionId, ttTargetIdc);
|
||||||
} catch (TikTokProxyRequestException ignored) {}
|
} catch (TikTokProxyRequestException ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return requestSendChat(roomInfo, content);
|
return requestSendChat(roomInfo, content, sessionId, ttTargetIdc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requestSendChat(LiveRoomInfo roomInfo, String content) {
|
public boolean requestSendChat(LiveRoomInfo roomInfo, String content, String sessionId, String ttTargetIdc) {
|
||||||
JsonObject body = new JsonObject();
|
JsonObject body = new JsonObject();
|
||||||
body.addProperty("content", content);
|
body.addProperty("content", content);
|
||||||
body.addProperty("sessionId", clientSettings.getSessionId());
|
body.addProperty("sessionId", sessionId);
|
||||||
body.addProperty("ttTargetIdc", clientSettings.getTtTargetIdc());
|
body.addProperty("ttTargetIdc", ttTargetIdc);
|
||||||
body.addProperty("roomId", roomInfo.getRoomId());
|
body.addProperty("roomId", roomInfo.getRoomId());
|
||||||
HttpClientBuilder builder = httpFactory.client(clientSettings.isUseEulerstreamEnterprise() ? TIKTOK_CHAT_ENTERPRISE_URL : TIKTOK_CHAT_URL)
|
HttpClientBuilder builder = httpFactory.client(clientSettings.isUseEulerstreamEnterprise() ? TIKTOK_CHAT_ENTERPRISE_URL : TIKTOK_CHAT_URL)
|
||||||
.withHeader("Content-Type", "application/json");
|
.withHeader("Content-Type", "application/json");
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class TikTokLiveHttpOfflineClient implements LiveHttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean sendChat(LiveRoomInfo roomInfo, String content) {
|
public boolean sendChat(LiveRoomInfo roomInfo, String content, String sessionId, String ttTargetIdc) {
|
||||||
// DO NOTHING
|
// DO NOTHING
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> ActionResult<T> toResponse(HttpResponse.BodyHandler<T> handler) {
|
protected <T> ActionResult<T> toResponse(HttpResponse.BodyHandler<T> handler) {
|
||||||
return toHttpResponse(handler).map(HttpResponse::body);
|
return toHttpResponse(handler).map(HttpResponse::body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,9 +31,11 @@ import java.io.IOException;
|
|||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.net.http.*;
|
import java.net.http.*;
|
||||||
import java.net.http.HttpResponse.ResponseInfo;
|
import java.net.http.HttpResponse.ResponseInfo;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.security.*;
|
import java.security.*;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.Flow;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class HttpProxyClient extends HttpClient {
|
public class HttpProxyClient extends HttpClient {
|
||||||
@@ -45,14 +47,14 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
this.proxySettings = httpClientSettings.getProxyClientSettings();
|
this.proxySettings = httpClientSettings.getProxyClientSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult<HttpResponse<byte[]>> toResponse() {
|
public <T> ActionResult<HttpResponse<T>> toHttpResponse(HttpResponse.BodyHandler<T> handler) {
|
||||||
return switch (proxySettings.getType()) {
|
return switch (proxySettings.getType()) {
|
||||||
case HTTP, DIRECT -> handleHttpProxyRequest();
|
case HTTP, DIRECT -> handleHttpProxyRequest(handler);
|
||||||
default -> handleSocksProxyRequest();
|
default -> handleSocksProxyRequest(handler);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult<HttpResponse<byte[]>> handleHttpProxyRequest() {
|
public <T> ActionResult<HttpResponse<T>> handleHttpProxyRequest(HttpResponse.BodyHandler<T> handler) {
|
||||||
var builder = java.net.http.HttpClient.newBuilder()
|
var builder = java.net.http.HttpClient.newBuilder()
|
||||||
.followRedirects(java.net.http.HttpClient.Redirect.NORMAL)
|
.followRedirects(java.net.http.HttpClient.Redirect.NORMAL)
|
||||||
.cookieHandler(new CookieManager())
|
.cookieHandler(new CookieManager())
|
||||||
@@ -67,7 +69,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
var client = builder.build();
|
var client = builder.build();
|
||||||
var request = prepareRequest();
|
var request = prepareRequest();
|
||||||
|
|
||||||
var response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
|
var response = client.send(request, handler);
|
||||||
if (response.statusCode() != 200)
|
if (response.statusCode() != 200)
|
||||||
continue;
|
continue;
|
||||||
return ActionResult.success(response);
|
return ActionResult.success(response);
|
||||||
@@ -77,7 +79,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
throw new TikTokProxyRequestException(e);
|
throw new TikTokProxyRequestException(e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (e.getMessage().contains("503") && proxySettings.isFallback()) // Indicates proxy protocol is not supported
|
if (e.getMessage().contains("503") && proxySettings.isFallback()) // Indicates proxy protocol is not supported
|
||||||
return super.toHttpResponse(HttpResponse.BodyHandlers.ofByteArray());
|
return super.toHttpResponse(handler);
|
||||||
throw new TikTokProxyRequestException(e);
|
throw new TikTokProxyRequestException(e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new TikTokLiveRequestException(e);
|
throw new TikTokLiveRequestException(e);
|
||||||
@@ -86,7 +88,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
throw new TikTokLiveRequestException("No more proxies available!");
|
throw new TikTokLiveRequestException("No more proxies available!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActionResult<HttpResponse<byte[]>> handleSocksProxyRequest() {
|
private <T> ActionResult<HttpResponse<T>> handleSocksProxyRequest(HttpResponse.BodyHandler<T> handler) {
|
||||||
try {
|
try {
|
||||||
SSLContext sc = SSLContext.getInstance("SSL");
|
SSLContext sc = SSLContext.getInstance("SSL");
|
||||||
sc.init(null, new TrustManager[]{ new X509TrustManager() {
|
sc.init(null, new TrustManager[]{ new X509TrustManager() {
|
||||||
@@ -95,7 +97,8 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
public X509Certificate[] getAcceptedIssuers() { return null; }
|
public X509Certificate[] getAcceptedIssuers() { return null; }
|
||||||
}}, null);
|
}}, null);
|
||||||
|
|
||||||
URL url = toUri().toURL();
|
URI uri = toUri();
|
||||||
|
URL url = uri.toURL();
|
||||||
|
|
||||||
if (proxySettings.hasNext()) {
|
if (proxySettings.hasNext()) {
|
||||||
try {
|
try {
|
||||||
@@ -117,12 +120,22 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
|
|
||||||
var responseInfo = createResponseInfo(socksConnection.getResponseCode(), headers);
|
var responseInfo = createResponseInfo(socksConnection.getResponseCode(), headers);
|
||||||
|
|
||||||
var response = createHttpResponse(body, toUri(), responseInfo);
|
HttpResponse.BodySubscriber<T> subscriber = handler.apply(responseInfo);
|
||||||
|
|
||||||
|
subscriber.onSubscribe(new Flow.Subscription() {
|
||||||
|
@Override public void request(long n) {}
|
||||||
|
@Override public void cancel() {}
|
||||||
|
});
|
||||||
|
|
||||||
|
subscriber.onNext(List.of(ByteBuffer.wrap(body)));
|
||||||
|
subscriber.onComplete();
|
||||||
|
|
||||||
|
var response = createHttpResponse(subscriber.getBody().toCompletableFuture().join(), uri, responseInfo);
|
||||||
|
|
||||||
return ActionResult.success(response);
|
return ActionResult.success(response);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (e.getMessage().contains("503") && proxySettings.isFallback()) // Indicates proxy protocol is not supported
|
if (e.getMessage().contains("503") && proxySettings.isFallback()) // Indicates proxy protocol is not supported
|
||||||
return super.toHttpResponse(HttpResponse.BodyHandlers.ofByteArray());
|
return super.toHttpResponse(handler);
|
||||||
if (proxySettings.isAutoDiscard())
|
if (proxySettings.isAutoDiscard())
|
||||||
proxySettings.remove();
|
proxySettings.remove();
|
||||||
throw new TikTokProxyRequestException(e);
|
throw new TikTokProxyRequestException(e);
|
||||||
@@ -160,7 +173,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpResponse<byte[]> createHttpResponse(byte[] body,
|
private <T> HttpResponse<T> createHttpResponse(T body,
|
||||||
URI uri,
|
URI uri,
|
||||||
ResponseInfo info) {
|
ResponseInfo info) {
|
||||||
return new HttpResponse<>()
|
return new HttpResponse<>()
|
||||||
@@ -176,7 +189,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<HttpResponse<byte[]>> previousResponse() {
|
public Optional<HttpResponse<T>> previousResponse() {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +199,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] body() {
|
public T body() {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import io.github.jwdeveloper.tiktok.data.models.users.User;
|
|||||||
import io.github.jwdeveloper.tiktok.data.requests.LiveUserData;
|
import io.github.jwdeveloper.tiktok.data.requests.LiveUserData;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class LiveUserDataMapper
|
public class LiveUserDataMapper
|
||||||
@@ -66,7 +66,6 @@ public class LiveUserDataMapper
|
|||||||
|
|
||||||
roomInfo.setTitle(liveRoom.get("title").getAsString());
|
roomInfo.setTitle(liveRoom.get("title").getAsString());
|
||||||
roomInfo.setStartTime(liveRoom.get("startTime").getAsLong());
|
roomInfo.setStartTime(liveRoom.get("startTime").getAsLong());
|
||||||
roomInfo.setTitle(liveRoom.get("title").getAsString());
|
|
||||||
roomInfo.setViewersCount(liveRoom.getAsJsonObject("liveRoomStats").get("userCount").getAsInt());
|
roomInfo.setViewersCount(liveRoom.getAsJsonObject("liveRoomStats").get("userCount").getAsInt());
|
||||||
roomInfo.setTotalViewersCount(liveRoom.getAsJsonObject("liveRoomStats").get("enterCount").getAsInt());
|
roomInfo.setTotalViewersCount(liveRoom.getAsJsonObject("liveRoomStats").get("enterCount").getAsInt());
|
||||||
roomInfo.setAgeRestricted(jsonObject.get("statusCode").getAsInt() == TikTokLiveHttpClient.TIKTOK_AGE_RESTRICTED_CODE);
|
roomInfo.setAgeRestricted(jsonObject.get("statusCode").getAsInt() == TikTokLiveHttpClient.TIKTOK_AGE_RESTRICTED_CODE);
|
||||||
@@ -92,9 +91,51 @@ public class LiveUserDataMapper
|
|||||||
roomInfo.setHostName(foundUser.getName());
|
roomInfo.setHostName(foundUser.getName());
|
||||||
|
|
||||||
return new LiveUserData.Response(json, statusEnum, roomInfo);
|
return new LiveUserData.Response(json, statusEnum, roomInfo);
|
||||||
} catch (JsonSyntaxException | IllegalStateException e) {
|
} catch (JsonSyntaxException | IllegalStateException | NullPointerException e) {
|
||||||
logger.warning("Malformed Json: '"+json+"' - Error Message: "+e.getMessage());
|
logger.warning("Malformed Json: '"+json+"' - Error Message: "+e.getMessage());
|
||||||
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, null);
|
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LiveUserData.Response mapEulerstream(JsonObject jsonObject, Logger logger) {
|
||||||
|
try {
|
||||||
|
JsonObject roomInfoJson = jsonObject.getAsJsonObject("roomInfo");
|
||||||
|
JsonObject userJson = jsonObject.getAsJsonObject("user");
|
||||||
|
|
||||||
|
var roomId = roomInfoJson.get("id").getAsString();
|
||||||
|
var status = roomInfoJson.get("status").getAsInt();
|
||||||
|
|
||||||
|
TikTokRoomInfo roomInfo = new TikTokRoomInfo();
|
||||||
|
roomInfo.setRoomId(roomId);
|
||||||
|
roomInfo.setTitle(roomInfoJson.get("title").getAsString());
|
||||||
|
roomInfo.setStartTime(roomInfoJson.get("startTime").getAsLong());
|
||||||
|
roomInfo.setViewersCount(Optional.ofNullable(roomInfoJson.get("currentViewers")).filter(JsonElement::isJsonPrimitive).map(JsonElement::getAsInt).orElse(0));
|
||||||
|
roomInfo.setTotalViewersCount(roomInfoJson.get("totalViewers").getAsInt());
|
||||||
|
|
||||||
|
var statusEnum = switch (status) {
|
||||||
|
case 2 -> LiveUserData.UserStatus.Live;
|
||||||
|
case 3 -> LiveUserData.UserStatus.LivePaused;
|
||||||
|
case 4 -> LiveUserData.UserStatus.Offline;
|
||||||
|
default -> LiveUserData.UserStatus.NotFound;
|
||||||
|
};
|
||||||
|
|
||||||
|
User foundUser = new User(
|
||||||
|
Long.parseLong(userJson.get("numericUid").getAsString()),
|
||||||
|
userJson.get("uniqueId").getAsString(),
|
||||||
|
userJson.get("nickname").getAsString(),
|
||||||
|
userJson.get("signature").getAsString(),
|
||||||
|
new Picture(userJson.get("avatarUrl").getAsString()),
|
||||||
|
userJson.get("following").getAsLong(),
|
||||||
|
userJson.get("followers").getAsLong(),
|
||||||
|
List.of());
|
||||||
|
|
||||||
|
roomInfo.setHost(foundUser);
|
||||||
|
roomInfo.setHostName(foundUser.getName());
|
||||||
|
|
||||||
|
return new LiveUserData.Response(jsonObject.toString(), statusEnum, roomInfo);
|
||||||
|
} catch (JsonSyntaxException | IllegalStateException | NullPointerException e) {
|
||||||
|
logger.warning("Malformed Json: '"+jsonObject.toString()+"' - Error Message: "+e.getMessage());
|
||||||
|
return new LiveUserData.Response(jsonObject.toString(), LiveUserData.UserStatus.NotFound, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ public class TikTokWebSocketEulerListener extends TikTokWebSocketListener
|
|||||||
switch (oMsg.get("type").getAsString()) { // Should only receive these 2 types ever
|
switch (oMsg.get("type").getAsString()) { // Should only receive these 2 types ever
|
||||||
case "workerInfo" -> liveClient.getLogger().info(oMsg.toString()); // Always 1st message
|
case "workerInfo" -> liveClient.getLogger().info(oMsg.toString()); // Always 1st message
|
||||||
case "roomInfo" -> { // Always 2nd message
|
case "roomInfo" -> { // Always 2nd message
|
||||||
LiveUserData.Response data = LiveUserDataMapper.map(oMsg.getAsJsonObject("data").getAsJsonObject("data").getAsJsonObject("raw").toString(), liveClient.getLogger());
|
LiveUserData.Response data = LiveUserDataMapper.mapEulerstream(oMsg.getAsJsonObject("data"), liveClient.getLogger());
|
||||||
liveClient.getRoomInfo().copy(data.getRoomInfo());
|
liveClient.getRoomInfo().copy(data.getRoomInfo());
|
||||||
eventHandler.publish(liveClient, new TikTokRoomInfoEvent(liveClient.getRoomInfo()));
|
eventHandler.publish(liveClient, new TikTokRoomInfoEvent(liveClient.getRoomInfo()));
|
||||||
}
|
}
|
||||||
@@ -67,6 +67,7 @@ public class TikTokWebSocketEulerListener extends TikTokWebSocketListener
|
|||||||
} else
|
} else
|
||||||
throw new IllegalArgumentException("Invalid JsonObject: "+element);
|
throw new IllegalArgumentException("Invalid JsonObject: "+element);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
eventHandler.publish(liveClient, new TikTokErrorEvent(e));
|
eventHandler.publish(liveClient, new TikTokErrorEvent(e));
|
||||||
}
|
}
|
||||||
if (isOpen()) {
|
if (isOpen()) {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.11.2-Release</version>
|
<version>1.11.8-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<version>1.11.2-Release</version>
|
<version>1.11.8-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.11.2-Release</version>
|
<version>1.11.8-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>extension-recorder</artifactId>
|
<artifactId>extension-recorder</artifactId>
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.11.2-Release</version>
|
<version>1.11.8-Release</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>API</module>
|
<module>API</module>
|
||||||
<module>Client</module>
|
<module>Client</module>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.11.2-Release</version>
|
<version>1.11.8-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user