mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-28 01:09:40 -05:00
Compare commits
9 Commits
0.0.23-Rel
...
0.0.24-Rel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84bbfa97e9 | ||
|
|
a2da5169db | ||
|
|
bf8defbe3c | ||
|
|
5ba935efaf | ||
|
|
0a244a4a58 | ||
|
|
ac911de6b3 | ||
|
|
74208361fd | ||
|
|
a6cb2be1a7 | ||
|
|
9267217ebd |
@@ -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>0.0.22-Release</version>
|
<version>0.0.23-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class ClientSettings {
|
|||||||
private boolean printMessageData;
|
private boolean printMessageData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tiktok user name
|
* Optional: Use it if you need to change tiktok live hostname in builder
|
||||||
*/
|
*/
|
||||||
private String hostName;
|
private String hostName;
|
||||||
|
|
||||||
@@ -68,10 +68,16 @@ public class ClientSettings {
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
* documentation how to obtain sessionId https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages
|
* documentation how to obtain sessionId https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages
|
||||||
*/
|
*/
|
||||||
private String sessionId;
|
private String sessionId;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Optional: By default roomID is fetched before connect to live, but you can set it manually
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String roomId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package io.github.jwdeveloper.tiktok.live;
|
|||||||
public interface LiveRoomInfo
|
public interface LiveRoomInfo
|
||||||
{
|
{
|
||||||
int getViewersCount();
|
int getViewersCount();
|
||||||
|
boolean isAgeRestricted();
|
||||||
String getRoomId();
|
String getRoomId();
|
||||||
String getUserName();
|
String getUserName();
|
||||||
ConnectionState getConnectionState();
|
ConnectionState getConnectionState();
|
||||||
|
|||||||
@@ -6,4 +6,6 @@ import lombok.Data;
|
|||||||
public class LiveRoomMeta
|
public class LiveRoomMeta
|
||||||
{
|
{
|
||||||
private int status;
|
private int status;
|
||||||
|
|
||||||
|
private boolean ageRestricted;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.mappers;
|
||||||
|
|
||||||
|
public interface Mapper<SOURCE,TARGET>
|
||||||
|
{
|
||||||
|
TARGET mapFrom(SOURCE source);
|
||||||
|
}
|
||||||
@@ -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>0.0.22-Release</version>
|
<version>0.0.23-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -89,8 +89,20 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
|
|
||||||
|
|
||||||
apiService.updateSessionId();
|
apiService.updateSessionId();
|
||||||
var roomId = apiService.fetchRoomId(liveRoomInfo.getUserName());
|
|
||||||
liveRoomInfo.setRoomId(roomId);
|
if(clientSettings.getRoomId() != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
liveRoomInfo.setRoomId(clientSettings.getRoomId());
|
||||||
|
logger.info("Using roomID from settings: "+clientSettings.getRoomId());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var roomId = apiService.fetchRoomId(liveRoomInfo.getUserName());
|
||||||
|
liveRoomInfo.setRoomId(roomId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var roomData = apiService.fetchRoomInfo();
|
var roomData = apiService.fetchRoomInfo();
|
||||||
if (roomData.getStatus() == 0 || roomData.getStatus() == 4) {
|
if (roomData.getStatus() == 0 || roomData.getStatus() == 4) {
|
||||||
throw new TikTokLiveOfflineHostException("LiveStream for HostID could not be found. Is the Host online?");
|
throw new TikTokLiveOfflineHostException("LiveStream for HostID could not be found. Is the Host online?");
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ public class TikTokRoomInfo implements LiveRoomInfo
|
|||||||
|
|
||||||
private String roomId;
|
private String roomId;
|
||||||
|
|
||||||
|
private boolean ageRestricted;
|
||||||
|
|
||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
private ConnectionState connectionState = ConnectionState.DISCONNECTED;
|
private ConnectionState connectionState = ConnectionState.DISCONNECTED;
|
||||||
|
|
||||||
public boolean hasConnectionState(ConnectionState state)
|
public boolean hasConnectionState(ConnectionState state)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
|||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveOfflineHostException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveOfflineHostException;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveRoomMeta;
|
import io.github.jwdeveloper.tiktok.live.LiveRoomMeta;
|
||||||
|
import io.github.jwdeveloper.tiktok.mappers.LiveRoomMetaMapper;
|
||||||
import io.github.jwdeveloper.tiktok.messages.WebcastResponse;
|
import io.github.jwdeveloper.tiktok.messages.WebcastResponse;
|
||||||
import io.github.jwdeveloper.tiktok.models.gifts.TikTokGiftInfo;
|
import io.github.jwdeveloper.tiktok.models.gifts.TikTokGiftInfo;
|
||||||
|
|
||||||
@@ -100,22 +101,10 @@ public class TikTokApiService {
|
|||||||
logger.info("Fetch RoomInfo");
|
logger.info("Fetch RoomInfo");
|
||||||
try {
|
try {
|
||||||
var response = tiktokHttpClient.getJObjectFromWebcastAPI("room/info/", clientSettings.getClientParameters());
|
var response = tiktokHttpClient.getJObjectFromWebcastAPI("room/info/", clientSettings.getClientParameters());
|
||||||
if (!response.has("data")) {
|
var mapper = new LiveRoomMetaMapper();
|
||||||
return new LiveRoomMeta();
|
var liveRoomMeta = mapper.mapFrom(response);
|
||||||
}
|
logger.info("RoomInfo status -> " + liveRoomMeta.getStatus());
|
||||||
|
return liveRoomMeta;
|
||||||
var data = response.getAsJsonObject("data");
|
|
||||||
if (!data.has("status")) {
|
|
||||||
return new LiveRoomMeta();
|
|
||||||
}
|
|
||||||
|
|
||||||
var status = data.get("status");
|
|
||||||
|
|
||||||
var info = new LiveRoomMeta();
|
|
||||||
info.setStatus(status.getAsInt());
|
|
||||||
|
|
||||||
logger.info("RoomInfo status -> " + info.getStatus());
|
|
||||||
return info;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new TikTokLiveRequestException("Failed to fetch room info from WebCast, see stacktrace for more info.", e);
|
throw new TikTokLiveRequestException("Failed to fetch room info from WebCast, see stacktrace for more info.", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,14 @@ public class TikTokHttpRequestFactory implements TikTokHttpRequest {
|
|||||||
public String get(String url) {
|
public String get(String url) {
|
||||||
var uri = URI.create(url);
|
var uri = URI.create(url);
|
||||||
var request = HttpRequest.newBuilder().GET();
|
var request = HttpRequest.newBuilder().GET();
|
||||||
|
for (var header : defaultHeaders.entrySet())
|
||||||
|
{
|
||||||
|
if(header.getKey().equals("Connection") || header.getKey().equals("Accept-Encoding"))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
request.setHeader(header.getKey(), header.getValue());
|
||||||
|
}
|
||||||
if (query != null) {
|
if (query != null) {
|
||||||
var baseUri = uri.toString();
|
var baseUri = uri.toString();
|
||||||
var requestUri = URI.create(baseUri + "?" + query);
|
var requestUri = URI.create(baseUri + "?" + query);
|
||||||
|
|||||||
@@ -19,10 +19,9 @@ public class TikTokListenersManager implements ListenersManager {
|
|||||||
|
|
||||||
public TikTokListenersManager(List<TikTokEventListener> listeners, TikTokEventObserver tikTokEventHandler) {
|
public TikTokListenersManager(List<TikTokEventListener> listeners, TikTokEventObserver tikTokEventHandler) {
|
||||||
this.eventObserver = tikTokEventHandler;
|
this.eventObserver = tikTokEventHandler;
|
||||||
this.bindingModels = listeners.stream().map(this::bindToEvents).toList();
|
this.bindingModels = new ArrayList<>(listeners.stream().map(this::bindToEvents).toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TikTokEventListener> getListeners() {
|
public List<TikTokEventListener> getListeners() {
|
||||||
return bindingModels.stream().map(ListenerBindingModel::getListener).toList();
|
return bindingModels.stream().map(ListenerBindingModel::getListener).toList();
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.mappers;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveRoomMeta;
|
||||||
|
|
||||||
|
public class LiveRoomMetaMapper implements Mapper<JsonObject, LiveRoomMeta>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public LiveRoomMeta mapFrom(JsonObject input) {
|
||||||
|
var liveRoomMeta = new LiveRoomMeta();
|
||||||
|
|
||||||
|
if (!input.has("data")) {
|
||||||
|
return liveRoomMeta;
|
||||||
|
}
|
||||||
|
var data = input.getAsJsonObject("data");
|
||||||
|
if (data.has("status")) {
|
||||||
|
var status = data.get("status");
|
||||||
|
liveRoomMeta.setStatus(status.getAsInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(data.has("age_restricted"))
|
||||||
|
{
|
||||||
|
var element = data.getAsJsonObject("age_restricted");
|
||||||
|
var restricted= element.get("restricted").getAsBoolean();
|
||||||
|
liveRoomMeta.setAgeRestricted(restricted);
|
||||||
|
}
|
||||||
|
return liveRoomMeta;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,2 @@
|
|||||||
github: [jwdeveloper]
|
|
||||||
patreon: jwdeveloper
|
patreon: jwdeveloper
|
||||||
custom: ["https://www.buymeacoffee.com/jwdev"]
|
custom: ["https://www.buymeacoffee.com/jwdev"]
|
||||||
|
|||||||
43
README.md
43
README.md
@@ -27,25 +27,25 @@ Do you prefer other programming languages?
|
|||||||
|
|
||||||
```xml
|
```xml
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>jitpack.io</id>
|
<id>jitpack.io</id>
|
||||||
<url>https://jitpack.io</url>
|
<url>https://jitpack.io</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<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>0.0.22-Release</version>
|
<version>0.0.23-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
<version>2.10.1</version>
|
<version>2.10.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Create your first chat connection
|
2. Create your first chat connection
|
||||||
@@ -119,9 +119,12 @@ public class ConfigurationExample {
|
|||||||
clientSettings.setRetryOnConnectionFailure(true); // Reconnecting if TikTok user is offline
|
clientSettings.setRetryOnConnectionFailure(true); // Reconnecting if TikTok user is offline
|
||||||
clientSettings.setRetryConnectionTimeout(Duration.ofSeconds(1)); // Timeout before next reconnection
|
clientSettings.setRetryConnectionTimeout(Duration.ofSeconds(1)); // Timeout before next reconnection
|
||||||
|
|
||||||
// Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId
|
//Optional: Sometimes not every message from chat are send to TikTokLiveJava to fix this issue you can set sessionId
|
||||||
// documentation how to obtain sessionId https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages
|
// documentation how to obtain sessionId https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages
|
||||||
clientSettings.setSessionId("86c3c8bf4b17ebb2d74bb7fa66fd0000");
|
clientSettings.setSessionId("86c3c8bf4b17ebb2d74bb7fa66fd0000");
|
||||||
|
|
||||||
|
//Optional:
|
||||||
|
clientSettings.setRoomId("XXXXXXXXXXXXXXXXX");
|
||||||
})
|
})
|
||||||
.buildAndRun();
|
.buildAndRun();
|
||||||
System.in.read();
|
System.in.read();
|
||||||
@@ -152,7 +155,7 @@ public class ListenerExample
|
|||||||
CustomListener customListener = new CustomListener();
|
CustomListener customListener = new CustomListener();
|
||||||
|
|
||||||
// set tiktok username
|
// set tiktok username
|
||||||
TikTokLive.newClient(Main.TEST_TIKTOK_USER)
|
var client = TikTokLive.newClient(Main.TEST_TIKTOK_USER)
|
||||||
.addListener(customListener)
|
.addListener(customListener)
|
||||||
.buildAndRun();
|
.buildAndRun();
|
||||||
|
|
||||||
|
|||||||
@@ -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>0.0.22-Release</version>
|
<version>0.0.23-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -21,9 +21,12 @@ public class ConfigurationExample {
|
|||||||
clientSettings.setRetryOnConnectionFailure(true); // Reconnecting if TikTok user is offline
|
clientSettings.setRetryOnConnectionFailure(true); // Reconnecting if TikTok user is offline
|
||||||
clientSettings.setRetryConnectionTimeout(Duration.ofSeconds(1)); // Timeout before next reconnection
|
clientSettings.setRetryConnectionTimeout(Duration.ofSeconds(1)); // Timeout before next reconnection
|
||||||
|
|
||||||
//Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId
|
//Optional: Sometimes not every message from chat are send to TikTokLiveJava to fix this issue you can set sessionId
|
||||||
// documentation how to obtain sessionId https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages
|
// documentation how to obtain sessionId https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages
|
||||||
clientSettings.setSessionId("86c3c8bf4b17ebb2d74bb7fa66fd0000");
|
clientSettings.setSessionId("86c3c8bf4b17ebb2d74bb7fa66fd0000");
|
||||||
|
|
||||||
|
//Optional:
|
||||||
|
clientSettings.setRoomId("XXXXXXXXXXXXXXXXX");
|
||||||
})
|
})
|
||||||
.buildAndRun();
|
.buildAndRun();
|
||||||
System.in.read();
|
System.in.read();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class ListenerExample
|
|||||||
CustomListener customListener = new CustomListener();
|
CustomListener customListener = new CustomListener();
|
||||||
|
|
||||||
// set tiktok username
|
// set tiktok username
|
||||||
TikTokLive.newClient(Main.TEST_TIKTOK_USER)
|
var client = TikTokLive.newClient(Main.TEST_TIKTOK_USER)
|
||||||
.addListener(customListener)
|
.addListener(customListener)
|
||||||
.buildAndRun();
|
.buildAndRun();
|
||||||
|
|
||||||
|
|||||||
@@ -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>0.0.22-Release</version>
|
<version>0.0.23-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -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>0.0.22-Release</version>
|
<version>0.0.23-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -35,5 +35,11 @@
|
|||||||
<version>0.0.7-Release</version>
|
<version>0.0.7-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.reflections</groupId>
|
||||||
|
<artifactId>reflections</artifactId>
|
||||||
|
<version>0.9.12</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -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>0.0.22-Release</version>
|
<version>0.0.23-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
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>0.0.22-Release</version>
|
<version>0.0.23-Release</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>API</module>
|
<module>API</module>
|
||||||
<module>Client</module>
|
<module>Client</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user