mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Compare commits
8 Commits
1.8.12-Rel
...
develop-1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33f9862758 | ||
|
|
d74c294323 | ||
|
|
31f0e4210d | ||
|
|
2e22da1fbe | ||
|
|
4b4874d33e | ||
|
|
9c7b24f33e | ||
|
|
7476a11ae0 | ||
|
|
125e421ea9 |
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.8.11-Release</version>
|
||||
<version>1.8.13-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>API</artifactId>
|
||||
|
||||
@@ -30,6 +30,8 @@ import io.github.jwdeveloper.tiktok.messages.enums.LinkMicBattleStatus;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Triggered every time a battle starts & ends
|
||||
*/
|
||||
@@ -73,21 +75,52 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
||||
public Team1v1 get1v1Team(String battleHostName) {
|
||||
if (!is1v1())
|
||||
throw new TikTokLiveException("Teams are not instance of 1v1 battle!");
|
||||
if (team1.getAs1v1Team().getHost().getName().equals(battleHostName))
|
||||
return team1.getAs1v1Team();
|
||||
if (team2.getAs1v1Team().getHost().getName().equals(battleHostName))
|
||||
return team2.getAs1v1Team();
|
||||
return null;
|
||||
List<Team> list = getTeams(battleHostName);
|
||||
return list.isEmpty() ? null : list.get(0).getAs1v1Team();
|
||||
}
|
||||
|
||||
public Team2v2 get2v2Team(String battleHostName) {
|
||||
if (!is2v2())
|
||||
throw new TikTokLiveException("Teams are not instance of 2v2 battle!");
|
||||
if (team1.getAs2v2Team().getHosts().stream().anyMatch(user -> user.getName().equals(battleHostName)))
|
||||
return team1.getAs2v2Team();
|
||||
if (team2.getAs2v2Team().getHosts().stream().anyMatch(user -> user.getName().equals(battleHostName)))
|
||||
return team2.getAs2v2Team();
|
||||
return null;
|
||||
List<Team> list = getTeams(battleHostName);
|
||||
return list.isEmpty() ? null : list.get(0).getAs2v2Team();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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() {
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.util.*;
|
||||
public class User {
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private String signature;
|
||||
private String profileName;
|
||||
private Picture picture;
|
||||
private long following;
|
||||
@@ -106,6 +107,7 @@ public class User {
|
||||
public User(Long id,
|
||||
String name,
|
||||
String profileName,
|
||||
String signature,
|
||||
Picture picture,
|
||||
long following,
|
||||
long followers,
|
||||
@@ -113,6 +115,7 @@ public class User {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.profileName = profileName;
|
||||
this.signature = signature;
|
||||
this.picture = picture;
|
||||
this.following = following;
|
||||
this.followers = followers;
|
||||
@@ -133,7 +136,7 @@ public class User {
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -142,6 +145,7 @@ public class User {
|
||||
|
||||
public User(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
||||
this(user.getId(), user.getDisplayId(), Picture.map(user.getAvatarThumb()));
|
||||
signature = user.getBioDescription();
|
||||
profileName = user.getNickname();
|
||||
following = user.getFollowInfo().getFollowingCount();
|
||||
followers = user.getFollowInfo().getFollowerCount();
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.function.Consumer;
|
||||
@Setter
|
||||
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 final List<ProxyData> proxyList = new ArrayList<>();
|
||||
private int index;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.8.11-Release</version>
|
||||
<version>1.8.13-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -219,7 +219,6 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
||||
protected ActionResult<HttpResponse<byte[]>> getByteResponse(String room_id) {
|
||||
HttpClientBuilder builder = httpFactory.client(TIKTOK_SIGN_API)
|
||||
.withParam("client", "ttlive-java")
|
||||
.withParam("uuc", "1") //MAGIC NUMBER!
|
||||
.withParam("room_id", room_id);
|
||||
|
||||
if (clientSettings.getApiKey() != null)
|
||||
|
||||
@@ -131,6 +131,7 @@ public class LiveDataMapper {
|
||||
var id = jsonElement.get("id").getAsLong();
|
||||
var name = jsonElement.get("display_id").getAsString();
|
||||
var profileName = jsonElement.get("nickname").getAsString();
|
||||
var signature = jsonElement.get("bio_description").getAsString();
|
||||
|
||||
|
||||
var followElement = jsonElement.getAsJsonObject("follow_info");
|
||||
@@ -142,7 +143,7 @@ public class LiveDataMapper {
|
||||
var link = pictureElement.getAsJsonArray("url_list").get(1).getAsString();
|
||||
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);
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ public class LiveUserDataMapper
|
||||
Long.parseLong(user.get("id").getAsString()),
|
||||
user.get("uniqueId").getAsString(),
|
||||
user.get("nickname").getAsString(),
|
||||
user.get("signature").getAsString(),
|
||||
new Picture(user.get("avatarLarger").getAsString()),
|
||||
stats.get("followingCount").getAsLong(),
|
||||
stats.get("followerCount").getAsLong(),
|
||||
|
||||
@@ -74,11 +74,11 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
||||
tikTokEventHandler,
|
||||
liveClient);
|
||||
|
||||
// ProxyClientSettings proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
||||
// if (proxyClientSettings.isEnabled())
|
||||
// connectProxy(proxyClientSettings);
|
||||
// else
|
||||
connectDefault();
|
||||
ProxyClientSettings proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
||||
if (proxyClientSettings.isEnabled() && proxyClientSettings.isAllowWebsocket())
|
||||
connectProxy(proxyClientSettings);
|
||||
else
|
||||
connectDefault();
|
||||
}
|
||||
|
||||
private void connectDefault() {
|
||||
@@ -115,15 +115,14 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
||||
}
|
||||
while (proxySettings.hasNext()) {
|
||||
ProxyData proxyData = proxySettings.next();
|
||||
if (!tryProxyConnection(proxySettings, proxyData)) {
|
||||
if (proxySettings.isAutoDiscard())
|
||||
proxySettings.remove();
|
||||
continue;
|
||||
}
|
||||
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
|
||||
isConnected = true;
|
||||
break;
|
||||
}
|
||||
if (tryProxyConnection(proxySettings, proxyData)) {
|
||||
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
|
||||
isConnected = true;
|
||||
break;
|
||||
}
|
||||
if (proxySettings.isAutoDiscard())
|
||||
proxySettings.remove();
|
||||
}
|
||||
if (!isConnected)
|
||||
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 java.util.Base64;
|
||||
|
||||
public class WebSocketHeartbeatTask
|
||||
{
|
||||
private Thread thread;
|
||||
private boolean isRunning = false;
|
||||
private final int MAX_TIMEOUT = 250;
|
||||
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) {
|
||||
stop();
|
||||
@@ -58,6 +60,5 @@ public class WebSocketHeartbeatTask
|
||||
isRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ Maven
|
||||
<dependency>
|
||||
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>1.8.7-Release</version>
|
||||
<version>1.8.13-Release</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -87,7 +87,7 @@ dependencyResolutionManagement {
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
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>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.8.11-Release</version>
|
||||
<version>1.8.13-Release</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<version>1.8.11-Release</version>
|
||||
<version>1.8.13-Release</version>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<dependency>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<artifactId>API</artifactId>
|
||||
<version>1.8.11-Release</version>
|
||||
<version>1.8.13-Release</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.8.11-Release</version>
|
||||
<version>1.8.13-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.8.11-Release</version>
|
||||
<version>1.8.13-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.8.11-Release</version>
|
||||
<version>1.8.13-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user