mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Compare commits
14 Commits
1.10.0-Rel
...
1.10.5-Rel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba69f5f5eb | ||
|
|
e9a91f5741 | ||
|
|
053bb5e3dc | ||
|
|
906796dc23 | ||
|
|
162092c638 | ||
|
|
a72d134796 | ||
|
|
75f6368f2c | ||
|
|
b9eb0eba93 | ||
|
|
50d6d6e515 | ||
|
|
42f9fe360b | ||
|
|
dff226740c | ||
|
|
951d30e6a7 | ||
|
|
1df912b722 | ||
|
|
4aec20cc35 |
@@ -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.9.2-Release</version>
|
<version>1.10.4-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -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());
|
||||||
|
|||||||
@@ -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();
|
||||||
@@ -128,4 +127,37 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
|||||||
int referencePoints = teams.get(0).getTotalPoints();
|
int referencePoints = teams.get(0).getTotalPoints();
|
||||||
return teams.stream().allMatch(team -> team.getTotalPoints() == referencePoints);
|
return teams.stream().allMatch(team -> team.getTotalPoints() == referencePoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param battleHostName name of host to search
|
||||||
|
* @return Team instance containing name of host or null if no team found */
|
||||||
|
public Team getTeam(String battleHostName) {
|
||||||
|
List<Team> list = getTeams(battleHostName);
|
||||||
|
return list.isEmpty() ? null : list.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param battleHostName name of host to search
|
||||||
|
* @return Team instances not containing name of host */
|
||||||
|
public List<Team> getOpponentTeams(String battleHostName) {
|
||||||
|
List<Team> list = getTeams(battleHostName);
|
||||||
|
return list.isEmpty() ? null : list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param battleHostName name of host to search
|
||||||
|
* @return {@link List<Team>} with host team first, then opponent teams
|
||||||
|
* <p> If host is in neither or teams is empty, returns empty
|
||||||
|
* <p> Otherwise always teams.length in length;
|
||||||
|
*/
|
||||||
|
public List<Team> getTeams(String battleHostName) {
|
||||||
|
if (teams.isEmpty() || teams.stream().noneMatch(team -> team.contains(battleHostName)))
|
||||||
|
return Collections.EMPTY_LIST;
|
||||||
|
Team hostTeam = teams.stream().filter(team -> team.contains(battleHostName)).findFirst().orElseThrow();
|
||||||
|
List<Team> opponentTeams = teams.stream().filter(team -> !team.contains(battleHostName)).toList();
|
||||||
|
List<Team> teams = new ArrayList<>();
|
||||||
|
teams.add(hostTeam);
|
||||||
|
teams.addAll(opponentTeams);
|
||||||
|
return teams;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -81,4 +81,8 @@ public class Team {
|
|||||||
this(anchorInfo);
|
this(anchorInfo);
|
||||||
this.winStreak = (int) battleCombo.getComboCount();
|
this.winStreak = (int) battleCombo.getComboCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean contains(String name) {
|
||||||
|
return hosts.stream().anyMatch(user -> user.getName().equals(name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -90,11 +90,18 @@ public class LiveClientSettings {
|
|||||||
private boolean throwOnAgeRestriction;
|
private boolean throwOnAgeRestriction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId
|
* Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId.
|
||||||
* @see <a href="https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages">Documentation: How to obtain sessionId</a>
|
* <p>This requires {@link #ttTargetIdc} also being set correctly for sessionid to be effective.
|
||||||
|
* @apiNote This cookie is supplied by <a href="https://www.tiktok.com">TikTok</a> and can be found in your browser cookies.
|
||||||
*/
|
*/
|
||||||
private String sessionId;
|
private String sessionId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used with {@link #sessionId} to verify it is valid and return extra chat messages and 18+ content.
|
||||||
|
* @apiNote This cookie is supplied by <a href="https://www.tiktok.com">TikTok</a> and can be found in your browser cookies.
|
||||||
|
*/
|
||||||
|
private String ttTargetIdc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional: By default roomID is fetched before connect to live, but you can set it manually
|
* Optional: By default roomID is fetched before connect to live, but you can set it manually
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
@@ -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.9.2-Release</version>
|
<version>1.10.4-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
.withParam("uniqueId", request.getUserName())
|
.withParam("uniqueId", request.getUserName())
|
||||||
.withParam("sourceType", "54") //MAGIC NUMBER, WHAT 54 means?
|
.withParam("sourceType", "54") //MAGIC NUMBER, WHAT 54 means?
|
||||||
.withCookie("sessionid", clientSettings.getSessionId())
|
.withCookie("sessionid", clientSettings.getSessionId())
|
||||||
|
.withCookie("tt-target-idc", clientSettings.getTtTargetIdc())
|
||||||
.build()
|
.build()
|
||||||
.toJsonResponse();
|
.toJsonResponse();
|
||||||
|
|
||||||
@@ -141,6 +142,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
var result = httpFactory.client(url)
|
var result = httpFactory.client(url)
|
||||||
.withParam("room_id", request.getRoomId())
|
.withParam("room_id", request.getRoomId())
|
||||||
.withCookie("sessionid", clientSettings.getSessionId())
|
.withCookie("sessionid", clientSettings.getSessionId())
|
||||||
|
.withCookie("tt-target-idc", clientSettings.getTtTargetIdc())
|
||||||
.build()
|
.build()
|
||||||
.toJsonResponse();
|
.toJsonResponse();
|
||||||
|
|
||||||
|
|||||||
@@ -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,14 +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;
|
return;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (proxySettings.isAutoDiscard())
|
if (proxySettings.isAutoDiscard())
|
||||||
proxySettings.remove();
|
proxySettings.remove();
|
||||||
}
|
}
|
||||||
if (!isConnected)
|
throw new TikTokLiveException("Failed to connect to the websocket");
|
||||||
throw new TikTokLiveException("Failed to connect to the websocket");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tryProxyConnection(ProxyClientSettings proxySettings, ProxyData proxyData) {
|
public boolean tryProxyConnection(ProxyClientSettings proxySettings, ProxyData proxyData) {
|
||||||
@@ -138,11 +129,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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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.9.2-Release</version>
|
<version>1.10.4-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.9.2-Release</version>
|
<version>1.10.4-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.9.2-Release</version>
|
<version>1.10.4-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.9.2-Release</version>
|
<version>1.10.4-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.9.2-Release</version>
|
<version>1.10.4-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user