Compare commits

...

6 Commits

Author SHA1 Message Date
David Kohler
75f6368f2c Merge pull request #125 from jwdeveloper/develop-1.10.3
Change websocket connection logic!
2025-05-10 22:06:35 -04:00
kohlerpop1
b9eb0eba93 Removal of debug print statements! 2025-05-04 21:59:22 -04:00
GitHub Action
50d6d6e515 Update version in pom.xml 2025-04-25 21:00:20 +00:00
kohlerpop1
42f9fe360b Removal of debug print statements! 2025-04-25 16:58:24 -04:00
GitHub Action
dff226740c Update version in pom.xml 2025-04-25 19:42:02 +00:00
David Kohler
951d30e6a7 Merge pull request #124 from jwdeveloper/develop-1.10.1
Add additional helper methods back to TikTokLinkMicBattleEvent!
2025-04-25 15:40:08 -04:00
13 changed files with 32 additions and 37 deletions

View File

@@ -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.10.0-Release</version> <version>1.10.2-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>API</artifactId> <artifactId>API</artifactId>

View File

@@ -51,7 +51,6 @@ public class TikTokLinkMicArmiesEvent extends TikTokHeaderEvent {
public TikTokLinkMicArmiesEvent(WebcastLinkMicArmies msg) { public TikTokLinkMicArmiesEvent(WebcastLinkMicArmies msg) {
super(msg.getCommon()); super(msg.getCommon());
System.out.println(msg);
battleId = msg.getBattleId(); battleId = msg.getBattleId();
armies = new HashMap<>(); armies = new HashMap<>();
picture = Picture.map(msg.getGifIconImage()); picture = Picture.map(msg.getGifIconImage());

View File

@@ -51,7 +51,6 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) { public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
super(msg.getCommon()); super(msg.getCommon());
System.out.println(msg);
battleId = msg.getBattleId(); battleId = msg.getBattleId();
finished = msg.getAction() == BattleAction.BATTLE_ACTION_FINISH; finished = msg.getAction() == BattleAction.BATTLE_ACTION_FINISH;
battleType = msg.getBattleSetting().getBattleType(); battleType = msg.getBattleSetting().getBattleType();

View File

@@ -28,4 +28,5 @@ import io.github.jwdeveloper.tiktok.live.LiveClient;
public interface LiveSocketClient { public interface LiveSocketClient {
void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient); void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient);
void stop(); void stop();
} boolean isConnected();
}

View File

@@ -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.10.0-Release</version> <version>1.10.2-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -154,12 +154,11 @@ public class TikTokLiveClient implements LiveClient
} }
public void disconnect() { public void disconnect() {
if (roomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) { if (webSocketClient.isConnected())
return; webSocketClient.stop();
} if (!roomInfo.hasConnectionState(ConnectionState.DISCONNECTED))
setState(ConnectionState.DISCONNECTED); setState(ConnectionState.DISCONNECTED);
webSocketClient.stop(); }
}
private void setState(ConnectionState connectionState) { private void setState(ConnectionState connectionState) {
logger.info("TikTokLive client state: " + connectionState.name()); logger.info("TikTokLive client state: " + connectionState.name());
@@ -174,9 +173,9 @@ public class TikTokLiveClient implements LiveClient
public void publishMessage(String webcastMessageName, String payloadBase64) { public void publishMessage(String webcastMessageName, String payloadBase64) {
this.publishMessage(webcastMessageName, Base64.getDecoder().decode(payloadBase64)); this.publishMessage(webcastMessageName, Base64.getDecoder().decode(payloadBase64));
} }
@Override @Override
public void publishMessage(String webcastMessageName, byte[] payload) { public void publishMessage(String webcastMessageName, byte[] payload) {
var builder = ProtoMessageFetchResult.BaseProtoMessage.newBuilder(); var builder = ProtoMessageFetchResult.BaseProtoMessage.newBuilder();
builder.setMethod(webcastMessageName); builder.setMethod(webcastMessageName);
builder.setPayload(ByteString.copyFrom(payload)); builder.setPayload(ByteString.copyFrom(payload));
@@ -184,7 +183,6 @@ public class TikTokLiveClient implements LiveClient
messageHandler.handleSingleMessage(this, message); messageHandler.handleSingleMessage(this, message);
} }
public void connectAsync(Consumer<LiveClient> onConnection) { public void connectAsync(Consumer<LiveClient> onConnection) {
connectAsync().thenAccept(onConnection); connectAsync().thenAccept(onConnection);
} }

View File

@@ -26,9 +26,7 @@ import io.github.jwdeveloper.tiktok.data.dto.ProxyData;
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData; import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
import io.github.jwdeveloper.tiktok.data.settings.*; import io.github.jwdeveloper.tiktok.data.settings.*;
import io.github.jwdeveloper.tiktok.exceptions.*; import io.github.jwdeveloper.tiktok.exceptions.*;
import io.github.jwdeveloper.tiktok.live.LiveClient; import io.github.jwdeveloper.tiktok.live.*;
import io.github.jwdeveloper.tiktok.live.LiveEventsHandler;
import io.github.jwdeveloper.tiktok.live.LiveMessagesHandler;
import org.java_websocket.client.WebSocketClient; import org.java_websocket.client.WebSocketClient;
import javax.net.ssl.*; import javax.net.ssl.*;
@@ -42,7 +40,6 @@ public class TikTokWebSocketClient implements LiveSocketClient {
private final LiveEventsHandler tikTokEventHandler; private final LiveEventsHandler tikTokEventHandler;
private final WebSocketHeartbeatTask heartbeatTask; private final WebSocketHeartbeatTask heartbeatTask;
private WebSocketClient webSocketClient; private WebSocketClient webSocketClient;
private boolean isConnected;
public TikTokWebSocketClient( public TikTokWebSocketClient(
LiveClientSettings clientSettings, LiveClientSettings clientSettings,
@@ -54,14 +51,12 @@ public class TikTokWebSocketClient implements LiveSocketClient {
this.messageHandler = messageHandler; this.messageHandler = messageHandler;
this.tikTokEventHandler = tikTokEventHandler; this.tikTokEventHandler = tikTokEventHandler;
this.heartbeatTask = heartbeatTask; this.heartbeatTask = heartbeatTask;
isConnected = false;
} }
@Override @Override
public void start(LiveConnectionData.Response connectionData, LiveClient liveClient) { public void start(LiveConnectionData.Response connectionData, LiveClient liveClient) {
if (isConnected) { if (isConnected())
stop(); stop();
}
messageHandler.handle(liveClient, connectionData.getWebcastResponse()); messageHandler.handle(liveClient, connectionData.getWebcastResponse());
@@ -85,9 +80,7 @@ public class TikTokWebSocketClient implements LiveSocketClient {
try { try {
webSocketClient.connect(); webSocketClient.connect();
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval()); heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
isConnected = true;
} catch (Exception e) { } catch (Exception e) {
isConnected = false;
throw new TikTokLiveException("Failed to connect to the websocket", e); throw new TikTokLiveException("Failed to connect to the websocket", e);
} }
} }
@@ -117,13 +110,12 @@ public class TikTokWebSocketClient implements LiveSocketClient {
ProxyData proxyData = proxySettings.next(); ProxyData proxyData = proxySettings.next();
if (tryProxyConnection(proxySettings, proxyData)) { if (tryProxyConnection(proxySettings, proxyData)) {
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval()); heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
isConnected = true;
break; break;
} }
if (proxySettings.isAutoDiscard()) if (proxySettings.isAutoDiscard())
proxySettings.remove(); proxySettings.remove();
} }
if (!isConnected) if (!isConnected())
throw new TikTokLiveException("Failed to connect to the websocket"); throw new TikTokLiveException("Failed to connect to the websocket");
} }
@@ -138,11 +130,14 @@ public class TikTokWebSocketClient implements LiveSocketClient {
} }
public void stop() { public void stop() {
if (isConnected && webSocketClient != null && webSocketClient.isOpen()) { if (isConnected()) {
webSocketClient.closeConnection(0, ""); webSocketClient.close();
heartbeatTask.stop(); heartbeatTask.stop();
} }
webSocketClient = null; webSocketClient = null;
isConnected = false; }
public boolean isConnected() {
return webSocketClient != null && webSocketClient.isOpen();
} }
} }

View File

@@ -45,9 +45,12 @@ public class TikTokWebSocketOfflineClient implements LiveSocketClient {
@Override @Override
public void stop() { public void stop() {
if (liveClient == null) { if (liveClient != null)
return; handler.publish(liveClient, new TikTokDisconnectedEvent("Stopping"));
} }
handler.publish(liveClient, new TikTokDisconnectedEvent("Stopping"));
@Override
public boolean isConnected() {
return false;
} }
} }

View File

@@ -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.10.0-Release</version> <version>1.10.2-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -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.10.0-Release</version> <version>1.10.2-Release</version>
</parent> </parent>

View File

@@ -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.10.0-Release</version> <version>1.10.2-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>extension-recorder</artifactId> <artifactId>extension-recorder</artifactId>

View File

@@ -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.10.0-Release</version> <version>1.10.2-Release</version>
<modules> <modules>
<module>API</module> <module>API</module>
<module>Client</module> <module>Client</module>

View File

@@ -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.10.0-Release</version> <version>1.10.2-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>