mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 08:49:40 -05:00
Compare commits
10 Commits
1.8.12-Rel
...
1.8.14-Rel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8fcbb4b20f | ||
|
|
d90ab60e52 | ||
|
|
33f9862758 | ||
|
|
d74c294323 | ||
|
|
31f0e4210d | ||
|
|
2e22da1fbe | ||
|
|
4b4874d33e | ||
|
|
9c7b24f33e | ||
|
|
7476a11ae0 | ||
|
|
125e421ea9 |
@@ -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.13-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import java.util.*;
|
|||||||
public class User {
|
public class User {
|
||||||
private final Long id;
|
private final Long id;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
private String signature;
|
||||||
private String profileName;
|
private String profileName;
|
||||||
private Picture picture;
|
private Picture picture;
|
||||||
private long following;
|
private long following;
|
||||||
@@ -106,6 +107,7 @@ public class User {
|
|||||||
public User(Long id,
|
public User(Long id,
|
||||||
String name,
|
String name,
|
||||||
String profileName,
|
String profileName,
|
||||||
|
String signature,
|
||||||
Picture picture,
|
Picture picture,
|
||||||
long following,
|
long following,
|
||||||
long followers,
|
long followers,
|
||||||
@@ -113,6 +115,7 @@ public class User {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.profileName = profileName;
|
this.profileName = profileName;
|
||||||
|
this.signature = signature;
|
||||||
this.picture = picture;
|
this.picture = picture;
|
||||||
this.following = following;
|
this.following = following;
|
||||||
this.followers = followers;
|
this.followers = followers;
|
||||||
@@ -133,7 +136,7 @@ public class User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public User(long id, String name, String profileId, Picture picture) {
|
public User(long id, String name, String profileId, Picture picture) {
|
||||||
this(id, name, profileId, picture, 0, 0, List.of(Badge.empty()));
|
this(id, name, profileId, null, picture, 0, 0, List.of(Badge.empty()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public User(WebcastLinkMicBattle.LinkMicBattleHost.HostGroup.Host host) {
|
public User(WebcastLinkMicBattle.LinkMicBattleHost.HostGroup.Host host) {
|
||||||
@@ -142,6 +145,7 @@ public class User {
|
|||||||
|
|
||||||
public User(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
public User(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
||||||
this(user.getId(), user.getDisplayId(), Picture.map(user.getAvatarThumb()));
|
this(user.getId(), user.getDisplayId(), Picture.map(user.getAvatarThumb()));
|
||||||
|
signature = user.getBioDescription();
|
||||||
profileName = user.getNickname();
|
profileName = user.getNickname();
|
||||||
following = user.getFollowInfo().getFollowingCount();
|
following = user.getFollowInfo().getFollowingCount();
|
||||||
followers = user.getFollowInfo().getFollowerCount();
|
followers = user.getFollowInfo().getFollowerCount();
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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.13-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -219,7 +219,6 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
protected ActionResult<HttpResponse<byte[]>> getByteResponse(String room_id) {
|
protected ActionResult<HttpResponse<byte[]>> getByteResponse(String room_id) {
|
||||||
HttpClientBuilder builder = httpFactory.client(TIKTOK_SIGN_API)
|
HttpClientBuilder builder = httpFactory.client(TIKTOK_SIGN_API)
|
||||||
.withParam("client", "ttlive-java")
|
.withParam("client", "ttlive-java")
|
||||||
.withParam("uuc", "1") //MAGIC NUMBER!
|
|
||||||
.withParam("room_id", room_id);
|
.withParam("room_id", room_id);
|
||||||
|
|
||||||
if (clientSettings.getApiKey() != null)
|
if (clientSettings.getApiKey() != null)
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ public class LiveDataMapper {
|
|||||||
var id = jsonElement.get("id").getAsLong();
|
var id = jsonElement.get("id").getAsLong();
|
||||||
var name = jsonElement.get("display_id").getAsString();
|
var name = jsonElement.get("display_id").getAsString();
|
||||||
var profileName = jsonElement.get("nickname").getAsString();
|
var profileName = jsonElement.get("nickname").getAsString();
|
||||||
|
var signature = jsonElement.get("bio_description").getAsString();
|
||||||
|
|
||||||
|
|
||||||
var followElement = jsonElement.getAsJsonObject("follow_info");
|
var followElement = jsonElement.getAsJsonObject("follow_info");
|
||||||
@@ -142,7 +143,7 @@ public class LiveDataMapper {
|
|||||||
var link = pictureElement.getAsJsonArray("url_list").get(1).getAsString();
|
var link = pictureElement.getAsJsonArray("url_list").get(1).getAsString();
|
||||||
var picture = new Picture(link);
|
var picture = new Picture(link);
|
||||||
|
|
||||||
var user = new User(id, name, profileName, picture, followingCount, followers, new ArrayList<>());
|
var user = new User(id, name, profileName, signature, picture, followingCount, followers, new ArrayList<>());
|
||||||
user.addAttribute(UserAttribute.LiveHost);
|
user.addAttribute(UserAttribute.LiveHost);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public class LiveUserDataMapper
|
|||||||
Long.parseLong(user.get("id").getAsString()),
|
Long.parseLong(user.get("id").getAsString()),
|
||||||
user.get("uniqueId").getAsString(),
|
user.get("uniqueId").getAsString(),
|
||||||
user.get("nickname").getAsString(),
|
user.get("nickname").getAsString(),
|
||||||
|
user.get("signature").getAsString(),
|
||||||
new Picture(user.get("avatarLarger").getAsString()),
|
new Picture(user.get("avatarLarger").getAsString()),
|
||||||
stats.get("followingCount").getAsLong(),
|
stats.get("followingCount").getAsLong(),
|
||||||
stats.get("followerCount").getAsLong(),
|
stats.get("followerCount").getAsLong(),
|
||||||
|
|||||||
@@ -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");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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.14-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.14-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>.
|
||||||
|
|||||||
@@ -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.13-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.8.11-Release</version>
|
<version>1.8.13-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.13-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -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.13-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.8.11-Release</version>
|
<version>1.8.13-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.8.11-Release</version>
|
<version>1.8.13-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user