mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-28 09:19:40 -05:00
Compare commits
4 Commits
1.11.4-Rel
...
develop-1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
763d470793 | ||
|
|
03180d6a1c | ||
|
|
19ed45e6de | ||
|
|
54433af65f |
@@ -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.3-Release</version>
|
<version>1.10.10-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -62,11 +62,12 @@ 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;
|
TextPieceUser userValue = 21;
|
||||||
TextPieceGift giftValue = 22;
|
TextPieceGift giftValue = 22;
|
||||||
TextPieceHeart heartValue = 23;
|
}
|
||||||
TextPiecePatternRef patternRefValue = 24;
|
TextPiecePatternRef patternRefValue = 24;
|
||||||
TextPieceImage imageValue = 25;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message TextFormat {
|
message TextFormat {
|
||||||
@@ -82,7 +83,7 @@ message Text {
|
|||||||
|
|
||||||
message TextPieceGift {
|
message TextPieceGift {
|
||||||
int32 giftId = 1;
|
int32 giftId = 1;
|
||||||
TextPiecePatternRef nameRef = 2;
|
PatternRef nameRef = 2;
|
||||||
ShowType showType = 3; // Enum
|
ShowType showType = 3; // Enum
|
||||||
int64 colorId = 4;
|
int64 colorId = 4;
|
||||||
}
|
}
|
||||||
@@ -97,19 +98,16 @@ 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
|
||||||
@@ -153,7 +151,7 @@ message BadgeStruct {
|
|||||||
bool is_customized = 24;
|
bool is_customized = 24;
|
||||||
|
|
||||||
message CombineBadge {
|
message CombineBadge {
|
||||||
BadgeDisplayType badge_display_type = 1;
|
int32 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.3-Release</version>
|
<version>1.10.10-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import io.github.jwdeveloper.tiktok.common.AsyncHandler;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.*;
|
import io.github.jwdeveloper.tiktok.data.events.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.control.*;
|
import io.github.jwdeveloper.tiktok.data.events.control.*;
|
||||||
@@ -40,7 +39,7 @@ import io.github.jwdeveloper.tiktok.websocket.*;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -90,11 +89,12 @@ public class TikTokLiveClient implements LiveClient
|
|||||||
tikTokEventHandler.publish(this, new TikTokDisconnectedEvent("Exception: " + e.getMessage()));
|
tikTokEventHandler.publish(this, new TikTokDisconnectedEvent("Exception: " + e.getMessage()));
|
||||||
|
|
||||||
if (e instanceof TikTokLiveOfflineHostException && clientSettings.isRetryOnConnectionFailure()) {
|
if (e instanceof TikTokLiveOfflineHostException && clientSettings.isRetryOnConnectionFailure()) {
|
||||||
AsyncHandler.getReconnectScheduler().schedule(() -> {
|
try {
|
||||||
|
Thread.sleep(clientSettings.getRetryConnectionTimeout().toMillis());
|
||||||
|
} catch (Exception ignored) {}
|
||||||
logger.info("Reconnecting");
|
logger.info("Reconnecting");
|
||||||
tikTokEventHandler.publish(this, new TikTokReconnectingEvent());
|
tikTokEventHandler.publish(this, new TikTokReconnectingEvent());
|
||||||
this.connect();
|
this.connect();
|
||||||
}, clientSettings.getRetryConnectionTimeout().toMillis(), TimeUnit.MILLISECONDS);
|
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -124,6 +124,7 @@ public class TikTokLiveClient implements LiveClient
|
|||||||
tikTokEventHandler.publish(this, new TikTokConnectingEvent());
|
tikTokEventHandler.publish(this, new TikTokConnectingEvent());
|
||||||
var userDataRequest = new LiveUserData.Request(roomInfo.getHostName());
|
var userDataRequest = new LiveUserData.Request(roomInfo.getHostName());
|
||||||
var userData = httpClient.fetchLiveUserData(userDataRequest);
|
var userData = httpClient.fetchLiveUserData(userDataRequest);
|
||||||
|
roomInfo.copy(userData.getRoomInfo());
|
||||||
|
|
||||||
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
|
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
|
||||||
throw new TikTokLiveOfflineHostException("User is offline: " + roomInfo.getHostName(), userData, null);
|
throw new TikTokLiveOfflineHostException("User is offline: " + roomInfo.getHostName(), userData, null);
|
||||||
@@ -131,8 +132,6 @@ public class TikTokLiveClient implements LiveClient
|
|||||||
if (userData.getUserStatus() == LiveUserData.UserStatus.NotFound)
|
if (userData.getUserStatus() == LiveUserData.UserStatus.NotFound)
|
||||||
throw new TikTokLiveUnknownHostException("User not found: " + roomInfo.getHostName(), userData, null);
|
throw new TikTokLiveUnknownHostException("User not found: " + roomInfo.getHostName(), userData, null);
|
||||||
|
|
||||||
roomInfo.copy(userData.getRoomInfo());
|
|
||||||
|
|
||||||
var liveDataRequest = new LiveData.Request(userData.getRoomInfo().getRoomId());
|
var liveDataRequest = new LiveData.Request(userData.getRoomInfo().getRoomId());
|
||||||
var liveData = httpClient.fetchLiveData(liveDataRequest);
|
var liveData = httpClient.fetchLiveData(liveDataRequest);
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
|
|
||||||
//networking
|
//networking
|
||||||
dependance.registerSingleton(HttpClientFactory.class);
|
dependance.registerSingleton(HttpClientFactory.class);
|
||||||
dependance.registerSingleton(WebSocketHeartbeatTask.class);
|
dependance.registerSingleton(WebSocketHeartbeatTask.class); // True global singleton - Static objects are located to serve as global
|
||||||
if (clientSettings.isOffline()) {
|
if (clientSettings.isOffline()) {
|
||||||
dependance.registerSingleton(LiveSocketClient.class, TikTokWebSocketOfflineClient.class);
|
dependance.registerSingleton(LiveSocketClient.class, TikTokWebSocketOfflineClient.class);
|
||||||
dependance.registerSingleton(LiveHttpClient.class, TikTokLiveHttpOfflineClient.class);
|
dependance.registerSingleton(LiveHttpClient.class, TikTokLiveHttpOfflineClient.class);
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ public class TikTokRoomInfo implements LiveRoomInfo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void copy(LiveRoomInfo roomInfo) {
|
public void copy(LiveRoomInfo roomInfo) {
|
||||||
if (roomInfo == null) return;
|
|
||||||
this.roomId = roomInfo.getRoomId();
|
this.roomId = roomInfo.getRoomId();
|
||||||
this.likesCount = roomInfo.getLikesCount();
|
this.likesCount = roomInfo.getLikesCount();
|
||||||
this.viewersCount = roomInfo.getViewersCount();
|
this.viewersCount = roomInfo.getViewersCount();
|
||||||
@@ -70,6 +69,6 @@ public class TikTokRoomInfo implements LiveRoomInfo
|
|||||||
this.hostName = roomInfo.getHostName();
|
this.hostName = roomInfo.getHostName();
|
||||||
this.title = roomInfo.getTitle();
|
this.title = roomInfo.getTitle();
|
||||||
this.language = roomInfo.getLanguage();
|
this.language = roomInfo.getLanguage();
|
||||||
// this.connectionState = roomInfo.getConnectionState(); // This should not be copied - Controlled elsewhere!
|
this.connectionState = roomInfo.getConnectionState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package io.github.jwdeveloper.tiktok.common;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.concurrent.*;
|
|
||||||
|
|
||||||
public class AsyncHandler
|
|
||||||
{
|
|
||||||
@Getter
|
|
||||||
private static final ScheduledExecutorService heartBeatScheduler = Executors.newScheduledThreadPool(1, r -> {
|
|
||||||
Thread t = new Thread(r, "heartbeat-pool");
|
|
||||||
t.setDaemon(true);
|
|
||||||
return t;
|
|
||||||
});
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private static final ScheduledExecutorService reconnectScheduler = Executors.newScheduledThreadPool(0, r -> {
|
|
||||||
Thread t = new Thread(r, "reconnect-pool");
|
|
||||||
t.setDaemon(true);
|
|
||||||
return t;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -142,7 +142,7 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
|||||||
case DISCONNECT -> webSocketClient.closeConnection(CloseFrame.NORMAL, "");
|
case DISCONNECT -> webSocketClient.closeConnection(CloseFrame.NORMAL, "");
|
||||||
default -> webSocketClient.close();
|
default -> webSocketClient.close();
|
||||||
}
|
}
|
||||||
heartbeatTask.stop();
|
heartbeatTask.stop(webSocketClient);
|
||||||
}
|
}
|
||||||
webSocketClient = null;
|
webSocketClient = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.websocket;
|
package io.github.jwdeveloper.tiktok.websocket;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.common.AsyncHandler;
|
|
||||||
import org.java_websocket.WebSocket;
|
import org.java_websocket.WebSocket;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -30,30 +29,47 @@ import java.util.concurrent.*;
|
|||||||
|
|
||||||
public class WebSocketHeartbeatTask
|
public class WebSocketHeartbeatTask
|
||||||
{
|
{
|
||||||
private ScheduledFuture<?> task;
|
// Single shared pool for all heartbeat tasks
|
||||||
private Long commTime;
|
private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, r -> {
|
||||||
|
Thread t = new Thread(r, "heartbeat-pool");
|
||||||
|
t.setDaemon(true);
|
||||||
|
return t;
|
||||||
|
});
|
||||||
|
private static final Map<WebSocket, ScheduledFuture<?>> tasks = new ConcurrentHashMap<>();
|
||||||
|
private static final Map<WebSocket, Long> commTime = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final static byte[] heartbeatBytes = Base64.getDecoder().decode("MgJwYjoCaGI="); // Used to be '3A026862' aka ':\x02hb', now is '2\x02pb:\x02hb'.
|
private final byte[] heartbeatBytes = Base64.getDecoder().decode("MgJwYjoCaGI="); // Used to be '3A026862' aka ':\x02hb', now is '2\x02pb:\x02hb'.
|
||||||
|
|
||||||
public void run(WebSocket webSocket, long pingTaskTime) {
|
public void run(WebSocket webSocket, long pingTaskTime) {
|
||||||
stop(); // remove existing task if any
|
stop(webSocket); // remove existing task if any
|
||||||
|
|
||||||
task = AsyncHandler.getHeartBeatScheduler().scheduleAtFixedRate(() -> {
|
tasks.put(webSocket, scheduler.scheduleAtFixedRate(() -> {
|
||||||
try {
|
try {
|
||||||
if (webSocket.isOpen()) {
|
if (webSocket.isOpen()) {
|
||||||
webSocket.send(heartbeatBytes);
|
webSocket.send(heartbeatBytes);
|
||||||
commTime = System.currentTimeMillis();
|
commTime.put(webSocket, System.currentTimeMillis());
|
||||||
} else if (commTime != null && System.currentTimeMillis() - commTime >= 60_000) // Stop if disconnected longer than 60s
|
} else {
|
||||||
stop();
|
Long time = commTime.get(webSocket);
|
||||||
|
if (time != null && System.currentTimeMillis() - time >= 60_000) // Stop if disconnected longer than 60s
|
||||||
|
stop(webSocket);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
stop();
|
stop(webSocket);
|
||||||
}
|
}
|
||||||
}, 0, pingTaskTime, TimeUnit.MILLISECONDS);
|
}, 0, pingTaskTime, TimeUnit.MILLISECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop(WebSocket webSocket) {
|
||||||
if (task != null)
|
ScheduledFuture<?> future = tasks.remove(webSocket);
|
||||||
task.cancel(true);
|
if (future != null)
|
||||||
|
future.cancel(true);
|
||||||
|
commTime.remove(webSocket);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
tasks.values().forEach(f -> f.cancel(true));
|
||||||
|
commTime.clear();
|
||||||
|
scheduler.shutdownNow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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("raw").toString(), liveClient.getLogger());
|
LiveUserData.Response data = LiveUserDataMapper.map(oMsg.getAsJsonObject("data").getAsJsonObject("data").getAsJsonObject("raw").toString(), 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,7 +67,6 @@ 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()) {
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ Maven
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
||||||
<artifactId>Client</artifactId>
|
<artifactId>Client</artifactId>
|
||||||
<version>1.11.0-Release</version>
|
<version>1.10.0-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -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.3-Release</version>
|
<version>1.10.10-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.3-Release</version>
|
<version>1.10.10-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.3-Release</version>
|
<version>1.10.10-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.3-Release</version>
|
<version>1.10.10-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.3-Release</version>
|
<version>1.10.10-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user