mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 08:49:40 -05:00
Compare commits
153 Commits
1.2.0-Rele
...
develop-1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
617d1c381a | ||
|
|
2bc1993ea5 | ||
|
|
3d4a517adb | ||
|
|
ee0b559758 | ||
|
|
1c9573dc39 | ||
|
|
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 | ||
|
|
5abfd95c89 | ||
|
|
5c715bfd52 | ||
|
|
b153afb332 | ||
|
|
d2ea00bcae | ||
|
|
4297af1349 | ||
|
|
d09c90ef54 | ||
|
|
9c96c8899a | ||
|
|
301df6392d | ||
|
|
fb9fc04ee5 | ||
|
|
43a8ba4225 | ||
|
|
dffccf1f0b | ||
|
|
6dcccccb78 | ||
|
|
0d467d79c3 | ||
|
|
33c98508c0 | ||
|
|
67948b14cc | ||
|
|
22e11a7822 | ||
|
|
4545503441 | ||
|
|
498d34a90b | ||
|
|
103ed7e3ed | ||
|
|
67e70c34bc | ||
|
|
786c24d267 | ||
|
|
966d2f65d8 | ||
|
|
7ba7143f5a | ||
|
|
92fde03f2b | ||
|
|
e058290118 | ||
|
|
d25741b229 | ||
|
|
560a8d7c3b | ||
|
|
6178bc25cf | ||
|
|
48d1138754 | ||
|
|
a5320db820 | ||
|
|
4e1ab35a60 | ||
|
|
cef4972f37 | ||
|
|
713c90a271 | ||
|
|
71853db5cc | ||
|
|
ef90d4cd58 | ||
|
|
dad4048bc0 | ||
|
|
9ba049d37a | ||
|
|
f7d657371b | ||
|
|
eea691a5aa | ||
|
|
a249ac0cdd | ||
|
|
b82c7184b3 | ||
|
|
29631ac468 | ||
|
|
15c642297c | ||
|
|
d3004d76c1 | ||
|
|
3ae73072ff | ||
|
|
9c5f97157a | ||
|
|
ea847bb883 | ||
|
|
45bac053b9 | ||
|
|
8cb647f27a | ||
|
|
ffbd67eef4 | ||
|
|
e923f3fad7 | ||
|
|
faa1185b97 | ||
|
|
ead954dd27 | ||
|
|
e37b30ff12 | ||
|
|
7a5c00d99a | ||
|
|
407f51fa73 | ||
|
|
8581df7f49 | ||
|
|
3e52523644 | ||
|
|
3387986ced | ||
|
|
0fcac60cbe | ||
|
|
63dd8c20ac | ||
|
|
b809bb6cda | ||
|
|
a68eaba5a1 | ||
|
|
0252b9a42f | ||
|
|
1b2a8bad93 | ||
|
|
6b22154c82 | ||
|
|
965816e846 | ||
|
|
6b6e82cd93 | ||
|
|
c93c3144ff | ||
|
|
12c64e1c67 | ||
|
|
5794ff2a57 | ||
|
|
d471e87dd7 | ||
|
|
c89bcad894 | ||
|
|
c9a84c39df | ||
|
|
c1105f1324 | ||
|
|
243ce9bc94 | ||
|
|
4f141edb1a |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,10 +1,11 @@
|
||||
backend-infrastructure/.aws-sam
|
||||
|
||||
|
||||
.db
|
||||
# Created by https://www.gitignore.io/api/osx,linux,python,windows,pycharm,visualstudiocode
|
||||
*.db
|
||||
### Linux ###
|
||||
*~
|
||||
.db
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.1.2-Release</version>
|
||||
<version>1.8.2-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<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)
|
||||
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);
|
||||
} 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) {
|
||||
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() {
|
||||
return new InetSocketAddress(address, port);
|
||||
}
|
||||
|
||||
@@ -38,8 +38,7 @@ public class TikTokBarrageEvent extends TikTokHeaderEvent {
|
||||
private final Picture rightIcon;
|
||||
private final String eventName;
|
||||
private final int duration;
|
||||
|
||||
private BarrageParam barrageParam;
|
||||
private final BarrageParam barrageParam;
|
||||
|
||||
public TikTokBarrageEvent(WebcastBarrageMessage msg) {
|
||||
super(msg.getCommon());
|
||||
@@ -49,6 +48,5 @@ public class TikTokBarrageEvent extends TikTokHeaderEvent {
|
||||
rightIcon = Picture.map(msg.getRightIcon());
|
||||
duration = msg.getDuration();
|
||||
barrageParam = BarrageParam.map(msg);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,9 +38,9 @@ public class TikTokCaptionEvent extends TikTokHeaderEvent {
|
||||
String text;
|
||||
|
||||
public TikTokCaptionEvent(WebcastCaptionMessage msg) {
|
||||
super(msg.getCommon());
|
||||
super(msg.getCommon());
|
||||
captionTimeStamp = msg.getTimeStamp();
|
||||
iSOLanguage = msg.getCaptionData().getLanguage();
|
||||
text = msg.getCaptionData().getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,26 +32,37 @@ import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Triggered every time a new chat comment arrives.
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokCommentEvent extends TikTokHeaderEvent {
|
||||
private final User user;
|
||||
private final String text;
|
||||
private final String getUserLanguage;
|
||||
private final String userLanguage;
|
||||
private final User mentionedUser;
|
||||
private final List<Picture> pictures;
|
||||
private final boolean visibleToSender;
|
||||
|
||||
public TikTokCommentEvent(WebcastChatMessage msg) {
|
||||
super(msg.getCommon());
|
||||
user = User.map(msg.getUser(),msg.getUserIdentity());
|
||||
user = User.map(msg.getUser(), msg.getUserIdentity());
|
||||
text = msg.getContent();
|
||||
visibleToSender = msg.getVisibleToSender();
|
||||
getUserLanguage = msg.getContentLanguage();
|
||||
userLanguage = msg.getContentLanguage();
|
||||
mentionedUser = User.map(msg.getAtUser());
|
||||
pictures = msg.getEmotesListList().stream().map(e -> Picture.map(e.getEmote().getImage())).toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static TikTokCommentEvent of(String userName, String message) {
|
||||
var builder = WebcastChatMessage.newBuilder();
|
||||
builder.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||
.setNickname(userName)
|
||||
.setDisplayId(userName)
|
||||
.build());
|
||||
builder.setContentLanguage("en");
|
||||
builder.setVisibleToSender(true);
|
||||
builder.setContent(message);
|
||||
return new TikTokCommentEvent(builder.build());
|
||||
}
|
||||
}
|
||||
@@ -25,11 +25,13 @@ import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
||||
|
||||
/**
|
||||
* Triggered when the connection is successfully established.
|
||||
*/
|
||||
@EventMeta(eventType = EventType.Control)
|
||||
public class TikTokConnectedEvent extends TikTokLiveClientEvent
|
||||
{
|
||||
|
||||
|
||||
public static TikTokConnectedEvent of()
|
||||
{
|
||||
return new TikTokConnectedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,14 +30,10 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokDetectEvent extends TikTokHeaderEvent {
|
||||
String language;
|
||||
private final String language;
|
||||
|
||||
|
||||
public TikTokDetectEvent(WebcastMsgDetectMessage msg) {
|
||||
super(msg.getCommon());
|
||||
language = msg.getFromRegion();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
public TikTokDetectEvent(WebcastMsgDetectMessage msg) {
|
||||
super(msg.getCommon());
|
||||
language = msg.getFromRegion();
|
||||
}
|
||||
}
|
||||
@@ -26,13 +26,12 @@ import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Triggered when the connection gets disconnected. In that case you can call connect() again to have a reconnect logic.
|
||||
* Note that you should wait a little bit before attempting a reconnect to to avoid being rate-limited.
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Control)
|
||||
public class TikTokDisconnectedEvent extends TikTokLiveClientEvent {
|
||||
@Getter private final String reason;
|
||||
private final String reason;
|
||||
|
||||
public TikTokDisconnectedEvent(String reason) {
|
||||
this.reason = reason.isBlank() ? "None" : reason;
|
||||
}
|
||||
@@ -40,4 +39,10 @@ public class TikTokDisconnectedEvent extends TikTokLiveClientEvent {
|
||||
public TikTokDisconnectedEvent() {
|
||||
this("None");
|
||||
}
|
||||
|
||||
|
||||
public static TikTokDisconnectedEvent of(String reason)
|
||||
{
|
||||
return new TikTokDisconnectedEvent(reason);
|
||||
}
|
||||
}
|
||||
@@ -36,9 +36,9 @@ import lombok.Value;
|
||||
@Value
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokEnvelopeEvent extends TikTokHeaderEvent {
|
||||
User user;
|
||||
public TikTokEnvelopeEvent(WebcastEnvelopeMessage msg) {
|
||||
super(msg.getCommon());
|
||||
user = User.map(msg.getEnvelopeInfo());
|
||||
}
|
||||
}
|
||||
User user;
|
||||
public TikTokEnvelopeEvent(WebcastEnvelopeMessage msg) {
|
||||
super(msg.getCommon());
|
||||
user = User.map(msg.getEnvelopeInfo());
|
||||
}
|
||||
}
|
||||
@@ -25,16 +25,18 @@ package io.github.jwdeveloper.tiktok.data.events;
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* General error event. You should handle this.
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@EventMeta(eventType = EventType.Control)
|
||||
public class TikTokErrorEvent extends TikTokLiveClientEvent
|
||||
{
|
||||
public class TikTokErrorEvent extends TikTokLiveClientEvent {
|
||||
private final Throwable exception;
|
||||
|
||||
|
||||
public static TikTokErrorEvent of(String message) {
|
||||
return new TikTokErrorEvent(new TikTokLiveException(message));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,10 @@ import java.util.List;
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokIMDeleteEvent extends TikTokHeaderEvent {
|
||||
|
||||
List<Long> userIds;
|
||||
private final List<Long> msgIds, userIds;
|
||||
public TikTokIMDeleteEvent(WebcastImDeleteMessage msg) {
|
||||
super(msg.getCommon());
|
||||
this.msgIds = msg.getDeleteMsgIdsListList();
|
||||
this.userIds = msg.getDeleteUserIdsListList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,10 +31,10 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokInRoomBannerEvent extends TikTokHeaderEvent {
|
||||
private final String json;
|
||||
private final String json;
|
||||
|
||||
public TikTokInRoomBannerEvent(WebcastInRoomBannerMessage msg) {
|
||||
super(msg.getHeader());
|
||||
json = msg.getJson();
|
||||
}
|
||||
}
|
||||
public TikTokInRoomBannerEvent(WebcastInRoomBannerMessage msg) {
|
||||
super(msg.getHeader());
|
||||
json = msg.getJson();
|
||||
}
|
||||
}
|
||||
@@ -33,11 +33,7 @@ import lombok.Getter;
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLinkLayerEvent extends TikTokHeaderEvent {
|
||||
|
||||
|
||||
public TikTokLinkLayerEvent(WebcastLinkLayerMessage msg) {
|
||||
super(msg.getCommon());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -27,12 +27,12 @@ import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.models.LinkMicArmy;
|
||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||
import io.github.jwdeveloper.tiktok.messages.enums.LinkMicBattleStatus;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicArmies;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Triggered every time a battle participant receives points. Contains the current status of the battle and the army that suported the group.
|
||||
*/
|
||||
@@ -40,8 +40,10 @@ import java.util.List;
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLinkMicArmiesEvent extends TikTokHeaderEvent {
|
||||
private final Long battleId;
|
||||
|
||||
private final Integer battleStatus;
|
||||
/**
|
||||
true if battle is finished otherwise false
|
||||
*/
|
||||
private final boolean finished;
|
||||
|
||||
private final Picture picture;
|
||||
|
||||
@@ -52,6 +54,6 @@ public class TikTokLinkMicArmiesEvent extends TikTokHeaderEvent {
|
||||
battleId = msg.getId();
|
||||
armies = msg.getBattleItemsList().stream().map(LinkMicArmy::new).toList();
|
||||
picture = Picture.map(msg.getImage());
|
||||
battleStatus = msg.getBattleStatus();
|
||||
finished = msg.getBattleStatus() == LinkMicBattleStatus.ARMY_FINISHED;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,29 +22,62 @@
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.data.events;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.models.LinkMicBattleTeam;
|
||||
import io.github.jwdeveloper.tiktok.data.models.battles.*;
|
||||
import io.github.jwdeveloper.tiktok.messages.enums.LinkMicBattleStatus;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||
import lombok.Getter;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Triggered every time a battle starts.
|
||||
* Triggered every time a battle starts & ends
|
||||
*/
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent {
|
||||
private final Long battleId;
|
||||
private final List<LinkMicBattleTeam> team1;
|
||||
private final List<LinkMicBattleTeam> team2;
|
||||
public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
||||
{
|
||||
private final Long battleId;
|
||||
/**
|
||||
true if battle is finished otherwise false
|
||||
*/
|
||||
private final boolean finished;
|
||||
private final List<Team> teams;
|
||||
|
||||
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
||||
super(msg.getCommon());
|
||||
battleId = msg.getId();
|
||||
team1 = msg.getTeams1List().stream().map(LinkMicBattleTeam::new).toList();
|
||||
team2 = msg.getTeams2List().stream().map(LinkMicBattleTeam::new).toList();
|
||||
}
|
||||
}
|
||||
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
||||
super(msg.getCommon());
|
||||
battleId = msg.getId();
|
||||
finished = msg.getBattleStatus() == LinkMicBattleStatus.BATTLE_FINISHED;
|
||||
teams = new ArrayList<>();
|
||||
if (msg.getHostTeamCount() == 2) { // 1v1 battle
|
||||
teams.add(new Team1v1(msg.getHostTeam(0), msg));
|
||||
teams.add(new Team1v1(msg.getHostTeam(1), msg));
|
||||
} else { // 2v2 battle
|
||||
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() == 2).findFirst().orElse(null), msg));
|
||||
} else {
|
||||
teams.add(new Team2v2(msg.getHostTeam(0), msg.getHostTeam(1), msg));
|
||||
teams.add(new Team2v2(msg.getHostTeam(2), msg.getHostTeam(3), msg));
|
||||
}
|
||||
}
|
||||
|
||||
// Info:
|
||||
// - msg.getDetailsList() & msg.getViewerTeamList() both only have content when battle is finished
|
||||
// - msg.getDetailsCount() & msg.getViewerTeamCount() always is 2 only when battle is finished
|
||||
// - msg.getHostTeamCount() always is 2 for 1v1 or 4 for 2v2
|
||||
}
|
||||
|
||||
public boolean is1v1() {
|
||||
return teams.get(0) instanceof Team1v1;
|
||||
}
|
||||
|
||||
public boolean is2v2() {
|
||||
return teams.get(0) instanceof Team2v2;
|
||||
}
|
||||
|
||||
public boolean isTie() {
|
||||
return isFinished() && teams.get(0).getTotalPoints() == teams.get(1).getTotalPoints();
|
||||
}
|
||||
}
|
||||
@@ -32,10 +32,8 @@ import lombok.Getter;
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLinkMicMethodEvent extends TikTokHeaderEvent {
|
||||
|
||||
public TikTokLinkMicMethodEvent(WebcastLinkMicMethod msg) {
|
||||
super(msg.getCommon());
|
||||
public TikTokLinkMicMethodEvent(WebcastLinkMicMethod msg) {
|
||||
super(msg.getCommon());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,11 +24,14 @@ package io.github.jwdeveloper.tiktok.data.events;
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.control.TikTokConnectingEvent;
|
||||
|
||||
|
||||
/**
|
||||
* Triggered when the live stream gets terminated by the host. Will also trigger the TikTokDisconnectedEvent event.
|
||||
*/
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLiveEndedEvent extends TikTokEvent {
|
||||
|
||||
|
||||
public static TikTokLiveEndedEvent of() {
|
||||
return new TikTokLiveEndedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,7 @@ import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastQuestionNewMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
/*
|
||||
Triggered every time someone asks a new question via the question feature.
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokQuestionEvent extends TikTokHeaderEvent {
|
||||
|
||||
@@ -32,15 +32,14 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokRankTextEvent extends TikTokHeaderEvent {
|
||||
private final String eventType;
|
||||
private final String eventType;
|
||||
|
||||
private final String label;
|
||||
private final String label;
|
||||
|
||||
public TikTokRankTextEvent(WebcastRankTextMessage msg) {
|
||||
super(msg.getCommon());
|
||||
var text = Text.map(msg.getSelfGetBadgeMsg());
|
||||
label = text.getPattern();
|
||||
eventType = text.getKey();
|
||||
}
|
||||
|
||||
}
|
||||
public TikTokRankTextEvent(WebcastRankTextMessage msg) {
|
||||
super(msg.getCommon());
|
||||
var text = Text.map(msg.getSelfGetBadgeMsg());
|
||||
label = text.getPattern();
|
||||
eventType = text.getKey();
|
||||
}
|
||||
}
|
||||
@@ -33,13 +33,11 @@ import lombok.Getter;
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokRankUpdateEvent extends TikTokHeaderEvent {
|
||||
|
||||
public TikTokRankUpdateEvent(WebcastHourlyRankMessage msg) {
|
||||
super(msg.getCommon());
|
||||
public TikTokRankUpdateEvent(WebcastHourlyRankMessage msg) {
|
||||
super(msg.getCommon());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TikTokRankUpdateEvent(WebcastRankUpdateMessage msg) {
|
||||
super(msg.getCommon());
|
||||
}
|
||||
|
||||
}
|
||||
public TikTokRankUpdateEvent(WebcastRankUpdateMessage msg) {
|
||||
super(msg.getCommon());
|
||||
}
|
||||
}
|
||||
@@ -32,25 +32,24 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokShopEvent extends TikTokHeaderEvent {
|
||||
private final String title;
|
||||
private final String title;
|
||||
|
||||
private final String price;
|
||||
private final String price;
|
||||
|
||||
private final Picture picture;
|
||||
private final Picture picture;
|
||||
|
||||
private final String shopUrl;
|
||||
private final String shopUrl;
|
||||
|
||||
private final String shopName;
|
||||
private final String shopName;
|
||||
|
||||
//Not working
|
||||
public TikTokShopEvent(WebcastOecLiveShoppingMessage msg) {
|
||||
super(msg.getCommon());
|
||||
var data = msg.getShopData();
|
||||
title = data.getTitle();
|
||||
price = data.getPriceString();
|
||||
picture = new Picture(data.getImageUrl());
|
||||
shopUrl = data.getShopUrl();
|
||||
shopName = data.getShopName();
|
||||
}
|
||||
|
||||
}
|
||||
//Not working
|
||||
public TikTokShopEvent(WebcastOecLiveShoppingMessage msg) {
|
||||
super(msg.getCommon());
|
||||
var data = msg.getShopData();
|
||||
title = data.getTitle();
|
||||
price = data.getPriceString();
|
||||
picture = new Picture(data.getImageUrl());
|
||||
shopUrl = data.getShopUrl();
|
||||
shopName = data.getShopName();
|
||||
}
|
||||
}
|
||||
@@ -31,15 +31,13 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastMemberMessage;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSubNotifyMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Triggers when a user creates a subscription.
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokSubscribeEvent extends TikTokHeaderEvent
|
||||
{
|
||||
public class TikTokSubscribeEvent extends TikTokHeaderEvent {
|
||||
private final User user;
|
||||
|
||||
|
||||
public TikTokSubscribeEvent(WebcastMemberMessage msg) {
|
||||
super(msg.getCommon());
|
||||
user = User.map(msg.getUser());
|
||||
@@ -52,4 +50,12 @@ public class TikTokSubscribeEvent extends TikTokHeaderEvent
|
||||
user.addAttribute(UserAttribute.Subscriber);
|
||||
}
|
||||
|
||||
public static TikTokSubscribeEvent of(String userName) {
|
||||
return new TikTokSubscribeEvent(WebcastMemberMessage.newBuilder()
|
||||
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||
.setDisplayId(userName)
|
||||
.setNickname(userName)
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,6 @@ package io.github.jwdeveloper.tiktok.data.events.common;
|
||||
import io.github.jwdeveloper.tiktok.utils.JsonUtil;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Base class for all events
|
||||
*/
|
||||
@Getter
|
||||
public abstract class TikTokEvent {
|
||||
|
||||
|
||||
@@ -31,7 +31,9 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
||||
* Triggered when client is connecting to live is successfully established.
|
||||
*/
|
||||
@EventMeta(eventType = EventType.Control)
|
||||
public class TikTokConnectingEvent extends TikTokLiveClientEvent
|
||||
{
|
||||
public class TikTokConnectingEvent extends TikTokLiveClientEvent {
|
||||
|
||||
public static TikTokConnectingEvent of() {
|
||||
return new TikTokConnectingEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,15 +27,14 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.requests.*;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* Triggered before the connection is established.
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Control)
|
||||
public class TikTokPreConnectionEvent extends TikTokLiveClientEvent
|
||||
{
|
||||
@Getter private final LiveUserData.Response userData;
|
||||
@Getter private final LiveData.Response roomData;
|
||||
@Getter @Setter boolean cancelConnection = false;
|
||||
private final LiveUserData.Response userData;
|
||||
private final LiveData.Response roomData;
|
||||
@Setter boolean cancelConnection = false;
|
||||
|
||||
public TikTokPreConnectionEvent(LiveUserData.Response userData, LiveData.Response liveData) {
|
||||
this.userData = userData;
|
||||
|
||||
@@ -22,35 +22,28 @@
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.data.events.gift;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||
import io.github.jwdeveloper.tiktok.data.models.gifts.GiftSendType;
|
||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
|
||||
/**
|
||||
* Triggered every time gift is sent
|
||||
*
|
||||
* @see GiftSendType 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)
|
||||
@Getter
|
||||
public class TikTokGiftComboEvent extends TikTokGiftEvent {
|
||||
private final GiftSendType comboState;
|
||||
private final GiftComboStateType comboState;
|
||||
|
||||
public TikTokGiftComboEvent(Gift gift, User host, WebcastGiftMessage msg, GiftSendType comboState) {
|
||||
public TikTokGiftComboEvent(Gift gift, User host, WebcastGiftMessage msg, GiftComboStateType comboState) {
|
||||
super(gift, host, msg);
|
||||
this.comboState = comboState;
|
||||
}
|
||||
}
|
||||
|
||||
public static TikTokGiftComboEvent of(Gift gift, int combo, GiftComboStateType comboState) {
|
||||
return new TikTokGiftComboEvent(
|
||||
gift,
|
||||
new User(0L, "Test", new Picture("")),
|
||||
WebcastGiftMessage.newBuilder().setComboCount(combo).build(),
|
||||
comboState);
|
||||
}
|
||||
}
|
||||
@@ -22,25 +22,14 @@
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.data.events.gift;
|
||||
|
||||
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||
import io.github.jwdeveloper.tiktok.data.models.gifts.GiftSendType;
|
||||
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
/**
|
||||
* Triggered when user sends gifts that has
|
||||
* no combo (most of expensive gifts)
|
||||
* or if combo has finished
|
||||
*/
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
@Getter
|
||||
public class TikTokGiftEvent extends TikTokHeaderEvent {
|
||||
@@ -60,4 +49,20 @@ public class TikTokGiftEvent extends TikTokHeaderEvent {
|
||||
}
|
||||
combo = msg.getComboCount();
|
||||
}
|
||||
|
||||
public TikTokGiftEvent(Gift gift) {
|
||||
this.gift = gift;
|
||||
user = new User(0L, "sender", new Picture(""));
|
||||
toUser = new User(0L, "receiver", new Picture(""));
|
||||
combo = 1;
|
||||
}
|
||||
|
||||
|
||||
public static TikTokGiftEvent of(Gift gift) {
|
||||
return new TikTokGiftEvent(gift);
|
||||
}
|
||||
|
||||
public static TikTokGiftEvent of(String name, int id, int diamonds) {
|
||||
return TikTokGiftEvent.of(new Gift(id, name, diamonds, ""));
|
||||
}
|
||||
}
|
||||
@@ -20,34 +20,26 @@
|
||||
* 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.tools.db.tables;
|
||||
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
public class ExceptionInfoModel
|
||||
{
|
||||
private String message;
|
||||
private String stackTrace;
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLinkAcceptNoticeEvent extends TikTokLinkEvent {
|
||||
|
||||
public ExceptionInfoModel(Throwable throwable) {
|
||||
this.message = throwable.getMessage();
|
||||
this.stackTrace = getStackTraceAsString(throwable);
|
||||
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();
|
||||
}
|
||||
|
||||
public static String getStackTraceAsString(Throwable throwable) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
throwable.printStackTrace(pw);
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
// Getters for message and stackTrace
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public String getStackTrace() {
|
||||
return stackTrace;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,18 +20,17 @@
|
||||
* 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;
|
||||
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
|
||||
public class EnumValue
|
||||
{
|
||||
public int value;
|
||||
public String name;
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLinkApplyEvent extends TikTokLinkEvent {
|
||||
|
||||
public static EnumValue Map(Enum<?> _enum)
|
||||
{
|
||||
return new EnumValue(_enum.ordinal() ,_enum.name());
|
||||
public TikTokLinkApplyEvent(WebcastLinkMessage msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.messages.webcast.WebcastLinkMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLinkCancelEvent extends TikTokLinkEvent {
|
||||
|
||||
private final long fromUserId, toUserId, cancelType, actionId;
|
||||
|
||||
public TikTokLinkCancelEvent(WebcastLinkMessage msg) {
|
||||
super(msg);
|
||||
if (!msg.hasCancelContent())
|
||||
throw new IllegalArgumentException("Expected WebcastLinkMessage with Cancel Content!");
|
||||
|
||||
var content = msg.getCancelContent();
|
||||
this.fromUserId = content.getFromUserId();
|
||||
this.toUserId = content.getToUserId();
|
||||
this.cancelType = content.getCancelType();
|
||||
this.actionId = content.getActionId();
|
||||
}
|
||||
}
|
||||
@@ -20,19 +20,20 @@
|
||||
* 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.http;
|
||||
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.requests.LiveData;
|
||||
import lombok.AllArgsConstructor;
|
||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@EventMeta(eventType = EventType.Debug)
|
||||
public class TikTokRoomDataResponseEvent extends TikTokEvent
|
||||
{
|
||||
private final LiveData.Response liveData;
|
||||
}
|
||||
@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();
|
||||
}
|
||||
}
|
||||
@@ -20,29 +20,29 @@
|
||||
* 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.events_generator;
|
||||
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||
|
||||
import lombok.Data;
|
||||
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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class EventGeneratorSettings
|
||||
{
|
||||
private String inputDictionary;
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLinkEnterEvent extends TikTokLinkEvent {
|
||||
|
||||
private String outputDictionary;
|
||||
private List<String> ignoredFiles = new ArrayList<>();
|
||||
private final List<ListUser> listUsers;
|
||||
private final int anchorMultiLiveEnum;
|
||||
|
||||
private String prefix;
|
||||
public TikTokLinkEnterEvent(WebcastLinkMessage msg) {
|
||||
super(msg);
|
||||
if (!msg.hasEnterContent())
|
||||
throw new IllegalArgumentException("Expected WebcastLinkMessage with Enter Content!");
|
||||
|
||||
private String endFix;
|
||||
|
||||
private boolean isTikTokEvent;
|
||||
|
||||
public void addIgnoredClass(String name)
|
||||
{
|
||||
ignoredFiles.add(name);
|
||||
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
|
||||
* 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.EventType;
|
||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||
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 lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLinkEvent extends TikTokHeaderEvent {
|
||||
|
||||
private final String extra, transferExtra;
|
||||
private final long expireTimestamp;
|
||||
|
||||
public TikTokLinkEvent(WebcastLinkMessage msg) {
|
||||
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
|
||||
* 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.EventType;
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class CustomEvent extends TikTokHeaderEvent {
|
||||
private final User user;
|
||||
private final String title;
|
||||
public class TikTokLinkMicIdxUpdateEvent extends TikTokLinkEvent {
|
||||
|
||||
public CustomEvent(User user, String title) {
|
||||
this.user = user;
|
||||
this.title = title;
|
||||
public TikTokLinkMicIdxUpdateEvent(WebcastLinkMessage msg) {
|
||||
super(msg);
|
||||
// if (!msg.hasMicIdxUpdateContent())
|
||||
// throw new IllegalArgumentException("Expected WebcastLinkMessage with Mic Idx Update Content!");
|
||||
// Proto Empty
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,18 +20,25 @@
|
||||
* 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.tools.collector.client;
|
||||
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.tools.db.TikTokDatabase;
|
||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
public class TikTokClientFactory {
|
||||
private final MessagesManager messageCollector;
|
||||
private final TikTokDatabase tikTokDatabase;
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLinkMuteEvent extends TikTokLinkEvent {
|
||||
|
||||
public TikTokClientFactory(MessagesManager messageCollector, TikTokDatabase tikTokDatabase) {
|
||||
this.messageCollector = messageCollector;
|
||||
this.tikTokDatabase = tikTokDatabase;
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -20,31 +20,25 @@
|
||||
* 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.events_generator;
|
||||
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||
|
||||
import lombok.Data;
|
||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLinkUpdateUserEvent extends TikTokLinkEvent {
|
||||
|
||||
@Data
|
||||
public class CSharpClassInfo
|
||||
{
|
||||
private String className;
|
||||
private List<FieldInfo> fields = new ArrayList<>();
|
||||
private List<ConstructorInfo> constructors = new ArrayList<>();
|
||||
private final long fromUserId, toUserId;
|
||||
|
||||
public void addField(String type, String fields)
|
||||
{
|
||||
this.fields.add(new FieldInfo(type,fields));
|
||||
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();
|
||||
}
|
||||
|
||||
public void addConstructor(List<FieldInfo> arguments)
|
||||
{
|
||||
this.constructors.add(new ConstructorInfo(arguments));
|
||||
}
|
||||
|
||||
public record FieldInfo(String type, String name){};
|
||||
|
||||
public record ConstructorInfo(List<FieldInfo> arguemtns){};
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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 TikTokLinkWaitListChangeEvent extends TikTokLinkEvent {
|
||||
|
||||
public TikTokLinkWaitListChangeEvent(WebcastLinkMessage msg) {
|
||||
super(msg);
|
||||
// if (!msg.hasWaitingListChangeContent())
|
||||
// throw new IllegalArgumentException("Expected WebcastLinkMessage with Waiting List Change Content!");
|
||||
// Proto Empty
|
||||
}
|
||||
}
|
||||
@@ -30,13 +30,11 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
|
||||
/*
|
||||
Triggered when LiveRoomInfo got updated such as likes, viewers, ranking ....
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokRoomInfoEvent extends TikTokEvent
|
||||
{
|
||||
LiveRoomInfo roomInfo;
|
||||
}
|
||||
}
|
||||
@@ -33,15 +33,13 @@ import lombok.Getter;
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokRoomPinEvent extends TikTokHeaderEvent
|
||||
{
|
||||
private final TikTokCommentEvent pinnedMessage;
|
||||
private final long timestamp;
|
||||
|
||||
private TikTokCommentEvent pinnedMessage;
|
||||
private long timestamp;
|
||||
|
||||
public TikTokRoomPinEvent(WebcastRoomPinMessage msg, TikTokCommentEvent commentEvent)
|
||||
{
|
||||
super(msg.getCommon());
|
||||
this.timestamp = msg.getTimestamp();
|
||||
this.pinnedMessage = commentEvent;
|
||||
}
|
||||
|
||||
}
|
||||
public TikTokRoomPinEvent(WebcastRoomPinMessage msg, TikTokCommentEvent commentEvent)
|
||||
{
|
||||
super(msg.getCommon());
|
||||
this.timestamp = msg.getTimestamp();
|
||||
this.pinnedMessage = commentEvent;
|
||||
}
|
||||
}
|
||||
@@ -29,20 +29,25 @@ import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
||||
import lombok.Value;
|
||||
|
||||
/**
|
||||
* Triggers when a user follows the streamer. Based on social event.
|
||||
*/
|
||||
|
||||
@Value
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokFollowEvent extends TikTokHeaderEvent
|
||||
{
|
||||
User user;
|
||||
int totalFollowers;
|
||||
public class TikTokFollowEvent extends TikTokHeaderEvent {
|
||||
User user;
|
||||
int totalFollowers;
|
||||
|
||||
public TikTokFollowEvent(WebcastSocialMessage msg) {
|
||||
super(msg.getCommon());
|
||||
user = User.map(msg.getUser());
|
||||
totalFollowers = msg.getFollowCount();
|
||||
}
|
||||
public TikTokFollowEvent(WebcastSocialMessage msg) {
|
||||
super(msg.getCommon());
|
||||
user = User.map(msg.getUser());
|
||||
totalFollowers = msg.getFollowCount();
|
||||
}
|
||||
|
||||
}
|
||||
public static TikTokFollowEvent of(String userName) {
|
||||
return new TikTokFollowEvent(WebcastSocialMessage.newBuilder()
|
||||
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||
.setDisplayId(userName)
|
||||
.setNickname(userName)
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||
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.WebcastLikeMessage;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastMemberMessage;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
||||
import lombok.Getter;
|
||||
@@ -47,4 +48,14 @@ public class TikTokJoinEvent extends TikTokHeaderEvent {
|
||||
user = User.map(msg.getUser());
|
||||
totalUsers = msg.getMemberCount();
|
||||
}
|
||||
|
||||
public static TikTokJoinEvent of(String userName)
|
||||
{
|
||||
return new TikTokJoinEvent(WebcastMemberMessage.newBuilder()
|
||||
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||
.setDisplayId(userName)
|
||||
.setNickname(userName)
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +31,7 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
||||
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
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokLikeEvent extends TikTokHeaderEvent
|
||||
@@ -57,4 +55,16 @@ public class TikTokLikeEvent extends TikTokHeaderEvent
|
||||
likes = msg.getCount();
|
||||
totalLikes = msg.getTotal();
|
||||
}
|
||||
|
||||
public static TikTokLikeEvent of(String userName, int likes)
|
||||
{
|
||||
return new TikTokLikeEvent(WebcastLikeMessage.newBuilder()
|
||||
.setCount(likes)
|
||||
.setTotal(likes)
|
||||
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||
.setDisplayId(userName)
|
||||
.setNickname(userName)
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,28 +26,35 @@ import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||
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.WebcastLikeMessage;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Triggers when a user shares the stream. Based on social event.
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Message)
|
||||
public class TikTokShareEvent extends TikTokHeaderEvent {
|
||||
private final User user;
|
||||
private final int totalShares;
|
||||
private final User user;
|
||||
private final int totalShares;
|
||||
|
||||
public TikTokShareEvent(WebcastSocialMessage msg, Integer amount) {
|
||||
super(msg.getCommon());
|
||||
user = User.map(msg.getUser());
|
||||
this.totalShares = amount;
|
||||
}
|
||||
public TikTokShareEvent(WebcastSocialMessage msg, Integer amount) {
|
||||
super(msg.getCommon());
|
||||
user = User.map(msg.getUser());
|
||||
this.totalShares = amount;
|
||||
}
|
||||
|
||||
public TikTokShareEvent(WebcastSocialMessage msg) {
|
||||
super(msg.getCommon());
|
||||
user = User.map(msg.getUser());
|
||||
totalShares = 1;
|
||||
}
|
||||
public TikTokShareEvent(WebcastSocialMessage msg) {
|
||||
super(msg.getCommon());
|
||||
user = User.map(msg.getUser());
|
||||
totalShares = 1;
|
||||
}
|
||||
|
||||
}
|
||||
public static TikTokShareEvent of(String userName, int shaders) {
|
||||
return new TikTokShareEvent(WebcastSocialMessage.newBuilder()
|
||||
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||
.setDisplayId(userName)
|
||||
.setNickname(userName)
|
||||
.build())
|
||||
.build(), shaders);
|
||||
}
|
||||
}
|
||||
@@ -35,10 +35,7 @@ import lombok.Value;
|
||||
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
|
||||
@AllArgsConstructor
|
||||
@EventMeta(eventType = EventType.Debug)
|
||||
|
||||
@@ -29,9 +29,7 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||
import lombok.Getter;
|
||||
|
||||
|
||||
/**
|
||||
* Triggered every time a protobuf encoded webcast message arrives. You can deserialize the binary object depending on the use case.
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@EventMeta(eventType = EventType.Debug)
|
||||
public class TikTokWebsocketUnhandledMessageEvent extends TikTokUnhandledEvent<WebcastResponse.Message>
|
||||
|
||||
@@ -46,4 +46,4 @@ public class LinkMicArmy {
|
||||
List<User> Users;
|
||||
Integer Points;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,11 +44,11 @@ public class Picture {
|
||||
}
|
||||
|
||||
public static Picture map(io.github.jwdeveloper.tiktok.messages.data.Image profilePicture) {
|
||||
var index = profilePicture.getUrlListCount() - 1;
|
||||
var index = profilePicture.getUrlCount() - 1;
|
||||
if (index < 0) {
|
||||
return new Picture("");
|
||||
}
|
||||
var url = profilePicture.getUrlList(index);
|
||||
var url = profilePicture.getUrl(index);
|
||||
return new Picture(url);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class Picture {
|
||||
}
|
||||
}
|
||||
|
||||
public static Picture Empty() {
|
||||
public static Picture empty() {
|
||||
return new Picture("");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
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.
|
||||
* @return true if this team is of type {@link Team1v1}, false otherwise.
|
||||
*/
|
||||
public boolean is1v1Team() {
|
||||
return this instanceof Team1v1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a check for verifying if this team represents a 1v1 Team.
|
||||
* @return true if this team is of type {@link Team1v1}, false otherwise.
|
||||
*/
|
||||
public boolean is2v2Team() {
|
||||
return this instanceof Team2v2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get this team as a {@link Team1v1}. If this team is of some
|
||||
* other type, an {@link IllegalStateException} will result. Hence it is best to use this method
|
||||
* after ensuring that this element is of the desired type by calling {@link #is1v1Team()} first.
|
||||
*
|
||||
* @return this team as a {@link Team1v1}.
|
||||
* @throws IllegalStateException if this team is of another type.
|
||||
*/
|
||||
public Team1v1 getAs1v1Team() {
|
||||
if (is1v1Team())
|
||||
return (Team1v1) this;
|
||||
throw new IllegalStateException("Not a 1v1Team: " + this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get this team as a {@link Team2v2}. If this team is of some
|
||||
* other type, an {@link IllegalStateException} will result. Hence it is best to use this method
|
||||
* after ensuring that this element is of the desired type by calling {@link #is2v2Team()} first.
|
||||
*
|
||||
* @return this team as a {@link Team2v2}.
|
||||
* @throws IllegalStateException if this team is of another type.
|
||||
*/
|
||||
public Team2v2 getAs2v2Team() {
|
||||
if (is2v2Team())
|
||||
return (Team2v2) this;
|
||||
throw new IllegalStateException("Not a 2v2Team: " + this);
|
||||
}
|
||||
}
|
||||
@@ -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.models.battles;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Getter
|
||||
public class Team1v1 extends Team {
|
||||
private final int winStreak;
|
||||
private final User host;
|
||||
private final List<Viewer> viewers;
|
||||
|
||||
public Team1v1(WebcastLinkMicBattle.LinkMicBattleHost hostTeam, WebcastLinkMicBattle msg) {
|
||||
long hostId = hostTeam.getId();
|
||||
this.winStreak = msg.getTeamDataList().stream().filter(data -> data.getTeamId() == hostId).map(data -> data.getData().getWinStreak()).findFirst().orElse(-1);
|
||||
this.totalPoints = msg.getDetailsList().stream().filter(dets -> dets.getId() == hostId).map(dets -> dets.getSummary().getPoints()).findFirst().orElse(-1);
|
||||
this.host = new User(hostTeam.getHostGroup(0).getHost(0));
|
||||
this.viewers = msg.getViewerTeamList().stream().filter(team -> team.getId() == hostId).findFirst().map(topViewers ->
|
||||
topViewers.getViewerGroup(0).getViewerList().stream().map(Viewer::new).toList()).orElseGet(ArrayList::new);
|
||||
}
|
||||
}
|
||||
@@ -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.models.battles;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Getter
|
||||
public class Team2v2 extends Team {
|
||||
private final List<User> hosts;
|
||||
private final List<Viewer> viewers;
|
||||
|
||||
public Team2v2(WebcastLinkMicBattle.LinkMicBattleHost hostTeam1, WebcastLinkMicBattle.LinkMicBattleHost hostTeam2, WebcastLinkMicBattle msg) {
|
||||
this.totalPoints = -1;
|
||||
this.hosts = List.of(new User(hostTeam1.getHostGroup(0).getHost(0)), new User(hostTeam2.getHostGroup(0).getHost(0)));
|
||||
this.viewers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Team2v2(WebcastLinkMicBattle.Host2v2Data hd, WebcastLinkMicBattle msg) {
|
||||
this.totalPoints = hd.getTotalPoints();
|
||||
var host = new User(msg.getHostTeamList().stream().filter(data -> data.getId() == hd.getHostdata(0).getHostId()).findFirst().orElseThrow().getHostGroup(0).getHost(0));
|
||||
var cohost = new User(msg.getHostTeamList().stream().filter(data -> data.getId() == hd.getHostdata(1).getHostId()).findFirst().orElseThrow().getHostGroup(0).getHost(0));
|
||||
this.hosts = List.of(host, cohost);
|
||||
this.viewers = msg.getViewerTeamList().stream().filter(team -> team.getId() == host.getId() || team.getId() == cohost.getId()).findFirst().map(topViewers ->
|
||||
topViewers.getViewerGroup(0).getViewerList().stream().map(Viewer::new).toList()).orElseGet(ArrayList::new);
|
||||
}
|
||||
}
|
||||
@@ -20,22 +20,20 @@
|
||||
* 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;
|
||||
|
||||
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||
import lombok.Value;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
@Getter
|
||||
public class Viewer {
|
||||
private final User user;
|
||||
private final int points;
|
||||
|
||||
@Value
|
||||
public class LinkMicBattleTeam {
|
||||
Long teamId;
|
||||
List<User> users;
|
||||
|
||||
public LinkMicBattleTeam(WebcastLinkMicBattle.LinkMicBattleTeam team) {
|
||||
this.teamId = team.getId();
|
||||
this.users = team.getUsersList().stream().map(User::new).toList();
|
||||
public Viewer(WebcastLinkMicBattle.LinkMicBattleTopViewers.TopViewerGroup.TopViewer topViewer) {
|
||||
this.user = new User(topViewer.getId(), null, topViewer.getProfileId(), Picture.map(topViewer.getImages(0)));
|
||||
this.points = topViewer.getPoints();
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -22,19 +22,15 @@
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.data.models.gifts;
|
||||
|
||||
public enum GiftSendType
|
||||
{
|
||||
Finished,
|
||||
public enum GiftComboStateType {
|
||||
Begin,
|
||||
Active;
|
||||
Active,
|
||||
Finished;
|
||||
|
||||
|
||||
public static GiftSendType fromNumber(long number)
|
||||
{
|
||||
public static GiftComboStateType fromNumber(long number) {
|
||||
return switch ((int) number) {
|
||||
case 0 -> GiftSendType.Finished;
|
||||
case 1, 2, 4 -> GiftSendType.Active;
|
||||
default -> GiftSendType.Finished;
|
||||
case 1, 2, 4 -> GiftComboStateType.Active;
|
||||
default -> GiftComboStateType.Finished;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ListUser{" +
|
||||
"user=" + user +
|
||||
", linkType=" + linkType +
|
||||
", linkMicId=" + linkMicId +
|
||||
", linkStatus=" + linkStatus +
|
||||
", modifyTime=" + modifyTime +
|
||||
", linkerId=" + linkerId +
|
||||
", userPosition=" + userPosition +
|
||||
", silenceStatus=" + silenceStatus +
|
||||
", roleType=" + roleType +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -22,16 +22,12 @@
|
||||
*/
|
||||
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.messages.webcast.WebcastEnvelopeMessage;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import io.github.jwdeveloper.tiktok.data.models.badges.Badge;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
@Getter
|
||||
public class User {
|
||||
@@ -49,12 +45,12 @@ public class User {
|
||||
return attributes.stream().toList();
|
||||
}
|
||||
|
||||
public boolean hasAttribute(UserAttribute userFlag) {
|
||||
return attributes.contains(userFlag);
|
||||
public boolean hasAttribute(UserAttribute attribute) {
|
||||
return attributes.contains(attribute);
|
||||
}
|
||||
|
||||
public void addAttribute(UserAttribute... flags) {
|
||||
this.attributes.addAll(Arrays.stream(flags).toList());
|
||||
public void addAttribute(UserAttribute... attributes) {
|
||||
this.attributes.addAll(List.of(attributes));
|
||||
}
|
||||
|
||||
public boolean isGiftGiver() {
|
||||
@@ -136,6 +132,14 @@ public class User {
|
||||
this.picture = picture;
|
||||
}
|
||||
|
||||
public User(long id, String name, String profileId, Picture picture) {
|
||||
this(id, name, profileId, picture, 0, 0, List.of(Badge.empty()));
|
||||
}
|
||||
|
||||
public User(WebcastLinkMicBattle.LinkMicBattleHost.HostGroup.Host host) {
|
||||
this(host.getId(), host.getName(), host.getProfileId(), Picture.map(host.getImages(0)));
|
||||
}
|
||||
|
||||
public User(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
||||
this(user.getId(), user.getDisplayId(), Picture.map(user.getAvatarThumb()));
|
||||
profileName = user.getNickname();
|
||||
@@ -159,13 +163,12 @@ public class User {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static User EMPTY = new User(0L,
|
||||
"",
|
||||
Picture.Empty(),
|
||||
0,
|
||||
0,
|
||||
List.of(Badge.empty()));
|
||||
"",
|
||||
Picture.empty(),
|
||||
0,
|
||||
0,
|
||||
List.of(Badge.empty()));
|
||||
|
||||
public static User map(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
||||
return new User(user);
|
||||
@@ -202,11 +205,25 @@ public class User {
|
||||
|
||||
public static User map(WebcastEnvelopeMessage.EnvelopeInfo envelopeInfo) {
|
||||
return new User(0L,
|
||||
//envelopeInfo.getSendUserId(),
|
||||
envelopeInfo.getSendUserName(),
|
||||
Picture.map(envelopeInfo.getSendUserAvatar()),
|
||||
0,
|
||||
0,
|
||||
List.of(Badge.empty()));
|
||||
//envelopeInfo.getSendUserId(),
|
||||
envelopeInfo.getSendUserName(),
|
||||
Picture.map(envelopeInfo.getSendUserAvatar()),
|
||||
0,
|
||||
0,
|
||||
List.of(Badge.empty()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"id=" + id +
|
||||
", name='" + name + "'" +
|
||||
", profileName='" + profileName + "'" +
|
||||
", picture=" + picture +
|
||||
", following=" + following +
|
||||
", followers=" + followers +
|
||||
", badges=" + badges +
|
||||
", attributes=" + attributes +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -23,35 +23,17 @@
|
||||
package io.github.jwdeveloper.tiktok.data.requests;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GiftsData
|
||||
{
|
||||
@Getter
|
||||
public final class Request
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public static final class Response
|
||||
{
|
||||
private String json;
|
||||
private List<GiftModel> gifts;
|
||||
private List<Gift> gifts;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class GiftModel
|
||||
{
|
||||
private int id;
|
||||
private String name;
|
||||
private int diamondCost;
|
||||
private String image;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ public class LiveData {
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class Response {
|
||||
private String json;
|
||||
private LiveStatus liveStatus;
|
||||
@@ -45,6 +46,11 @@ public class LiveData {
|
||||
private boolean ageRestricted;
|
||||
private User host;
|
||||
private LiveType liveType;
|
||||
public Response() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public enum LiveStatus {
|
||||
|
||||
@@ -27,18 +27,23 @@ import lombok.*;
|
||||
public class LiveUserData {
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
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
|
||||
@AllArgsConstructor
|
||||
public static class Response {
|
||||
private String json;
|
||||
private UserStatus userStatus;
|
||||
private String roomId;
|
||||
private long startedAtTimeStamp;
|
||||
private final String json;
|
||||
private final UserStatus userStatus;
|
||||
private final String roomId;
|
||||
private final long startTime;
|
||||
|
||||
public boolean isLiveOnline() {
|
||||
return userStatus == LiveUserData.UserStatus.Live || userStatus == LiveUserData.UserStatus.LivePaused;
|
||||
|
||||
@@ -34,30 +34,24 @@ import java.util.TreeMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
@Getter
|
||||
public class HttpClientSettings {
|
||||
|
||||
@Getter
|
||||
final Map<String, Object> params;
|
||||
private final Map<String, Object> params;
|
||||
|
||||
@Getter
|
||||
final Map<String, String> headers;
|
||||
private final Map<String, String> headers;
|
||||
|
||||
@Getter
|
||||
final Map<String, String> cookies;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
ProxyClientSettings proxyClientSettings;
|
||||
|
||||
@Getter
|
||||
Consumer<HttpClient.Builder> onClientCreating;
|
||||
|
||||
@Getter
|
||||
Consumer<HttpRequest.Builder> onRequestCreating;
|
||||
private final Map<String, String> cookies;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
Duration timeout;
|
||||
private ProxyClientSettings proxyClientSettings;
|
||||
|
||||
private Consumer<HttpClient.Builder> onClientCreating;
|
||||
|
||||
private Consumer<HttpRequest.Builder> onRequestCreating;
|
||||
|
||||
@Setter
|
||||
private Duration timeout;
|
||||
|
||||
public HttpClientSettings() {
|
||||
this.params = new TreeMap<>();
|
||||
@@ -65,10 +59,8 @@ public class HttpClientSettings {
|
||||
this.cookies = new HashMap<>();
|
||||
this.timeout = Duration.ofSeconds(2);
|
||||
this.proxyClientSettings = new ProxyClientSettings();
|
||||
this.onClientCreating = (x) -> {
|
||||
};
|
||||
this.onRequestCreating = (x) -> {
|
||||
};
|
||||
this.onClientCreating = (x) -> {};
|
||||
this.onRequestCreating = (x) -> {};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,7 +97,7 @@ public class HttpClientSettings {
|
||||
newSettings.getHeaders().putAll(new TreeMap<>(this.headers));
|
||||
newSettings.getCookies().putAll(new TreeMap<>(this.cookies));
|
||||
newSettings.getParams().putAll(new TreeMap<>(this.params));
|
||||
newSettings.proxyClientSettings = this.proxyClientSettings;
|
||||
newSettings.setProxyClientSettings(this.proxyClientSettings);
|
||||
|
||||
return newSettings;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,18 @@ import java.util.logging.Level;
|
||||
@Data
|
||||
public class LiveClientSettings {
|
||||
|
||||
/**
|
||||
* Sets client to offline mode, prohibits connection to TikTok servers
|
||||
* @apiNote Useful when testing client with custom events
|
||||
*/
|
||||
private boolean offline;
|
||||
|
||||
/**
|
||||
* Fetch and download gifts data before TikTokLive starts
|
||||
* @apiNote If `false`, client.giftManager() does not contain initial gifts
|
||||
*/
|
||||
private boolean fetchGifts = true;
|
||||
|
||||
/**
|
||||
* ISO-Language for Client
|
||||
*/
|
||||
@@ -69,19 +81,31 @@ public class LiveClientSettings {
|
||||
private HttpClientSettings httpSettings;
|
||||
|
||||
/**
|
||||
* Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId
|
||||
* documentation how to obtain sessionId https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages
|
||||
* Interval of time in milliseconds between pings to TikTok
|
||||
* @apiNote Min: 250 (0.25 seconds), Default: 5000 (5 seconds)
|
||||
*/
|
||||
private long pingInterval = 5000;
|
||||
|
||||
/** Throw an exception on 18+ Age Restriction */
|
||||
private boolean throwOnAgeRestriction;
|
||||
|
||||
/**
|
||||
* Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId
|
||||
* @see <a href="https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages">Documentation: How to obtain sessionId</a>
|
||||
*/
|
||||
private String sessionId;
|
||||
|
||||
/**
|
||||
* Optional: By default roomID is fetched before connect to live, but you can set it manually
|
||||
*
|
||||
*/
|
||||
private String roomId;
|
||||
|
||||
public static LiveClientSettings createDefault()
|
||||
{
|
||||
/**
|
||||
* Optional: API Key for increased limit to signing server
|
||||
*/
|
||||
private String apiKey;
|
||||
|
||||
public static LiveClientSettings createDefault() {
|
||||
var httpSettings = new HttpClientSettings();
|
||||
httpSettings.getParams().putAll(DefaultClientParams());
|
||||
httpSettings.getHeaders().putAll(DefaultRequestHeaders());
|
||||
|
||||
@@ -31,17 +31,17 @@ import java.util.function.Consumer;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ProxyClientSettings implements Iterator<ProxyData>
|
||||
public class ProxyClientSettings implements Iterator<ProxyData>, Iterable<ProxyData>
|
||||
{
|
||||
private boolean enabled, lastSuccess, autoDiscard = true, fallback = true;
|
||||
private boolean enabled, autoDiscard = true, fallback = true;
|
||||
private Rotation rotation = Rotation.CONSECUTIVE;
|
||||
private final List<ProxyData> proxyList = new ArrayList<>();
|
||||
private int index = -1;
|
||||
private int index;
|
||||
private Proxy.Type type = Proxy.Type.DIRECT;
|
||||
private Consumer<ProxyData> onProxyUpdated = x -> {};
|
||||
|
||||
public boolean addProxy(String addressPort) {
|
||||
return proxyList.add(ProxyData.map(addressPort));
|
||||
return addProxy(ProxyData.map(addressPort).toSocketAddress());
|
||||
}
|
||||
|
||||
public boolean addProxy(String address, int port) {
|
||||
@@ -57,39 +57,28 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
public synchronized boolean hasNext() {
|
||||
return !proxyList.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProxyData next() {
|
||||
return lastSuccess ? proxyList.get(index) : rotate();
|
||||
}
|
||||
|
||||
public ProxyData rotate() {
|
||||
var nextProxy = switch (rotation)
|
||||
{
|
||||
case CONSECUTIVE -> {
|
||||
index = (index+1) % proxyList.size();
|
||||
yield proxyList.get(index).clone();
|
||||
public synchronized ProxyData next() {
|
||||
try {
|
||||
var nextProxy = proxyList.get(index);
|
||||
onProxyUpdated.accept(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);
|
||||
}
|
||||
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);
|
||||
return nextProxy;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
public synchronized void remove() {
|
||||
proxyList.remove(index);
|
||||
lastSuccess = false; // index is no longer valid and lastSuccess needs falsified
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
@@ -102,8 +91,8 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
||||
}
|
||||
}
|
||||
|
||||
public ProxyClientSettings clone()
|
||||
{
|
||||
@Override
|
||||
public ProxyClientSettings clone() {
|
||||
ProxyClientSettings settings = new ProxyClientSettings();
|
||||
settings.setEnabled(enabled);
|
||||
settings.setRotation(rotation);
|
||||
@@ -114,6 +103,27 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
||||
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
|
||||
{
|
||||
/** Rotate addresses consecutively, from proxy 0 -> 1 -> 2 -> ...etc. */
|
||||
|
||||
@@ -20,15 +20,11 @@
|
||||
* 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.downloader;
|
||||
package io.github.jwdeveloper.tiktok.exceptions;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GiftDto
|
||||
public class TikTokLiveUnknownHostException extends TikTokLiveException
|
||||
{
|
||||
private int id;
|
||||
private String name;
|
||||
private int diamondCost;
|
||||
private String image;
|
||||
}
|
||||
public TikTokLiveUnknownHostException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -27,38 +27,46 @@ import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
|
||||
import io.github.jwdeveloper.tiktok.data.requests.LiveData;
|
||||
import io.github.jwdeveloper.tiktok.data.requests.LiveUserData;
|
||||
|
||||
public interface LiveHttpClient {
|
||||
|
||||
|
||||
public interface LiveHttpClient
|
||||
{
|
||||
/**
|
||||
* @return list of gifts that are available in your country
|
||||
* @return {@link GiftsData.Response} list of gifts that are compiled and available on github
|
||||
*/
|
||||
GiftsData.Response fetchGiftsData();
|
||||
|
||||
/**
|
||||
* Returns information about user that is having a livestream
|
||||
*
|
||||
* @param userName
|
||||
* @return
|
||||
* @return {@link GiftsData.Response} list of gifts that are available in your region / livestream
|
||||
*/
|
||||
LiveUserData.Response fetchLiveUserData(String userName);
|
||||
GiftsData.Response fetchRoomGiftsData(String room_id);
|
||||
|
||||
/**
|
||||
* Returns information about user that is having a livestream
|
||||
* @param userName name of user
|
||||
* @return {@link LiveUserData.Response}
|
||||
*/
|
||||
default LiveUserData.Response fetchLiveUserData(String userName) {
|
||||
return fetchLiveUserData(new LiveUserData.Request(userName));
|
||||
}
|
||||
|
||||
LiveUserData.Response fetchLiveUserData(LiveUserData.Request request);
|
||||
|
||||
/**
|
||||
* @param roomId can be obtained from browsers cookies or by invoked fetchLiveUserData
|
||||
* @return
|
||||
* @return {@link LiveData.Response}
|
||||
*/
|
||||
LiveData.Response fetchLiveData(String roomId);
|
||||
default LiveData.Response fetchLiveData(String roomId) {
|
||||
return fetchLiveData(new LiveData.Request(roomId));
|
||||
}
|
||||
|
||||
LiveData.Response fetchLiveData(LiveData.Request request);
|
||||
|
||||
|
||||
/**
|
||||
* @param roomId can be obtained from browsers cookies or by invoked fetchLiveUserData
|
||||
* @return
|
||||
* @return {@link LiveConnectionData.Response}
|
||||
*/
|
||||
LiveConnectionData.Response fetchLiveConnectionData(String roomId);
|
||||
default LiveConnectionData.Response fetchLiveConnectionData(String roomId) {
|
||||
return fetchLiveConnectionData(new LiveConnectionData.Request(roomId));
|
||||
}
|
||||
|
||||
LiveConnectionData.Response fetchLiveConnectionData(LiveConnectionData.Request request);
|
||||
}
|
||||
}
|
||||
@@ -25,15 +25,13 @@ package io.github.jwdeveloper.tiktok.listener;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* You can dynamically add or removing TikTokEventListener
|
||||
*
|
||||
* @see TikTokEventListener
|
||||
*
|
||||
* Manage events listeners objects
|
||||
*/
|
||||
public interface ListenersManager
|
||||
{
|
||||
List<TikTokEventListener> getListeners();
|
||||
void addListener(TikTokEventListener listener);
|
||||
List<Object> getListeners();
|
||||
|
||||
void removeListener(TikTokEventListener listener);
|
||||
void addListener(Object listener);
|
||||
|
||||
void removeListener(Object listener);
|
||||
}
|
||||
|
||||
@@ -22,53 +22,54 @@
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.listener;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see ListenersManager
|
||||
*
|
||||
* ListenersManager
|
||||
* <p>
|
||||
* TikTokEventListener is an alternative way of handing TikTok events.
|
||||
* <p>
|
||||
* {@code TikTokLive.newClient("someuser").addListener(listener);}
|
||||
* <p>
|
||||
* After registertion, all listeners are kept in Listener manager - {@link LiveClient#getListenersManager()}
|
||||
* <p>
|
||||
* Method in TikTokEventListener should meet requirements below to be detected
|
||||
* <p>- @TikTokEventObserver annotation
|
||||
* <p>- 2 parameters of (LiveClient, Class extending TikTokEvent)
|
||||
* <pre>
|
||||
* {@code
|
||||
* public static class CustomListener implements TikTokEventListener
|
||||
* {
|
||||
* @TikTokEventObserver
|
||||
* public void onError(LiveClient liveClient, TikTokErrorEvent event)
|
||||
* {
|
||||
* System.out.println(event.getException().getMessage());
|
||||
* }
|
||||
*
|
||||
* TikTokLive.newClient("someuser").addListener(listener)
|
||||
* @TikTokEventObserver
|
||||
* public void onCommentMessage(LiveClient liveClient, TikTokCommentEvent event)
|
||||
* {
|
||||
* System.out.println(event.getText());
|
||||
* }
|
||||
*
|
||||
* After registertion all listeners are kept in Listener manager
|
||||
* that could be obtained by client.getListenerManager();
|
||||
*
|
||||
* Method in TikTokEventListener should meet 4 requirements to be detected
|
||||
* - must have @TikTokEventHandler annotation
|
||||
* - must have 2 parameters
|
||||
* - first parameter must be LiveClient
|
||||
* - second must be class that extending TikTokEvent
|
||||
*
|
||||
* public static class CustomListener implements TikTokEventListener
|
||||
* {
|
||||
* @TikTokEventHandler
|
||||
* public void onError(LiveClient liveClient, TikTokErrorEvent event)
|
||||
* {
|
||||
* System.out.println(event.getException().getMessage());
|
||||
* }
|
||||
*
|
||||
* @TikTokEventHandler
|
||||
* public void onCommentMessage(LiveClient liveClient, TikTokCommentEvent event)
|
||||
* {
|
||||
* System.out.println(event.getText());
|
||||
* }
|
||||
*
|
||||
* @TikTokEventHandler
|
||||
* public void onGiftMessage(LiveClient liveClient, TikTokGiftMessageEvent event)
|
||||
* {
|
||||
* System.out.println(event.getGift().getDescription());
|
||||
* }
|
||||
*
|
||||
* @TikTokEventHandler
|
||||
* public void onAnyEvent(LiveClient liveClient, TikTokEvent event)
|
||||
* {
|
||||
* System.out.println(event.getClass().getSimpleName());
|
||||
* }
|
||||
* }
|
||||
* @TikTokEventObserver
|
||||
* public void onGiftMessage(LiveClient liveClient, TikTokGiftMessageEvent event)
|
||||
* {
|
||||
* System.out.println(event.getGift().getDescription());
|
||||
* }
|
||||
*
|
||||
* @TikTokEventObserver
|
||||
* public void onAnyEvent(LiveClient liveClient, TikTokEvent event)
|
||||
* {
|
||||
* 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) {}
|
||||
}
|
||||
@@ -22,42 +22,65 @@
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.live;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||
import com.google.gson.JsonObject;
|
||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface GiftManager {
|
||||
public interface GiftsManager {
|
||||
|
||||
/**
|
||||
* In case you can't find your gift in Gift enum. You can register gift
|
||||
* manually here to make it detected while TikTokGiftEvent
|
||||
* You can create and attach your own custom gift to manager
|
||||
*
|
||||
* @param id gift's id
|
||||
* @param name gift's name
|
||||
* @param diamondCost diamond cost
|
||||
* @return
|
||||
* @param gift
|
||||
*/
|
||||
Gift registerGift(int id, String name, int diamondCost, Picture picture);
|
||||
void attachGift(Gift gift);
|
||||
|
||||
/**
|
||||
* You can create and attach your own custom gift to manager
|
||||
*
|
||||
* @param gifts
|
||||
*/
|
||||
void attachGiftsList(List<Gift> gifts);
|
||||
|
||||
/**
|
||||
* finds gift by name
|
||||
* When gift not found return Gift.UNDEFINED;
|
||||
*
|
||||
* @param name gift name
|
||||
*/
|
||||
Gift getByName(String name);
|
||||
|
||||
/**
|
||||
* finds gift by id
|
||||
* When gift not found return Gift.UNDEFINED;
|
||||
*
|
||||
* @param giftId giftId
|
||||
*/
|
||||
Gift getById(int giftId);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param giftId
|
||||
* @return
|
||||
* finds gift by filter
|
||||
* When gift not found return Gift.UNDEFINED;
|
||||
*/
|
||||
Gift findById(int giftId);
|
||||
Gift getByFilter(Predicate<Gift> filter);
|
||||
|
||||
List<Gift> getManyByFilter(Predicate<Gift> filter);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param giftName
|
||||
* @return
|
||||
* @return list of all gifts
|
||||
*/
|
||||
Gift findByName(String giftName);
|
||||
List<Gift> toList();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return all gifts
|
||||
* @return list of all map of all gifts where Integer is gift Id
|
||||
*/
|
||||
List<Gift> getGifts();
|
||||
}
|
||||
Map<Integer, Gift> toMap();
|
||||
}
|
||||
@@ -59,12 +59,21 @@ public interface LiveClient {
|
||||
/**
|
||||
* Use to manually invoke event
|
||||
*/
|
||||
void publishEvent(TikTokEvent event);
|
||||
void publishEvent(TikTokEvent event);
|
||||
|
||||
|
||||
/**
|
||||
* @param webcastMessageName name of TikTok protocol-buffer message
|
||||
* @param payloadBase64 protocol-buffer message bytes payload
|
||||
*/
|
||||
void publishMessage(String webcastMessageName, String payloadBase64);
|
||||
|
||||
void publishMessage(String webcastMessageName, byte[] payload);
|
||||
|
||||
/**
|
||||
* Get information about gifts
|
||||
*/
|
||||
GiftManager getGiftManager();
|
||||
GiftsManager getGiftManager();
|
||||
|
||||
/**
|
||||
* Gets the current room info from TikTok API including streamer info, room status and statistics.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public interface LiveRoomInfo
|
||||
String getRoomId();
|
||||
String getHostName();
|
||||
String getTitle();
|
||||
User getHostUser();
|
||||
User getHost();
|
||||
List<RankingUser> getUsersRanking();
|
||||
ConnectionState getConnectionState();
|
||||
}
|
||||
@@ -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.live.LiveClient;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface EventConsumer<T extends TikTokEvent>
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @param liveClient TikTok live client
|
||||
* @param event event data object
|
||||
*/
|
||||
void onEvent(LiveClient liveClient, T event);
|
||||
}
|
||||
|
||||
@@ -22,8 +22,9 @@
|
||||
*/
|
||||
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.common.TikTokEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.control.TikTokConnectingEvent;
|
||||
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.TikTokGiftEvent;
|
||||
@@ -36,6 +37,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.TikTokWebsocketResponseEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.models.gifts.GiftComboStateType;
|
||||
|
||||
|
||||
public interface EventsBuilder<T> {
|
||||
@@ -52,131 +54,269 @@ public interface EventsBuilder<T> {
|
||||
/**
|
||||
* Invoked whenever any event is triggered
|
||||
*
|
||||
* @param action
|
||||
* @return
|
||||
* @param action consumable action
|
||||
* @return self instance
|
||||
*/
|
||||
T onEvent(EventConsumer<TikTokEvent> action);
|
||||
default T onEvent(EventConsumer<TikTokEvent> action) {
|
||||
return onEvent(TikTokEvent.class, action);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* As a first event after method `LiveClient::connect()` is performed
|
||||
*
|
||||
* @param action consumable action
|
||||
* @return self instance
|
||||
*/
|
||||
default T onConnecting(EventConsumer<TikTokConnectingEvent> action)
|
||||
{
|
||||
return onEvent(TikTokConnectingEvent.class, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when information about room (live) got updated such as viewer count, etc..
|
||||
*
|
||||
* @param action
|
||||
* @return
|
||||
* @param action consumable action
|
||||
* @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
|
||||
*
|
||||
* @param action
|
||||
* @return
|
||||
* @param action consumable action
|
||||
* @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
|
||||
*
|
||||
* @param action
|
||||
* @return
|
||||
* @param action consumable action
|
||||
* @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
|
||||
* events contains protocol-buffer "Message" and TikTokLiveJava "Event"
|
||||
*
|
||||
* @param action
|
||||
* @return
|
||||
* @param action consumable action
|
||||
* @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
|
||||
* @return
|
||||
* @param action consumable action
|
||||
* @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
|
||||
* 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
|
||||
* @param action
|
||||
* @return
|
||||
* Triggers for these different reasons:
|
||||
* <ol>
|
||||
* <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
|
||||
* @param action
|
||||
* @return
|
||||
* Triggered every time a gift is sent
|
||||
* <p>Example when user sends gift with combo</p>
|
||||
* <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);
|
||||
|
||||
T onLiveEnded(EventConsumer<TikTokLiveEndedEvent> action);
|
||||
/**
|
||||
* Triggered when the live stream gets terminated by the host. Will also trigger the TikTokDisconnectedEvent event.
|
||||
*
|
||||
* @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
|
||||
* @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
|
||||
* @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
|
||||
* @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
|
||||
* @param action
|
||||
* @return
|
||||
* Triggered when the connection gets disconnected. In that case you can call connect() again to have a reconnect logic.
|
||||
* Note that you should wait a little bit before attempting a reconnect to avoid being rate-limited.
|
||||
*
|
||||
* @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
|
||||
* @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
|
||||
@@ -223,4 +363,10 @@ public interface EventsBuilder<T> {
|
||||
//T onLinkMicBattle(TikTokEventConsumer<TikTokLinkMicBattleEvent> 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;
|
||||
|
||||
import io.github.jwdeveloper.dependance.implementation.DependanceContainerBuilder;
|
||||
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.mappers.TikTokMapper;
|
||||
import io.github.jwdeveloper.tiktok.mappers.LiveMapper;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
|
||||
|
||||
|
||||
/**
|
||||
* This method is triggered after default mappings are registered
|
||||
* 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
|
||||
*
|
||||
* @param onCustomMappings lambda method
|
||||
* @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
|
||||
* @see LiveClientSettings
|
||||
*
|
||||
* @param onConfigure
|
||||
* @return
|
||||
* @see LiveClientSettings
|
||||
*/
|
||||
LiveClientBuilder configure(Consumer<LiveClientSettings> onConfigure);
|
||||
|
||||
/**
|
||||
* @see TikTokEventListener
|
||||
* Adding events listener class, its fancy way to register events without using lamda method
|
||||
* but actual method in class that implements TikTokEventListener
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return LiveClient object and connects to TikTok live asynchronously
|
||||
*/
|
||||
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.MappingResult;
|
||||
|
||||
import java.util.List;
|
||||
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
|
||||
* @return TikTokMapperModel
|
||||
*/
|
||||
TikTokMapperModel forMessage(String messageName);
|
||||
|
||||
/**
|
||||
* @param mapperName protocol buffer class type
|
||||
* @return
|
||||
*/
|
||||
TikTokMapperModel forMessage(Class<? extends GeneratedMessageV3> mapperName);
|
||||
|
||||
TikTokMapperModel forMessage(String mapperName, MappingAction<MappingResult> onMapping);
|
||||
@@ -49,10 +54,9 @@ public interface TikTokMapper {
|
||||
|
||||
TikTokMapperModel forAnyMessage();
|
||||
|
||||
List<TikTokEvent> handleMapping(String messageName, byte[] bytes);
|
||||
|
||||
boolean isRegistered(String 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.utils.ProtoBufferObject;
|
||||
|
||||
public interface TikTokMapperHelper {
|
||||
public interface LiveMapperHelper {
|
||||
|
||||
/**
|
||||
* @param bytes protocol buffer data bytes
|
||||
@@ -22,7 +22,7 @@
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.mappers.data;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.mappers.TikTokMapperHelper;
|
||||
import io.github.jwdeveloper.tiktok.mappers.LiveMapperHelper;
|
||||
|
||||
@FunctionalInterface
|
||||
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
|
||||
* @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.live.LiveClient;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||
|
||||
public interface SocketClient {
|
||||
public interface LiveSocketClient {
|
||||
void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient);
|
||||
void stop();
|
||||
}
|
||||
@@ -102,7 +102,8 @@ message Text {
|
||||
|
||||
// @Image
|
||||
message Image {
|
||||
repeated string urlList = 1;
|
||||
repeated string url = 1;
|
||||
string extras = 2;
|
||||
bool isAnimated = 9;
|
||||
}
|
||||
|
||||
@@ -1061,9 +1062,9 @@ message CohostListChangeContent {
|
||||
|
||||
|
||||
message LinkerListChangeContent {
|
||||
repeated ListUser linkedUsersList = 1;
|
||||
repeated ListUser appliedUsersList = 2;
|
||||
repeated ListUser connectingUsersList = 3;
|
||||
repeated ListUser linkedUsers = 1;
|
||||
repeated ListUser appliedUsers = 2;
|
||||
repeated ListUser connectingUsers = 3;
|
||||
}
|
||||
|
||||
message LinkerMediaChangeContent {
|
||||
|
||||
@@ -35,6 +35,14 @@ enum LinkmicApplierSortSetting {
|
||||
LINKMIC_APPLIER_SORT_SETTING_BY_GIFT_SCORE = 1;
|
||||
}
|
||||
|
||||
enum LinkMicBattleStatus {
|
||||
BATTLE_ARMY_UNKNOWN = 0;
|
||||
ARMY_ONGOING = 1;
|
||||
ARMY_FINISHED = 2;
|
||||
BATTLE_ONGOING = 4;
|
||||
BATTLE_FINISHED = 5;
|
||||
}
|
||||
|
||||
enum HashtagNamespace {
|
||||
GLOBAL = 0;
|
||||
GAMING = 1;
|
||||
@@ -242,21 +250,21 @@ enum CommonContentCase {
|
||||
|
||||
|
||||
enum LinkMessageType {
|
||||
TPYE_LINKER_UNKNOWN = 0;
|
||||
TYPE_LINKER_UNKNOWN = 0;
|
||||
TYPE_LINKER_CREATE = 1;
|
||||
TYPE_LINKER_CLOSE = 2;
|
||||
TYPE_LINKER_INVITE = 3;
|
||||
TYPE_LINKER_APPLY = 4;
|
||||
TYPE_LINKER_REPLY = 5;
|
||||
TPYE_LINKER_ENTER = 6;
|
||||
TPYE_LINKER_LEAVE = 7;
|
||||
TYPE_LINKER_ENTER = 6;
|
||||
TYPE_LINKER_LEAVE = 7;
|
||||
TYPE_LINKER_PERMIT = 8;
|
||||
TPYE_LINKER_CANCEL_INVITE = 9;
|
||||
TYPE_LINKER_CANCEL_INVITE = 9;
|
||||
TYPE_LINKER_WAITING_LIST_CHANGE = 10;
|
||||
TYPE_LINKER_LINKED_LIST_CHANGE = 11;
|
||||
TYPE_LINKER_UPDATE_USER = 12;
|
||||
TPYE_LINKER_KICK_OUT = 13;
|
||||
TPYE_LINKER_CANCEL_APPLY = 14;
|
||||
TYPE_LINKER_KICK_OUT = 13;
|
||||
TYPE_LINKER_CANCEL_APPLY = 14;
|
||||
TYPE_LINKER_MUTE = 15;
|
||||
TYPE_LINKER_MATCH = 16;
|
||||
TYPE_LINKER_UPDATE_USER_SETTING = 17;
|
||||
@@ -267,8 +275,8 @@ enum LinkMessageType {
|
||||
TYPE_LINKER_COHOST_LIST_CHANGE = 22;
|
||||
TYPE_LINKER_MEDIA_CHANGE = 23;
|
||||
TYPE_LINKER_ACCEPT_NOTICE = 24;
|
||||
TPYE_LINKER_SYS_KICK_OUT = 101;
|
||||
TPYE_LINKMIC_USER_TOAST = 102;
|
||||
TYPE_LINKER_SYS_KICK_OUT = 101;
|
||||
TYPE_LINKMIC_USER_TOAST = 102;
|
||||
}
|
||||
|
||||
enum MessageType {
|
||||
|
||||
@@ -521,7 +521,7 @@ message WebcastLinkMicArmies {
|
||||
uint64 id2 = 4;
|
||||
uint64 timeStamp1 = 5;
|
||||
uint64 timeStamp2 = 6;
|
||||
int32 battleStatus = 7; // SHOULD BE AN ENUM
|
||||
LinkMicBattleStatus battleStatus = 7;
|
||||
uint64 data1 = 8;
|
||||
uint64 data2 = 9;
|
||||
uint32 data3 = 10;
|
||||
@@ -574,11 +574,26 @@ message WebcastLinkMicBattle {
|
||||
Common common = 1;
|
||||
uint64 id = 2;
|
||||
LinkMicBattleConfig battleConfig = 3;
|
||||
uint32 data2 = 4;
|
||||
LinkMicBattleStatus battleStatus = 4;
|
||||
repeated LinkMicBattleDetails details = 5;
|
||||
repeated LinkMicBattleTeam teams1 = 9;
|
||||
repeated LinkMicBattleTeam teams2 = 10;
|
||||
repeated LinkMicBattleTopViewers viewerTeam = 9;
|
||||
repeated LinkMicBattleHost hostTeam = 10;
|
||||
repeated LinkMicBattleTeamData teamData = 13;
|
||||
uint64 unknownData16 = 16;
|
||||
repeated Host2v2Data hostData2v2 = 17;
|
||||
|
||||
message Host2v2Data {
|
||||
uint32 teamNumber = 1;
|
||||
repeated HostData hostdata = 2;
|
||||
uint32 unknownData3 = 3;
|
||||
uint32 totalPoints = 4;
|
||||
|
||||
message HostData {
|
||||
uint64 hostId = 1;
|
||||
uint32 points = 2;
|
||||
string hostIdStr = 3;
|
||||
}
|
||||
}
|
||||
|
||||
message LinkMicBattleConfig {
|
||||
uint64 id1 = 1;
|
||||
@@ -586,29 +601,69 @@ message WebcastLinkMicBattle {
|
||||
uint32 data1 = 3;
|
||||
uint64 id2 = 4;
|
||||
uint32 data2 = 5;
|
||||
uint32 data3 = 6;
|
||||
uint32 data4 = 8;
|
||||
}
|
||||
|
||||
message LinkMicBattleTeamData {
|
||||
uint64 teamId = 1;
|
||||
LinkMicBattleData data = 2;
|
||||
}
|
||||
|
||||
message LinkMicBattleData {
|
||||
uint64 id = 1;
|
||||
uint32 data1 = 2;
|
||||
uint32 data2 = 3;
|
||||
uint32 winStreak = 3;
|
||||
uint32 data3 = 5;
|
||||
string url = 6;
|
||||
}
|
||||
|
||||
message LinkMicBattleDetails {
|
||||
uint64 id = 1;
|
||||
LinkMicBattleData details = 2;
|
||||
LinkMicBattleDetailsSummary summary = 2;
|
||||
|
||||
message LinkMicBattleDetailsSummary {
|
||||
uint64 id = 1;
|
||||
uint32 unknownData2 = 2;
|
||||
uint32 points = 3;
|
||||
}
|
||||
}
|
||||
|
||||
message LinkMicBattleTeam {
|
||||
message LinkMicBattleTopViewers {
|
||||
uint64 id = 1;
|
||||
repeated User users = 2;
|
||||
repeated TopViewerGroup viewerGroup = 2;
|
||||
|
||||
message TopViewerGroup {
|
||||
repeated TopViewer viewer = 1;
|
||||
uint32 points = 2;
|
||||
string hostIdOrTeamNum = 3; // 1v1 Battle = HostId | 2v2 Battle = Team # - 1 & 2
|
||||
|
||||
message TopViewer {
|
||||
uint64 id = 1;
|
||||
uint32 points = 2;
|
||||
string profileId = 3;
|
||||
repeated Image images = 4;
|
||||
string stringId = 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
message LinkMicBattleTeamData {
|
||||
uint64 teamId = 1;
|
||||
LinkMicBattleData data = 2;
|
||||
message LinkMicBattleHost {
|
||||
uint64 id = 1;
|
||||
repeated HostGroup hostGroup = 2;
|
||||
|
||||
message HostGroup {
|
||||
repeated Host host = 1;
|
||||
uint32 points = 2;
|
||||
string hostId = 3;
|
||||
|
||||
message Host {
|
||||
uint64 id = 1;
|
||||
string profileId = 2;
|
||||
repeated Image images = 3;
|
||||
string name = 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -750,7 +805,7 @@ message WebcastLinkMessage {
|
||||
LinkerListChangeContent ListChangeContent = 20;
|
||||
CohostListChangeContent CohostListChangeContent = 21;
|
||||
LinkerMediaChangeContent MediaChangeContent = 22;
|
||||
LinkerAcceptNoticeContent ReplyAcceptNoticeContent = 23;
|
||||
LinkerAcceptNoticeContent AcceptNoticeContent = 23;
|
||||
LinkerSysKickOutContent SysKickOutContent = 101;
|
||||
LinkmicUserToastContent UserToastContent = 102;
|
||||
string extra = 200;
|
||||
@@ -792,6 +847,4 @@ message RoomVerifyMessage {
|
||||
string content = 3;
|
||||
int64 noticeType = 4;
|
||||
bool closeRoom = 5;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,13 +5,14 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.1.2-Release</version>
|
||||
<version>1.8.2-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>Client</artifactId>
|
||||
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
|
||||
@@ -23,16 +23,21 @@
|
||||
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.http.LiveHttpClient;
|
||||
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
||||
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TikTokLive {
|
||||
|
||||
/**
|
||||
* @param hostName profile name of Tiktok user could be found in profile link
|
||||
* 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
|
||||
* @return LiveClientBuilder
|
||||
*/
|
||||
public static LiveClientBuilder newClient(String hostName) {
|
||||
@@ -40,47 +45,52 @@ public class TikTokLive {
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||
*
|
||||
* @param hostName profile name of Tiktok user could be found in profile link
|
||||
* example: https://www.tiktok.com/@dostawcavideo hostName would be dostawcavideo
|
||||
* @param hostName profile name of TikTok user could be found in profile link
|
||||
* @return true if live is Online, false if is offline
|
||||
*/
|
||||
public static boolean isLiveOnline(String hostName)
|
||||
{
|
||||
public static boolean isLiveOnline(String hostName) {
|
||||
return requests().fetchLiveUserData(hostName).isLiveOnline();
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||
*
|
||||
* @param hostName profile name of Tiktok user could be found in profile link
|
||||
* example: https://www.tiktok.com/@dostawcavideo hostName would be dostawcavideo
|
||||
* @param hostName profile name of TikTok user could be found in profile link
|
||||
* @return true if live is Online, false if is offline
|
||||
*/
|
||||
public static CompletableFuture<Boolean> isLiveOnlineAsync(String hostName)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(()-> isLiveOnline(hostName));
|
||||
public static CompletableFuture<Boolean> isLiveOnlineAsync(String hostName) {
|
||||
return CompletableFuture.supplyAsync(() -> isLiveOnline(hostName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||
*
|
||||
* @param hostName profile name of Tiktok user could be found in profile link
|
||||
* example: https://www.tiktok.com/@dostawcavideo hostName would be dostawcavideo
|
||||
* @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
|
||||
*/
|
||||
public static boolean isHostNameValid(String hostName)
|
||||
{
|
||||
public static boolean isHostNameValid(String hostName) {
|
||||
return requests().fetchLiveUserData(hostName).isHostNameValid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||
*
|
||||
* @param hostName profile name of Tiktok user could be found in profile link
|
||||
* example: https://www.tiktok.com/@dostawcavideo hostName would be dostawcavideo
|
||||
* @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
|
||||
*/
|
||||
public static CompletableFuture<Boolean> isHostNameValidAsync(String hostName)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(()-> isHostNameValid(hostName));
|
||||
public static CompletableFuture<Boolean> isHostNameValidAsync(String hostName) {
|
||||
return CompletableFuture.supplyAsync(() -> isHostNameValid(hostName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use to get some data from TikTok about users are lives
|
||||
*
|
||||
* @return LiveHttpClient
|
||||
*/
|
||||
public static LiveHttpClient requests(Consumer<LiveClientSettings> consumer) {
|
||||
return new TikTokLiveHttpClient(consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,6 +99,22 @@ public class TikTokLive {
|
||||
* @return LiveHttpClient
|
||||
*/
|
||||
public static LiveHttpClient requests() {
|
||||
return new TikTokLiveHttpClient();
|
||||
return requests(liveClientSettings -> {});
|
||||
}
|
||||
|
||||
private static GiftsManager giftsManager;
|
||||
|
||||
/**
|
||||
* Fetch gifts from endpoint and returns GiftManager
|
||||
*
|
||||
* @return GiftsManager
|
||||
*/
|
||||
public static GiftsManager gifts() {
|
||||
if (giftsManager == null) {
|
||||
synchronized (GiftsManager.class) {
|
||||
giftsManager = new TikTokGiftsManager(requests().fetchGiftsData().getGifts());
|
||||
}
|
||||
}
|
||||
return giftsManager;
|
||||
}
|
||||
}
|
||||
@@ -22,52 +22,53 @@
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.events.TikTokDisconnectedEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.TikTokReconnectingEvent;
|
||||
import com.google.protobuf.ByteString;
|
||||
import io.github.jwdeveloper.tiktok.data.events.*;
|
||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.control.*;
|
||||
import io.github.jwdeveloper.tiktok.data.events.http.TikTokRoomDataResponseEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.events.room.TikTokRoomInfoEvent;
|
||||
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
|
||||
import io.github.jwdeveloper.tiktok.data.requests.LiveData;
|
||||
import io.github.jwdeveloper.tiktok.data.requests.LiveUserData;
|
||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveOfflineHostException;
|
||||
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftManager;
|
||||
import io.github.jwdeveloper.tiktok.listener.ListenersManager;
|
||||
import io.github.jwdeveloper.tiktok.listener.TikTokListenersManager;
|
||||
import io.github.jwdeveloper.tiktok.live.GiftManager;
|
||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||
import io.github.jwdeveloper.tiktok.live.LiveRoomInfo;
|
||||
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
||||
import io.github.jwdeveloper.tiktok.data.requests.*;
|
||||
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||
import io.github.jwdeveloper.tiktok.websocket.SocketClient;
|
||||
import io.github.jwdeveloper.tiktok.exceptions.*;
|
||||
import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
|
||||
import io.github.jwdeveloper.tiktok.listener.*;
|
||||
import io.github.jwdeveloper.tiktok.live.*;
|
||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
||||
import io.github.jwdeveloper.tiktok.websocket.LiveSocketClient;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class TikTokLiveClient implements LiveClient {
|
||||
private final TikTokRoomInfo liveRoomInfo;
|
||||
private final TikTokGiftManager tikTokGiftManager;
|
||||
private final TikTokLiveHttpClient httpClient;
|
||||
private final SocketClient webSocketClient;
|
||||
private final TikTokLiveEventHandler tikTokEventHandler;
|
||||
@Getter
|
||||
public class TikTokLiveClient implements LiveClient
|
||||
{
|
||||
private final TikTokRoomInfo roomInfo;
|
||||
private final LiveHttpClient httpClient;
|
||||
private final LiveSocketClient webSocketClient;
|
||||
private final LiveEventsHandler tikTokEventHandler;
|
||||
private final LiveClientSettings clientSettings;
|
||||
private final TikTokListenersManager listenersManager;
|
||||
private final ListenersManager listenersManager;
|
||||
private final Logger logger;
|
||||
private final GiftsManager giftManager;
|
||||
private final LiveMessagesHandler messageHandler;
|
||||
|
||||
public TikTokLiveClient(TikTokRoomInfo tikTokLiveMeta,
|
||||
TikTokLiveHttpClient tiktokHttpClient,
|
||||
SocketClient webSocketClient,
|
||||
TikTokGiftManager tikTokGiftManager,
|
||||
TikTokLiveEventHandler tikTokEventHandler,
|
||||
LiveClientSettings clientSettings,
|
||||
TikTokListenersManager listenersManager,
|
||||
Logger logger) {
|
||||
this.liveRoomInfo = tikTokLiveMeta;
|
||||
this.tikTokGiftManager = tikTokGiftManager;
|
||||
public TikTokLiveClient(
|
||||
LiveMessagesHandler messageHandler,
|
||||
GiftsManager giftsManager,
|
||||
TikTokRoomInfo tikTokLiveMeta,
|
||||
LiveHttpClient tiktokHttpClient,
|
||||
LiveSocketClient webSocketClient,
|
||||
LiveEventsHandler tikTokEventHandler,
|
||||
LiveClientSettings clientSettings,
|
||||
ListenersManager listenersManager,
|
||||
Logger logger) {
|
||||
this.messageHandler = messageHandler;
|
||||
this.giftManager = giftsManager;
|
||||
this.roomInfo = tikTokLiveMeta;
|
||||
this.httpClient = tiktokHttpClient;
|
||||
this.webSocketClient = webSocketClient;
|
||||
this.tikTokEventHandler = tikTokEventHandler;
|
||||
@@ -76,22 +77,6 @@ public class TikTokLiveClient implements LiveClient {
|
||||
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() {
|
||||
try {
|
||||
tryConnect();
|
||||
@@ -117,54 +102,59 @@ public class TikTokLiveClient implements LiveClient {
|
||||
}
|
||||
|
||||
public void tryConnect() {
|
||||
if (!liveRoomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) {
|
||||
if (!roomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) {
|
||||
throw new TikTokLiveException("Already connected");
|
||||
}
|
||||
|
||||
setState(ConnectionState.CONNECTING);
|
||||
tikTokEventHandler.publish(this,new TikTokConnectingEvent());
|
||||
var userDataRequest = new LiveUserData.Request(liveRoomInfo.getHostName());
|
||||
tikTokEventHandler.publish(this, new TikTokConnectingEvent());
|
||||
var userDataRequest = new LiveUserData.Request(roomInfo.getHostName());
|
||||
var userData = httpClient.fetchLiveUserData(userDataRequest);
|
||||
liveRoomInfo.setStartTime(userData.getStartedAtTimeStamp());
|
||||
liveRoomInfo.setRoomId(userData.getRoomId());
|
||||
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline) {
|
||||
throw new TikTokLiveOfflineHostException("User is offline: "+liveRoomInfo.getHostUser());
|
||||
}
|
||||
if (userData.getUserStatus() == LiveUserData.UserStatus.NotFound) {
|
||||
throw new TikTokLiveOfflineHostException("User not found: "+liveRoomInfo.getHostUser());
|
||||
}
|
||||
roomInfo.setStartTime(userData.getStartTime());
|
||||
roomInfo.setRoomId(userData.getRoomId());
|
||||
|
||||
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
|
||||
throw new TikTokLiveOfflineHostException("User is offline: " + roomInfo.getHostName());
|
||||
|
||||
if (userData.getUserStatus() == LiveUserData.UserStatus.NotFound)
|
||||
throw new TikTokLiveUnknownHostException("User not found: " + roomInfo.getHostName());
|
||||
|
||||
var liveDataRequest = new LiveData.Request(userData.getRoomId());
|
||||
var liveData = httpClient.fetchLiveData(liveDataRequest);
|
||||
tikTokEventHandler.publish(this, new TikTokRoomDataResponseEvent(liveData));
|
||||
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostNotFound) {
|
||||
throw new TikTokLiveOfflineHostException("LiveStream for Host name could not be found.");
|
||||
}
|
||||
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostOffline) {
|
||||
throw new TikTokLiveOfflineHostException("LiveStream for not be found, is the Host offline?");
|
||||
}
|
||||
|
||||
liveRoomInfo.setTitle(liveData.getTitle());
|
||||
liveRoomInfo.setViewersCount(liveData.getViewers());
|
||||
liveRoomInfo.setTotalViewersCount(liveData.getTotalViewers());
|
||||
liveRoomInfo.setAgeRestricted(liveData.isAgeRestricted());
|
||||
liveRoomInfo.setHost(liveData.getHost());
|
||||
if (liveData.isAgeRestricted() && clientSettings.isThrowOnAgeRestriction())
|
||||
throw new TikTokLiveException("Livestream for " + roomInfo.getHostName() + " is 18+ or age restricted!");
|
||||
|
||||
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostNotFound)
|
||||
throw new TikTokLiveUnknownHostException("LiveStream for " + roomInfo.getHostName() + " could not be found.");
|
||||
|
||||
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostOffline)
|
||||
throw new TikTokLiveOfflineHostException("LiveStream for " + roomInfo.getHostName() + " not found, is the Host offline?");
|
||||
|
||||
roomInfo.setTitle(liveData.getTitle());
|
||||
roomInfo.setViewersCount(liveData.getViewers());
|
||||
roomInfo.setTotalViewersCount(liveData.getTotalViewers());
|
||||
roomInfo.setAgeRestricted(liveData.isAgeRestricted());
|
||||
roomInfo.setHost(liveData.getHost());
|
||||
|
||||
var preconnectEvent = new TikTokPreConnectionEvent(userData, liveData);
|
||||
tikTokEventHandler.publish(this, preconnectEvent);
|
||||
if (preconnectEvent.isCancelConnection())
|
||||
throw new TikTokLiveException("TikTokPreConnectionEvent cancelled connection!");
|
||||
|
||||
var liveConnectionRequest =new LiveConnectionData.Request(userData.getRoomId());
|
||||
if (clientSettings.isFetchGifts())
|
||||
giftManager.attachGiftsList(httpClient.fetchRoomGiftsData(userData.getRoomId()).getGifts());
|
||||
|
||||
var liveConnectionRequest = new LiveConnectionData.Request(userData.getRoomId());
|
||||
var liveConnectionData = httpClient.fetchLiveConnectionData(liveConnectionRequest);
|
||||
webSocketClient.start(liveConnectionData, this);
|
||||
|
||||
setState(ConnectionState.CONNECTED);
|
||||
tikTokEventHandler.publish(this, new TikTokRoomInfoEvent(liveRoomInfo));
|
||||
tikTokEventHandler.publish(this, new TikTokRoomInfoEvent(roomInfo));
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (liveRoomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) {
|
||||
if (roomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) {
|
||||
return;
|
||||
}
|
||||
setState(ConnectionState.DISCONNECTED);
|
||||
@@ -173,29 +163,36 @@ public class TikTokLiveClient implements LiveClient {
|
||||
|
||||
private void setState(ConnectionState connectionState) {
|
||||
logger.info("TikTokLive client state: " + connectionState.name());
|
||||
liveRoomInfo.setConnectionState(connectionState);
|
||||
roomInfo.setConnectionState(connectionState);
|
||||
}
|
||||
|
||||
public void publishEvent(TikTokEvent event) {
|
||||
tikTokEventHandler.publish(this, event);
|
||||
}
|
||||
|
||||
public LiveRoomInfo getRoomInfo() {
|
||||
return liveRoomInfo;
|
||||
@Override
|
||||
public void publishMessage(String webcastMessageName, String payloadBase64) {
|
||||
this.publishMessage(webcastMessageName, Base64.getDecoder().decode(payloadBase64));
|
||||
}
|
||||
@Override
|
||||
public void publishMessage(String webcastMessageName, byte[] payload) {
|
||||
|
||||
var builder = WebcastResponse.Message.newBuilder();
|
||||
builder.setMethod(webcastMessageName);
|
||||
builder.setPayload(ByteString.copyFrom(payload));
|
||||
var message = builder.build();
|
||||
messageHandler.handleSingleMessage(this, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenersManager getListenersManager() {
|
||||
return listenersManager;
|
||||
|
||||
public void connectAsync(Consumer<LiveClient> onConnection) {
|
||||
connectAsync().thenAccept(onConnection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GiftManager getGiftManager() {
|
||||
return tikTokGiftManager;
|
||||
public CompletableFuture<LiveClient> connectAsync() {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
connect();
|
||||
return this;
|
||||
});
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user