mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 08:49:40 -05:00
Compare commits
6 Commits
develop-1.
...
1.10.3-Rel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75f6368f2c | ||
|
|
b9eb0eba93 | ||
|
|
50d6d6e515 | ||
|
|
42f9fe360b | ||
|
|
dff226740c | ||
|
|
951d30e6a7 |
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.10.0-Release</version>
|
||||
<version>1.10.2-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>API</artifactId>
|
||||
|
||||
@@ -51,7 +51,6 @@ public class TikTokLinkMicArmiesEvent extends TikTokHeaderEvent {
|
||||
|
||||
public TikTokLinkMicArmiesEvent(WebcastLinkMicArmies msg) {
|
||||
super(msg.getCommon());
|
||||
System.out.println(msg);
|
||||
battleId = msg.getBattleId();
|
||||
armies = new HashMap<>();
|
||||
picture = Picture.map(msg.getGifIconImage());
|
||||
|
||||
@@ -51,7 +51,6 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
||||
|
||||
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
||||
super(msg.getCommon());
|
||||
System.out.println(msg);
|
||||
battleId = msg.getBattleId();
|
||||
finished = msg.getAction() == BattleAction.BATTLE_ACTION_FINISH;
|
||||
battleType = msg.getBattleSetting().getBattleType();
|
||||
|
||||
@@ -28,4 +28,5 @@ import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||
public interface LiveSocketClient {
|
||||
void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient);
|
||||
void stop();
|
||||
boolean isConnected();
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.10.0-Release</version>
|
||||
<version>1.10.2-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -154,11 +154,10 @@ public class TikTokLiveClient implements LiveClient
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (roomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) {
|
||||
return;
|
||||
}
|
||||
setState(ConnectionState.DISCONNECTED);
|
||||
if (webSocketClient.isConnected())
|
||||
webSocketClient.stop();
|
||||
if (!roomInfo.hasConnectionState(ConnectionState.DISCONNECTED))
|
||||
setState(ConnectionState.DISCONNECTED);
|
||||
}
|
||||
|
||||
private void setState(ConnectionState connectionState) {
|
||||
@@ -174,9 +173,9 @@ public class TikTokLiveClient implements LiveClient
|
||||
public void publishMessage(String webcastMessageName, String payloadBase64) {
|
||||
this.publishMessage(webcastMessageName, Base64.getDecoder().decode(payloadBase64));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publishMessage(String webcastMessageName, byte[] payload) {
|
||||
|
||||
var builder = ProtoMessageFetchResult.BaseProtoMessage.newBuilder();
|
||||
builder.setMethod(webcastMessageName);
|
||||
builder.setPayload(ByteString.copyFrom(payload));
|
||||
@@ -184,7 +183,6 @@ public class TikTokLiveClient implements LiveClient
|
||||
messageHandler.handleSingleMessage(this, message);
|
||||
}
|
||||
|
||||
|
||||
public void connectAsync(Consumer<LiveClient> onConnection) {
|
||||
connectAsync().thenAccept(onConnection);
|
||||
}
|
||||
|
||||
@@ -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.settings.*;
|
||||
import io.github.jwdeveloper.tiktok.exceptions.*;
|
||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||
import io.github.jwdeveloper.tiktok.live.LiveEventsHandler;
|
||||
import io.github.jwdeveloper.tiktok.live.LiveMessagesHandler;
|
||||
import io.github.jwdeveloper.tiktok.live.*;
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
@@ -42,7 +40,6 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
||||
private final LiveEventsHandler tikTokEventHandler;
|
||||
private final WebSocketHeartbeatTask heartbeatTask;
|
||||
private WebSocketClient webSocketClient;
|
||||
private boolean isConnected;
|
||||
|
||||
public TikTokWebSocketClient(
|
||||
LiveClientSettings clientSettings,
|
||||
@@ -54,14 +51,12 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
||||
this.messageHandler = messageHandler;
|
||||
this.tikTokEventHandler = tikTokEventHandler;
|
||||
this.heartbeatTask = heartbeatTask;
|
||||
isConnected = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(LiveConnectionData.Response connectionData, LiveClient liveClient) {
|
||||
if (isConnected) {
|
||||
if (isConnected())
|
||||
stop();
|
||||
}
|
||||
|
||||
messageHandler.handle(liveClient, connectionData.getWebcastResponse());
|
||||
|
||||
@@ -85,9 +80,7 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
||||
try {
|
||||
webSocketClient.connect();
|
||||
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
|
||||
isConnected = true;
|
||||
} catch (Exception e) {
|
||||
isConnected = false;
|
||||
throw new TikTokLiveException("Failed to connect to the websocket", e);
|
||||
}
|
||||
}
|
||||
@@ -117,13 +110,12 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
||||
ProxyData proxyData = proxySettings.next();
|
||||
if (tryProxyConnection(proxySettings, proxyData)) {
|
||||
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
|
||||
isConnected = true;
|
||||
break;
|
||||
}
|
||||
if (proxySettings.isAutoDiscard())
|
||||
proxySettings.remove();
|
||||
}
|
||||
if (!isConnected)
|
||||
if (!isConnected())
|
||||
throw new TikTokLiveException("Failed to connect to the websocket");
|
||||
}
|
||||
|
||||
@@ -138,11 +130,14 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (isConnected && webSocketClient != null && webSocketClient.isOpen()) {
|
||||
webSocketClient.closeConnection(0, "");
|
||||
if (isConnected()) {
|
||||
webSocketClient.close();
|
||||
heartbeatTask.stop();
|
||||
}
|
||||
webSocketClient = null;
|
||||
isConnected = false;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return webSocketClient != null && webSocketClient.isOpen();
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,12 @@ public class TikTokWebSocketOfflineClient implements LiveSocketClient {
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (liveClient == null) {
|
||||
return;
|
||||
}
|
||||
if (liveClient != null)
|
||||
handler.publish(liveClient, new TikTokDisconnectedEvent("Stopping"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.10.0-Release</version>
|
||||
<version>1.10.2-Release</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<version>1.10.0-Release</version>
|
||||
<version>1.10.2-Release</version>
|
||||
</parent>
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.10.0-Release</version>
|
||||
<version>1.10.2-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>extension-recorder</artifactId>
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.10.0-Release</version>
|
||||
<version>1.10.2-Release</version>
|
||||
<modules>
|
||||
<module>API</module>
|
||||
<module>Client</module>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.10.0-Release</version>
|
||||
<version>1.10.2-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user