mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Changes:
LiveRoomInfo
+ new method getConnectionState() getting current state of connection
+ ListenersManager
getBindingModels() renamed to getListeners()
+ Introducing documentation, each public interface got small documentation
+ New property in config .setSessionId()
+ New event: onReconnecting()
Bugs:
CommentEvent was throwing mapping exception
This commit is contained in:
@@ -3,69 +3,75 @@ package io.github.jwdeveloper.tiktok;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@Data
|
||||
public class ClientSettings {
|
||||
/// <summary>
|
||||
/// Timeout for Connections
|
||||
/// </summary>
|
||||
/**
|
||||
* Timeout for Connections
|
||||
*/
|
||||
private Duration timeout;
|
||||
|
||||
// public RotatingProxy Proxy;
|
||||
/// <summary>
|
||||
/// ISO-Language for Client
|
||||
/// </summary>
|
||||
/**
|
||||
* ISO-Language for Client
|
||||
*/
|
||||
|
||||
private String clientLanguage;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to Retry if Connection Fails
|
||||
/// </summary>
|
||||
/**
|
||||
* Whether to Retry if Connection Fails
|
||||
*/
|
||||
private boolean retryOnConnectionFailure;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Wait to connect again for selected amount of time
|
||||
/// </summary>
|
||||
/**
|
||||
* Wait to connect again for selected amount of time
|
||||
*/
|
||||
private Duration retryConnectionTimeout;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to handle Messages received from Room when Connecting
|
||||
/// </summary>
|
||||
/**
|
||||
* Whether to handle Messages received from Room when Connecting
|
||||
*/
|
||||
private boolean handleExistingMessagesOnConnect;
|
||||
/// <summary>
|
||||
/// Whether to download List of Gifts for Room when Connecting
|
||||
/// </summary>
|
||||
/**
|
||||
* Whether to download List of Gifts for Room when Connecting
|
||||
*/
|
||||
private boolean downloadGiftInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to print Logs to Console
|
||||
/// </summary>
|
||||
/**
|
||||
* Whether to print Logs to Console
|
||||
*/
|
||||
|
||||
private boolean printToConsole;
|
||||
/// <summary>
|
||||
/// LoggingLevel for Logs
|
||||
/// </summary>
|
||||
/**
|
||||
* LoggingLevel for Logs
|
||||
*/
|
||||
private Level logLevel;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to print Base64-Data for Messages to Console
|
||||
/// </summary>
|
||||
/**
|
||||
* Whether to print Base64-Data for Messages to Console
|
||||
*/
|
||||
private boolean printMessageData;
|
||||
|
||||
/// <summary>
|
||||
/// Tiktok user name
|
||||
/// </summary>
|
||||
/**
|
||||
* Tiktok user name
|
||||
*/
|
||||
private String hostName;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Parameters used in requests to tiktok api
|
||||
/// </summary>
|
||||
/**
|
||||
* Parameters used in requests to Tiktok api
|
||||
*/
|
||||
private Map<String, Object> clientParameters;
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
private String sessionId;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -8,33 +8,32 @@ import java.util.logging.Level;
|
||||
|
||||
public class Constants {
|
||||
|
||||
/// <summary>
|
||||
/// Web-URL for TikTok
|
||||
/// </summary>
|
||||
/**
|
||||
* Web-URL for TikTok
|
||||
*/
|
||||
public static final String TIKTOK_URL_WEB = "https://www.tiktok.com/";
|
||||
/// <summary>
|
||||
/// WebCast-BaseURL for TikTok
|
||||
/// </summary>
|
||||
/**
|
||||
* WebCast-BaseURL for TikTok
|
||||
*/
|
||||
public static final String TIKTOK_URL_WEBCAST = "https://webcast.tiktok.com/webcast/";
|
||||
/// <summary>
|
||||
/// Signing API by Isaac Kogan
|
||||
/// https://github-wiki-see.page/m/isaackogan/TikTokLive/wiki/All-About-Signatures
|
||||
/// </summary>
|
||||
/**
|
||||
* Signing API by Isaac Kogan
|
||||
* https://github-wiki-see.page/m/isaackogan/TikTokLive/wiki/All-About-Signatures
|
||||
*/
|
||||
public static final String TIKTOK_SIGN_API = "https://tiktok.eulerstream.com/webcast/sign_url";
|
||||
|
||||
/// <summary>
|
||||
/// Default TimeOut for Connections
|
||||
/// </summary>
|
||||
/**
|
||||
* Default TimeOut for Connections
|
||||
*/
|
||||
public static final int DEFAULT_TIMEOUT = 20;
|
||||
/// <summary>
|
||||
/// Default Polling-Time for Socket-Connection
|
||||
/// </summary>
|
||||
/**
|
||||
* Default Polling-Time for Socket-Connection
|
||||
*/
|
||||
public static final int DEFAULT_POLLTIME = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Default Settings for Client
|
||||
/// </summary>
|
||||
|
||||
/**
|
||||
* Default Settings for Client
|
||||
*/
|
||||
|
||||
|
||||
public static ClientSettings DefaultClientSettings() {
|
||||
@@ -53,15 +52,13 @@ public class Constants {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default Parameters for HTTP-Request
|
||||
*/
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Default Parameters for HTTP-Request
|
||||
/// </summary>
|
||||
|
||||
|
||||
public static Map<String,Object> DefaultClientParams() {
|
||||
var clientParams = new TreeMap<String,Object>();
|
||||
public static Map<String, Object> DefaultClientParams() {
|
||||
var clientParams = new TreeMap<String, Object>();
|
||||
clientParams.put("aid", 1988);
|
||||
clientParams.put("app_language", "en-US");
|
||||
clientParams.put("app_name", "tiktok_web");
|
||||
@@ -100,11 +97,11 @@ public class Constants {
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Default Headers for HTTP-Request
|
||||
/// </summary>
|
||||
public static Map<String,String> DefaultRequestHeaders() {
|
||||
var headers = new HashMap<String,String>();
|
||||
/**
|
||||
* Default Headers for HTTP-Request
|
||||
*/
|
||||
public static Map<String, String> DefaultRequestHeaders() {
|
||||
var headers = new HashMap<String, String>();
|
||||
|
||||
headers.put("Connection", "keep-alive");
|
||||
headers.put("Cache-Control", "max-age=0");
|
||||
|
||||
@@ -7,7 +7,6 @@ import io.github.jwdeveloper.tiktok.events.objects.Picture;
|
||||
import io.github.jwdeveloper.tiktok.events.objects.User;
|
||||
import io.github.jwdeveloper.tiktok.messages.WebcastChatMessage;
|
||||
import io.github.jwdeveloper.tiktok.messages.WebcastRoomPinMessage;
|
||||
import lombok.Getter;
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -16,11 +15,11 @@ import java.util.List;
|
||||
@Value
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokCommentEvent extends TikTokHeaderEvent {
|
||||
User user;
|
||||
String text;
|
||||
String language;
|
||||
List<User> mentionedUsers;
|
||||
List<Picture> pictures;
|
||||
User user;
|
||||
String text;
|
||||
String language;
|
||||
List<User> mentionedUsers;
|
||||
List<Picture> pictures;
|
||||
|
||||
public TikTokCommentEvent(WebcastRoomPinMessage.RoomPinMessageData data) {
|
||||
super(data.getDetails().getRoomId(), data.getDetails().getMessageId(), data.getDetails().getServerTime());
|
||||
@@ -32,11 +31,11 @@ public class TikTokCommentEvent extends TikTokHeaderEvent {
|
||||
}
|
||||
|
||||
public TikTokCommentEvent(WebcastChatMessage msg) {
|
||||
super(msg.getHeader());
|
||||
user = User.MapOrEmpty(msg.getSender());
|
||||
text = msg.getComment();
|
||||
language = msg.getLanguage();
|
||||
mentionedUsers = msg.getMentionedUsersList().stream().map(User::new).toList();
|
||||
pictures = msg.getImagesList().stream().map(e -> new Picture(e.getImage())).toList();
|
||||
super(msg.getCommon());
|
||||
user = User.MapOrEmpty(msg.getUser());
|
||||
text = msg.getContent();
|
||||
language = msg.getContentLanguage();
|
||||
mentionedUsers = List.of(User.MapOrEmpty(msg.getAtUser()));
|
||||
pictures = msg.getEmotesListList().stream().map(e -> new Picture(e.getEmote().getImage())).toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import lombok.Getter;
|
||||
@EventMeta(eventType = EventType.Custom)
|
||||
public class TikTokJoinEvent extends TikTokHeaderEvent {
|
||||
private User user;
|
||||
|
||||
private final Long totalViewers;
|
||||
|
||||
public TikTokJoinEvent(WebcastSocialMessage msg) {
|
||||
|
||||
@@ -2,9 +2,15 @@ package io.github.jwdeveloper.tiktok.listener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* You can dynamically add or removing TikTokEventListener
|
||||
*
|
||||
* @see TikTokEventListener
|
||||
*
|
||||
*/
|
||||
public interface ListenersManager
|
||||
{
|
||||
List<TikTokEventListener> getBindingModels();
|
||||
List<TikTokEventListener> getListeners();
|
||||
void addListener(TikTokEventListener listener);
|
||||
|
||||
void removeListener(TikTokEventListener listener);
|
||||
|
||||
@@ -1,5 +1,51 @@
|
||||
package io.github.jwdeveloper.tiktok.listener;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @see ListenersManager
|
||||
*
|
||||
* TikTokEventListener is an alternative way of handing TikTok events.
|
||||
*
|
||||
* TikTokLive.newClient("someuser").addListener(listener)
|
||||
*
|
||||
* After registertion all listeners are kept in Listener manager
|
||||
* that could be obtained by client.getListenerManager();
|
||||
*
|
||||
* Method in TikTokEventListener should meet 4 requirements to be detected
|
||||
* - must have @TikTokEventHandler annotation
|
||||
* - must have 2 parameters
|
||||
* - first parameter must be LiveClient
|
||||
* - second must be class that extending TikTokEvent
|
||||
*
|
||||
* public static class CustomListener implements TikTokEventListener
|
||||
* {
|
||||
* @TikTokEventHandler
|
||||
* public void onError(LiveClient liveClient, TikTokErrorEvent event)
|
||||
* {
|
||||
* System.out.println(event.getException().getMessage());
|
||||
* }
|
||||
*
|
||||
* @TikTokEventHandler
|
||||
* public void onCommentMessage(LiveClient liveClient, TikTokCommentEvent event)
|
||||
* {
|
||||
* System.out.println(event.getText());
|
||||
* }
|
||||
*
|
||||
* @TikTokEventHandler
|
||||
* public void onGiftMessage(LiveClient liveClient, TikTokGiftMessageEvent event)
|
||||
* {
|
||||
* System.out.println(event.getGift().getDescription());
|
||||
* }
|
||||
*
|
||||
* @TikTokEventHandler
|
||||
* public void onAnyEvent(LiveClient liveClient, TikTokEvent event)
|
||||
* {
|
||||
* System.out.println(event.getClass().getSimpleName());
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public interface TikTokEventListener
|
||||
{
|
||||
|
||||
|
||||
@@ -6,9 +6,25 @@ import io.github.jwdeveloper.tiktok.models.gifts.TikTokGiftInfo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface GiftManager
|
||||
{
|
||||
Map<Integer, TikTokGiftInfo> getGiftsInfo();
|
||||
public interface GiftManager {
|
||||
|
||||
Map<GiftId, TikTokGift> getActiveGifts();
|
||||
/**
|
||||
* Meta information about all TikTok available gifts such as, name, id, description, cost, etc
|
||||
* TikTokGiftInfos are downloaded only if `clientSettings.setDownloadGiftInfo(true);`
|
||||
*
|
||||
* @return map of metainformations about gitfts where Integer is Gift Id and TikTokGiftInfo is gift data
|
||||
* @see TikTokGiftInfo
|
||||
*/
|
||||
Map<Integer, TikTokGiftInfo> getGiftsInfo();
|
||||
|
||||
|
||||
/**
|
||||
* Active Gifts are updated after TikTokGiftMessageEvent. This map contains gifts that
|
||||
* recently send to host and have active strike
|
||||
*
|
||||
* @return map of active gifts
|
||||
* @see TikTokGift
|
||||
* @see io.github.jwdeveloper.tiktok.events.messages.TikTokGiftMessageEvent
|
||||
*/
|
||||
Map<GiftId, TikTokGift> getActiveGifts();
|
||||
}
|
||||
|
||||
@@ -1,19 +1,34 @@
|
||||
package io.github.jwdeveloper.tiktok.live;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.listener.ListenersManager;
|
||||
import io.github.jwdeveloper.tiktok.listener.TikTokEventListener;
|
||||
|
||||
public interface LiveClient {
|
||||
|
||||
// Connects to the live stream.
|
||||
/**
|
||||
* Connects to the live stream.
|
||||
*/
|
||||
void connect();
|
||||
|
||||
// Disconnects the connection.
|
||||
/**
|
||||
* Disconnects the connection.
|
||||
*/
|
||||
void disconnect();
|
||||
|
||||
// Gets the meta information about all gifts.
|
||||
|
||||
/**
|
||||
* Get information about gifts
|
||||
*/
|
||||
GiftManager getGiftManager();
|
||||
|
||||
// Gets the current room info from TikTok API including streamer info, room status and statistics.
|
||||
/**
|
||||
* Gets the current room info from TikTok API including streamer info, room status and statistics.
|
||||
*/
|
||||
LiveRoomInfo getRoomInfo();
|
||||
|
||||
/**
|
||||
* Manage TikTokEventListener
|
||||
* @see TikTokEventListener
|
||||
*/
|
||||
ListenersManager getListenersManager();
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ public interface LiveRoomInfo
|
||||
int getViewersCount();
|
||||
String getRoomId();
|
||||
String getUserName();
|
||||
ConnectionState getConnectionState();
|
||||
}
|
||||
|
||||
@@ -1348,19 +1348,57 @@ message ModerationData {
|
||||
|
||||
// Comment sent by User
|
||||
message WebcastChatMessage {
|
||||
MessageHeader header = 1;
|
||||
User sender = 2; // User who sent message
|
||||
string comment = 3; // Text for Chat-Message
|
||||
uint64 data1 = 11;
|
||||
repeated User mentionedUsers = 12; // Users mentioned in comment
|
||||
repeated ChatImage images = 13;
|
||||
string language = 14; // Language for sender
|
||||
DataContainer chatData = 18;
|
||||
repeated ModerationData moderationData = 19;
|
||||
Common common = 1;
|
||||
User user = 2;
|
||||
string content = 3;
|
||||
bool visibleToSender = 4;
|
||||
Image backgroundImage = 5;
|
||||
string fullScreenTextColor = 6;
|
||||
Image backgroundImageV2 = 7;
|
||||
Image giftImage = 10;
|
||||
int32 inputType = 11;
|
||||
User atUser = 12;
|
||||
repeated EmoteWithIndex emotesList = 13;
|
||||
string contentLanguage = 14;
|
||||
int32 quickChatScene = 16;
|
||||
int32 communityFlaggedStatus = 17;
|
||||
|
||||
message ChatImage {
|
||||
uint64 data1 = 1;
|
||||
Image Image = 2;
|
||||
// @EmoteWithIndex
|
||||
// proto.webcast.im.ChatMessage
|
||||
// C:\Users\ja\RiderProjects\TikTokProBufferGenerator\Application\output\sources\test.js
|
||||
message EmoteWithIndex {
|
||||
int64 index = 1;
|
||||
Emote emote = 2;
|
||||
}
|
||||
|
||||
message Emote {
|
||||
string emoteId = 1;
|
||||
Image image = 2;
|
||||
AuditStatus auditStatus = 3; // Enum
|
||||
string uuid = 4;
|
||||
EmoteType emoteType = 5; // Enum
|
||||
ContentSource contentSource = 6; // Enum
|
||||
EmotePrivateType emotePrivateType = 7; // Enum
|
||||
}
|
||||
enum AuditStatus {
|
||||
AUDITSTATUSUNKNOWN = 0;
|
||||
AUDITSTATUSPASS = 1;
|
||||
AUDITSTATUSFAILED = 2;
|
||||
AUDITSTATUSREVIEWING = 3;
|
||||
AUDITSTATUSFORBIDDEN = 4;
|
||||
}
|
||||
enum EmoteType {
|
||||
EMOTETYPENORMAL = 0;
|
||||
EMOTETYPEWITHSTICKER = 1;
|
||||
}
|
||||
enum ContentSource {
|
||||
CONTENTSOURCEUNKNOWN = 0;
|
||||
CONTENTSOURCENORMAL = 1;
|
||||
CONTENTSOURCECAMERA = 2;
|
||||
}
|
||||
enum EmotePrivateType {
|
||||
EMOTE_PRIVATE_TYPE_NORMAL = 0;
|
||||
EMOTE_PRIVATE_TYPE_SUB_WAVE = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user