mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Compare commits
71 Commits
develop-1.
...
1.8.1-Rele
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b17c33236 | ||
|
|
b59373254c | ||
|
|
5524d9f8c4 | ||
|
|
aa56f8eaea | ||
|
|
e40bde8e7c | ||
|
|
b769eb9c1f | ||
|
|
3e555a502a | ||
|
|
316868818b | ||
|
|
36475c2cf6 | ||
|
|
2dbe81278c | ||
|
|
91fc32b20b | ||
|
|
fa855fa3aa | ||
|
|
cfea12dacc | ||
|
|
16cd819aaf | ||
|
|
290a4970fd | ||
|
|
660cb287e9 | ||
|
|
f5de7720cd | ||
|
|
f986efd2d5 | ||
|
|
1054453451 | ||
|
|
7005f58edd | ||
|
|
63672fe9eb | ||
|
|
fed9de3fd0 | ||
|
|
b223651a8f | ||
|
|
8d715d4f50 | ||
|
|
1736236ccf | ||
|
|
85d99ce4f1 | ||
|
|
87727070e9 | ||
|
|
71f744cf49 | ||
|
|
046d5f1756 | ||
|
|
c36b0f1f62 | ||
|
|
a2082ebee3 | ||
|
|
412c72c119 | ||
|
|
6728fd9963 | ||
|
|
47493d4955 | ||
|
|
4d4317d96c | ||
|
|
b1954a708c | ||
|
|
14317337e9 | ||
|
|
947c9c49a2 | ||
|
|
f2bd07377b | ||
|
|
3f268f3a1a | ||
|
|
55fcf83870 | ||
|
|
8d3828cca8 | ||
|
|
1c88491b8c | ||
|
|
47b050d0ba | ||
|
|
cfef082d3b | ||
|
|
34ddc74189 | ||
|
|
9a66d240bc | ||
|
|
d825803187 | ||
|
|
77c9cd6b52 | ||
|
|
0329d3cfeb | ||
|
|
26659bb37d | ||
|
|
0b9852c4d4 | ||
|
|
31618a16ba | ||
|
|
243791f6b8 | ||
|
|
4f74a0f1b7 | ||
|
|
d1eec34fca | ||
|
|
82196ef8e3 | ||
|
|
8685d96ccf | ||
|
|
69f1d5b5c2 | ||
|
|
6f322b2a46 | ||
|
|
73c4c09ea1 | ||
|
|
95e357af92 | ||
|
|
6b31ec7d80 | ||
|
|
919554bbc8 | ||
|
|
bd0a1f0d01 | ||
|
|
f48479a92c | ||
|
|
68a86f3dbd | ||
|
|
c3a7a27948 | ||
|
|
af52e15a45 | ||
|
|
5577df7c9c | ||
|
|
2c68fe3421 |
@@ -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.6.1-Release</version>
|
<version>1.8.0-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.annotations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HIGHEST 1
|
||||||
|
* HIGH 2
|
||||||
|
* NORMAL 3
|
||||||
|
* LOW 4
|
||||||
|
* LOWEST 5
|
||||||
|
*/
|
||||||
|
public enum Priority {
|
||||||
|
LOWEST(2), LOW(1), NORMAL(0), HIGH(-1), HIGHEST(-2);
|
||||||
|
|
||||||
|
public final int value;
|
||||||
|
|
||||||
|
Priority(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,5 +28,14 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface TikTokEventObserver
|
public @interface TikTokEventObserver
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* When more than one method listen for certain Event, you can specify the method priority
|
||||||
|
* @see Priority
|
||||||
|
*/
|
||||||
|
Priority priority() default Priority.NORMAL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When true, action is invoked on a thread, from the threads pool
|
||||||
|
*/
|
||||||
|
boolean async() default false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,16 +50,12 @@ public class ProxyData
|
|||||||
|
|
||||||
return new ProxyData(address, port);
|
return new ProxyData(address, port);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new IllegalArgumentException("Port must be a valid integer!");
|
throw new IllegalArgumentException("Port must be a valid integer!", e);
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
throw new IllegalArgumentException("Address must be valid IPv4, IPv6, or domain name!");
|
throw new IllegalArgumentException("Address must be valid IPv4, IPv6, or domain name!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyData clone() {
|
|
||||||
return new ProxyData(address, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
public InetSocketAddress toSocketAddress() {
|
public InetSocketAddress toSocketAddress() {
|
||||||
return new InetSocketAddress(address, port);
|
return new InetSocketAddress(address, port);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ public class TikTokBarrageEvent extends TikTokHeaderEvent {
|
|||||||
private final Picture rightIcon;
|
private final Picture rightIcon;
|
||||||
private final String eventName;
|
private final String eventName;
|
||||||
private final int duration;
|
private final int duration;
|
||||||
|
private final BarrageParam barrageParam;
|
||||||
private BarrageParam barrageParam;
|
|
||||||
|
|
||||||
public TikTokBarrageEvent(WebcastBarrageMessage msg) {
|
public TikTokBarrageEvent(WebcastBarrageMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
@@ -49,6 +48,5 @@ public class TikTokBarrageEvent extends TikTokHeaderEvent {
|
|||||||
rightIcon = Picture.map(msg.getRightIcon());
|
rightIcon = Picture.map(msg.getRightIcon());
|
||||||
duration = msg.getDuration();
|
duration = msg.getDuration();
|
||||||
barrageParam = BarrageParam.map(msg);
|
barrageParam = BarrageParam.map(msg);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,15 +32,13 @@ import lombok.Getter;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered every time a new chat comment arrives.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokCommentEvent extends TikTokHeaderEvent {
|
public class TikTokCommentEvent extends TikTokHeaderEvent {
|
||||||
private final User user;
|
private final User user;
|
||||||
private final String text;
|
private final String text;
|
||||||
private final String getUserLanguage;
|
private final String userLanguage;
|
||||||
private final User mentionedUser;
|
private final User mentionedUser;
|
||||||
private final List<Picture> pictures;
|
private final List<Picture> pictures;
|
||||||
private final boolean visibleToSender;
|
private final boolean visibleToSender;
|
||||||
@@ -50,7 +48,7 @@ public class TikTokCommentEvent extends TikTokHeaderEvent {
|
|||||||
user = User.map(msg.getUser(), msg.getUserIdentity());
|
user = User.map(msg.getUser(), msg.getUserIdentity());
|
||||||
text = msg.getContent();
|
text = msg.getContent();
|
||||||
visibleToSender = msg.getVisibleToSender();
|
visibleToSender = msg.getVisibleToSender();
|
||||||
getUserLanguage = msg.getContentLanguage();
|
userLanguage = msg.getContentLanguage();
|
||||||
mentionedUser = User.map(msg.getAtUser());
|
mentionedUser = User.map(msg.getAtUser());
|
||||||
pictures = msg.getEmotesListList().stream().map(e -> Picture.map(e.getEmote().getImage())).toList();
|
pictures = msg.getEmotesListList().stream().map(e -> Picture.map(e.getEmote().getImage())).toList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,9 +25,6 @@ import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
|||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when the connection is successfully established.
|
|
||||||
*/
|
|
||||||
@EventMeta(eventType = EventType.Control)
|
@EventMeta(eventType = EventType.Control)
|
||||||
public class TikTokConnectedEvent extends TikTokLiveClientEvent
|
public class TikTokConnectedEvent extends TikTokLiveClientEvent
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,14 +30,10 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokDetectEvent extends TikTokHeaderEvent {
|
public class TikTokDetectEvent extends TikTokHeaderEvent {
|
||||||
String language;
|
private final String language;
|
||||||
|
|
||||||
|
|
||||||
public TikTokDetectEvent(WebcastMsgDetectMessage msg) {
|
public TikTokDetectEvent(WebcastMsgDetectMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
language = msg.getFromRegion();
|
language = msg.getFromRegion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -26,13 +26,12 @@ import io.github.jwdeveloper.tiktok.annotations.EventType;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when the connection gets disconnected. In that case you can call connect() again to have a reconnect logic.
|
@Getter
|
||||||
* Note that you should wait a little bit before attempting a reconnect to to avoid being rate-limited.
|
|
||||||
*/
|
|
||||||
@EventMeta(eventType = EventType.Control)
|
@EventMeta(eventType = EventType.Control)
|
||||||
public class TikTokDisconnectedEvent extends TikTokLiveClientEvent {
|
public class TikTokDisconnectedEvent extends TikTokLiveClientEvent {
|
||||||
@Getter private final String reason;
|
private final String reason;
|
||||||
|
|
||||||
public TikTokDisconnectedEvent(String reason) {
|
public TikTokDisconnectedEvent(String reason) {
|
||||||
this.reason = reason.isBlank() ? "None" : reason;
|
this.reason = reason.isBlank() ? "None" : reason;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,9 +28,6 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
|
||||||
* General error event. You should handle this.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EventMeta(eventType = EventType.Control)
|
@EventMeta(eventType = EventType.Control)
|
||||||
|
|||||||
@@ -34,9 +34,10 @@ import java.util.List;
|
|||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokIMDeleteEvent extends TikTokHeaderEvent {
|
public class TikTokIMDeleteEvent extends TikTokHeaderEvent {
|
||||||
|
|
||||||
List<Long> userIds;
|
private final List<Long> msgIds, userIds;
|
||||||
public TikTokIMDeleteEvent(WebcastImDeleteMessage msg) {
|
public TikTokIMDeleteEvent(WebcastImDeleteMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
|
this.msgIds = msg.getDeleteMsgIdsListList();
|
||||||
this.userIds = msg.getDeleteUserIdsListList();
|
this.userIds = msg.getDeleteUserIdsListList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,11 +33,7 @@ import lombok.Getter;
|
|||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLinkLayerEvent extends TikTokHeaderEvent {
|
public class TikTokLinkLayerEvent extends TikTokHeaderEvent {
|
||||||
|
|
||||||
|
|
||||||
public TikTokLinkLayerEvent(WebcastLinkLayerMessage msg) {
|
public TikTokLinkLayerEvent(WebcastLinkLayerMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -43,8 +43,6 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
|||||||
true if battle is finished otherwise false
|
true if battle is finished otherwise false
|
||||||
*/
|
*/
|
||||||
private final boolean finished;
|
private final boolean finished;
|
||||||
@Getter(AccessLevel.NONE)
|
|
||||||
private final boolean oneVsOne;
|
|
||||||
private final List<Team> teams;
|
private final List<Team> teams;
|
||||||
|
|
||||||
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
||||||
@@ -55,7 +53,6 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
|||||||
if (msg.getHostTeamCount() == 2) { // 1v1 battle
|
if (msg.getHostTeamCount() == 2) { // 1v1 battle
|
||||||
teams.add(new Team1v1(msg.getHostTeam(0), msg));
|
teams.add(new Team1v1(msg.getHostTeam(0), msg));
|
||||||
teams.add(new Team1v1(msg.getHostTeam(1), msg));
|
teams.add(new Team1v1(msg.getHostTeam(1), msg));
|
||||||
oneVsOne = true;
|
|
||||||
} else { // 2v2 battle
|
} else { // 2v2 battle
|
||||||
if (isFinished()) {
|
if (isFinished()) {
|
||||||
teams.add(new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 1).findFirst().orElse(null), msg));
|
teams.add(new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 1).findFirst().orElse(null), msg));
|
||||||
@@ -64,7 +61,6 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
|||||||
teams.add(new Team2v2(msg.getHostTeam(0), msg.getHostTeam(1), msg));
|
teams.add(new Team2v2(msg.getHostTeam(0), msg.getHostTeam(1), msg));
|
||||||
teams.add(new Team2v2(msg.getHostTeam(2), msg.getHostTeam(3), msg));
|
teams.add(new Team2v2(msg.getHostTeam(2), msg.getHostTeam(3), msg));
|
||||||
}
|
}
|
||||||
oneVsOne = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info:
|
// Info:
|
||||||
@@ -74,10 +70,14 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean is1v1() {
|
public boolean is1v1() {
|
||||||
return oneVsOne;
|
return teams.get(0) instanceof Team1v1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean is2v2() {
|
public boolean is2v2() {
|
||||||
return !oneVsOne;
|
return teams.get(0) instanceof Team2v2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTie() {
|
||||||
|
return isFinished() && teams.get(0).getTotalPoints() == teams.get(1).getTotalPoints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,6 +36,4 @@ public class TikTokLinkMicMethodEvent extends TikTokHeaderEvent {
|
|||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -26,9 +26,7 @@ import io.github.jwdeveloper.tiktok.annotations.EventType;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when the live stream gets terminated by the host. Will also trigger the TikTokDisconnectedEvent event.
|
|
||||||
*/
|
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLiveEndedEvent extends TikTokEvent {
|
public class TikTokLiveEndedEvent extends TikTokEvent {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,7 @@ import io.github.jwdeveloper.tiktok.data.models.users.User;
|
|||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastQuestionNewMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastQuestionNewMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/*
|
|
||||||
Triggered every time someone asks a new question via the question feature.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokQuestionEvent extends TikTokHeaderEvent {
|
public class TikTokQuestionEvent extends TikTokHeaderEvent {
|
||||||
|
|||||||
@@ -42,5 +42,4 @@ public class TikTokRankTextEvent extends TikTokHeaderEvent {
|
|||||||
label = text.getPattern();
|
label = text.getPattern();
|
||||||
eventType = text.getKey();
|
eventType = text.getKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -35,11 +35,9 @@ public class TikTokRankUpdateEvent extends TikTokHeaderEvent {
|
|||||||
|
|
||||||
public TikTokRankUpdateEvent(WebcastHourlyRankMessage msg) {
|
public TikTokRankUpdateEvent(WebcastHourlyRankMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokRankUpdateEvent(WebcastRankUpdateMessage msg) {
|
public TikTokRankUpdateEvent(WebcastRankUpdateMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -52,5 +52,4 @@ public class TikTokShopEvent extends TikTokHeaderEvent {
|
|||||||
shopUrl = data.getShopUrl();
|
shopUrl = data.getShopUrl();
|
||||||
shopName = data.getShopName();
|
shopName = data.getShopName();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -31,9 +31,7 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastMemberMessage;
|
|||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSubNotifyMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSubNotifyMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers when a user creates a subscription.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokSubscribeEvent extends TikTokHeaderEvent {
|
public class TikTokSubscribeEvent extends TikTokHeaderEvent {
|
||||||
|
|||||||
@@ -26,9 +26,6 @@ package io.github.jwdeveloper.tiktok.data.events.common;
|
|||||||
import io.github.jwdeveloper.tiktok.utils.JsonUtil;
|
import io.github.jwdeveloper.tiktok.utils.JsonUtil;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class for all events
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
public abstract class TikTokEvent {
|
public abstract class TikTokEvent {
|
||||||
|
|
||||||
|
|||||||
@@ -27,15 +27,14 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
|||||||
import io.github.jwdeveloper.tiktok.data.requests.*;
|
import io.github.jwdeveloper.tiktok.data.requests.*;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered before the connection is established.
|
@Getter
|
||||||
*/
|
|
||||||
@EventMeta(eventType = EventType.Control)
|
@EventMeta(eventType = EventType.Control)
|
||||||
public class TikTokPreConnectionEvent extends TikTokLiveClientEvent
|
public class TikTokPreConnectionEvent extends TikTokLiveClientEvent
|
||||||
{
|
{
|
||||||
@Getter private final LiveUserData.Response userData;
|
private final LiveUserData.Response userData;
|
||||||
@Getter private final LiveData.Response roomData;
|
private final LiveData.Response roomData;
|
||||||
@Getter @Setter boolean cancelConnection = false;
|
@Setter boolean cancelConnection = false;
|
||||||
|
|
||||||
public TikTokPreConnectionEvent(LiveUserData.Response userData, LiveData.Response liveData) {
|
public TikTokPreConnectionEvent(LiveUserData.Response userData, LiveData.Response liveData) {
|
||||||
this.userData = userData;
|
this.userData = userData;
|
||||||
|
|||||||
@@ -29,20 +29,6 @@ import io.github.jwdeveloper.tiktok.data.models.users.User;
|
|||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered every time gift is sent
|
|
||||||
*
|
|
||||||
* @see GiftComboStateType it has 3 states
|
|
||||||
*
|
|
||||||
* <p>Example when user sends gift with combo</p>
|
|
||||||
* <p>>Combo: 1 -> comboState = GiftSendType.Begin</p>
|
|
||||||
* <p>Combo: 4 -> comboState = GiftSendType.Active</p>
|
|
||||||
* <p>Combo: 8 -> comboState = GiftSendType.Active</p>
|
|
||||||
* <p>Combo: 12 -> comboState = GiftSendType.Finsihed</p>
|
|
||||||
* <p>
|
|
||||||
* Remember if comboState is Finsihed both TikTokGiftComboEvent and TikTokGiftEvent event gets triggered
|
|
||||||
*/
|
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
@Getter
|
@Getter
|
||||||
public class TikTokGiftComboEvent extends TikTokGiftEvent {
|
public class TikTokGiftComboEvent extends TikTokGiftEvent {
|
||||||
@@ -57,10 +43,7 @@ public class TikTokGiftComboEvent extends TikTokGiftEvent {
|
|||||||
return new TikTokGiftComboEvent(
|
return new TikTokGiftComboEvent(
|
||||||
gift,
|
gift,
|
||||||
new User(0L, "Test", new Picture("")),
|
new User(0L, "Test", new Picture("")),
|
||||||
WebcastGiftMessage
|
WebcastGiftMessage.newBuilder().setComboCount(combo).build(),
|
||||||
.newBuilder()
|
|
||||||
.setComboCount(combo)
|
|
||||||
.build(),
|
|
||||||
comboState);
|
comboState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.events.gift;
|
package io.github.jwdeveloper.tiktok.data.events.gift;
|
||||||
|
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
@@ -31,12 +30,6 @@ import io.github.jwdeveloper.tiktok.data.models.users.User;
|
|||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when user sends gifts that has
|
|
||||||
* no combo (most of expensive gifts)
|
|
||||||
* or if combo has finished
|
|
||||||
*/
|
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
@Getter
|
@Getter
|
||||||
public class TikTokGiftEvent extends TikTokHeaderEvent {
|
public class TikTokGiftEvent extends TikTokHeaderEvent {
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkAcceptNoticeEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long fromUserId, fromRoomId, toUserId;
|
||||||
|
|
||||||
|
public TikTokLinkAcceptNoticeEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasAcceptNoticeContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Accept Notice Content!");
|
||||||
|
|
||||||
|
var content = msg.getAcceptNoticeContent();
|
||||||
|
this.fromUserId = content.getFromUserId();
|
||||||
|
this.fromRoomId = content.getFromRoomId();
|
||||||
|
this.toUserId = content.getToUserId();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,18 +20,17 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
import lombok.Value;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
@Value
|
@Getter
|
||||||
public class EnumValue
|
@EventMeta(eventType = EventType.Message)
|
||||||
{
|
public class TikTokLinkApplyEvent extends TikTokLinkEvent {
|
||||||
public int value;
|
|
||||||
public String name;
|
|
||||||
|
|
||||||
public static EnumValue Map(Enum<?> _enum)
|
public TikTokLinkApplyEvent(WebcastLinkMessage msg) {
|
||||||
{
|
super(msg);
|
||||||
return new EnumValue(_enum.ordinal() ,_enum.name());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,36 +20,27 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.common;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkCancelEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
import java.io.IOException;
|
private final long fromUserId, toUserId, cancelType, actionId;
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
public class TikTokBaseTest
|
public TikTokLinkCancelEvent(WebcastLinkMessage msg) {
|
||||||
{
|
super(msg);
|
||||||
public byte[] getFileBytes(String path)
|
if (!msg.hasCancelContent())
|
||||||
{
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Cancel Content!");
|
||||||
try {
|
|
||||||
var stream = getClass().getClassLoader().getResourceAsStream(path);
|
var content = msg.getCancelContent();
|
||||||
var bytes= stream.readAllBytes();
|
this.fromUserId = content.getFromUserId();
|
||||||
stream.close();
|
this.toUserId = content.getToUserId();
|
||||||
return bytes;
|
this.cancelType = content.getCancelType();
|
||||||
} catch (IOException e) {
|
this.actionId = content.getActionId();
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getFileBytesUtf(String path)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
var stream = getClass().getClassLoader().getResourceAsStream(path);
|
|
||||||
var bytes= stream.readAllBytes();
|
|
||||||
stream.close();
|
|
||||||
return Base64.getDecoder().decode(bytes);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,24 +20,20 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.gifts;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.GiftOld;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.mockito.InjectMocks;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
|
||||||
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
|
||||||
|
|
||||||
public class TikTokGiftManagerTest {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkCloseEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
public TikTokLinkCloseEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
// if (!msg.hasCloseContent())
|
||||||
|
// throw new IllegalArgumentException("Expected WebcastLinkMessage with Close Content!");
|
||||||
|
// Proto Empty
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkCohostListChangeEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
public TikTokLinkCohostListChangeEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
// if (!msg.hasCohostListChangeContent())
|
||||||
|
// throw new IllegalArgumentException("Expected WebcastLinkMessage with Cohost List Change Content!");
|
||||||
|
// Proto Empty
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkCreateEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long hostId, roomId, linkType;
|
||||||
|
public TikTokLinkCreateEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasCreateContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Create Content!");
|
||||||
|
|
||||||
|
var content = msg.getCreateContent();
|
||||||
|
this.hostId = content.getOwnerId();
|
||||||
|
this.roomId = content.getOwnerRoomId();
|
||||||
|
this.linkType = content.getLinkType();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.ListUser;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkEnterEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final List<ListUser> listUsers;
|
||||||
|
private final int anchorMultiLiveEnum;
|
||||||
|
|
||||||
|
public TikTokLinkEnterEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasEnterContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Enter Content!");
|
||||||
|
|
||||||
|
var content = msg.getEnterContent();
|
||||||
|
this.listUsers = content.getLinkedUsersListList().stream().map(ListUser::map).toList();
|
||||||
|
this.anchorMultiLiveEnum = content.getAnchorMultiLiveEnum();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,24 +20,24 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.events;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLinkEvent extends TikTokHeaderEvent {
|
public class TikTokLinkEvent extends TikTokHeaderEvent {
|
||||||
|
|
||||||
|
private final String extra, transferExtra;
|
||||||
|
private final long expireTimestamp;
|
||||||
|
|
||||||
public TikTokLinkEvent(WebcastLinkMessage msg) {
|
public TikTokLinkEvent(WebcastLinkMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
|
this.extra = msg.getExtra();
|
||||||
|
this.expireTimestamp = msg.getExpireTimestamp();
|
||||||
|
this.transferExtra = msg.getTransferExtra();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkInviteEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long roomId;
|
||||||
|
private final User inviter;
|
||||||
|
|
||||||
|
public TikTokLinkInviteEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasInviteContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Invite Content!");
|
||||||
|
|
||||||
|
var content = msg.getInviteContent();
|
||||||
|
this.roomId = content.getFromRoomId();
|
||||||
|
this.inviter = User.map(content.getFromUser());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkKickOutEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long fromUserId;
|
||||||
|
private final KickOutReason kickOutReason;
|
||||||
|
|
||||||
|
public TikTokLinkKickOutEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasKickOutContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Kick Out Content!");
|
||||||
|
|
||||||
|
var content = msg.getKickOutContent();
|
||||||
|
this.fromUserId = content.getFromUserId();
|
||||||
|
this.kickOutReason = KickOutReason.values()[content.getKickoutReasonValue()];
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum KickOutReason {
|
||||||
|
KICKOUT_REASON_UNKNOWN,
|
||||||
|
KICKOUT_REASON_FIRST_FRAME_TIMEOUT,
|
||||||
|
KICKOUT_REASON_BY_HOST,
|
||||||
|
KICKOUT_REASON_RTC_LOST_CONNECTION,
|
||||||
|
KICKOUT_REASON_BY_PUNISH,
|
||||||
|
KICKOUT_REASON_BY_ADMIN,
|
||||||
|
KICKOUT_REASON_HOST_REMOVE_ALL_GUESTS
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkLeaveEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long userId, sendLeaveUid, leaveReason;
|
||||||
|
private final String linkmicIdStr;
|
||||||
|
|
||||||
|
public TikTokLinkLeaveEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasLeaveContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Leave Content!");
|
||||||
|
|
||||||
|
var content = msg.getLeaveContent();
|
||||||
|
this.userId = content.getUserId();
|
||||||
|
this.linkmicIdStr = content.getLinkmicIdStr();
|
||||||
|
this.sendLeaveUid = content.getSendLeaveUid();
|
||||||
|
this.leaveReason = content.getLeaveReason();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkLinkedListChangeEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
public TikTokLinkLinkedListChangeEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
// if (!msg.hasLinkedListChangeContent())
|
||||||
|
// throw new IllegalArgumentException("Expected WebcastLinkMessage with Linked List Change Content!");
|
||||||
|
// Proto Empty
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkListChangeEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final List<ListUser> linkedUsers, appliedUsers, connectingUsers;
|
||||||
|
|
||||||
|
public TikTokLinkListChangeEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasListChangeContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with List Change Content!");
|
||||||
|
|
||||||
|
var content = msg.getListChangeContent();
|
||||||
|
this.linkedUsers = content.getLinkedUsersList().stream().map(ListUser::map).toList();
|
||||||
|
this.appliedUsers = content.getAppliedUsersList().stream().map(ListUser::map).toList();
|
||||||
|
this.connectingUsers = content.getConnectingUsersList().stream().map(ListUser::map).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkMediaChangeEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long op, toUserId, anchorId, roomId, changeScene;
|
||||||
|
|
||||||
|
public TikTokLinkMediaChangeEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasMediaChangeContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Media Change Content!");
|
||||||
|
|
||||||
|
var content = msg.getMediaChangeContent();
|
||||||
|
this.op = content.getOp();
|
||||||
|
this.toUserId = content.getToUserId();
|
||||||
|
this.anchorId = content.getAnchorId();
|
||||||
|
this.roomId = content.getRoomId();
|
||||||
|
this.changeScene = content.getChangeScene();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,24 +20,20 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.events;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import lombok.Getter;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
@Getter
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class CustomEvent extends TikTokHeaderEvent {
|
public class TikTokLinkMicIdxUpdateEvent extends TikTokLinkEvent {
|
||||||
private final User user;
|
|
||||||
private final String title;
|
|
||||||
|
|
||||||
public CustomEvent(User user, String title) {
|
public TikTokLinkMicIdxUpdateEvent(WebcastLinkMessage msg) {
|
||||||
this.user = user;
|
super(msg);
|
||||||
this.title = title;
|
// if (!msg.hasMicIdxUpdateContent())
|
||||||
|
// throw new IllegalArgumentException("Expected WebcastLinkMessage with Mic Idx Update Content!");
|
||||||
|
// Proto Empty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkMuteEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long userId, status;
|
||||||
|
|
||||||
|
public TikTokLinkMuteEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasMuteContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Mute Content!");
|
||||||
|
|
||||||
|
var content = msg.getMuteContent();
|
||||||
|
this.userId = content.getUserId();
|
||||||
|
this.status = content.getStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkRandomMatchEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final User user;
|
||||||
|
private final long roomId, inviteType, innerChannelId;
|
||||||
|
private final String matchId;
|
||||||
|
|
||||||
|
public TikTokLinkRandomMatchEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasRandomMatchContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Random Match Content!");
|
||||||
|
|
||||||
|
var content = msg.getRandomMatchContent();
|
||||||
|
this.user = User.map(content.getUser());
|
||||||
|
this.roomId = content.getRoomId();
|
||||||
|
this.inviteType = content.getInviteType();
|
||||||
|
this.matchId = content.getMatchId();
|
||||||
|
this.innerChannelId = content.getInnerChannelId();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkReplyEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long roomId;
|
||||||
|
private final User fromUser, toUser;
|
||||||
|
|
||||||
|
public TikTokLinkReplyEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasReplyContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Reply Content!");
|
||||||
|
|
||||||
|
var content = msg.getReplyContent();
|
||||||
|
this.roomId = content.getFromRoomId();
|
||||||
|
this.fromUser = User.map(content.getFromUser());
|
||||||
|
this.toUser = User.map(content.getToUser());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkSysKickOutEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long userId;
|
||||||
|
private final String linkmicIdStr;
|
||||||
|
|
||||||
|
public TikTokLinkSysKickOutEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasSysKickOutContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Sys Kick Out Content!");
|
||||||
|
|
||||||
|
var content = msg.getSysKickOutContent();
|
||||||
|
this.userId = content.getUserId();
|
||||||
|
this.linkmicIdStr = content.getLinkmicIdStr();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkUpdateUserEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long fromUserId, toUserId;
|
||||||
|
|
||||||
|
public TikTokLinkUpdateUserEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasUpdateUserContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Update User Content!");
|
||||||
|
|
||||||
|
var content = msg.getUpdateUserContent();
|
||||||
|
this.fromUserId = content.getFromUserId();
|
||||||
|
this.toUserId = content.getToUserId();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkUpdateUserSettingEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
public TikTokLinkUpdateUserSettingEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
// if (!msg.hasUpdateUserSettingContent())
|
||||||
|
// throw new IllegalArgumentException("Expected WebcastLinkMessage with Update User Setting Content!");
|
||||||
|
// Proto Empty
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.Text;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkUserToastEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long userId, roomId;
|
||||||
|
private final Text displayText;
|
||||||
|
|
||||||
|
public TikTokLinkUserToastEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasUserToastContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with User Toast Content!");
|
||||||
|
|
||||||
|
var content = msg.getUserToastContent();
|
||||||
|
this.userId = content.getUserId();
|
||||||
|
this.roomId = content.getRoomId();
|
||||||
|
this.displayText = Text.map(content.getDisplayText());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,15 +20,20 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.handler;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkWaitListChangeEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
import java.util.List;
|
public TikTokLinkWaitListChangeEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
// if (!msg.hasWaitingListChangeContent())
|
||||||
public interface TikTokMessageHandler
|
// throw new IllegalArgumentException("Expected WebcastLinkMessage with Waiting List Change Content!");
|
||||||
{
|
// Proto Empty
|
||||||
List<TikTokEvent> handle(byte[] messagePayload) throws Exception;
|
}
|
||||||
}
|
}
|
||||||
@@ -30,9 +30,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Triggered when LiveRoomInfo got updated such as likes, viewers, ranking ....
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
|||||||
@@ -33,9 +33,8 @@ import lombok.Getter;
|
|||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokRoomPinEvent extends TikTokHeaderEvent
|
public class TikTokRoomPinEvent extends TikTokHeaderEvent
|
||||||
{
|
{
|
||||||
|
private final TikTokCommentEvent pinnedMessage;
|
||||||
private TikTokCommentEvent pinnedMessage;
|
private final long timestamp;
|
||||||
private long timestamp;
|
|
||||||
|
|
||||||
public TikTokRoomPinEvent(WebcastRoomPinMessage msg, TikTokCommentEvent commentEvent)
|
public TikTokRoomPinEvent(WebcastRoomPinMessage msg, TikTokCommentEvent commentEvent)
|
||||||
{
|
{
|
||||||
@@ -43,5 +42,4 @@ public class TikTokRoomPinEvent extends TikTokHeaderEvent
|
|||||||
this.timestamp = msg.getTimestamp();
|
this.timestamp = msg.getTimestamp();
|
||||||
this.pinnedMessage = commentEvent;
|
this.pinnedMessage = commentEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,16 +24,12 @@ package io.github.jwdeveloper.tiktok.data.events.social;
|
|||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokSubscribeEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastMemberMessage;
|
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers when a user follows the streamer. Based on social event.
|
|
||||||
*/
|
|
||||||
@Value
|
@Value
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokFollowEvent extends TikTokHeaderEvent
|
public class TikTokFollowEvent extends TikTokHeaderEvent
|
||||||
|
|||||||
@@ -31,9 +31,7 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when a viewer sends likes to the streamer. For streams with many viewers, this event is not always triggered by TikTok.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLikeEvent extends TikTokHeaderEvent
|
public class TikTokLikeEvent extends TikTokHeaderEvent
|
||||||
|
|||||||
@@ -29,9 +29,7 @@ import io.github.jwdeveloper.tiktok.data.models.users.User;
|
|||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers when a user shares the stream. Based on social event.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokShareEvent extends TikTokHeaderEvent {
|
public class TikTokShareEvent extends TikTokHeaderEvent {
|
||||||
@@ -49,5 +47,4 @@ public class TikTokShareEvent extends TikTokHeaderEvent {
|
|||||||
user = User.map(msg.getUser());
|
user = User.map(msg.getUser());
|
||||||
totalShares = 1;
|
totalShares = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -35,10 +35,7 @@ import lombok.Value;
|
|||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered every time TikTok sends data. Data incoming as protobuf message.
|
|
||||||
* You can deserialize the binary object depending on the use case.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EventMeta(eventType = EventType.Debug)
|
@EventMeta(eventType = EventType.Debug)
|
||||||
|
|||||||
@@ -29,9 +29,7 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered every time a protobuf encoded webcast message arrives. You can deserialize the binary object depending on the use case.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Debug)
|
@EventMeta(eventType = EventType.Debug)
|
||||||
public class TikTokWebsocketUnhandledMessageEvent extends TikTokUnhandledEvent<WebcastResponse.Message>
|
public class TikTokWebsocketUnhandledMessageEvent extends TikTokUnhandledEvent<WebcastResponse.Message>
|
||||||
|
|||||||
@@ -1,6 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.battles;
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
public abstract class Team {
|
public abstract class Team {
|
||||||
|
/** Value >= 0 when finished otherwise -1 */
|
||||||
|
@Getter protected int totalPoints;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a check for verifying if this team represents a 1v1 Team.
|
* Provides a check for verifying if this team represents a 1v1 Team.
|
||||||
* @return true if this team is of type {@link Team1v1}, false otherwise.
|
* @return true if this team is of type {@link Team1v1}, false otherwise.
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.battles;
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
@@ -7,10 +29,7 @@ import lombok.Getter;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class Team1v1 extends Team
|
public class Team1v1 extends Team {
|
||||||
{
|
|
||||||
/** Value >= 0 when finished otherwise -1 */
|
|
||||||
private final int totalPoints;
|
|
||||||
private final int winStreak;
|
private final int winStreak;
|
||||||
private final User host;
|
private final User host;
|
||||||
private final List<Viewer> viewers;
|
private final List<Viewer> viewers;
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.battles;
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
@@ -8,9 +30,6 @@ import java.util.*;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class Team2v2 extends Team {
|
public class Team2v2 extends Team {
|
||||||
/** Value >= 0 when finished otherwise -1 */
|
|
||||||
private final int totalPoints;
|
|
||||||
|
|
||||||
private final List<User> hosts;
|
private final List<User> hosts;
|
||||||
private final List<Viewer> viewers;
|
private final List<Viewer> viewers;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.battles;
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.gifts;
|
package io.github.jwdeveloper.tiktok.data.models.gifts;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|||||||
@@ -22,11 +22,10 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.gifts;
|
package io.github.jwdeveloper.tiktok.data.models.gifts;
|
||||||
|
|
||||||
//TODO it should be called GiftComboStateType
|
|
||||||
public enum GiftComboStateType {
|
public enum GiftComboStateType {
|
||||||
Finished,
|
|
||||||
Begin,
|
Begin,
|
||||||
Active;
|
Active,
|
||||||
|
Finished;
|
||||||
|
|
||||||
public static GiftComboStateType fromNumber(long number) {
|
public static GiftComboStateType fromNumber(long number) {
|
||||||
return switch ((int) number) {
|
return switch ((int) number) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.models.users;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class ListUser
|
||||||
|
{
|
||||||
|
private final User user;
|
||||||
|
private final LinkType linkType;
|
||||||
|
private final long linkMicId, linkStatus, modifyTime, linkerId;
|
||||||
|
private final int userPosition, silenceStatus, roleType;
|
||||||
|
|
||||||
|
public ListUser(io.github.jwdeveloper.tiktok.messages.data.ListUser listUser) {
|
||||||
|
this.user = User.map(listUser.getUser());
|
||||||
|
this.linkMicId = listUser.getLinkmicId();
|
||||||
|
this.linkStatus = listUser.getLinkStatus();
|
||||||
|
this.linkType = LinkType.values()[listUser.getLinkTypeValue()];
|
||||||
|
this.userPosition = listUser.getUserPosition();
|
||||||
|
this.silenceStatus = listUser.getSilenceStatus();
|
||||||
|
this.modifyTime = listUser.getModifyTime();
|
||||||
|
this.linkerId = listUser.getLinkerId();
|
||||||
|
this.roleType = listUser.getRoleType();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ListUser map(io.github.jwdeveloper.tiktok.messages.data.ListUser listUser) {
|
||||||
|
return new ListUser(listUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum LinkType {
|
||||||
|
UNKNOWN,
|
||||||
|
AUDIO,
|
||||||
|
VIDEO
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,16 +22,12 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.users;
|
package io.github.jwdeveloper.tiktok.data.models.users;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.badges.Badge;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.badges.Badge;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
||||||
import lombok.AccessLevel;
|
import lombok.*;
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class User {
|
public class User {
|
||||||
@@ -49,12 +45,12 @@ public class User {
|
|||||||
return attributes.stream().toList();
|
return attributes.stream().toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAttribute(UserAttribute userFlag) {
|
public boolean hasAttribute(UserAttribute attribute) {
|
||||||
return attributes.contains(userFlag);
|
return attributes.contains(attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAttribute(UserAttribute... flags) {
|
public void addAttribute(UserAttribute... attributes) {
|
||||||
this.attributes.addAll(Arrays.stream(flags).toList());
|
this.attributes.addAll(List.of(attributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGiftGiver() {
|
public boolean isGiftGiver() {
|
||||||
|
|||||||
@@ -23,20 +23,12 @@
|
|||||||
package io.github.jwdeveloper.tiktok.data.requests;
|
package io.github.jwdeveloper.tiktok.data.requests;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.Data;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GiftsData
|
public class GiftsData
|
||||||
{
|
{
|
||||||
@Getter
|
|
||||||
public final class Request
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static final class Response
|
public static final class Response
|
||||||
@@ -44,5 +36,4 @@ public class GiftsData
|
|||||||
private String json;
|
private String json;
|
||||||
private List<Gift> gifts;
|
private List<Gift> gifts;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -27,18 +27,23 @@ import lombok.*;
|
|||||||
public class LiveUserData {
|
public class LiveUserData {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
|
||||||
public static class Request {
|
public static class Request {
|
||||||
private String userName;
|
private final String userName;
|
||||||
|
|
||||||
|
public Request(String userName) {
|
||||||
|
if (userName == null || userName.isBlank())
|
||||||
|
throw new IllegalArgumentException("Invalid empty username!");
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class Response {
|
public static class Response {
|
||||||
private String json;
|
private final String json;
|
||||||
private UserStatus userStatus;
|
private final UserStatus userStatus;
|
||||||
private String roomId;
|
private final String roomId;
|
||||||
private long startedAtTimeStamp;
|
private final long startTime;
|
||||||
|
|
||||||
public boolean isLiveOnline() {
|
public boolean isLiveOnline() {
|
||||||
return userStatus == LiveUserData.UserStatus.Live || userStatus == LiveUserData.UserStatus.LivePaused;
|
return userStatus == LiveUserData.UserStatus.Live || userStatus == LiveUserData.UserStatus.LivePaused;
|
||||||
|
|||||||
@@ -34,30 +34,24 @@ import java.util.TreeMap;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class HttpClientSettings {
|
public class HttpClientSettings {
|
||||||
|
|
||||||
@Getter
|
private final Map<String, Object> params;
|
||||||
final Map<String, Object> params;
|
|
||||||
|
|
||||||
@Getter
|
private final Map<String, String> headers;
|
||||||
final Map<String, String> headers;
|
|
||||||
|
|
||||||
@Getter
|
private final Map<String, String> cookies;
|
||||||
final Map<String, String> cookies;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
ProxyClientSettings proxyClientSettings;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
Consumer<HttpClient.Builder> onClientCreating;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
Consumer<HttpRequest.Builder> onRequestCreating;
|
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
private ProxyClientSettings proxyClientSettings;
|
||||||
Duration timeout;
|
|
||||||
|
private Consumer<HttpClient.Builder> onClientCreating;
|
||||||
|
|
||||||
|
private Consumer<HttpRequest.Builder> onRequestCreating;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private Duration timeout;
|
||||||
|
|
||||||
public HttpClientSettings() {
|
public HttpClientSettings() {
|
||||||
this.params = new TreeMap<>();
|
this.params = new TreeMap<>();
|
||||||
@@ -65,10 +59,8 @@ public class HttpClientSettings {
|
|||||||
this.cookies = new HashMap<>();
|
this.cookies = new HashMap<>();
|
||||||
this.timeout = Duration.ofSeconds(2);
|
this.timeout = Duration.ofSeconds(2);
|
||||||
this.proxyClientSettings = new ProxyClientSettings();
|
this.proxyClientSettings = new ProxyClientSettings();
|
||||||
this.onClientCreating = (x) -> {
|
this.onClientCreating = (x) -> {};
|
||||||
};
|
this.onRequestCreating = (x) -> {};
|
||||||
this.onRequestCreating = (x) -> {
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +97,7 @@ public class HttpClientSettings {
|
|||||||
newSettings.getHeaders().putAll(new TreeMap<>(this.headers));
|
newSettings.getHeaders().putAll(new TreeMap<>(this.headers));
|
||||||
newSettings.getCookies().putAll(new TreeMap<>(this.cookies));
|
newSettings.getCookies().putAll(new TreeMap<>(this.cookies));
|
||||||
newSettings.getParams().putAll(new TreeMap<>(this.params));
|
newSettings.getParams().putAll(new TreeMap<>(this.params));
|
||||||
newSettings.proxyClientSettings = this.proxyClientSettings;
|
newSettings.setProxyClientSettings(this.proxyClientSettings);
|
||||||
|
|
||||||
return newSettings;
|
return newSettings;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,6 +178,4 @@ public class LiveClientSettings {
|
|||||||
headers.put("Accept-Language", "en-US,en; q=0.9");
|
headers.put("Accept-Language", "en-US,en; q=0.9");
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -31,17 +31,17 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class ProxyClientSettings implements Iterator<ProxyData>
|
public class ProxyClientSettings implements Iterator<ProxyData>, Iterable<ProxyData>
|
||||||
{
|
{
|
||||||
private boolean enabled, autoDiscard = true, fallback = true;
|
private boolean enabled, autoDiscard = true, fallback = 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 = -1;
|
private int index;
|
||||||
private Proxy.Type type = Proxy.Type.DIRECT;
|
private Proxy.Type type = Proxy.Type.DIRECT;
|
||||||
private Consumer<ProxyData> onProxyUpdated = x -> {};
|
private Consumer<ProxyData> onProxyUpdated = x -> {};
|
||||||
|
|
||||||
public boolean addProxy(String addressPort) {
|
public boolean addProxy(String addressPort) {
|
||||||
return proxyList.add(ProxyData.map(addressPort));
|
return addProxy(ProxyData.map(addressPort).toSocketAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addProxy(String address, int port) {
|
public boolean addProxy(String address, int port) {
|
||||||
@@ -57,33 +57,27 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public synchronized boolean hasNext() {
|
||||||
return !proxyList.isEmpty();
|
return !proxyList.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProxyData next() {
|
public synchronized ProxyData next() {
|
||||||
var nextProxy = switch (rotation)
|
try {
|
||||||
{
|
var nextProxy = proxyList.get(index);
|
||||||
case CONSECUTIVE -> {
|
|
||||||
index = (index+1) % proxyList.size();
|
|
||||||
yield proxyList.get(index).clone();
|
|
||||||
}
|
|
||||||
case RANDOM -> {
|
|
||||||
index = new Random().nextInt(proxyList.size());
|
|
||||||
yield proxyList.get(index).clone();
|
|
||||||
}
|
|
||||||
case NONE -> {
|
|
||||||
index = Math.max(index, 0);
|
|
||||||
yield proxyList.get(index).clone();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
onProxyUpdated.accept(nextProxy);
|
onProxyUpdated.accept(nextProxy);
|
||||||
return nextProxy;
|
return nextProxy;
|
||||||
|
} finally {
|
||||||
|
switch (rotation) {
|
||||||
|
case CONSECUTIVE -> index = ++index % proxyList.size();
|
||||||
|
case RANDOM -> index = (int) (Math.random() * proxyList.size());
|
||||||
|
case NONE -> index = Math.max(index, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public synchronized void remove() {
|
||||||
proxyList.remove(index);
|
proxyList.remove(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,8 +91,8 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyClientSettings clone()
|
@Override
|
||||||
{
|
public ProxyClientSettings clone() {
|
||||||
ProxyClientSettings settings = new ProxyClientSettings();
|
ProxyClientSettings settings = new ProxyClientSettings();
|
||||||
settings.setEnabled(enabled);
|
settings.setEnabled(enabled);
|
||||||
settings.setRotation(rotation);
|
settings.setRotation(rotation);
|
||||||
@@ -109,6 +103,27 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ProxyClientSettings{" +
|
||||||
|
"enabled=" + enabled +
|
||||||
|
", autoDiscard=" + autoDiscard +
|
||||||
|
", fallback=" + fallback +
|
||||||
|
", rotation=" + rotation +
|
||||||
|
", proxyList=" + proxyList +
|
||||||
|
", index=" + index +
|
||||||
|
", type=" + type +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* With {@code Iterable<ProxyData>} interface, you can use this object inside for loop!
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Iterator<ProxyData> iterator() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public enum Rotation
|
public enum Rotation
|
||||||
{
|
{
|
||||||
/** Rotate addresses consecutively, from proxy 0 -> 1 -> 2 -> ...etc. */
|
/** Rotate addresses consecutively, from proxy 0 -> 1 -> 2 -> ...etc. */
|
||||||
|
|||||||
@@ -20,7 +20,11 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.mappers.handlers;
|
package io.github.jwdeveloper.tiktok.exceptions;
|
||||||
|
|
||||||
public class TikTokChestEventHandler {
|
public class TikTokLiveUnknownHostException extends TikTokLiveException
|
||||||
|
{
|
||||||
|
public TikTokLiveUnknownHostException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -25,15 +25,13 @@ package io.github.jwdeveloper.tiktok.listener;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You can dynamically add or removing TikTokEventListener
|
* Manage events listeners objects
|
||||||
*
|
|
||||||
* @see TikTokEventListener
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface ListenersManager
|
public interface ListenersManager
|
||||||
{
|
{
|
||||||
List<TikTokEventListener> getListeners();
|
List<Object> getListeners();
|
||||||
void addListener(TikTokEventListener listener);
|
|
||||||
|
|
||||||
void removeListener(TikTokEventListener listener);
|
void addListener(Object listener);
|
||||||
|
|
||||||
|
void removeListener(Object listener);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,53 +22,54 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.listener;
|
package io.github.jwdeveloper.tiktok.listener;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* ListenersManager
|
||||||
* @see ListenersManager
|
* <p>
|
||||||
*
|
|
||||||
* TikTokEventListener is an alternative way of handing TikTok events.
|
* TikTokEventListener is an alternative way of handing TikTok events.
|
||||||
*
|
* <p>
|
||||||
* TikTokLive.newClient("someuser").addListener(listener)
|
* {@code TikTokLive.newClient("someuser").addListener(listener);}
|
||||||
*
|
* <p>
|
||||||
* After registertion all listeners are kept in Listener manager
|
* After registertion, all listeners are kept in Listener manager - {@link LiveClient#getListenersManager()}
|
||||||
* that could be obtained by client.getListenerManager();
|
* <p>
|
||||||
*
|
* Method in TikTokEventListener should meet requirements below to be detected
|
||||||
* Method in TikTokEventListener should meet 4 requirements to be detected
|
* <p>- @TikTokEventObserver annotation
|
||||||
* - must have @TikTokEventHandler annotation
|
* <p>- 2 parameters of (LiveClient, Class extending TikTokEvent)
|
||||||
* - must have 2 parameters
|
* <pre>
|
||||||
* - first parameter must be LiveClient
|
* {@code
|
||||||
* - second must be class that extending TikTokEvent
|
|
||||||
*
|
|
||||||
* public static class CustomListener implements TikTokEventListener
|
* public static class CustomListener implements TikTokEventListener
|
||||||
* {
|
* {
|
||||||
* @TikTokEventHandler
|
* @TikTokEventObserver
|
||||||
* public void onError(LiveClient liveClient, TikTokErrorEvent event)
|
* public void onError(LiveClient liveClient, TikTokErrorEvent event)
|
||||||
* {
|
* {
|
||||||
* System.out.println(event.getException().getMessage());
|
* System.out.println(event.getException().getMessage());
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @TikTokEventHandler
|
* @TikTokEventObserver
|
||||||
* public void onCommentMessage(LiveClient liveClient, TikTokCommentEvent event)
|
* public void onCommentMessage(LiveClient liveClient, TikTokCommentEvent event)
|
||||||
* {
|
* {
|
||||||
* System.out.println(event.getText());
|
* System.out.println(event.getText());
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @TikTokEventHandler
|
* @TikTokEventObserver
|
||||||
* public void onGiftMessage(LiveClient liveClient, TikTokGiftMessageEvent event)
|
* public void onGiftMessage(LiveClient liveClient, TikTokGiftMessageEvent event)
|
||||||
* {
|
* {
|
||||||
* System.out.println(event.getGift().getDescription());
|
* System.out.println(event.getGift().getDescription());
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @TikTokEventHandler
|
* @TikTokEventObserver
|
||||||
* public void onAnyEvent(LiveClient liveClient, TikTokEvent event)
|
* public void onAnyEvent(LiveClient liveClient, TikTokEvent event)
|
||||||
* {
|
* {
|
||||||
* System.out.println(event.getClass().getSimpleName());
|
* System.out.println(event.getClass().getSimpleName());
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
* }
|
||||||
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public interface TikTokEventListener
|
//TODO I think this interface can be removed, since we are using,
|
||||||
{
|
//annotation @TikTokEventHandler to check methods that are events
|
||||||
|
@Deprecated(forRemoval = true, since = "1.8.1 (This interface is not longer needed, please remove it from your class)")
|
||||||
|
public interface TikTokEventListener {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.listener;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.control.TikTokPreConnectionEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.envelop.TikTokChestEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.gift.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.http.TikTokHttpResponseEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.link.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.poll.TikTokPollEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.room.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.social.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.websocket.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
|
||||||
|
public abstract class TikTokEventListenerBase implements TikTokEventListener
|
||||||
|
{
|
||||||
|
public void onUnhandledSocial(LiveClient client, TikTokUnhandledSocialEvent event) {}
|
||||||
|
|
||||||
|
public void onChest(LiveClient client, TikTokChestEvent event) {}
|
||||||
|
|
||||||
|
public void onLinkMicFanTicket(LiveClient client, TikTokLinkMicFanTicketEvent event) {}
|
||||||
|
|
||||||
|
public void onEnvelope(LiveClient client, TikTokEnvelopeEvent event) {}
|
||||||
|
|
||||||
|
public void onShop(LiveClient client, TikTokShopEvent event) {}
|
||||||
|
|
||||||
|
public void onDetect(LiveClient client, TikTokDetectEvent event) {}
|
||||||
|
|
||||||
|
public void onLinkLayer(LiveClient client, TikTokLinkLayerEvent event) {}
|
||||||
|
|
||||||
|
public void onConnected(LiveClient client, TikTokConnectedEvent event) {}
|
||||||
|
|
||||||
|
public void onPreConnection(LiveClient client, TikTokPreConnectionEvent event) {}
|
||||||
|
|
||||||
|
public void onCaption(LiveClient client, TikTokCaptionEvent event) {}
|
||||||
|
|
||||||
|
public void onQuestion(LiveClient client, TikTokQuestionEvent event) {}
|
||||||
|
|
||||||
|
public void onRoomPin(LiveClient client, TikTokRoomPinEvent event) {}
|
||||||
|
|
||||||
|
public void onRoomInfo(LiveClient client, TikTokRoomInfoEvent event) {}
|
||||||
|
|
||||||
|
public void onLivePaused(LiveClient client, TikTokLivePausedEvent event) {}
|
||||||
|
|
||||||
|
public void onLiveUnpaused(LiveClient client, TikTokLiveUnpausedEvent event) {}
|
||||||
|
|
||||||
|
public void onLike(LiveClient client, TikTokLikeEvent event) {}
|
||||||
|
|
||||||
|
public void onLink(LiveClient client, TikTokLinkEvent event) {}
|
||||||
|
public void onLinkInvite(LiveClient client, TikTokLinkInviteEvent event) {}
|
||||||
|
public void onLinkReply(LiveClient client, TikTokLinkReplyEvent event) {}
|
||||||
|
public void onLinkCreate(LiveClient client, TikTokLinkCreateEvent event) {}
|
||||||
|
public void onLinkClose(LiveClient client, TikTokLinkCloseEvent event) {}
|
||||||
|
public void onLinkEnter(LiveClient client, TikTokLinkEnterEvent event) {}
|
||||||
|
public void onLinkLeave(LiveClient client, TikTokLinkLeaveEvent event) {}
|
||||||
|
public void onLinkCancel(LiveClient client, TikTokLinkCancelEvent event) {}
|
||||||
|
public void onLinkKickOut(LiveClient client, TikTokLinkKickOutEvent event) {}
|
||||||
|
public void onLinkLinkedListChange(LiveClient client, TikTokLinkLinkedListChangeEvent event) {}
|
||||||
|
public void onLinkUpdateUser(LiveClient client, TikTokLinkUpdateUserEvent event) {}
|
||||||
|
public void onLinkWaitListChange(LiveClient client, TikTokLinkWaitListChangeEvent event) {}
|
||||||
|
public void onLinkMute(LiveClient client, TikTokLinkMuteEvent event) {}
|
||||||
|
public void onLinkRandomMatch(LiveClient client, TikTokLinkRandomMatchEvent event) {}
|
||||||
|
public void onLinkUpdateUserSettings(LiveClient client, TikTokLinkUpdateUserSettingEvent event) {}
|
||||||
|
public void onLinkMicIdxUpdate(LiveClient client, TikTokLinkMicIdxUpdateEvent event) {}
|
||||||
|
public void onLinkListChange(LiveClient client, TikTokLinkListChangeEvent event) {}
|
||||||
|
public void onLinkCohostListChange(LiveClient client, TikTokLinkCohostListChangeEvent event) {}
|
||||||
|
public void onLinkMediaChange(LiveClient client, TikTokLinkMediaChangeEvent event) {}
|
||||||
|
public void onLinkAcceptNotice(LiveClient client, TikTokLinkAcceptNoticeEvent event) {}
|
||||||
|
public void onLinkSysKickOut(LiveClient client, TikTokLinkSysKickOutEvent event) {}
|
||||||
|
public void onLinkUserToast(LiveClient client, TikTokLinkUserToastEvent event) {}
|
||||||
|
|
||||||
|
public void onBarrage(LiveClient client, TikTokBarrageEvent event) {}
|
||||||
|
|
||||||
|
public void onGift(LiveClient client, TikTokGiftEvent event) {}
|
||||||
|
|
||||||
|
public void onGiftCombo(LiveClient client, TikTokGiftComboEvent event) {}
|
||||||
|
|
||||||
|
public void onLinkMicArmies(LiveClient client, TikTokLinkMicArmiesEvent event) {}
|
||||||
|
|
||||||
|
public void onEmote(LiveClient client, TikTokEmoteEvent event) {}
|
||||||
|
|
||||||
|
public void onUnauthorizedMember(LiveClient client, TikTokUnauthorizedMemberEvent event) {}
|
||||||
|
|
||||||
|
public void onInRoomBanner(LiveClient client, TikTokInRoomBannerEvent event) {}
|
||||||
|
|
||||||
|
public void onLinkMicMethod(LiveClient client, TikTokLinkMicMethodEvent event) {}
|
||||||
|
|
||||||
|
public void onSubscribe(LiveClient client, TikTokSubscribeEvent event) {}
|
||||||
|
|
||||||
|
public void onPoll(LiveClient client, TikTokPollEvent event) {}
|
||||||
|
|
||||||
|
public void onFollow(LiveClient client, TikTokFollowEvent event) {}
|
||||||
|
|
||||||
|
public void onComment(LiveClient client, TikTokCommentEvent event) {}
|
||||||
|
|
||||||
|
public void onHttpResponse(LiveClient client, TikTokHttpResponseEvent action) {}
|
||||||
|
|
||||||
|
public void onGoalUpdate(LiveClient client, TikTokGoalUpdateEvent event) {}
|
||||||
|
|
||||||
|
public void onRankUpdate(LiveClient client, TikTokRankUpdateEvent event) {}
|
||||||
|
|
||||||
|
public void onIMDelete(LiveClient client, TikTokIMDeleteEvent event) {}
|
||||||
|
|
||||||
|
public void onLiveEnded(LiveClient client, TikTokLiveEndedEvent event) {}
|
||||||
|
|
||||||
|
public void onError(LiveClient client, TikTokErrorEvent event) {}
|
||||||
|
|
||||||
|
public void onJoin(LiveClient client, TikTokJoinEvent event) {}
|
||||||
|
|
||||||
|
public void onRankText(LiveClient client, TikTokRankTextEvent event) {}
|
||||||
|
|
||||||
|
public void onShare(LiveClient client, TikTokShareEvent event) {}
|
||||||
|
|
||||||
|
public void onUnhandledMember(LiveClient client, TikTokUnhandledMemberEvent event) {}
|
||||||
|
|
||||||
|
public void onSubNotify(LiveClient client, TikTokSubNotifyEvent event) {}
|
||||||
|
|
||||||
|
public void onLinkMicBattle(LiveClient client, TikTokLinkMicBattleEvent event) {}
|
||||||
|
|
||||||
|
public void onDisconnected(LiveClient client, TikTokDisconnectedEvent event) {}
|
||||||
|
|
||||||
|
public void onUnhandledControl(LiveClient client, TikTokUnhandledControlEvent event) {}
|
||||||
|
|
||||||
|
public void onEvent(LiveClient client, TikTokEvent event) {}
|
||||||
|
|
||||||
|
public void onWebsocketResponse(LiveClient client, TikTokWebsocketResponseEvent event) {}
|
||||||
|
|
||||||
|
public void onWebsocketMessage(LiveClient client, TikTokWebsocketMessageEvent event) {}
|
||||||
|
|
||||||
|
public void onWebsocketUnhandledMessage(LiveClient client, TikTokWebsocketUnhandledMessageEvent event) {}
|
||||||
|
|
||||||
|
public void onReconnecting(LiveClient client, TikTokReconnectingEvent event) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.live;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.builder.EventConsumer;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface LiveEventsHandler {
|
||||||
|
void publish(LiveClient tikTokLiveClient, TikTokEvent tikTokEvent);
|
||||||
|
|
||||||
|
<T extends TikTokEvent> void subscribe(Class<?> clazz, EventConsumer<T> event);
|
||||||
|
|
||||||
|
<T extends TikTokEvent> void unsubscribeAll(Class<?> clazz);
|
||||||
|
|
||||||
|
<T extends TikTokEvent> void unsubscribe(EventConsumer<T> consumer);
|
||||||
|
|
||||||
|
<T extends TikTokEvent> void unsubscribe(Class<?> clazz, EventConsumer<T> consumer);
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.live;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.dto.MessageMetaData;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketMessageEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketResponseEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveMessageException;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||||
|
import io.github.jwdeveloper.tiktok.utils.Stopwatch;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
public interface LiveMessagesHandler {
|
||||||
|
void handle(LiveClient client, WebcastResponse webcastResponse);
|
||||||
|
|
||||||
|
void handleSingleMessage(LiveClient client, WebcastResponse.Message message);
|
||||||
|
}
|
||||||
@@ -25,7 +25,13 @@ package io.github.jwdeveloper.tiktok.live.builder;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
public interface EventConsumer<T extends TikTokEvent>
|
public interface EventConsumer<T extends TikTokEvent>
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param liveClient TikTok live client
|
||||||
|
* @param event event data object
|
||||||
|
*/
|
||||||
void onEvent(LiveClient liveClient, T event);
|
void onEvent(LiveClient liveClient, T event);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.live.builder;
|
package io.github.jwdeveloper.tiktok.live.builder;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.*;
|
import io.github.jwdeveloper.tiktok.data.events.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.control.TikTokPreConnectionEvent;
|
import io.github.jwdeveloper.tiktok.data.events.control.TikTokPreConnectionEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftComboEvent;
|
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftComboEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftEvent;
|
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftEvent;
|
||||||
@@ -36,6 +36,7 @@ import io.github.jwdeveloper.tiktok.data.events.social.TikTokShareEvent;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketMessageEvent;
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketMessageEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketResponseEvent;
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketResponseEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.gifts.GiftComboStateType;
|
||||||
|
|
||||||
|
|
||||||
public interface EventsBuilder<T> {
|
public interface EventsBuilder<T> {
|
||||||
@@ -52,131 +53,257 @@ public interface EventsBuilder<T> {
|
|||||||
/**
|
/**
|
||||||
* Invoked whenever any event is triggered
|
* Invoked whenever any event is triggered
|
||||||
*
|
*
|
||||||
* @param action
|
* @param action consumable action
|
||||||
* @return
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onEvent(EventConsumer<TikTokEvent> action);
|
default T onEvent(EventConsumer<TikTokEvent> action) {
|
||||||
|
return onEvent(TikTokEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when information about room (live) got updated such as viewer count, etc..
|
* Invoked when information about room (live) got updated such as viewer count, etc..
|
||||||
*
|
*
|
||||||
* @param action
|
* @param action consumable action
|
||||||
* @return
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onRoomInfo(EventConsumer<TikTokRoomInfoEvent> action);
|
default T onRoomInfo(EventConsumer<TikTokRoomInfoEvent> action) {
|
||||||
|
return onEvent(TikTokRoomInfoEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when someone send message to chat
|
* Invoked when someone send message to chat
|
||||||
*
|
*
|
||||||
* @param action
|
* @param action consumable action
|
||||||
* @return
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onComment(EventConsumer<TikTokCommentEvent> action);
|
default T onComment(EventConsumer<TikTokCommentEvent> action) {
|
||||||
|
return onEvent(TikTokCommentEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when TikTokLiveJava makes http request and getting response
|
* Invoked when TikTokLiveJava makes http request and getting response
|
||||||
*
|
*
|
||||||
* @param action
|
* @param action consumable action
|
||||||
* @return
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onHttpResponse(EventConsumer<TikTokHttpResponseEvent> action);
|
default T onHttpResponse(EventConsumer<TikTokHttpResponseEvent> action) {
|
||||||
|
return onEvent(TikTokHttpResponseEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when TikTok protocolBuffer data "message" was successfully mapped to event
|
* Invoked when TikTok protocolBuffer data "message" was successfully mapped to event
|
||||||
* events contains protocol-buffer "Message" and TikTokLiveJava "Event"
|
* events contains protocol-buffer "Message" and TikTokLiveJava "Event"
|
||||||
*
|
*
|
||||||
* @param action
|
* @param action consumable action
|
||||||
* @return
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onWebsocketMessage(EventConsumer<TikTokWebsocketMessageEvent> action);
|
default T onWebsocketMessage(EventConsumer<TikTokWebsocketMessageEvent> action) {
|
||||||
|
return onEvent(TikTokWebsocketMessageEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when there was not found event mapper for TikTok protocolBuffer data "message"
|
* Triggered every time a protobuf encoded webcast message arrives. You can deserialize the binary object depending on the use case.
|
||||||
*
|
*
|
||||||
* @param action
|
* @param action consumable action
|
||||||
* @return
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onWebsocketUnhandledMessage(EventConsumer<TikTokWebsocketUnhandledMessageEvent> action);
|
default T onWebsocketUnhandledMessage(EventConsumer<TikTokWebsocketUnhandledMessageEvent> action) {
|
||||||
|
return onEvent(TikTokWebsocketUnhandledMessageEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked every time TikTok sends protocolBuffer data to websocket
|
* Invoked every time TikTok sends protocolBuffer data to websocket
|
||||||
* Response contains list of messages that are later mapped to events
|
* Response contains list of messages that are later mapped to events
|
||||||
* @param action
|
*
|
||||||
* @return
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onWebsocketResponse(EventConsumer<TikTokWebsocketResponseEvent> action);
|
default T onWebsocketResponse(EventConsumer<TikTokWebsocketResponseEvent> action) {
|
||||||
|
return onEvent(TikTokWebsocketResponseEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked for gifts that has no combo, or when combo finishes
|
* Triggers for these different reasons:
|
||||||
* @param action
|
* <ol>
|
||||||
* @return
|
* <li>User sends gifts that have no combo (most of expensive gifts)</li>
|
||||||
|
* <li>{@link TikTokGiftComboEvent} has combaState = {@link GiftComboStateType#Finished}</li>
|
||||||
|
* </ol>
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onGift(EventConsumer<TikTokGiftEvent> action);
|
default T onGift(EventConsumer<TikTokGiftEvent> action) {
|
||||||
|
return onEvent(TikTokGiftEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked for gifts that has combo options such as roses
|
* Triggered every time a gift is sent
|
||||||
* @param action
|
* <p>Example when user sends gift with combo</p>
|
||||||
* @return
|
* <ul>
|
||||||
|
* <li>Combo: 1 -> comboState = {@link GiftComboStateType#Begin}</li>
|
||||||
|
* <li>Combo: 4 -> comboState = {@link GiftComboStateType#Active}</li>
|
||||||
|
* <li>Combo: 8 -> comboState = {@link GiftComboStateType#Active}</li>
|
||||||
|
* <li>Combo: 12 -> comboState = {@link GiftComboStateType#Finished}</li>
|
||||||
|
* </ul>
|
||||||
|
* Both {@link TikTokGiftComboEvent} and {@link TikTokGiftEvent} events are triggered when comboState is Finished
|
||||||
|
*
|
||||||
|
* @apiNote {@link GiftComboStateType} has 3 states: {@link GiftComboStateType#Begin Begin}, {@link GiftComboStateType#Active Active}, & {@link GiftComboStateType#Finished Finished}
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onGiftCombo(EventConsumer<TikTokGiftComboEvent> action);
|
default T onGiftCombo(EventConsumer<TikTokGiftComboEvent> action) {
|
||||||
|
return onEvent(TikTokGiftComboEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered every time someone asks a new question via the question feature.
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onQuestion(EventConsumer<TikTokQuestionEvent> action) {
|
||||||
|
return onEvent(TikTokQuestionEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onQuestion(EventConsumer<TikTokQuestionEvent> action);
|
/**
|
||||||
|
* Triggers when a user subscribe the streamer.
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onSubscribe(EventConsumer<TikTokSubscribeEvent> action) {
|
||||||
|
return onEvent(TikTokSubscribeEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onSubscribe(EventConsumer<TikTokSubscribeEvent> action);
|
/**
|
||||||
|
* Triggers when a user follows the streamer. Based on social event.
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onFollow(EventConsumer<TikTokFollowEvent> action) {
|
||||||
|
return onEvent(TikTokFollowEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onFollow(EventConsumer<TikTokFollowEvent> action);
|
/**
|
||||||
|
* Triggered when a viewer sends likes to the streamer. For streams with many viewers, this event is not always triggered by TikTok.
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onLike(EventConsumer<TikTokLikeEvent> action) {
|
||||||
|
return onEvent(TikTokLikeEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onLike(EventConsumer<TikTokLikeEvent> action);
|
/**
|
||||||
|
* Triggers when a user sends emote
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onEmote(EventConsumer<TikTokEmoteEvent> action) {
|
||||||
|
return onEvent(TikTokEmoteEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onEmote(EventConsumer<TikTokEmoteEvent> action);
|
/**
|
||||||
|
* Triggers when a user joins to the live
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onJoin(EventConsumer<TikTokJoinEvent> action) {
|
||||||
|
return onEvent(TikTokJoinEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onJoin(EventConsumer<TikTokJoinEvent> action);
|
/**
|
||||||
|
* Triggers when a user shares the stream.
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onShare(EventConsumer<TikTokShareEvent> action) {
|
||||||
|
return onEvent(TikTokShareEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onShare(EventConsumer<TikTokShareEvent> action);
|
/**
|
||||||
|
* Triggered when the live stream gets paused
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onLivePaused(EventConsumer<TikTokLivePausedEvent> action) {
|
||||||
|
return onEvent(TikTokLivePausedEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onLivePaused(EventConsumer<TikTokLivePausedEvent> action);
|
/**
|
||||||
|
* Triggered when the live stream gets unpaused
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onLiveUnpaused(EventConsumer<TikTokLiveUnpausedEvent> action) {
|
||||||
|
return onEvent(TikTokLiveUnpausedEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onLiveUnpaused(EventConsumer<TikTokLiveUnpausedEvent> action);
|
/**
|
||||||
|
* Triggered when the live stream gets terminated by the host. Will also trigger the TikTokDisconnectedEvent event.
|
||||||
T onLiveEnded(EventConsumer<TikTokLiveEndedEvent> action);
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onLiveEnded(EventConsumer<TikTokLiveEndedEvent> action) {
|
||||||
|
return onEvent(TikTokLiveEndedEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when client has been successfully connected to live
|
* Invoked when client has been successfully connected to live
|
||||||
* @param action
|
*
|
||||||
* @return
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onConnected(EventConsumer<TikTokConnectedEvent> action);
|
default T onConnected(EventConsumer<TikTokConnectedEvent> action) {
|
||||||
|
return onEvent(TikTokConnectedEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked before client has been successfully connected to live
|
* Invoked before client has been successfully connected to live
|
||||||
* @param action
|
*
|
||||||
* @return
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onPreConnection(EventConsumer<TikTokPreConnectionEvent> action);
|
default T onPreConnection(EventConsumer<TikTokPreConnectionEvent> action) {
|
||||||
|
return onEvent(TikTokPreConnectionEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when client tries to reconnect
|
* Invoked when client tries to reconnect
|
||||||
* @param action
|
*
|
||||||
* @return
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onReconnecting(EventConsumer<TikTokReconnectingEvent> action);
|
default T onReconnecting(EventConsumer<TikTokReconnectingEvent> action) {
|
||||||
|
return onEvent(TikTokReconnectingEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when client disconnected
|
* Triggered when the connection gets disconnected. In that case you can call connect() again to have a reconnect logic.
|
||||||
* @param action
|
* Note that you should wait a little bit before attempting a reconnect to avoid being rate-limited.
|
||||||
* @return
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onDisconnected(EventConsumer<TikTokDisconnectedEvent> action);
|
default T onDisconnected(EventConsumer<TikTokDisconnectedEvent> action) {
|
||||||
|
return onEvent(TikTokDisconnectedEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when exception was throed inside client or event handler
|
* Invoked when exception was throed inside client or event handler
|
||||||
* @param action
|
*
|
||||||
* @return
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onError(EventConsumer<TikTokErrorEvent> action);
|
default T onError(EventConsumer<TikTokErrorEvent> action) {
|
||||||
|
return onEvent(TikTokErrorEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO Figure out how those events works
|
// TODO Figure out how those events works
|
||||||
@@ -223,4 +350,10 @@ public interface EventsBuilder<T> {
|
|||||||
//T onLinkMicBattle(TikTokEventConsumer<TikTokLinkMicBattleEvent> event);
|
//T onLinkMicBattle(TikTokEventConsumer<TikTokLinkMicBattleEvent> event);
|
||||||
|
|
||||||
//T onUnhandledControl(TikTokEventConsumer<TikTokUnhandledControlEvent> event);
|
//T onUnhandledControl(TikTokEventConsumer<TikTokUnhandledControlEvent> event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To do figure out how to use Annotation processor.
|
||||||
|
* Goal is to generates methods for all possible events, everytime library is compiled
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -22,58 +22,73 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.live.builder;
|
package io.github.jwdeveloper.tiktok.live.builder;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.dependance.implementation.DependanceContainerBuilder;
|
||||||
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
import io.github.jwdeveloper.tiktok.listener.TikTokEventListener;
|
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.TikTokMapper;
|
import io.github.jwdeveloper.tiktok.mappers.LiveMapper;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
|
public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is triggered after default mappings are registered
|
* This method is triggered after default mappings are registered
|
||||||
* It could be used to OVERRIDE behaviour of mappings and implement custom behaviour
|
* It could be used to OVERRIDE behaviour of mappings and implement custom behaviour
|
||||||
*
|
* <p>
|
||||||
* Be aware if for example you override WebcastGiftEvent, onGiftEvent() will not be working
|
* Be aware if for example you override WebcastGiftEvent, onGiftEvent() will not be working
|
||||||
*
|
*
|
||||||
* @param onCustomMappings lambda method
|
* @param onCustomMappings lambda method
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
LiveClientBuilder onMapping(Consumer<TikTokMapper> onCustomMappings);
|
LiveClientBuilder mappings(Consumer<LiveMapper> onCustomMappings);
|
||||||
|
|
||||||
|
@Deprecated(forRemoval = true, since = "1.8.2 use `mappings` method instead")
|
||||||
|
LiveClientBuilder onMappings(Consumer<LiveMapper> onCustomMappings);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration of client settings
|
* Configuration of client settings
|
||||||
* @see LiveClientSettings
|
*
|
||||||
* @param onConfigure
|
* @param onConfigure
|
||||||
* @return
|
* @return
|
||||||
|
* @see LiveClientSettings
|
||||||
*/
|
*/
|
||||||
LiveClientBuilder configure(Consumer<LiveClientSettings> onConfigure);
|
LiveClientBuilder configure(Consumer<LiveClientSettings> onConfigure);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TikTokEventListener
|
|
||||||
* Adding events listener class, its fancy way to register events without using lamda method
|
* Adding events listener class, its fancy way to register events without using lamda method
|
||||||
* but actual method in class that implements TikTokEventListener
|
* but actual method in class that implements TikTokEventListener
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
LiveClientBuilder addListener(TikTokEventListener listener);
|
LiveClientBuilder addListener(Object listener);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Allows you to use own implementation of internal TikTokLive dependencies,
|
||||||
|
* when the default implementation does not meet your needs
|
||||||
|
*
|
||||||
|
* @param onCustomizeDependencies access to dependency container
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
LiveClientBuilder customize(Consumer<DependanceContainerBuilder> onCustomizeDependencies);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds new instance of the LiveClient
|
||||||
*
|
*
|
||||||
* @return LiveClient object
|
* @return LiveClient object
|
||||||
*/
|
*/
|
||||||
LiveClient build();
|
LiveClient build();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Builds new instance of the LiveClient and connects to live
|
||||||
*
|
*
|
||||||
* @return LiveClient object and connects to TikTok live
|
* @return LiveClient object
|
||||||
*/
|
*/
|
||||||
LiveClient buildAndConnect();
|
LiveClient buildAndConnect();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return LiveClient object and connects to TikTok live asynchronously
|
* @return LiveClient object and connects to TikTok live asynchronously
|
||||||
*/
|
*/
|
||||||
CompletableFuture<LiveClient> buildAndConnectAsync();
|
CompletableFuture<LiveClient> buildAndConnectAsync();
|
||||||
|
|||||||
@@ -27,18 +27,23 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
|||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingAction;
|
import io.github.jwdeveloper.tiktok.mappers.data.MappingAction;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public interface TikTokMapper {
|
public interface LiveMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * if mapper is not found for messageName, TikTokLiveException is thrown
|
* when mapper is not found for messageName, TikTokLiveException is thrown
|
||||||
*
|
*
|
||||||
* @param messageName
|
* @param messageName
|
||||||
* @return TikTokMapperModel
|
* @return TikTokMapperModel
|
||||||
*/
|
*/
|
||||||
TikTokMapperModel forMessage(String messageName);
|
TikTokMapperModel forMessage(String messageName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mapperName protocol buffer class type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
TikTokMapperModel forMessage(Class<? extends GeneratedMessageV3> mapperName);
|
TikTokMapperModel forMessage(Class<? extends GeneratedMessageV3> mapperName);
|
||||||
|
|
||||||
TikTokMapperModel forMessage(String mapperName, MappingAction<MappingResult> onMapping);
|
TikTokMapperModel forMessage(String mapperName, MappingAction<MappingResult> onMapping);
|
||||||
@@ -49,10 +54,9 @@ public interface TikTokMapper {
|
|||||||
|
|
||||||
TikTokMapperModel forAnyMessage();
|
TikTokMapperModel forAnyMessage();
|
||||||
|
|
||||||
|
List<TikTokEvent> handleMapping(String messageName, byte[] bytes);
|
||||||
|
|
||||||
boolean isRegistered(String mapperName);
|
boolean isRegistered(String mapperName);
|
||||||
|
|
||||||
<T extends GeneratedMessageV3> boolean isRegistered(Class<T> mapperName);
|
<T extends GeneratedMessageV3> boolean isRegistered(Class<T> mapperName);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ import com.google.protobuf.GeneratedMessageV3;
|
|||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokMessageMappingException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokMessageMappingException;
|
||||||
import io.github.jwdeveloper.tiktok.utils.ProtoBufferObject;
|
import io.github.jwdeveloper.tiktok.utils.ProtoBufferObject;
|
||||||
|
|
||||||
public interface TikTokMapperHelper {
|
public interface LiveMapperHelper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bytes protocol buffer data bytes
|
* @param bytes protocol buffer data bytes
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.mappers.data;
|
package io.github.jwdeveloper.tiktok.mappers.data;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.mappers.TikTokMapperHelper;
|
import io.github.jwdeveloper.tiktok.mappers.LiveMapperHelper;
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface MappingAction<T> {
|
public interface MappingAction<T> {
|
||||||
@@ -33,6 +33,6 @@ public interface MappingAction<T> {
|
|||||||
* @param mapperHelper utils and helper methods that can be use to debbug/display/deserialize protocol buffer data
|
* @param mapperHelper utils and helper methods that can be use to debbug/display/deserialize protocol buffer data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
T onMapping(byte[] inputBytes, String messageName, TikTokMapperHelper mapperHelper);
|
T onMapping(byte[] inputBytes, String messageName, LiveMapperHelper mapperHelper);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,8 @@ package io.github.jwdeveloper.tiktok.websocket;
|
|||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
|
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
|
||||||
|
|
||||||
public interface SocketClient {
|
public interface LiveSocketClient {
|
||||||
void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient);
|
void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient);
|
||||||
void stop();
|
void stop();
|
||||||
}
|
}
|
||||||
@@ -1062,9 +1062,9 @@ message CohostListChangeContent {
|
|||||||
|
|
||||||
|
|
||||||
message LinkerListChangeContent {
|
message LinkerListChangeContent {
|
||||||
repeated ListUser linkedUsersList = 1;
|
repeated ListUser linkedUsers = 1;
|
||||||
repeated ListUser appliedUsersList = 2;
|
repeated ListUser appliedUsers = 2;
|
||||||
repeated ListUser connectingUsersList = 3;
|
repeated ListUser connectingUsers = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message LinkerMediaChangeContent {
|
message LinkerMediaChangeContent {
|
||||||
|
|||||||
@@ -250,21 +250,21 @@ enum CommonContentCase {
|
|||||||
|
|
||||||
|
|
||||||
enum LinkMessageType {
|
enum LinkMessageType {
|
||||||
TPYE_LINKER_UNKNOWN = 0;
|
TYPE_LINKER_UNKNOWN = 0;
|
||||||
TYPE_LINKER_CREATE = 1;
|
TYPE_LINKER_CREATE = 1;
|
||||||
TYPE_LINKER_CLOSE = 2;
|
TYPE_LINKER_CLOSE = 2;
|
||||||
TYPE_LINKER_INVITE = 3;
|
TYPE_LINKER_INVITE = 3;
|
||||||
TYPE_LINKER_APPLY = 4;
|
TYPE_LINKER_APPLY = 4;
|
||||||
TYPE_LINKER_REPLY = 5;
|
TYPE_LINKER_REPLY = 5;
|
||||||
TPYE_LINKER_ENTER = 6;
|
TYPE_LINKER_ENTER = 6;
|
||||||
TPYE_LINKER_LEAVE = 7;
|
TYPE_LINKER_LEAVE = 7;
|
||||||
TYPE_LINKER_PERMIT = 8;
|
TYPE_LINKER_PERMIT = 8;
|
||||||
TPYE_LINKER_CANCEL_INVITE = 9;
|
TYPE_LINKER_CANCEL_INVITE = 9;
|
||||||
TYPE_LINKER_WAITING_LIST_CHANGE = 10;
|
TYPE_LINKER_WAITING_LIST_CHANGE = 10;
|
||||||
TYPE_LINKER_LINKED_LIST_CHANGE = 11;
|
TYPE_LINKER_LINKED_LIST_CHANGE = 11;
|
||||||
TYPE_LINKER_UPDATE_USER = 12;
|
TYPE_LINKER_UPDATE_USER = 12;
|
||||||
TPYE_LINKER_KICK_OUT = 13;
|
TYPE_LINKER_KICK_OUT = 13;
|
||||||
TPYE_LINKER_CANCEL_APPLY = 14;
|
TYPE_LINKER_CANCEL_APPLY = 14;
|
||||||
TYPE_LINKER_MUTE = 15;
|
TYPE_LINKER_MUTE = 15;
|
||||||
TYPE_LINKER_MATCH = 16;
|
TYPE_LINKER_MATCH = 16;
|
||||||
TYPE_LINKER_UPDATE_USER_SETTING = 17;
|
TYPE_LINKER_UPDATE_USER_SETTING = 17;
|
||||||
@@ -275,8 +275,8 @@ enum LinkMessageType {
|
|||||||
TYPE_LINKER_COHOST_LIST_CHANGE = 22;
|
TYPE_LINKER_COHOST_LIST_CHANGE = 22;
|
||||||
TYPE_LINKER_MEDIA_CHANGE = 23;
|
TYPE_LINKER_MEDIA_CHANGE = 23;
|
||||||
TYPE_LINKER_ACCEPT_NOTICE = 24;
|
TYPE_LINKER_ACCEPT_NOTICE = 24;
|
||||||
TPYE_LINKER_SYS_KICK_OUT = 101;
|
TYPE_LINKER_SYS_KICK_OUT = 101;
|
||||||
TPYE_LINKMIC_USER_TOAST = 102;
|
TYPE_LINKMIC_USER_TOAST = 102;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MessageType {
|
enum MessageType {
|
||||||
|
|||||||
@@ -805,7 +805,7 @@ message WebcastLinkMessage {
|
|||||||
LinkerListChangeContent ListChangeContent = 20;
|
LinkerListChangeContent ListChangeContent = 20;
|
||||||
CohostListChangeContent CohostListChangeContent = 21;
|
CohostListChangeContent CohostListChangeContent = 21;
|
||||||
LinkerMediaChangeContent MediaChangeContent = 22;
|
LinkerMediaChangeContent MediaChangeContent = 22;
|
||||||
LinkerAcceptNoticeContent ReplyAcceptNoticeContent = 23;
|
LinkerAcceptNoticeContent AcceptNoticeContent = 23;
|
||||||
LinkerSysKickOutContent SysKickOutContent = 101;
|
LinkerSysKickOutContent SysKickOutContent = 101;
|
||||||
LinkmicUserToastContent UserToastContent = 102;
|
LinkmicUserToastContent UserToastContent = 102;
|
||||||
string extra = 200;
|
string extra = 200;
|
||||||
|
|||||||
@@ -5,13 +5,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.6.1-Release</version>
|
<version>1.8.0-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>Client</artifactId>
|
<artifactId>Client</artifactId>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
|||||||
@@ -23,19 +23,21 @@
|
|||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftsManager;
|
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftsManager;
|
||||||
import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
|
import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
|
||||||
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
||||||
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
|
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class TikTokLive {
|
public class TikTokLive {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of Tiktok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return LiveClientBuilder
|
* @return LiveClientBuilder
|
||||||
*/
|
*/
|
||||||
public static LiveClientBuilder newClient(String hostName) {
|
public static LiveClientBuilder newClient(String hostName) {
|
||||||
@@ -45,7 +47,7 @@ public class TikTokLive {
|
|||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of Tiktok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return true if live is Online, false if is offline
|
* @return true if live is Online, false if is offline
|
||||||
*/
|
*/
|
||||||
public static boolean isLiveOnline(String hostName) {
|
public static boolean isLiveOnline(String hostName) {
|
||||||
@@ -55,7 +57,7 @@ public class TikTokLive {
|
|||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of Tiktok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return true if live is Online, false if is offline
|
* @return true if live is Online, false if is offline
|
||||||
*/
|
*/
|
||||||
public static CompletableFuture<Boolean> isLiveOnlineAsync(String hostName) {
|
public static CompletableFuture<Boolean> isLiveOnlineAsync(String hostName) {
|
||||||
@@ -65,7 +67,7 @@ public class TikTokLive {
|
|||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of Tiktok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return true is hostName name is valid and exists, false if not
|
* @return true is hostName name is valid and exists, false if not
|
||||||
*/
|
*/
|
||||||
public static boolean isHostNameValid(String hostName) {
|
public static boolean isHostNameValid(String hostName) {
|
||||||
@@ -75,7 +77,7 @@ public class TikTokLive {
|
|||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of Tiktok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return true is hostName name is valid and exists, false if not
|
* @return true is hostName name is valid and exists, false if not
|
||||||
*/
|
*/
|
||||||
public static CompletableFuture<Boolean> isHostNameValidAsync(String hostName) {
|
public static CompletableFuture<Boolean> isHostNameValidAsync(String hostName) {
|
||||||
@@ -87,11 +89,19 @@ public class TikTokLive {
|
|||||||
*
|
*
|
||||||
* @return LiveHttpClient
|
* @return LiveHttpClient
|
||||||
*/
|
*/
|
||||||
public static LiveHttpClient requests() {
|
public static LiveHttpClient requests(Consumer<LiveClientSettings> consumer) {
|
||||||
return new TikTokLiveHttpClient();
|
return new TikTokLiveHttpClient(consumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use to get some data from TikTok about users are lives
|
||||||
|
*
|
||||||
|
* @return LiveHttpClient
|
||||||
|
*/
|
||||||
|
public static LiveHttpClient requests() {
|
||||||
|
return requests(liveClientSettings -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
//I don't like it, but it is reasonable for now
|
|
||||||
private static GiftsManager giftsManager;
|
private static GiftsManager giftsManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -36,37 +36,40 @@ import io.github.jwdeveloper.tiktok.listener.*;
|
|||||||
import io.github.jwdeveloper.tiktok.live.*;
|
import io.github.jwdeveloper.tiktok.live.*;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||||
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
||||||
import io.github.jwdeveloper.tiktok.websocket.SocketClient;
|
import io.github.jwdeveloper.tiktok.websocket.LiveSocketClient;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class TikTokLiveClient implements LiveClient {
|
@Getter
|
||||||
private final TikTokRoomInfo liveRoomInfo;
|
public class TikTokLiveClient implements LiveClient
|
||||||
|
{
|
||||||
|
private final TikTokRoomInfo roomInfo;
|
||||||
private final LiveHttpClient httpClient;
|
private final LiveHttpClient httpClient;
|
||||||
private final SocketClient webSocketClient;
|
private final LiveSocketClient webSocketClient;
|
||||||
private final TikTokLiveEventHandler tikTokEventHandler;
|
private final LiveEventsHandler tikTokEventHandler;
|
||||||
private final LiveClientSettings clientSettings;
|
private final LiveClientSettings clientSettings;
|
||||||
private final TikTokListenersManager listenersManager;
|
private final ListenersManager listenersManager;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final GiftsManager giftsManager;
|
private final GiftsManager giftManager;
|
||||||
private final TikTokLiveMessageHandler messageHandler;
|
private final LiveMessagesHandler messageHandler;
|
||||||
|
|
||||||
public TikTokLiveClient(
|
public TikTokLiveClient(
|
||||||
TikTokLiveMessageHandler messageHandler,
|
LiveMessagesHandler messageHandler,
|
||||||
GiftsManager giftsManager,
|
GiftsManager giftsManager,
|
||||||
TikTokRoomInfo tikTokLiveMeta,
|
TikTokRoomInfo tikTokLiveMeta,
|
||||||
LiveHttpClient tiktokHttpClient,
|
LiveHttpClient tiktokHttpClient,
|
||||||
SocketClient webSocketClient,
|
LiveSocketClient webSocketClient,
|
||||||
TikTokLiveEventHandler tikTokEventHandler,
|
LiveEventsHandler tikTokEventHandler,
|
||||||
LiveClientSettings clientSettings,
|
LiveClientSettings clientSettings,
|
||||||
TikTokListenersManager listenersManager,
|
ListenersManager listenersManager,
|
||||||
Logger logger) {
|
Logger logger) {
|
||||||
this.messageHandler = messageHandler;
|
this.messageHandler = messageHandler;
|
||||||
this.giftsManager = giftsManager;
|
this.giftManager = giftsManager;
|
||||||
this.liveRoomInfo = tikTokLiveMeta;
|
this.roomInfo = tikTokLiveMeta;
|
||||||
this.httpClient = tiktokHttpClient;
|
this.httpClient = tiktokHttpClient;
|
||||||
this.webSocketClient = webSocketClient;
|
this.webSocketClient = webSocketClient;
|
||||||
this.tikTokEventHandler = tikTokEventHandler;
|
this.tikTokEventHandler = tikTokEventHandler;
|
||||||
@@ -75,22 +78,6 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void connectAsync(Consumer<LiveClient> onConnection) {
|
|
||||||
CompletableFuture.runAsync(() -> {
|
|
||||||
connect();
|
|
||||||
onConnection.accept(this);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public CompletableFuture<LiveClient> connectAsync() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
|
||||||
connect();
|
|
||||||
return this;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void connect() {
|
public void connect() {
|
||||||
try {
|
try {
|
||||||
tryConnect();
|
tryConnect();
|
||||||
@@ -117,61 +104,61 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void tryConnect() {
|
public void tryConnect() {
|
||||||
if (!liveRoomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) {
|
if (!roomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) {
|
||||||
throw new TikTokLiveException("Already connected");
|
throw new TikTokLiveException("Already connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(ConnectionState.CONNECTING);
|
setState(ConnectionState.CONNECTING);
|
||||||
tikTokEventHandler.publish(this, new TikTokConnectingEvent());
|
tikTokEventHandler.publish(this, new TikTokConnectingEvent());
|
||||||
var userDataRequest = new LiveUserData.Request(liveRoomInfo.getHostName());
|
var userDataRequest = new LiveUserData.Request(roomInfo.getHostName());
|
||||||
var userData = httpClient.fetchLiveUserData(userDataRequest);
|
var userData = httpClient.fetchLiveUserData(userDataRequest);
|
||||||
liveRoomInfo.setStartTime(userData.getStartedAtTimeStamp());
|
roomInfo.setStartTime(userData.getStartTime());
|
||||||
liveRoomInfo.setRoomId(userData.getRoomId());
|
roomInfo.setRoomId(userData.getRoomId());
|
||||||
|
|
||||||
if (clientSettings.isFetchGifts())
|
|
||||||
giftsManager.attachGiftsList(httpClient.fetchRoomGiftsData(userData.getRoomId()).getGifts());
|
|
||||||
|
|
||||||
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
|
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
|
||||||
throw new TikTokLiveOfflineHostException("User is offline: " + liveRoomInfo.getHostName());
|
throw new TikTokLiveOfflineHostException("User is offline: " + roomInfo.getHostName());
|
||||||
|
|
||||||
if (userData.getUserStatus() == LiveUserData.UserStatus.NotFound)
|
if (userData.getUserStatus() == LiveUserData.UserStatus.NotFound)
|
||||||
throw new TikTokLiveOfflineHostException("User not found: " + liveRoomInfo.getHostName());
|
throw new TikTokLiveUnknownHostException("User not found: " + roomInfo.getHostName());
|
||||||
|
|
||||||
var liveDataRequest = new LiveData.Request(userData.getRoomId());
|
var liveDataRequest = new LiveData.Request(userData.getRoomId());
|
||||||
var liveData = httpClient.fetchLiveData(liveDataRequest);
|
var liveData = httpClient.fetchLiveData(liveDataRequest);
|
||||||
|
|
||||||
if (liveData.isAgeRestricted() && clientSettings.isThrowOnAgeRestriction())
|
if (liveData.isAgeRestricted() && clientSettings.isThrowOnAgeRestriction())
|
||||||
throw new TikTokLiveException("Livestream for " + liveRoomInfo.getHostName() + " is 18+ or age restricted!");
|
throw new TikTokLiveException("Livestream for " + roomInfo.getHostName() + " is 18+ or age restricted!");
|
||||||
|
|
||||||
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostNotFound)
|
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostNotFound)
|
||||||
throw new TikTokLiveOfflineHostException("LiveStream for " + liveRoomInfo.getHostName() + " could not be found.");
|
throw new TikTokLiveUnknownHostException("LiveStream for " + roomInfo.getHostName() + " could not be found.");
|
||||||
|
|
||||||
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostOffline)
|
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostOffline)
|
||||||
throw new TikTokLiveOfflineHostException("LiveStream for " + liveRoomInfo.getHostName() + " not found, is the Host offline?");
|
throw new TikTokLiveOfflineHostException("LiveStream for " + roomInfo.getHostName() + " not found, is the Host offline?");
|
||||||
|
|
||||||
tikTokEventHandler.publish(this, new TikTokRoomDataResponseEvent(liveData));
|
tikTokEventHandler.publish(this, new TikTokRoomDataResponseEvent(liveData));
|
||||||
|
|
||||||
liveRoomInfo.setTitle(liveData.getTitle());
|
roomInfo.setTitle(liveData.getTitle());
|
||||||
liveRoomInfo.setViewersCount(liveData.getViewers());
|
roomInfo.setViewersCount(liveData.getViewers());
|
||||||
liveRoomInfo.setTotalViewersCount(liveData.getTotalViewers());
|
roomInfo.setTotalViewersCount(liveData.getTotalViewers());
|
||||||
liveRoomInfo.setAgeRestricted(liveData.isAgeRestricted());
|
roomInfo.setAgeRestricted(liveData.isAgeRestricted());
|
||||||
liveRoomInfo.setHost(liveData.getHost());
|
roomInfo.setHost(liveData.getHost());
|
||||||
|
|
||||||
var preconnectEvent = new TikTokPreConnectionEvent(userData, liveData);
|
var preconnectEvent = new TikTokPreConnectionEvent(userData, liveData);
|
||||||
tikTokEventHandler.publish(this, preconnectEvent);
|
tikTokEventHandler.publish(this, preconnectEvent);
|
||||||
if (preconnectEvent.isCancelConnection())
|
if (preconnectEvent.isCancelConnection())
|
||||||
throw new TikTokLiveException("TikTokPreConnectionEvent cancelled connection!");
|
throw new TikTokLiveException("TikTokPreConnectionEvent cancelled connection!");
|
||||||
|
|
||||||
|
if (clientSettings.isFetchGifts())
|
||||||
|
giftManager.attachGiftsList(httpClient.fetchRoomGiftsData(userData.getRoomId()).getGifts());
|
||||||
|
|
||||||
var liveConnectionRequest = new LiveConnectionData.Request(userData.getRoomId());
|
var liveConnectionRequest = new LiveConnectionData.Request(userData.getRoomId());
|
||||||
var liveConnectionData = httpClient.fetchLiveConnectionData(liveConnectionRequest);
|
var liveConnectionData = httpClient.fetchLiveConnectionData(liveConnectionRequest);
|
||||||
webSocketClient.start(liveConnectionData, this);
|
webSocketClient.start(liveConnectionData, this);
|
||||||
|
|
||||||
setState(ConnectionState.CONNECTED);
|
setState(ConnectionState.CONNECTED);
|
||||||
tikTokEventHandler.publish(this, new TikTokRoomInfoEvent(liveRoomInfo));
|
tikTokEventHandler.publish(this, new TikTokRoomInfoEvent(roomInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
if (liveRoomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) {
|
if (roomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setState(ConnectionState.DISCONNECTED);
|
setState(ConnectionState.DISCONNECTED);
|
||||||
@@ -180,7 +167,7 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
|
|
||||||
private void setState(ConnectionState connectionState) {
|
private void setState(ConnectionState connectionState) {
|
||||||
logger.info("TikTokLive client state: " + connectionState.name());
|
logger.info("TikTokLive client state: " + connectionState.name());
|
||||||
liveRoomInfo.setConnectionState(connectionState);
|
roomInfo.setConnectionState(connectionState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void publishEvent(TikTokEvent event) {
|
public void publishEvent(TikTokEvent event) {
|
||||||
@@ -201,22 +188,15 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
messageHandler.handleSingleMessage(this, message);
|
messageHandler.handleSingleMessage(this, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public GiftsManager getGiftManager() {
|
public void connectAsync(Consumer<LiveClient> onConnection) {
|
||||||
return giftsManager;
|
connectAsync().thenAccept(onConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveRoomInfo getRoomInfo() {
|
public CompletableFuture<LiveClient> connectAsync() {
|
||||||
return liveRoomInfo;
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
}
|
connect();
|
||||||
|
return this;
|
||||||
@Override
|
});
|
||||||
public ListenersManager getListenersManager() {
|
|
||||||
return listenersManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Logger getLogger() {
|
|
||||||
return logger;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,30 +22,26 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.dependance.Dependance;
|
||||||
|
import io.github.jwdeveloper.dependance.api.DependanceContainer;
|
||||||
|
import io.github.jwdeveloper.dependance.implementation.DependanceContainerBuilder;
|
||||||
|
import io.github.jwdeveloper.tiktok.mappers.MessagesMapperFactory;
|
||||||
import io.github.jwdeveloper.tiktok.common.LoggerFactory;
|
import io.github.jwdeveloper.tiktok.common.LoggerFactory;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.*;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.control.TikTokPreConnectionEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.envelop.TikTokChestEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.gift.*;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.http.TikTokHttpResponseEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.poll.TikTokPollEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.room.*;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.social.*;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.websocket.*;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
||||||
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftsManager;
|
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftsManager;
|
||||||
import io.github.jwdeveloper.tiktok.http.HttpClientFactory;
|
import io.github.jwdeveloper.tiktok.http.HttpClientFactory;
|
||||||
|
import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
|
||||||
import io.github.jwdeveloper.tiktok.listener.*;
|
import io.github.jwdeveloper.tiktok.listener.*;
|
||||||
import io.github.jwdeveloper.tiktok.live.*;
|
import io.github.jwdeveloper.tiktok.live.*;
|
||||||
import io.github.jwdeveloper.tiktok.live.builder.*;
|
import io.github.jwdeveloper.tiktok.live.builder.*;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.*;
|
import io.github.jwdeveloper.tiktok.mappers.*;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokCommonEventHandler;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.handlers.*;
|
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokGiftEventHandler;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokRoomInfoEventHandler;
|
||||||
import io.github.jwdeveloper.tiktok.websocket.TikTokWebSocketClient;
|
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokSocialMediaEventHandler;
|
||||||
import io.github.jwdeveloper.tiktok.websocket.TikTokWebSocketOfflineClient;
|
import io.github.jwdeveloper.tiktok.websocket.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@@ -55,23 +51,28 @@ import java.util.logging.Logger;
|
|||||||
public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
||||||
|
|
||||||
protected final LiveClientSettings clientSettings;
|
protected final LiveClientSettings clientSettings;
|
||||||
protected final TikTokLiveEventHandler eventHandler;
|
protected final LiveEventsHandler eventHandler;
|
||||||
protected final List<TikTokEventListener> listeners;
|
protected final List<Object> listeners;
|
||||||
protected Consumer<TikTokMapper> onCustomMappings;
|
protected final List<Consumer<LiveMapper>> onCustomMappings;
|
||||||
protected Logger logger;
|
protected final List<Consumer<DependanceContainerBuilder>> onCustomDependencies;
|
||||||
protected GiftsManager giftsManager;
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder(String userName) {
|
public TikTokLiveClientBuilder(String userName) {
|
||||||
this.clientSettings = LiveClientSettings.createDefault();
|
this.clientSettings = LiveClientSettings.createDefault();
|
||||||
this.clientSettings.setHostName(userName);
|
this.clientSettings.setHostName(userName);
|
||||||
this.eventHandler = new TikTokLiveEventHandler();
|
this.eventHandler = new TikTokLiveEventHandler();
|
||||||
this.listeners = new ArrayList<>();
|
this.listeners = new ArrayList<>();
|
||||||
this.onCustomMappings = (e) -> {
|
this.onCustomMappings = new ArrayList<>();
|
||||||
};
|
this.onCustomDependencies = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveClientBuilder onMapping(Consumer<TikTokMapper> onCustomMappings) {
|
public LiveClientBuilder mappings(Consumer<LiveMapper> consumer) {
|
||||||
this.onCustomMappings = onCustomMappings;
|
this.onCustomMappings.add(consumer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiveClientBuilder onMappings(Consumer<LiveMapper> onCustomMappings) {
|
||||||
|
mappings(onCustomMappings);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,12 +81,18 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder addListener(TikTokEventListener listener) {
|
public TikTokLiveClientBuilder addListener(Object listener) {
|
||||||
if (listener != null)
|
if (listener != null)
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiveClientBuilder customize(Consumer<DependanceContainerBuilder> onCustomizeDependencies) {
|
||||||
|
this.onCustomDependencies.add(onCustomizeDependencies);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
protected void validate() {
|
protected void validate() {
|
||||||
if (clientSettings.getClientLanguage() == null || clientSettings.getClientLanguage().isEmpty())
|
if (clientSettings.getClientLanguage() == null || clientSettings.getClientLanguage().isEmpty())
|
||||||
clientSettings.setClientLanguage("en");
|
clientSettings.setClientLanguage("en");
|
||||||
@@ -96,147 +103,91 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
if (clientSettings.getHostName().startsWith("@"))
|
if (clientSettings.getHostName().startsWith("@"))
|
||||||
clientSettings.setHostName(clientSettings.getHostName().substring(1));
|
clientSettings.setHostName(clientSettings.getHostName().substring(1));
|
||||||
|
|
||||||
|
//TODO 250 Magic number
|
||||||
if (clientSettings.getPingInterval() < 250)
|
if (clientSettings.getPingInterval() < 250)
|
||||||
throw new TikTokLiveException("Minimum allowed ping interval is 250 millseconds");
|
throw new TikTokLiveException("Minimum allowed ping interval is 250 milliseconds");
|
||||||
|
|
||||||
var httpSettings = clientSettings.getHttpSettings();
|
var httpSettings = clientSettings.getHttpSettings();
|
||||||
httpSettings.getParams().put("app_language", clientSettings.getClientLanguage());
|
httpSettings.getParams().put("app_language", clientSettings.getClientLanguage());
|
||||||
httpSettings.getParams().put("webcast_language", clientSettings.getClientLanguage());
|
httpSettings.getParams().put("webcast_language", clientSettings.getClientLanguage());
|
||||||
|
|
||||||
this.logger = LoggerFactory.create(clientSettings.getHostName(), clientSettings);
|
|
||||||
this.giftsManager = clientSettings.isFetchGifts() ? TikTokLive.gifts() : new TikTokGiftsManager(List.of());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO each class registered to container should implement own interface,
|
||||||
public LiveClient build() {
|
public LiveClient build() {
|
||||||
validate();
|
validate();
|
||||||
|
|
||||||
var tiktokRoomInfo = new TikTokRoomInfo();
|
//Docs: https://github.com/jwdeveloper/DepenDance?tab=readme-ov-file#01-basic
|
||||||
tiktokRoomInfo.setHostName(clientSettings.getHostName());
|
var dependance = Dependance.newContainer();
|
||||||
|
|
||||||
var listenerManager = new TikTokListenersManager(listeners, eventHandler);
|
//config
|
||||||
|
dependance.registerSingleton(LiveClientSettings.class, clientSettings);
|
||||||
|
dependance.registerSingleton(Logger.class, LoggerFactory.create(clientSettings.getHostName(), clientSettings));
|
||||||
|
dependance.registerSingleton(TikTokRoomInfo.class, container ->
|
||||||
|
{
|
||||||
|
var roomInfo = new TikTokRoomInfo();
|
||||||
|
roomInfo.setHostName(clientSettings.getHostName());
|
||||||
|
return roomInfo;
|
||||||
|
});
|
||||||
|
|
||||||
var httpClientFactory = new HttpClientFactory(clientSettings);
|
//messages
|
||||||
|
dependance.registerSingleton(LiveEventsHandler.class, eventHandler);
|
||||||
|
dependance.registerSingleton(LiveMessagesHandler.class, TikTokLiveMessageHandler.class);
|
||||||
|
|
||||||
var liveHttpClient = clientSettings.isOffline() ?
|
//listeners
|
||||||
new TikTokLiveHttpOfflineClient() :
|
dependance.registerSingleton(ListenersManager.class, TikTokListenersManager.class);
|
||||||
new TikTokLiveHttpClient(httpClientFactory, clientSettings);
|
|
||||||
|
|
||||||
var eventsMapper = createMapper(giftsManager, tiktokRoomInfo);
|
//networking
|
||||||
var messageHandler = new TikTokLiveMessageHandler(eventHandler, eventsMapper);
|
dependance.registerSingleton(HttpClientFactory.class);
|
||||||
|
dependance.registerSingleton(TikTokWebSocketPingingTask.class);
|
||||||
var webSocketClient = clientSettings.isOffline() ?
|
if (clientSettings.isOffline()) {
|
||||||
new TikTokWebSocketOfflineClient(eventHandler) :
|
dependance.registerSingleton(LiveSocketClient.class, TikTokWebSocketOfflineClient.class);
|
||||||
new TikTokWebSocketClient(
|
dependance.registerSingleton(LiveHttpClient.class, TikTokLiveHttpOfflineClient.class);
|
||||||
clientSettings,
|
} else {
|
||||||
messageHandler,
|
dependance.registerSingleton(LiveSocketClient.class, TikTokWebSocketClient.class);
|
||||||
eventHandler);
|
dependance.registerSingleton(LiveHttpClient.class, TikTokLiveHttpClient.class);
|
||||||
|
|
||||||
return new TikTokLiveClient(
|
|
||||||
messageHandler,
|
|
||||||
giftsManager,
|
|
||||||
tiktokRoomInfo,
|
|
||||||
liveHttpClient,
|
|
||||||
webSocketClient,
|
|
||||||
eventHandler,
|
|
||||||
clientSettings,
|
|
||||||
listenerManager,
|
|
||||||
logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveMapper createMapper(GiftsManager giftsManager, TikTokRoomInfo roomInfo) {
|
/* TODO in future, custom proxy implementation that can be provided via builder
|
||||||
|
* if(customProxy != null)
|
||||||
|
* dependance.registerSingleton(TikTokProxyProvider.class,customProxy);
|
||||||
|
* else
|
||||||
|
* dependance.registerSingleton(TikTokProxyProvider.class,DefaultProxyProvider.class);
|
||||||
|
*/
|
||||||
|
|
||||||
|
//gifts
|
||||||
|
if (clientSettings.isFetchGifts()) {
|
||||||
|
dependance.registerSingleton(GiftsManager.class, TikTokLive.gifts());
|
||||||
|
} else {
|
||||||
|
dependance.registerSingleton(GiftsManager.class, new TikTokGiftsManager(List.of()));
|
||||||
|
}
|
||||||
|
|
||||||
var eventMapper = new TikTokGenericEventMapper();
|
//mapper
|
||||||
var mapper = new TikTokLiveMapper(new TikTokLiveMapperHelper(eventMapper));
|
dependance.registerSingleton(TikTokGenericEventMapper.class);
|
||||||
|
dependance.registerSingleton(LiveMapperHelper.class, TikTokLiveMapperHelper.class);
|
||||||
//ConnectionEvents events
|
dependance.registerSingleton(LiveMapper.class, (container) ->
|
||||||
var commonHandler = new TikTokCommonEventHandler();
|
|
||||||
var giftHandler = new TikTokGiftEventHandler(giftsManager, roomInfo);
|
|
||||||
var roomInfoHandler = new TikTokRoomInfoEventHandler(roomInfo);
|
|
||||||
var socialHandler = new TikTokSocialMediaEventHandler(roomInfo);
|
|
||||||
|
|
||||||
|
|
||||||
mapper.forMessage(WebcastControlMessage.class, commonHandler::handleWebcastControlMessage);
|
|
||||||
|
|
||||||
//Room status events
|
|
||||||
mapper.forMessage(WebcastLiveIntroMessage.class, roomInfoHandler::handleIntro);
|
|
||||||
mapper.forMessage(WebcastRoomUserSeqMessage.class, roomInfoHandler::handleUserRanking);
|
|
||||||
mapper.forMessage(WebcastCaptionMessage.class, (inputBytes, messageName, mapperHelper) ->
|
|
||||||
{
|
{
|
||||||
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastCaptionMessage.class);
|
var dependace = (DependanceContainer) container.find(DependanceContainer.class);
|
||||||
return MappingResult.of(messageObject, new TikTokCaptionEvent(messageObject));
|
var mapper = MessagesMapperFactory.create(dependace);
|
||||||
});
|
onCustomMappings.forEach(action -> action.accept(mapper));
|
||||||
|
|
||||||
|
|
||||||
//User Interactions events
|
|
||||||
mapper.forMessage(WebcastChatMessage.class, (inputBytes, messageName, mapperHelper) ->
|
|
||||||
{
|
|
||||||
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastChatMessage.class);
|
|
||||||
return MappingResult.of(messageObject, new TikTokCommentEvent(messageObject));
|
|
||||||
});
|
|
||||||
mapper.forMessage(WebcastSubNotifyMessage.class, (inputBytes, messageName, mapperHelper) ->
|
|
||||||
{
|
|
||||||
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastSubNotifyMessage.class);
|
|
||||||
return MappingResult.of(messageObject, new TikTokSubscribeEvent(messageObject));
|
|
||||||
});
|
|
||||||
mapper.forMessage(WebcastEmoteChatMessage.class, (inputBytes, messageName, mapperHelper) ->
|
|
||||||
{
|
|
||||||
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastEmoteChatMessage.class);
|
|
||||||
return MappingResult.of(messageObject, new TikTokEmoteEvent(messageObject));
|
|
||||||
});
|
|
||||||
mapper.forMessage(WebcastQuestionNewMessage.class, (inputBytes, messageName, mapperHelper) ->
|
|
||||||
{
|
|
||||||
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastQuestionNewMessage.class);
|
|
||||||
return MappingResult.of(messageObject, new TikTokQuestionEvent(messageObject));
|
|
||||||
});
|
|
||||||
|
|
||||||
mapper.forMessage(WebcastLikeMessage.class, roomInfoHandler::handleLike);
|
|
||||||
mapper.forMessage(WebcastGiftMessage.class, giftHandler::handleGifts);
|
|
||||||
mapper.forMessage(WebcastSocialMessage.class, socialHandler::handle);
|
|
||||||
mapper.forMessage(WebcastMemberMessage.class, roomInfoHandler::handleMemberMessage);
|
|
||||||
|
|
||||||
|
|
||||||
//Host Interaction events
|
|
||||||
mapper.forMessage(WebcastPollMessage.class, commonHandler::handlePollEvent);
|
|
||||||
mapper.forMessage(WebcastRoomPinMessage.class, commonHandler::handlePinMessage);
|
|
||||||
mapper.forMessage(WebcastChatMessage.class, (inputBytes, messageName, mapperHelper) ->
|
|
||||||
{
|
|
||||||
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastChatMessage.class);
|
|
||||||
return MappingResult.of(messageObject, new TikTokCommentEvent(messageObject));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
//LinkMic events
|
|
||||||
mapper.forMessage(WebcastLinkMicBattle.class, (inputBytes, messageName, mapperHelper) -> {
|
|
||||||
var message = mapperHelper.bytesToWebcastObject(inputBytes, WebcastLinkMicBattle.class);
|
|
||||||
return MappingResult.of(message, new TikTokLinkMicBattleEvent(message));
|
|
||||||
});
|
|
||||||
mapper.forMessage(WebcastLinkMicArmies.class, (inputBytes, messageName, mapperHelper) -> {
|
|
||||||
var message = mapperHelper.bytesToWebcastObject(inputBytes, WebcastLinkMicArmies.class);
|
|
||||||
return MappingResult.of(message, new TikTokLinkMicArmiesEvent(message));
|
|
||||||
});
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastLinkMicMethod.class, TikTokLinkMicMethodEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastLinkMicFanTicketMethod.class, TikTokLinkMicFanTicketEvent.class);
|
|
||||||
|
|
||||||
//Rank events
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastRankTextMessage.class, TikTokRankTextEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastRankUpdateMessage.class, TikTokRankUpdateEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastHourlyRankMessage.class, TikTokRankUpdateEvent.class);
|
|
||||||
|
|
||||||
//Others events
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastInRoomBannerMessage.class, TikTokInRoomBannerEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastMsgDetectMessage.class, TikTokDetectEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastBarrageMessage.class, TikTokBarrageEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastUnauthorizedMemberMessage.class, TikTokUnauthorizedMemberEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastOecLiveShoppingMessage.class, TikTokShopEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastImDeleteMessage.class, TikTokIMDeleteEvent.class);
|
|
||||||
// mapper.bytesToEvents(WebcastEnvelopeMessage.class, commonHandler::handleEnvelop);
|
|
||||||
|
|
||||||
|
|
||||||
onCustomMappings.accept(mapper);
|
|
||||||
return mapper;
|
return mapper;
|
||||||
}
|
});
|
||||||
|
|
||||||
|
//mapper handlers
|
||||||
|
dependance.registerSingleton(TikTokCommonEventHandler.class);
|
||||||
|
dependance.registerSingleton(TikTokGiftEventHandler.class);
|
||||||
|
dependance.registerSingleton(TikTokRoomInfoEventHandler.class);
|
||||||
|
dependance.registerSingleton(TikTokSocialMediaEventHandler.class);
|
||||||
|
|
||||||
|
//client
|
||||||
|
dependance.registerSingleton(LiveClient.class, TikTokLiveClient.class);
|
||||||
|
|
||||||
|
onCustomDependencies.forEach(action -> action.accept(dependance));
|
||||||
|
var container = dependance.build();
|
||||||
|
|
||||||
|
var listenerManager = container.find(ListenersManager.class);
|
||||||
|
listeners.forEach(listenerManager::addListener);
|
||||||
|
return container.find(LiveClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
public LiveClient buildAndConnect() {
|
public LiveClient buildAndConnect() {
|
||||||
var client = build();
|
var client = build();
|
||||||
@@ -248,256 +199,9 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
return build().connectAsync();
|
return build().connectAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onUnhandledSocial(EventConsumer<TikTokUnhandledSocialEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokUnhandledSocialEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiveClientBuilder onChest(EventConsumer<TikTokChestEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokChestEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkMicFanTicket(EventConsumer<TikTokLinkMicFanTicketEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLinkMicFanTicketEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onEnvelope(EventConsumer<TikTokEnvelopeEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokEnvelopeEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onShop(EventConsumer<TikTokShopEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokShopEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onDetect(EventConsumer<TikTokDetectEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokDetectEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkLayer(EventConsumer<TikTokLinkLayerEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLinkLayerEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onConnected(EventConsumer<TikTokConnectedEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokConnectedEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onPreConnection(EventConsumer<TikTokPreConnectionEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokPreConnectionEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onCaption(EventConsumer<TikTokCaptionEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokCaptionEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onQuestion(EventConsumer<TikTokQuestionEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokQuestionEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onRoomPin(EventConsumer<TikTokRoomPinEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokRoomPinEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends TikTokEvent> LiveClientBuilder onEvent(Class<E> eventClass, EventConsumer<E> event) {
|
public <E extends TikTokEvent> LiveClientBuilder onEvent(Class<E> eventClass, EventConsumer<E> action) {
|
||||||
eventHandler.subscribe(eventClass, event);
|
eventHandler.subscribe(eventClass, action);
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TikTokLiveClientBuilder onRoomInfo(EventConsumer<TikTokRoomInfoEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokRoomInfoEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLivePaused(EventConsumer<TikTokLivePausedEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLivePausedEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TikTokLiveClientBuilder onLiveUnpaused(EventConsumer<TikTokLiveUnpausedEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLiveUnpausedEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLike(EventConsumer<TikTokLikeEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLikeEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLink(EventConsumer<TikTokLinkEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLinkEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onBarrage(EventConsumer<TikTokBarrageEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokBarrageEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onGift(EventConsumer<TikTokGiftEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokGiftEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onGiftCombo(EventConsumer<TikTokGiftComboEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokGiftComboEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkMicArmies(EventConsumer<TikTokLinkMicArmiesEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLinkMicArmiesEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onEmote(EventConsumer<TikTokEmoteEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokEmoteEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onUnauthorizedMember(EventConsumer<TikTokUnauthorizedMemberEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokUnauthorizedMemberEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onInRoomBanner(EventConsumer<TikTokInRoomBannerEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokInRoomBannerEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkMicMethod(EventConsumer<TikTokLinkMicMethodEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLinkMicMethodEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onSubscribe(EventConsumer<TikTokSubscribeEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokSubscribeEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onPoll(EventConsumer<TikTokPollEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokPollEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onFollow(EventConsumer<TikTokFollowEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokFollowEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onComment(EventConsumer<TikTokCommentEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokCommentEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LiveClientBuilder onHttpResponse(EventConsumer<TikTokHttpResponseEvent> action) {
|
|
||||||
eventHandler.subscribe(TikTokHttpResponseEvent.class, action);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onGoalUpdate(EventConsumer<TikTokGoalUpdateEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokGoalUpdateEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onRankUpdate(EventConsumer<TikTokRankUpdateEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokRankUpdateEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onIMDelete(EventConsumer<TikTokIMDeleteEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokIMDeleteEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLiveEnded(EventConsumer<TikTokLiveEndedEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLiveEndedEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onError(EventConsumer<TikTokErrorEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokErrorEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onJoin(EventConsumer<TikTokJoinEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokJoinEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onRankText(EventConsumer<TikTokRankTextEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokRankTextEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onShare(EventConsumer<TikTokShareEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokShareEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onUnhandledMember(EventConsumer<TikTokUnhandledMemberEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokUnhandledMemberEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onSubNotify(EventConsumer<TikTokSubNotifyEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokSubNotifyEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkMicBattle(EventConsumer<TikTokLinkMicBattleEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLinkMicBattleEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onDisconnected(EventConsumer<TikTokDisconnectedEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokDisconnectedEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onUnhandledControl(EventConsumer<TikTokUnhandledControlEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokUnhandledControlEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onEvent(EventConsumer<TikTokEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TikTokLiveClientBuilder onWebsocketResponse(EventConsumer<TikTokWebsocketResponseEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokWebsocketResponseEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TikTokLiveClientBuilder onWebsocketMessage(EventConsumer<TikTokWebsocketMessageEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokWebsocketMessageEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TikTokLiveClientBuilder onWebsocketUnhandledMessage(EventConsumer<TikTokWebsocketUnhandledMessageEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokWebsocketUnhandledMessageEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TikTokLiveClientBuilder onReconnecting(EventConsumer<TikTokReconnectingEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokReconnectingEvent.class, event);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,15 +23,13 @@
|
|||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveEventsHandler;
|
||||||
import io.github.jwdeveloper.tiktok.live.builder.EventConsumer;
|
import io.github.jwdeveloper.tiktok.live.builder.EventConsumer;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class TikTokLiveEventHandler {
|
public class TikTokLiveEventHandler implements LiveEventsHandler {
|
||||||
private final Map<Class<?>, Set<EventConsumer>> events;
|
private final Map<Class<?>, Set<EventConsumer>> events;
|
||||||
|
|
||||||
public TikTokLiveEventHandler() {
|
public TikTokLiveEventHandler() {
|
||||||
@@ -39,21 +37,8 @@ public class TikTokLiveEventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void publish(LiveClient tikTokLiveClient, TikTokEvent tikTokEvent) {
|
public void publish(LiveClient tikTokLiveClient, TikTokEvent tikTokEvent) {
|
||||||
if (events.containsKey(TikTokEvent.class)) {
|
Optional.ofNullable(events.get(TikTokEvent.class)).ifPresent(handlers -> handlers.forEach(handler -> handler.onEvent(tikTokLiveClient, tikTokEvent)));
|
||||||
var handlers = events.get(TikTokEvent.class);
|
Optional.ofNullable(events.get(tikTokEvent.getClass())).ifPresent(handlers -> handlers.forEach(handler -> handler.onEvent(tikTokLiveClient, tikTokEvent)));
|
||||||
for (var handle : handlers) {
|
|
||||||
handle.onEvent(tikTokLiveClient, tikTokEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!events.containsKey(tikTokEvent.getClass())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var handlers = events.get(tikTokEvent.getClass());
|
|
||||||
for (var handler : handlers) {
|
|
||||||
handler.onEvent(tikTokLiveClient, tikTokEvent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends TikTokEvent> void subscribe(Class<?> clazz, EventConsumer<T> event) {
|
public <T extends TikTokEvent> void subscribe(Class<?> clazz, EventConsumer<T> event) {
|
||||||
@@ -65,22 +50,10 @@ public class TikTokLiveEventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <T extends TikTokEvent> void unsubscribe(EventConsumer<T> consumer) {
|
public <T extends TikTokEvent> void unsubscribe(EventConsumer<T> consumer) {
|
||||||
for (var entry : events.entrySet()) {
|
events.forEach((key, value) -> value.remove(consumer));
|
||||||
entry.getValue().remove(consumer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends TikTokEvent> void unsubscribe(Class<?> clazz, EventConsumer<T> consumer) {
|
public <T extends TikTokEvent> void unsubscribe(Class<?> clazz, EventConsumer<T> consumer) {
|
||||||
if (clazz == null) {
|
Optional.ofNullable(clazz).map(events::get).ifPresent(consumers -> consumers.remove(consumer));
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!events.containsKey(clazz)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var eventSet = events.get(clazz);
|
|
||||||
eventSet.remove(consumer);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import io.github.jwdeveloper.dependance.injector.api.annotations.Inject;
|
||||||
import io.github.jwdeveloper.tiktok.common.*;
|
import io.github.jwdeveloper.tiktok.common.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.*;
|
import io.github.jwdeveloper.tiktok.data.requests.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
@@ -32,6 +33,7 @@ import io.github.jwdeveloper.tiktok.http.mappers.*;
|
|||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||||
|
|
||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class TikTokLiveHttpClient implements LiveHttpClient
|
public class TikTokLiveHttpClient implements LiveHttpClient
|
||||||
@@ -53,17 +55,19 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
private final GiftsDataMapper giftsDataMapper;
|
private final GiftsDataMapper giftsDataMapper;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
public TikTokLiveHttpClient(HttpClientFactory factory, LiveClientSettings settings) {
|
@Inject
|
||||||
|
public TikTokLiveHttpClient(HttpClientFactory factory) {
|
||||||
this.httpFactory = factory;
|
this.httpFactory = factory;
|
||||||
this.clientSettings = settings;
|
this.clientSettings = factory.getLiveClientSettings();
|
||||||
this.logger = LoggerFactory.create("HttpClient", clientSettings);
|
this.logger = LoggerFactory.create("HttpClient-"+hashCode(), clientSettings);
|
||||||
liveUserDataMapper = new LiveUserDataMapper();
|
liveUserDataMapper = new LiveUserDataMapper();
|
||||||
liveDataMapper = new LiveDataMapper();
|
liveDataMapper = new LiveDataMapper();
|
||||||
giftsDataMapper = new GiftsDataMapper();
|
giftsDataMapper = new GiftsDataMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveHttpClient() {
|
public TikTokLiveHttpClient(Consumer<LiveClientSettings> consumer) {
|
||||||
this(new HttpClientFactory(LiveClientSettings.createDefault()), LiveClientSettings.createDefault());
|
this(new HttpClientFactory(LiveClientSettings.createDefault()));
|
||||||
|
consumer.accept(clientSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GiftsData.Response fetchRoomGiftsData(String room_id) {
|
public GiftsData.Response fetchRoomGiftsData(String room_id) {
|
||||||
@@ -132,7 +136,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
var url = TIKTOK_URL_WEB + "api-live/user/room";
|
var url = TIKTOK_URL_WEB + "api-live/user/room";
|
||||||
var result = httpFactory.client(url)
|
var result = httpFactory.client(url)
|
||||||
.withParam("uniqueId", request.getUserName())
|
.withParam("uniqueId", request.getUserName())
|
||||||
.withParam("sourceType", "54")
|
.withParam("sourceType", "54") //MAGIC NUMBER, WHAT 54 means?
|
||||||
.build()
|
.build()
|
||||||
.toJsonResponse();
|
.toJsonResponse();
|
||||||
|
|
||||||
@@ -191,7 +195,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
.withParam("internal_ext", webcastResponse.getInternalExt())
|
.withParam("internal_ext", webcastResponse.getInternalExt())
|
||||||
.withParams(webcastResponse.getRouteParamsMapMap())
|
.withParams(webcastResponse.getRouteParamsMapMap())
|
||||||
.build()
|
.build()
|
||||||
.toUrl();
|
.toUri();
|
||||||
|
|
||||||
return new LiveConnectionData.Response(websocketCookie, webSocketUrl, webcastResponse);
|
return new LiveConnectionData.Response(websocketCookie, webSocketUrl, webcastResponse);
|
||||||
} catch (InvalidProtocolBufferException e) {
|
} catch (InvalidProtocolBufferException e) {
|
||||||
@@ -214,7 +218,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
private ActionResult<HttpResponse<byte[]>> getByteResponse(String room_id) {
|
private 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")
|
.withParam("uuc", "1") //MAGIC NUMBER!
|
||||||
.withParam("room_id", room_id);
|
.withParam("room_id", room_id);
|
||||||
|
|
||||||
if (clientSettings.getApiKey() != null)
|
if (clientSettings.getApiKey() != null)
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
|
|||||||
@@ -30,18 +30,20 @@ import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketRespons
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveMessageException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveMessageException;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.TikTokLiveMapper;
|
import io.github.jwdeveloper.tiktok.live.LiveEventsHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveMessagesHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.mappers.LiveMapper;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||||
import io.github.jwdeveloper.tiktok.utils.Stopwatch;
|
import io.github.jwdeveloper.tiktok.utils.Stopwatch;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
||||||
public class TikTokLiveMessageHandler {
|
public class TikTokLiveMessageHandler implements LiveMessagesHandler {
|
||||||
|
|
||||||
private final TikTokLiveEventHandler tikTokEventHandler;
|
private final LiveEventsHandler tikTokEventHandler;
|
||||||
private final TikTokLiveMapper mapper;
|
private final LiveMapper mapper;
|
||||||
|
|
||||||
public TikTokLiveMessageHandler(TikTokLiveEventHandler tikTokEventHandler, TikTokLiveMapper mapper) {
|
public TikTokLiveMessageHandler(LiveEventsHandler tikTokEventHandler, LiveMapper mapper) {
|
||||||
this.tikTokEventHandler = tikTokEventHandler;
|
this.tikTokEventHandler = tikTokEventHandler;
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
}
|
}
|
||||||
@@ -58,13 +60,13 @@ public class TikTokLiveMessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleSingleMessage(LiveClient client, WebcastResponse.Message message)
|
public void handleSingleMessage(LiveClient client, WebcastResponse.Message message) {
|
||||||
{
|
|
||||||
var messageClassName = message.getMethod();
|
var messageClassName = message.getMethod();
|
||||||
if (!mapper.isRegistered(messageClassName)) {
|
if (!mapper.isRegistered(messageClassName)) {
|
||||||
tikTokEventHandler.publish(client, new TikTokWebsocketUnhandledMessageEvent(message));
|
tikTokEventHandler.publish(client, new TikTokWebsocketUnhandledMessageEvent(message));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var stopwatch = new Stopwatch();
|
var stopwatch = new Stopwatch();
|
||||||
stopwatch.start();
|
stopwatch.start();
|
||||||
var events = mapper.handleMapping(messageClassName, message.getPayload().toByteArray());
|
var events = mapper.handleMapping(messageClassName, message.getPayload().toByteArray());
|
||||||
@@ -76,5 +78,4 @@ public class TikTokLiveMessageHandler {
|
|||||||
tikTokEventHandler.publish(client, event);
|
tikTokEventHandler.publish(client, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.common;
|
package io.github.jwdeveloper.tiktok.common;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
@@ -18,8 +40,8 @@ public class ActionResult<T> {
|
|||||||
.setPrettyPrinting().create();
|
.setPrettyPrinting().create();
|
||||||
|
|
||||||
private boolean success = true;
|
private boolean success = true;
|
||||||
private T content;
|
|
||||||
private String message;
|
private String message;
|
||||||
|
private T content;
|
||||||
@Accessors(chain = true, fluent = true)
|
@Accessors(chain = true, fluent = true)
|
||||||
private ActionResult<?> previous;
|
private ActionResult<?> previous;
|
||||||
|
|
||||||
@@ -100,8 +122,8 @@ public class ActionResult<T> {
|
|||||||
public JsonObject toJson() {
|
public JsonObject toJson() {
|
||||||
JsonObject map = new JsonObject();
|
JsonObject map = new JsonObject();
|
||||||
map.addProperty("success", success);
|
map.addProperty("success", success);
|
||||||
map.add("content", gson.toJsonTree(content));
|
|
||||||
map.addProperty("message", message);
|
map.addProperty("message", message);
|
||||||
|
map.add("content", gson.toJsonTree(content));
|
||||||
map.add("previous", hasPrevious() ? previous.toJson() : null);
|
map.add("previous", hasPrevious() ? previous.toJson() : null);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.common;
|
package io.github.jwdeveloper.tiktok.common;
|
||||||
|
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.common;
|
package io.github.jwdeveloper.tiktok.common;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.gifts;
|
package io.github.jwdeveloper.tiktok.gifts;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||||
@@ -7,6 +29,7 @@ import java.util.*;
|
|||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
//TODO I should've been called it TikTokGiftsRepository
|
||||||
public class TikTokGiftsManager implements GiftsManager {
|
public class TikTokGiftsManager implements GiftsManager {
|
||||||
private final Map<Integer, Gift> giftsByIdIndex;
|
private final Map<Integer, Gift> giftsByIdIndex;
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.net.http.*;
|
import java.net.http.*;
|
||||||
import java.nio.charset.*;
|
import java.nio.charset.*;
|
||||||
|
import java.time.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -47,7 +48,21 @@ public class HttpClient {
|
|||||||
try {
|
try {
|
||||||
var response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
|
var response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
|
||||||
var result = ActionResult.of(response);
|
var result = ActionResult.of(response);
|
||||||
return response.statusCode() != 200 ? result.message("HttpResponse Code: ", response.statusCode()).failure() : result.success();
|
return switch (response.statusCode()) {
|
||||||
|
case 420 -> result.message("HttpResponse Code:", response.statusCode(), "| IP Cloudflare Blocked.").failure();
|
||||||
|
case 429 -> {
|
||||||
|
var wait = response.headers().firstValue("ratelimit-reset");
|
||||||
|
if (wait.isEmpty())
|
||||||
|
yield result.message("HttpResponse Code:", response.statusCode(), "| Sign server rate limit reached. Try again later.").failure();
|
||||||
|
Duration duration = Duration.ofSeconds(Long.parseLong(wait.get()));
|
||||||
|
yield result.message("HttpResponse Code:", response.statusCode(),
|
||||||
|
String.format("| Sign server rate limit reached. Try again in %02d:%02d.", duration.toMinutesPart(), duration.toSecondsPart())).failure();
|
||||||
|
}
|
||||||
|
case 500, 501, 502, 503 -> result.message("HttpResponse Code:", response.statusCode(), "| Sign server Error. Try again later.").failure();
|
||||||
|
case 504 -> result.message("HttpResponse Code:", response.statusCode(), "| Sign server Timeout. Try again later.").failure();
|
||||||
|
case 200 -> result.success();
|
||||||
|
default -> result.message("HttpResponse Code:", response.statusCode()).failure();
|
||||||
|
};
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new TikTokLiveRequestException(e);
|
throw new TikTokLiveRequestException(e);
|
||||||
}
|
}
|
||||||
@@ -75,14 +90,14 @@ public class HttpClient {
|
|||||||
return toResponse().map(HttpResponse::body);
|
return toResponse().map(HttpResponse::body);
|
||||||
}
|
}
|
||||||
|
|
||||||
public URI toUrl() {
|
public URI toUri() {
|
||||||
var stringUrl = prepareUrlWithParameters(url, httpClientSettings.getParams());
|
var stringUrl = prepareUrlWithParameters(url, httpClientSettings.getParams());
|
||||||
return URI.create(stringUrl);
|
return URI.create(stringUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpRequest prepareGetRequest() {
|
protected HttpRequest prepareGetRequest() {
|
||||||
var requestBuilder = HttpRequest.newBuilder().GET();
|
var requestBuilder = HttpRequest.newBuilder().GET();
|
||||||
requestBuilder.uri(toUrl());
|
requestBuilder.uri(toUri());
|
||||||
requestBuilder.timeout(httpClientSettings.getTimeout());
|
requestBuilder.timeout(httpClientSettings.getTimeout());
|
||||||
httpClientSettings.getHeaders().forEach(requestBuilder::setHeader);
|
httpClientSettings.getHeaders().forEach(requestBuilder::setHeader);
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,9 @@
|
|||||||
package io.github.jwdeveloper.tiktok.http;
|
package io.github.jwdeveloper.tiktok.http;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.settings.*;
|
import io.github.jwdeveloper.tiktok.data.settings.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class HttpClientFactory {
|
public class HttpClientFactory {
|
||||||
private final LiveClientSettings liveClientSettings;
|
private final LiveClientSettings liveClientSettings;
|
||||||
|
|
||||||
@@ -34,11 +36,4 @@ public class HttpClientFactory {
|
|||||||
public HttpClientBuilder client(String url) {
|
public HttpClientBuilder client(String url) {
|
||||||
return new HttpClientBuilder(url, liveClientSettings.getHttpSettings().clone());
|
return new HttpClientBuilder(url, liveClientSettings.getHttpSettings().clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Does not contains default httpClientSettings, Params, headers, etd
|
|
||||||
public HttpClientBuilder clientEmpty(String url) {
|
|
||||||
var settings = new HttpClientSettings();
|
|
||||||
settings.setProxyClientSettings(liveClientSettings.getHttpSettings().getProxyClientSettings());
|
|
||||||
return new HttpClientBuilder(url, settings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
public X509Certificate[] getAcceptedIssuers() { return null; }
|
public X509Certificate[] getAcceptedIssuers() { return null; }
|
||||||
}}, null);
|
}}, null);
|
||||||
|
|
||||||
URL url = toUrl().toURL();
|
URL url = toUri().toURL();
|
||||||
|
|
||||||
if (proxySettings.hasNext()) {
|
if (proxySettings.hasNext()) {
|
||||||
try {
|
try {
|
||||||
@@ -105,6 +105,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
socksConnection.setSSLSocketFactory(sc.getSocketFactory());
|
socksConnection.setSSLSocketFactory(sc.getSocketFactory());
|
||||||
socksConnection.setConnectTimeout(httpClientSettings.getTimeout().toMillisPart());
|
socksConnection.setConnectTimeout(httpClientSettings.getTimeout().toMillisPart());
|
||||||
socksConnection.setReadTimeout(httpClientSettings.getTimeout().toMillisPart());
|
socksConnection.setReadTimeout(httpClientSettings.getTimeout().toMillisPart());
|
||||||
|
httpClientSettings.getHeaders().forEach(socksConnection::setRequestProperty);
|
||||||
|
|
||||||
byte[] body = socksConnection.getInputStream().readAllBytes();
|
byte[] body = socksConnection.getInputStream().readAllBytes();
|
||||||
|
|
||||||
@@ -116,7 +117,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
|
|
||||||
var responseInfo = createResponseInfo(socksConnection.getResponseCode(), headers);
|
var responseInfo = createResponseInfo(socksConnection.getResponseCode(), headers);
|
||||||
|
|
||||||
var response = createHttpResponse(body, toUrl(), responseInfo);
|
var response = createHttpResponse(body, toUri(), responseInfo);
|
||||||
|
|
||||||
return ActionResult.success(response);
|
return ActionResult.success(response);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.http.mappers;
|
package io.github.jwdeveloper.tiktok.http.mappers;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user