Compare commits

...

6 Commits

Author SHA1 Message Date
David Kohler
31f0e4210d Update README.md 2024-12-23 22:42:53 -05:00
David Kohler
2e22da1fbe Merge pull request #115 from jwdeveloper/develop-1.8.13
Develop 1.8.13
2024-12-23 22:41:01 -05:00
kohlerpop1
4b4874d33e Update bytes required for ping task! 2024-12-23 22:17:27 -05:00
kohlerpop1
9c7b24f33e Add settings for allowing proxies to be used for working through Websockets. 2024-12-23 22:16:49 -05:00
kohlerpop1
7476a11ae0 Optimized TikTokLinkMicBattleEvent and added helper methods! 2024-12-23 22:14:55 -05:00
GitHub Action
125e421ea9 Update version in pom.xml 2024-12-19 18:48:50 +00:00
12 changed files with 71 additions and 38 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.8.11-Release</version> <version>1.8.12-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>API</artifactId> <artifactId>API</artifactId>

View File

@@ -30,6 +30,8 @@ import io.github.jwdeveloper.tiktok.messages.enums.LinkMicBattleStatus;
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle; import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
import lombok.Getter; import lombok.Getter;
import java.util.List;
/** /**
* Triggered every time a battle starts & ends * Triggered every time a battle starts & ends
*/ */
@@ -73,21 +75,52 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
public Team1v1 get1v1Team(String battleHostName) { public Team1v1 get1v1Team(String battleHostName) {
if (!is1v1()) if (!is1v1())
throw new TikTokLiveException("Teams are not instance of 1v1 battle!"); throw new TikTokLiveException("Teams are not instance of 1v1 battle!");
if (team1.getAs1v1Team().getHost().getName().equals(battleHostName)) List<Team> list = getTeams(battleHostName);
return team1.getAs1v1Team(); return list.isEmpty() ? null : list.get(0).getAs1v1Team();
if (team2.getAs1v1Team().getHost().getName().equals(battleHostName))
return team2.getAs1v1Team();
return null;
} }
public Team2v2 get2v2Team(String battleHostName) { public Team2v2 get2v2Team(String battleHostName) {
if (!is2v2()) if (!is2v2())
throw new TikTokLiveException("Teams are not instance of 2v2 battle!"); throw new TikTokLiveException("Teams are not instance of 2v2 battle!");
if (team1.getAs2v2Team().getHosts().stream().anyMatch(user -> user.getName().equals(battleHostName))) List<Team> list = getTeams(battleHostName);
return team1.getAs2v2Team(); return list.isEmpty() ? null : list.get(0).getAs2v2Team();
if (team2.getAs2v2Team().getHosts().stream().anyMatch(user -> user.getName().equals(battleHostName))) }
return team2.getAs2v2Team();
return null; /**
* @param battleHostName name of host to search
* @return Team1v1 instance not containing name of host */
public Team1v1 get1v1OpponentTeam(String battleHostName) {
if (!is1v1())
throw new TikTokLiveException("Teams are not instance of 1v1 battle!");
List<Team> list = getTeams(battleHostName);
return list.isEmpty() ? null : list.get(1).getAs1v1Team();
}
public Team2v2 get2x2OpponentTeam(String battleHostName) {
if (!is2v2())
throw new TikTokLiveException("Teams are not instance of 2v2 battle!");
List<Team> list = getTeams(battleHostName);
return list.isEmpty() ? null : list.get(1).getAs2v2Team();
}
/**
* @param battleHostName name of host to search
* @return {@link List<Team>} with host team first, then opponent team
* <p> Empty if host is in neither otherwise always 2 in length;
*/
public List<Team> getTeams(String battleHostName) {
if (is1v1()) {
if (team1.getAs1v1Team().getHost().getName().equals(battleHostName))
return List.of(team1, team2);
if (team2.getAs1v1Team().getHost().getName().equals(battleHostName))
return List.of(team2, team1);
} else {
if (team1.getAs2v2Team().getHosts().stream().anyMatch(user -> user.getName().equals(battleHostName)))
return List.of(team1, team2);
if (team2.getAs2v2Team().getHosts().stream().anyMatch(user -> user.getName().equals(battleHostName)))
return List.of(team2, team1);
}
return List.of();
} }
public boolean is1v1() { public boolean is1v1() {

View File

@@ -33,7 +33,7 @@ import java.util.function.Consumer;
@Setter @Setter
public class ProxyClientSettings implements Iterator<ProxyData>, Iterable<ProxyData> public class ProxyClientSettings implements Iterator<ProxyData>, Iterable<ProxyData>
{ {
private boolean enabled, autoDiscard = true, fallback = true; private boolean enabled, autoDiscard = true, fallback = true, allowWebsocket = true;
private Rotation rotation = Rotation.CONSECUTIVE; private Rotation rotation = Rotation.CONSECUTIVE;
private final List<ProxyData> proxyList = new ArrayList<>(); private final List<ProxyData> proxyList = new ArrayList<>();
private int index; private int index;

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.8.11-Release</version> <version>1.8.12-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -74,11 +74,11 @@ public class TikTokWebSocketClient implements LiveSocketClient {
tikTokEventHandler, tikTokEventHandler,
liveClient); liveClient);
// ProxyClientSettings proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings(); ProxyClientSettings proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
// if (proxyClientSettings.isEnabled()) if (proxyClientSettings.isEnabled() && proxyClientSettings.isAllowWebsocket())
// connectProxy(proxyClientSettings); connectProxy(proxyClientSettings);
// else else
connectDefault(); connectDefault();
} }
private void connectDefault() { private void connectDefault() {
@@ -115,15 +115,14 @@ public class TikTokWebSocketClient implements LiveSocketClient {
} }
while (proxySettings.hasNext()) { while (proxySettings.hasNext()) {
ProxyData proxyData = proxySettings.next(); ProxyData proxyData = proxySettings.next();
if (!tryProxyConnection(proxySettings, proxyData)) { if (tryProxyConnection(proxySettings, proxyData)) {
if (proxySettings.isAutoDiscard()) heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
proxySettings.remove(); isConnected = true;
continue; break;
} }
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval()); if (proxySettings.isAutoDiscard())
isConnected = true; proxySettings.remove();
break; }
}
if (!isConnected) if (!isConnected)
throw new TikTokLiveException("Failed to connect to the websocket"); throw new TikTokLiveException("Failed to connect to the websocket");
} }

View File

@@ -24,13 +24,15 @@ package io.github.jwdeveloper.tiktok.websocket;
import org.java_websocket.WebSocket; import org.java_websocket.WebSocket;
import java.util.Base64;
public class WebSocketHeartbeatTask public class WebSocketHeartbeatTask
{ {
private Thread thread; private Thread thread;
private boolean isRunning = false; private boolean isRunning = false;
private final int MAX_TIMEOUT = 250; private final int MAX_TIMEOUT = 250;
private final int SLEEP_TIME = 500; private final int SLEEP_TIME = 500;
private final byte[] heartbeatBytes = {58, 2, 104, 98}; // Byte Array of "3A026862" which is TikTok's custom heartbeat value 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(); stop();
@@ -58,6 +60,5 @@ public class WebSocketHeartbeatTask
isRunning = false; isRunning = false;
} }
} }
} }
} }

View File

@@ -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.8.7-Release</version> <version>1.8.13-Release</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
@@ -87,7 +87,7 @@ dependencyResolutionManagement {
} }
dependencies { dependencies {
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.8.5-Release' implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.8.13-Release'
} }
``` ```
@@ -754,4 +754,4 @@ public static class CustomListener {
[Library documentation for contributors](https://github.com/jwdeveloper/TikTokLiveJava/wiki) [Library documentation for contributors](https://github.com/jwdeveloper/TikTokLiveJava/wiki)
Your improvements are welcome! Feel free to open an <a href="https://github.com/jwdeveloper/TikTok-Live-Java/issues">issue</a> or <a href="https://github.com/jwdeveloper/TikTok-Live-Java/pulls">pull request</a>. Your improvements are welcome! Feel free to open an <a href="https://github.com/jwdeveloper/TikTok-Live-Java/issues">issue</a> or <a href="https://github.com/jwdeveloper/TikTok-Live-Java/pulls">pull request</a>.

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.8.11-Release</version> <version>1.8.12-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.8.11-Release</version> <version>1.8.12-Release</version>
</parent> </parent>
@@ -33,7 +33,7 @@
<dependency> <dependency>
<groupId>io.github.jwdeveloper.tiktok</groupId> <groupId>io.github.jwdeveloper.tiktok</groupId>
<artifactId>API</artifactId> <artifactId>API</artifactId>
<version>1.8.11-Release</version> <version>1.8.12-Release</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

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.8.11-Release</version> <version>1.8.12-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.8.11-Release</version> <version>1.8.12-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.8.11-Release</version> <version>1.8.12-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>