mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-28 09:19:40 -05:00
Compare commits
12 Commits
1.8.4-Rele
...
1.8.7-Rele
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a28df44cee | ||
|
|
ee866762a3 | ||
|
|
3cb7c83ef4 | ||
|
|
bf755bcb89 | ||
|
|
20bb05e527 | ||
|
|
d5a3213ad8 | ||
|
|
7e496373ef | ||
|
|
1f3c1c7d41 | ||
|
|
c160259863 | ||
|
|
fb458e7e7d | ||
|
|
5f5ada312a | ||
|
|
cb20c3dd3a |
@@ -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.3-Release</version>
|
<version>1.8.6-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -82,9 +82,9 @@ public class LiveClientSettings {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Interval of time in milliseconds between pings to TikTok
|
* Interval of time in milliseconds between pings to TikTok
|
||||||
* @apiNote Min: 250 (0.25 seconds), Default: 5000 (5 seconds)
|
* @apiNote Min: 250 (0.25 seconds), Default: 10000 (10 seconds - TikTok Default)
|
||||||
*/
|
*/
|
||||||
private long pingInterval = 5000;
|
private long pingInterval = 10000;
|
||||||
|
|
||||||
/** Throw an exception on 18+ Age Restriction */
|
/** Throw an exception on 18+ Age Restriction */
|
||||||
private boolean throwOnAgeRestriction;
|
private boolean throwOnAgeRestriction;
|
||||||
|
|||||||
@@ -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.3-Release</version>
|
<version>1.8.6-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
|
|
||||||
//networking
|
//networking
|
||||||
dependance.registerSingleton(HttpClientFactory.class);
|
dependance.registerSingleton(HttpClientFactory.class);
|
||||||
dependance.registerSingleton(TikTokWebSocketPingingTask.class);
|
dependance.registerSingleton(WebSocketHeartbeatTask.class);
|
||||||
if (clientSettings.isOffline()) {
|
if (clientSettings.isOffline()) {
|
||||||
dependance.registerSingleton(LiveSocketClient.class, TikTokWebSocketOfflineClient.class);
|
dependance.registerSingleton(LiveSocketClient.class, TikTokWebSocketOfflineClient.class);
|
||||||
dependance.registerSingleton(LiveHttpClient.class, TikTokLiveHttpOfflineClient.class);
|
dependance.registerSingleton(LiveHttpClient.class, TikTokLiveHttpOfflineClient.class);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import io.github.jwdeveloper.tiktok.data.models.Picture;
|
|||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.GiftsData;
|
import io.github.jwdeveloper.tiktok.data.requests.GiftsData;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GiftsDataMapper {
|
public class GiftsDataMapper {
|
||||||
@@ -56,9 +57,13 @@ public class GiftsDataMapper {
|
|||||||
var parsedJson = JsonParser.parseString(json);
|
var parsedJson = JsonParser.parseString(json);
|
||||||
var jsonObject = parsedJson.getAsJsonObject();
|
var jsonObject = parsedJson.getAsJsonObject();
|
||||||
if (jsonObject.get("data") instanceof JsonObject data && data.get("gifts") instanceof JsonArray giftArray) {
|
if (jsonObject.get("data") instanceof JsonObject data && data.get("gifts") instanceof JsonArray giftArray) {
|
||||||
var gifts = giftArray.asList().parallelStream()
|
var gifts = new ArrayList<Gift>();
|
||||||
.map(this::mapSingleRoomGift)
|
|
||||||
.toList();
|
for(int i = 0; i < giftArray.size(); i++) {
|
||||||
|
JsonElement element = giftArray.get(i);
|
||||||
|
Gift gift = mapSingleRoomGift(element);
|
||||||
|
gifts.add(gift);
|
||||||
|
}
|
||||||
|
|
||||||
return new GiftsData.Response(json, gifts);
|
return new GiftsData.Response(json, gifts);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,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, followers, followingCount, new ArrayList<>());
|
var user = new User(id, name, profileName, picture, followingCount, followers, new ArrayList<>());
|
||||||
user.addAttribute(UserAttribute.LiveHost);
|
user.addAttribute(UserAttribute.LiveHost);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
|||||||
private final LiveClientSettings clientSettings;
|
private final LiveClientSettings clientSettings;
|
||||||
private final LiveMessagesHandler messageHandler;
|
private final LiveMessagesHandler messageHandler;
|
||||||
private final LiveEventsHandler tikTokEventHandler;
|
private final LiveEventsHandler tikTokEventHandler;
|
||||||
private final TikTokWebSocketPingingTask pingingTask;
|
private final WebSocketHeartbeatTask heartbeatTask;
|
||||||
private WebSocketClient webSocketClient;
|
private WebSocketClient webSocketClient;
|
||||||
private boolean isConnected;
|
private boolean isConnected;
|
||||||
|
|
||||||
@@ -48,12 +48,12 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
|||||||
LiveClientSettings clientSettings,
|
LiveClientSettings clientSettings,
|
||||||
LiveMessagesHandler messageHandler,
|
LiveMessagesHandler messageHandler,
|
||||||
LiveEventsHandler tikTokEventHandler,
|
LiveEventsHandler tikTokEventHandler,
|
||||||
TikTokWebSocketPingingTask pingingTask)
|
WebSocketHeartbeatTask heartbeatTask)
|
||||||
{
|
{
|
||||||
this.clientSettings = clientSettings;
|
this.clientSettings = clientSettings;
|
||||||
this.messageHandler = messageHandler;
|
this.messageHandler = messageHandler;
|
||||||
this.tikTokEventHandler = tikTokEventHandler;
|
this.tikTokEventHandler = tikTokEventHandler;
|
||||||
this.pingingTask = pingingTask;
|
this.heartbeatTask = heartbeatTask;
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
|||||||
private void connectDefault() {
|
private void connectDefault() {
|
||||||
try {
|
try {
|
||||||
webSocketClient.connect();
|
webSocketClient.connect();
|
||||||
pingingTask.run(webSocketClient, clientSettings.getPingInterval());
|
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
@@ -120,7 +120,7 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
|||||||
proxySettings.remove();
|
proxySettings.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pingingTask.run(webSocketClient, clientSettings.getPingInterval());
|
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
|||||||
public void stop() {
|
public void stop() {
|
||||||
if (isConnected && webSocketClient != null && webSocketClient.isOpen()) {
|
if (isConnected && webSocketClient != null && webSocketClient.isOpen()) {
|
||||||
webSocketClient.closeConnection(0, "");
|
webSocketClient.closeConnection(0, "");
|
||||||
pingingTask.stop();
|
heartbeatTask.stop();
|
||||||
}
|
}
|
||||||
webSocketClient = null;
|
webSocketClient = null;
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
|
|||||||
@@ -22,18 +22,19 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.websocket;
|
package io.github.jwdeveloper.tiktok.websocket;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveEventsHandler;
|
|
||||||
import org.java_websocket.WebSocket;
|
import org.java_websocket.WebSocket;
|
||||||
|
|
||||||
public class TikTokWebSocketPingingTask {
|
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
|
||||||
|
|
||||||
public void run(WebSocket webSocket, long pingTaskTime) {
|
public void run(WebSocket webSocket, long pingTaskTime) {
|
||||||
stop();
|
stop();
|
||||||
thread = new Thread(() -> pingTask(webSocket, pingTaskTime), "pinging-task");
|
thread = new Thread(() -> heartbeatTask(webSocket, pingTaskTime), "heartbeat-task");
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
@@ -44,11 +45,11 @@ public class TikTokWebSocketPingingTask {
|
|||||||
isRunning = false;
|
isRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pingTask(WebSocket webSocket, long pingTaskTime) {
|
private void heartbeatTask(WebSocket webSocket, long pingTaskTime) {
|
||||||
while (isRunning) {
|
while (isRunning) {
|
||||||
try {
|
try {
|
||||||
if (webSocket.isOpen()) {
|
if (webSocket.isOpen()) {
|
||||||
webSocket.sendPing();
|
webSocket.send(heartbeatBytes);
|
||||||
Thread.sleep(pingTaskTime + (int) (Math.random() * MAX_TIMEOUT));
|
Thread.sleep(pingTaskTime + (int) (Math.random() * MAX_TIMEOUT));
|
||||||
} else
|
} else
|
||||||
Thread.sleep(SLEEP_TIME);
|
Thread.sleep(SLEEP_TIME);
|
||||||
@@ -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.0-Release</version>
|
<version>1.8.5-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.5.0-Release'
|
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.8.5-Release'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -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.3-Release</version>
|
<version>1.8.6-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.3-Release</version>
|
<version>1.8.6-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.3-Release</version>
|
<version>1.8.6-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.3-Release</version>
|
<version>1.8.6-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.3-Release</version>
|
<version>1.8.6-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.3-Release</version>
|
<version>1.8.6-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user