mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Compare commits
84 Commits
develop-1.
...
1.7.2-Rele
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.3.0-Release</version>
|
<version>1.7.1-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ public class TikTokBarrageEvent extends TikTokHeaderEvent {
|
|||||||
private final Picture rightIcon;
|
private final Picture rightIcon;
|
||||||
private final String eventName;
|
private final String eventName;
|
||||||
private final int duration;
|
private final int duration;
|
||||||
|
private final BarrageParam barrageParam;
|
||||||
private BarrageParam barrageParam;
|
|
||||||
|
|
||||||
public TikTokBarrageEvent(WebcastBarrageMessage msg) {
|
public TikTokBarrageEvent(WebcastBarrageMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
@@ -49,6 +48,5 @@ public class TikTokBarrageEvent extends TikTokHeaderEvent {
|
|||||||
rightIcon = Picture.map(msg.getRightIcon());
|
rightIcon = Picture.map(msg.getRightIcon());
|
||||||
duration = msg.getDuration();
|
duration = msg.getDuration();
|
||||||
barrageParam = BarrageParam.map(msg);
|
barrageParam = BarrageParam.map(msg);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ public class TikTokCaptionEvent extends TikTokHeaderEvent {
|
|||||||
String text;
|
String text;
|
||||||
|
|
||||||
public TikTokCaptionEvent(WebcastCaptionMessage msg) {
|
public TikTokCaptionEvent(WebcastCaptionMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
captionTimeStamp = msg.getTimeStamp();
|
captionTimeStamp = msg.getTimeStamp();
|
||||||
iSOLanguage = msg.getCaptionData().getLanguage();
|
iSOLanguage = msg.getCaptionData().getLanguage();
|
||||||
text = msg.getCaptionData().getText();
|
text = msg.getCaptionData().getText();
|
||||||
|
|||||||
@@ -40,18 +40,30 @@ import java.util.List;
|
|||||||
public class TikTokCommentEvent extends TikTokHeaderEvent {
|
public class TikTokCommentEvent extends TikTokHeaderEvent {
|
||||||
private final User user;
|
private final User user;
|
||||||
private final String text;
|
private final String text;
|
||||||
private final String getUserLanguage;
|
private final String userLanguage;
|
||||||
private final User mentionedUser;
|
private final User mentionedUser;
|
||||||
private final List<Picture> pictures;
|
private final List<Picture> pictures;
|
||||||
private final boolean visibleToSender;
|
private final boolean visibleToSender;
|
||||||
|
|
||||||
public TikTokCommentEvent(WebcastChatMessage msg) {
|
public TikTokCommentEvent(WebcastChatMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
user = User.map(msg.getUser(),msg.getUserIdentity());
|
user = User.map(msg.getUser(), msg.getUserIdentity());
|
||||||
text = msg.getContent();
|
text = msg.getContent();
|
||||||
visibleToSender = msg.getVisibleToSender();
|
visibleToSender = msg.getVisibleToSender();
|
||||||
getUserLanguage = msg.getContentLanguage();
|
userLanguage = msg.getContentLanguage();
|
||||||
mentionedUser = User.map(msg.getAtUser());
|
mentionedUser = User.map(msg.getAtUser());
|
||||||
pictures = msg.getEmotesListList().stream().map(e -> Picture.map(e.getEmote().getImage())).toList();
|
pictures = msg.getEmotesListList().stream().map(e -> Picture.map(e.getEmote().getImage())).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static TikTokCommentEvent of(String userName, String message) {
|
||||||
|
var builder = WebcastChatMessage.newBuilder();
|
||||||
|
builder.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
|
.setNickname(userName)
|
||||||
|
.build());
|
||||||
|
builder.setContentLanguage("en");
|
||||||
|
builder.setVisibleToSender(true);
|
||||||
|
builder.setContent(message);
|
||||||
|
return new TikTokCommentEvent(builder.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -30,14 +30,10 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokDetectEvent extends TikTokHeaderEvent {
|
public class TikTokDetectEvent extends TikTokHeaderEvent {
|
||||||
String language;
|
private final String language;
|
||||||
|
|
||||||
|
|
||||||
public TikTokDetectEvent(WebcastMsgDetectMessage msg) {
|
|
||||||
super(msg.getCommon());
|
|
||||||
language = msg.getFromRegion();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public TikTokDetectEvent(WebcastMsgDetectMessage msg) {
|
||||||
|
super(msg.getCommon());
|
||||||
|
language = msg.getFromRegion();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -30,9 +30,11 @@ import lombok.Getter;
|
|||||||
* Triggered when the connection gets disconnected. In that case you can call connect() again to have a reconnect logic.
|
* 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.
|
* Note that you should wait a little bit before attempting a reconnect to to avoid being rate-limited.
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Control)
|
@EventMeta(eventType = EventType.Control)
|
||||||
public class TikTokDisconnectedEvent extends TikTokLiveClientEvent {
|
public class TikTokDisconnectedEvent extends TikTokLiveClientEvent {
|
||||||
@Getter private final String reason;
|
private final String reason;
|
||||||
|
|
||||||
public TikTokDisconnectedEvent(String reason) {
|
public TikTokDisconnectedEvent(String reason) {
|
||||||
this.reason = reason.isBlank() ? "None" : reason;
|
this.reason = reason.isBlank() ? "None" : reason;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ import lombok.Value;
|
|||||||
@Value
|
@Value
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokEnvelopeEvent extends TikTokHeaderEvent {
|
public class TikTokEnvelopeEvent extends TikTokHeaderEvent {
|
||||||
User user;
|
User user;
|
||||||
public TikTokEnvelopeEvent(WebcastEnvelopeMessage msg) {
|
public TikTokEnvelopeEvent(WebcastEnvelopeMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
user = User.map(msg.getEnvelopeInfo());
|
user = User.map(msg.getEnvelopeInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,9 +34,10 @@ import java.util.List;
|
|||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokIMDeleteEvent extends TikTokHeaderEvent {
|
public class TikTokIMDeleteEvent extends TikTokHeaderEvent {
|
||||||
|
|
||||||
List<Long> userIds;
|
private final List<Long> msgIds, userIds;
|
||||||
public TikTokIMDeleteEvent(WebcastImDeleteMessage msg) {
|
public TikTokIMDeleteEvent(WebcastImDeleteMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
|
this.msgIds = msg.getDeleteMsgIdsListList();
|
||||||
this.userIds = msg.getDeleteUserIdsListList();
|
this.userIds = msg.getDeleteUserIdsListList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,10 +31,10 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokInRoomBannerEvent extends TikTokHeaderEvent {
|
public class TikTokInRoomBannerEvent extends TikTokHeaderEvent {
|
||||||
private final String json;
|
private final String json;
|
||||||
|
|
||||||
public TikTokInRoomBannerEvent(WebcastInRoomBannerMessage msg) {
|
public TikTokInRoomBannerEvent(WebcastInRoomBannerMessage msg) {
|
||||||
super(msg.getHeader());
|
super(msg.getHeader());
|
||||||
json = msg.getJson();
|
json = msg.getJson();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,11 +33,7 @@ import lombok.Getter;
|
|||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLinkLayerEvent extends TikTokHeaderEvent {
|
public class TikTokLinkLayerEvent extends TikTokHeaderEvent {
|
||||||
|
|
||||||
|
|
||||||
public TikTokLinkLayerEvent(WebcastLinkLayerMessage msg) {
|
public TikTokLinkLayerEvent(WebcastLinkLayerMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.LinkMicArmy;
|
import io.github.jwdeveloper.tiktok.data.models.LinkMicArmy;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
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 io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicArmies;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.List;
|
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.
|
* 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)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLinkMicArmiesEvent extends TikTokHeaderEvent {
|
public class TikTokLinkMicArmiesEvent extends TikTokHeaderEvent {
|
||||||
private final Long battleId;
|
private final Long battleId;
|
||||||
|
/**
|
||||||
private final Integer battleStatus;
|
true if battle is finished otherwise false
|
||||||
|
*/
|
||||||
|
private final boolean finished;
|
||||||
|
|
||||||
private final Picture picture;
|
private final Picture picture;
|
||||||
|
|
||||||
@@ -52,6 +54,6 @@ public class TikTokLinkMicArmiesEvent extends TikTokHeaderEvent {
|
|||||||
battleId = msg.getId();
|
battleId = msg.getId();
|
||||||
armies = msg.getBattleItemsList().stream().map(LinkMicArmy::new).toList();
|
armies = msg.getBattleItemsList().stream().map(LinkMicArmy::new).toList();
|
||||||
picture = Picture.map(msg.getImage());
|
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;
|
package io.github.jwdeveloper.tiktok.data.events;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.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 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
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent {
|
public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
||||||
private final Long battleId;
|
{
|
||||||
private final List<LinkMicBattleTeam> team1;
|
private final Long battleId;
|
||||||
private final List<LinkMicBattleTeam> team2;
|
/**
|
||||||
|
true if battle is finished otherwise false
|
||||||
|
*/
|
||||||
|
private final boolean finished;
|
||||||
|
@Getter(AccessLevel.NONE)
|
||||||
|
private final boolean oneVsOne;
|
||||||
|
private final List<Team> teams;
|
||||||
|
|
||||||
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
battleId = msg.getId();
|
battleId = msg.getId();
|
||||||
team1 = msg.getTeams1List().stream().map(LinkMicBattleTeam::new).toList();
|
finished = msg.getBattleStatus() == LinkMicBattleStatus.BATTLE_FINISHED;
|
||||||
team2 = msg.getTeams2List().stream().map(LinkMicBattleTeam::new).toList();
|
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));
|
||||||
|
oneVsOne = true;
|
||||||
|
} 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));
|
||||||
|
}
|
||||||
|
oneVsOne = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 oneVsOne;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean is2v2() {
|
||||||
|
return !oneVsOne;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -32,10 +32,8 @@ import lombok.Getter;
|
|||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLinkMicMethodEvent extends TikTokHeaderEvent {
|
public class TikTokLinkMicMethodEvent extends TikTokHeaderEvent {
|
||||||
|
|
||||||
public TikTokLinkMicMethodEvent(WebcastLinkMicMethod msg) {
|
public TikTokLinkMicMethodEvent(WebcastLinkMicMethod msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -32,15 +32,14 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokRankTextEvent extends TikTokHeaderEvent {
|
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)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokRankUpdateEvent extends TikTokHeaderEvent {
|
public class TikTokRankUpdateEvent extends TikTokHeaderEvent {
|
||||||
|
|
||||||
public TikTokRankUpdateEvent(WebcastHourlyRankMessage msg) {
|
public TikTokRankUpdateEvent(WebcastHourlyRankMessage msg) {
|
||||||
super(msg.getCommon());
|
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
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokShopEvent extends TikTokHeaderEvent {
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -36,10 +36,10 @@ import lombok.Getter;
|
|||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokSubscribeEvent extends TikTokHeaderEvent
|
public class TikTokSubscribeEvent extends TikTokHeaderEvent {
|
||||||
{
|
|
||||||
private final User user;
|
private final User user;
|
||||||
|
|
||||||
|
|
||||||
public TikTokSubscribeEvent(WebcastMemberMessage msg) {
|
public TikTokSubscribeEvent(WebcastMemberMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
user = User.map(msg.getUser());
|
user = User.map(msg.getUser());
|
||||||
@@ -52,4 +52,11 @@ public class TikTokSubscribeEvent extends TikTokHeaderEvent
|
|||||||
user.addAttribute(UserAttribute.Subscriber);
|
user.addAttribute(UserAttribute.Subscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TikTokSubscribeEvent of(String userName) {
|
||||||
|
return new TikTokSubscribeEvent(WebcastMemberMessage.newBuilder()
|
||||||
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
|
.setNickname(userName)
|
||||||
|
.build())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,13 @@ import lombok.*;
|
|||||||
/**
|
/**
|
||||||
* Triggered before the connection is established.
|
* Triggered before the connection is established.
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Control)
|
@EventMeta(eventType = EventType.Control)
|
||||||
public class TikTokPreConnectionEvent extends TikTokLiveClientEvent
|
public class TikTokPreConnectionEvent extends TikTokLiveClientEvent
|
||||||
{
|
{
|
||||||
@Getter private final LiveUserData.Response userData;
|
private final LiveUserData.Response userData;
|
||||||
@Getter private final LiveData.Response roomData;
|
private final LiveData.Response roomData;
|
||||||
@Getter @Setter boolean cancelConnection = false;
|
@Setter boolean cancelConnection = false;
|
||||||
|
|
||||||
public TikTokPreConnectionEvent(LiveUserData.Response userData, LiveData.Response liveData) {
|
public TikTokPreConnectionEvent(LiveUserData.Response userData, LiveData.Response liveData) {
|
||||||
this.userData = userData;
|
this.userData = userData;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
package io.github.jwdeveloper.tiktok.data.events.gift;
|
package io.github.jwdeveloper.tiktok.data.events.gift;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
||||||
@@ -32,7 +33,7 @@ import lombok.Getter;
|
|||||||
/**
|
/**
|
||||||
* Triggered every time gift is sent
|
* Triggered every time gift is sent
|
||||||
*
|
*
|
||||||
* @see GiftSendType it has 3 states
|
* @see GiftComboStateType it has 3 states
|
||||||
*
|
*
|
||||||
* <p>Example when user sends gift with combo</p>
|
* <p>Example when user sends gift with combo</p>
|
||||||
* <p>>Combo: 1 -> comboState = GiftSendType.Begin</p>
|
* <p>>Combo: 1 -> comboState = GiftSendType.Begin</p>
|
||||||
@@ -45,10 +46,21 @@ import lombok.Getter;
|
|||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
@Getter
|
@Getter
|
||||||
public class TikTokGiftComboEvent extends TikTokGiftEvent {
|
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);
|
super(gift, host, msg);
|
||||||
this.comboState = comboState;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,7 @@ package io.github.jwdeveloper.tiktok.data.events.gift;
|
|||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
||||||
@@ -55,4 +56,20 @@ public class TikTokGiftEvent extends TikTokHeaderEvent {
|
|||||||
}
|
}
|
||||||
combo = msg.getComboCount();
|
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
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.tools.db.tables;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
import java.io.StringWriter;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
public class ExceptionInfoModel
|
@Getter
|
||||||
{
|
@EventMeta(eventType = EventType.Message)
|
||||||
private String message;
|
public class TikTokLinkAcceptNoticeEvent extends TikTokLinkEvent {
|
||||||
private String stackTrace;
|
|
||||||
|
|
||||||
public ExceptionInfoModel(Throwable throwable) {
|
private final long fromUserId, fromRoomId, toUserId;
|
||||||
this.message = throwable.getMessage();
|
|
||||||
this.stackTrace = getStackTraceAsString(throwable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getStackTraceAsString(Throwable throwable) {
|
public TikTokLinkAcceptNoticeEvent(WebcastLinkMessage msg) {
|
||||||
StringWriter sw = new StringWriter();
|
super(msg);
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
if (!msg.hasAcceptNoticeContent())
|
||||||
throwable.printStackTrace(pw);
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Accept Notice Content!");
|
||||||
return sw.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters for message and stackTrace
|
var content = msg.getAcceptNoticeContent();
|
||||||
public String getMessage() {
|
this.fromUserId = content.getFromUserId();
|
||||||
return message;
|
this.fromRoomId = content.getFromRoomId();
|
||||||
}
|
this.toUserId = content.getToUserId();
|
||||||
|
|
||||||
public String getStackTrace() {
|
|
||||||
return stackTrace;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,18 +20,17 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
import lombok.Value;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
@Value
|
@Getter
|
||||||
public class EnumValue
|
@EventMeta(eventType = EventType.Message)
|
||||||
{
|
public class TikTokLinkApplyEvent extends TikTokLinkEvent {
|
||||||
public int value;
|
|
||||||
public String name;
|
|
||||||
|
|
||||||
public static EnumValue Map(Enum<?> _enum)
|
public TikTokLinkApplyEvent(WebcastLinkMessage msg) {
|
||||||
{
|
super(msg);
|
||||||
return new EnumValue(_enum.ordinal() ,_enum.name());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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,22 +20,20 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
@Getter
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
@EventMeta(eventType = EventType.Message)
|
||||||
import lombok.Value;
|
public class TikTokLinkCloseEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
import java.util.List;
|
public TikTokLinkCloseEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
@Value
|
// if (!msg.hasCloseContent())
|
||||||
public class LinkMicBattleTeam {
|
// throw new IllegalArgumentException("Expected WebcastLinkMessage with Close Content!");
|
||||||
Long teamId;
|
// Proto Empty
|
||||||
List<User> users;
|
|
||||||
|
|
||||||
public LinkMicBattleTeam(WebcastLinkMicBattle.LinkMicBattleTeam team) {
|
|
||||||
this.teamId = team.getId();
|
|
||||||
this.users = team.getUsersList().stream().map(User::new).toList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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,25 +20,29 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.tools.db;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.tools.db.tables.TikTokErrorModel;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.ListUser;
|
||||||
import org.jdbi.v3.sqlobject.config.RegisterBeanMapper;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
import org.jdbi.v3.sqlobject.customizer.BindBean;
|
import lombok.Getter;
|
||||||
import org.jdbi.v3.sqlobject.statement.SqlQuery;
|
|
||||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkEnterEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
@RegisterBeanMapper(TikTokErrorModel.class)
|
private final List<ListUser> listUsers;
|
||||||
public interface TikTokErrorModelDAO
|
private final int anchorMultiLiveEnum;
|
||||||
{
|
|
||||||
@SqlUpdate("INSERT INTO TikTokErrorModel (hostName, errorName, errorType, exceptionContent, message, response, createdAt) " +
|
|
||||||
"VALUES (:hostName, :errorName, :errorType, :exceptionContent, :message, :response, :createdAt)")
|
|
||||||
void insertTikTokMessage(@BindBean TikTokErrorModel message);
|
|
||||||
|
|
||||||
@SqlQuery("SELECT * FROM TikTokErrorModel")
|
public TikTokLinkEnterEvent(WebcastLinkMessage msg) {
|
||||||
List<TikTokErrorModel> selectErrors();
|
super(msg);
|
||||||
|
if (!msg.hasEnterContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Enter Content!");
|
||||||
|
|
||||||
|
var content = msg.getEnterContent();
|
||||||
|
this.listUsers = content.getLinkedUsersListList().stream().map(ListUser::map).toList();
|
||||||
|
this.anchorMultiLiveEnum = content.getAnchorMultiLiveEnum();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -20,24 +20,24 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.events;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLinkEvent extends TikTokHeaderEvent {
|
public class TikTokLinkEvent extends TikTokHeaderEvent {
|
||||||
|
|
||||||
|
private final String extra, transferExtra;
|
||||||
|
private final long expireTimestamp;
|
||||||
|
|
||||||
public TikTokLinkEvent(WebcastLinkMessage msg) {
|
public TikTokLinkEvent(WebcastLinkMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
|
this.extra = msg.getExtra();
|
||||||
|
this.expireTimestamp = msg.getExpireTimestamp();
|
||||||
|
this.transferExtra = msg.getTransferExtra();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,14 +20,27 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.tools.collector.api;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
public interface DataCollector {
|
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;
|
||||||
|
|
||||||
void connect();
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkInviteEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long roomId;
|
||||||
|
private final User inviter;
|
||||||
|
|
||||||
void disconnect();
|
public TikTokLinkInviteEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasInviteContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Invite Content!");
|
||||||
|
|
||||||
void disconnect(boolean keepDatabase);
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,22 +20,29 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.tools.collector.api;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
import lombok.Data;
|
import io.github.jwdeveloper.tiktok.data.models.users.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
@Data
|
@Getter
|
||||||
public class TikTokDataCollectorModel {
|
@EventMeta(eventType = EventType.Message)
|
||||||
private List<String> users;
|
public class TikTokLinkListChangeEvent extends TikTokLinkEvent {
|
||||||
private String outputPath;
|
|
||||||
private String outputName;
|
private final List<ListUser> linkedUsers, appliedUsers, connectingUsers;
|
||||||
private Set<String> eventsFilter;
|
|
||||||
private Set<String> messagesFilter;
|
public TikTokLinkListChangeEvent(WebcastLinkMessage msg) {
|
||||||
private String sessionTag ="";
|
super(msg);
|
||||||
private Consumer<LiveClientBuilder> onConfigureLiveClient;
|
if (!msg.hasListChangeContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with List Change Content!");
|
||||||
|
|
||||||
|
var content = msg.getListChangeContent();
|
||||||
|
this.linkedUsers = content.getLinkedUsersList().stream().map(ListUser::map).toList();
|
||||||
|
this.appliedUsers = content.getAppliedUsersList().stream().map(ListUser::map).toList();
|
||||||
|
this.connectingUsers = content.getConnectingUsersList().stream().map(ListUser::map).toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkMediaChangeEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long op, toUserId, anchorId, roomId, changeScene;
|
||||||
|
|
||||||
|
public TikTokLinkMediaChangeEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasMediaChangeContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Media Change Content!");
|
||||||
|
|
||||||
|
var content = msg.getMediaChangeContent();
|
||||||
|
this.op = content.getOp();
|
||||||
|
this.toUserId = content.getToUserId();
|
||||||
|
this.anchorId = content.getAnchorId();
|
||||||
|
this.roomId = content.getRoomId();
|
||||||
|
this.changeScene = content.getChangeScene();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,24 +20,20 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.events;
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import lombok.Getter;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
@Getter
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class CustomEvent extends TikTokHeaderEvent {
|
public class TikTokLinkMicIdxUpdateEvent extends TikTokLinkEvent {
|
||||||
private final User user;
|
|
||||||
private final String title;
|
|
||||||
|
|
||||||
public CustomEvent(User user, String title) {
|
public TikTokLinkMicIdxUpdateEvent(WebcastLinkMessage msg) {
|
||||||
this.user = user;
|
super(msg);
|
||||||
this.title = title;
|
// if (!msg.hasMicIdxUpdateContent())
|
||||||
|
// throw new IllegalArgumentException("Expected WebcastLinkMessage with Mic Idx Update Content!");
|
||||||
|
// Proto Empty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,18 +20,25 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.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 {
|
@Getter
|
||||||
private final MessagesManager messageCollector;
|
@EventMeta(eventType = EventType.Message)
|
||||||
private final TikTokDatabase tikTokDatabase;
|
public class TikTokLinkMuteEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
public TikTokClientFactory(MessagesManager messageCollector, TikTokDatabase tikTokDatabase) {
|
private final long userId, status;
|
||||||
this.messageCollector = messageCollector;
|
|
||||||
this.tikTokDatabase = tikTokDatabase;
|
public TikTokLinkMuteEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasMuteContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Mute Content!");
|
||||||
|
|
||||||
|
var content = msg.getMuteContent();
|
||||||
|
this.userId = content.getUserId();
|
||||||
|
this.status = content.getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkRandomMatchEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final User user;
|
||||||
|
private final long roomId, inviteType, innerChannelId;
|
||||||
|
private final String matchId;
|
||||||
|
|
||||||
|
public TikTokLinkRandomMatchEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasRandomMatchContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Random Match Content!");
|
||||||
|
|
||||||
|
var content = msg.getRandomMatchContent();
|
||||||
|
this.user = User.map(content.getUser());
|
||||||
|
this.roomId = content.getRoomId();
|
||||||
|
this.inviteType = content.getInviteType();
|
||||||
|
this.matchId = content.getMatchId();
|
||||||
|
this.innerChannelId = content.getInnerChannelId();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkReplyEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long roomId;
|
||||||
|
private final User fromUser, toUser;
|
||||||
|
|
||||||
|
public TikTokLinkReplyEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasReplyContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Reply Content!");
|
||||||
|
|
||||||
|
var content = msg.getReplyContent();
|
||||||
|
this.roomId = content.getFromRoomId();
|
||||||
|
this.fromUser = User.map(content.getFromUser());
|
||||||
|
this.toUser = User.map(content.getToUser());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkSysKickOutEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long userId;
|
||||||
|
private final String linkmicIdStr;
|
||||||
|
|
||||||
|
public TikTokLinkSysKickOutEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasSysKickOutContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Sys Kick Out Content!");
|
||||||
|
|
||||||
|
var content = msg.getSysKickOutContent();
|
||||||
|
this.userId = content.getUserId();
|
||||||
|
this.linkmicIdStr = content.getLinkmicIdStr();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkUpdateUserEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long fromUserId, toUserId;
|
||||||
|
|
||||||
|
public TikTokLinkUpdateUserEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasUpdateUserContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with Update User Content!");
|
||||||
|
|
||||||
|
var content = msg.getUpdateUserContent();
|
||||||
|
this.fromUserId = content.getFromUserId();
|
||||||
|
this.toUserId = content.getToUserId();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkUpdateUserSettingEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
public TikTokLinkUpdateUserSettingEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
// if (!msg.hasUpdateUserSettingContent())
|
||||||
|
// throw new IllegalArgumentException("Expected WebcastLinkMessage with Update User Setting Content!");
|
||||||
|
// Proto Empty
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.data.events.link;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.Text;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
public class TikTokLinkUserToastEvent extends TikTokLinkEvent {
|
||||||
|
|
||||||
|
private final long userId, roomId;
|
||||||
|
private final Text displayText;
|
||||||
|
|
||||||
|
public TikTokLinkUserToastEvent(WebcastLinkMessage msg) {
|
||||||
|
super(msg);
|
||||||
|
if (!msg.hasUserToastContent())
|
||||||
|
throw new IllegalArgumentException("Expected WebcastLinkMessage with User Toast Content!");
|
||||||
|
|
||||||
|
var content = msg.getUserToastContent();
|
||||||
|
this.userId = content.getUserId();
|
||||||
|
this.roomId = content.getRoomId();
|
||||||
|
this.displayText = Text.map(content.getDisplayText());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,7 +30,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
Triggered when LiveRoomInfo got updated such as likes, viewers, ranking ....
|
Triggered when LiveRoomInfo got updated such as likes, viewers, ranking ....
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
|
|||||||
@@ -33,15 +33,13 @@ import lombok.Getter;
|
|||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokRoomPinEvent extends TikTokHeaderEvent
|
public class TikTokRoomPinEvent extends TikTokHeaderEvent
|
||||||
{
|
{
|
||||||
|
private final TikTokCommentEvent pinnedMessage;
|
||||||
|
private final long timestamp;
|
||||||
|
|
||||||
private TikTokCommentEvent pinnedMessage;
|
public TikTokRoomPinEvent(WebcastRoomPinMessage msg, TikTokCommentEvent commentEvent)
|
||||||
private long timestamp;
|
{
|
||||||
|
super(msg.getCommon());
|
||||||
public TikTokRoomPinEvent(WebcastRoomPinMessage msg, TikTokCommentEvent commentEvent)
|
this.timestamp = msg.getTimestamp();
|
||||||
{
|
this.pinnedMessage = commentEvent;
|
||||||
super(msg.getCommon());
|
}
|
||||||
this.timestamp = msg.getTimestamp();
|
|
||||||
this.pinnedMessage = commentEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -36,13 +36,21 @@ import lombok.Value;
|
|||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokFollowEvent extends TikTokHeaderEvent
|
public class TikTokFollowEvent extends TikTokHeaderEvent
|
||||||
{
|
{
|
||||||
User user;
|
User user;
|
||||||
int totalFollowers;
|
int totalFollowers;
|
||||||
|
|
||||||
public TikTokFollowEvent(WebcastSocialMessage msg) {
|
public TikTokFollowEvent(WebcastSocialMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
user = User.map(msg.getUser());
|
user = User.map(msg.getUser());
|
||||||
totalFollowers = msg.getFollowCount();
|
totalFollowers = msg.getFollowCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TikTokFollowEvent of(String userName)
|
||||||
|
{
|
||||||
|
return new TikTokFollowEvent(WebcastSocialMessage.newBuilder()
|
||||||
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
|
.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.annotations.EventType;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.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.WebcastMemberMessage;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -47,4 +48,13 @@ public class TikTokJoinEvent extends TikTokHeaderEvent {
|
|||||||
user = User.map(msg.getUser());
|
user = User.map(msg.getUser());
|
||||||
totalUsers = msg.getMemberCount();
|
totalUsers = msg.getMemberCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TikTokJoinEvent of(String userName)
|
||||||
|
{
|
||||||
|
return new TikTokJoinEvent(WebcastMemberMessage.newBuilder()
|
||||||
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
|
.setNickname(userName)
|
||||||
|
.build())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,4 +57,15 @@ public class TikTokLikeEvent extends TikTokHeaderEvent
|
|||||||
likes = msg.getCount();
|
likes = msg.getCount();
|
||||||
totalLikes = msg.getTotal();
|
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()
|
||||||
|
.setNickname(userName)
|
||||||
|
.build())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,19 +35,18 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokShareEvent extends TikTokHeaderEvent {
|
public class TikTokShareEvent extends TikTokHeaderEvent {
|
||||||
private final User user;
|
private final User user;
|
||||||
private final int totalShares;
|
private final int totalShares;
|
||||||
|
|
||||||
public TikTokShareEvent(WebcastSocialMessage msg, Integer amount) {
|
public TikTokShareEvent(WebcastSocialMessage msg, Integer amount) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
user = User.map(msg.getUser());
|
user = User.map(msg.getUser());
|
||||||
this.totalShares = amount;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -44,11 +44,11 @@ public class Picture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Picture map(io.github.jwdeveloper.tiktok.messages.data.Image profilePicture) {
|
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) {
|
if (index < 0) {
|
||||||
return new Picture("");
|
return new Picture("");
|
||||||
}
|
}
|
||||||
var url = profilePicture.getUrlList(index);
|
var url = profilePicture.getUrl(index);
|
||||||
return new Picture(url);
|
return new Picture(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ public class Picture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Picture Empty() {
|
public static Picture empty() {
|
||||||
return new Picture("");
|
return new Picture("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
|
public abstract class Team {
|
||||||
|
/**
|
||||||
|
* Provides a check for verifying if this team represents a 1v1 Team.
|
||||||
|
* @return true if this team is of type {@link Team1v1}, false otherwise.
|
||||||
|
*/
|
||||||
|
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,26 @@
|
|||||||
|
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
|
||||||
|
{
|
||||||
|
/** Value >= 0 when finished otherwise -1 */
|
||||||
|
private final int totalPoints;
|
||||||
|
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,31 @@
|
|||||||
|
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 {
|
||||||
|
/** Value >= 0 when finished otherwise -1 */
|
||||||
|
private final int totalPoints;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
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.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class Viewer {
|
||||||
|
private final User user;
|
||||||
|
private final int points;
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,7 @@ package io.github.jwdeveloper.tiktok.data.models.gifts;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import lombok.*;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class Gift {
|
public class Gift {
|
||||||
@@ -16,7 +14,7 @@ public class Gift {
|
|||||||
|
|
||||||
private final int diamondCost;
|
private final int diamondCost;
|
||||||
|
|
||||||
private final Picture picture;
|
private Picture picture;
|
||||||
|
|
||||||
private final JsonObject properties;
|
private final JsonObject properties;
|
||||||
|
|
||||||
|
|||||||
@@ -22,17 +22,15 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.gifts;
|
package io.github.jwdeveloper.tiktok.data.models.gifts;
|
||||||
|
|
||||||
public enum GiftSendType
|
public enum GiftComboStateType {
|
||||||
{
|
|
||||||
Finished,
|
Finished,
|
||||||
Begin,
|
Begin,
|
||||||
Active;
|
Active;
|
||||||
|
|
||||||
public static GiftSendType fromNumber(long number)
|
public static GiftComboStateType fromNumber(long number) {
|
||||||
{
|
|
||||||
return switch ((int) number) {
|
return switch ((int) number) {
|
||||||
case 1, 2, 4 -> GiftSendType.Active;
|
case 1, 2, 4 -> GiftComboStateType.Active;
|
||||||
default -> GiftSendType.Finished;
|
default -> GiftComboStateType.Finished;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,34 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@ package io.github.jwdeveloper.tiktok.data.models.users;
|
|||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.badges.Badge;
|
import io.github.jwdeveloper.tiktok.data.models.badges.Badge;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastEnvelopeMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@@ -136,6 +136,14 @@ public class User {
|
|||||||
this.picture = picture;
|
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) {
|
public User(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
||||||
this(user.getId(), user.getDisplayId(), Picture.map(user.getAvatarThumb()));
|
this(user.getId(), user.getDisplayId(), Picture.map(user.getAvatarThumb()));
|
||||||
profileName = user.getNickname();
|
profileName = user.getNickname();
|
||||||
@@ -159,10 +167,9 @@ public class User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static User EMPTY = new User(0L,
|
public static User EMPTY = new User(0L,
|
||||||
"",
|
"",
|
||||||
Picture.Empty(),
|
Picture.empty(),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
List.of(Badge.empty()));
|
List.of(Badge.empty()));
|
||||||
@@ -209,4 +216,18 @@ public class User {
|
|||||||
0,
|
0,
|
||||||
List.of(Badge.empty()));
|
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,20 +23,12 @@
|
|||||||
package io.github.jwdeveloper.tiktok.data.requests;
|
package io.github.jwdeveloper.tiktok.data.requests;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.Data;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GiftsData
|
public class GiftsData
|
||||||
{
|
{
|
||||||
@Getter
|
|
||||||
public final class Request
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static final class Response
|
public static final class Response
|
||||||
@@ -44,5 +36,4 @@ public class GiftsData
|
|||||||
private String json;
|
private String json;
|
||||||
private List<Gift> gifts;
|
private List<Gift> gifts;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -35,6 +35,7 @@ public class LiveData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
public static class Response {
|
public static class Response {
|
||||||
private String json;
|
private String json;
|
||||||
private LiveStatus liveStatus;
|
private LiveStatus liveStatus;
|
||||||
@@ -45,6 +46,11 @@ public class LiveData {
|
|||||||
private boolean ageRestricted;
|
private boolean ageRestricted;
|
||||||
private User host;
|
private User host;
|
||||||
private LiveType liveType;
|
private LiveType liveType;
|
||||||
|
public Response() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum LiveStatus {
|
public enum LiveStatus {
|
||||||
|
|||||||
@@ -34,30 +34,24 @@ import java.util.TreeMap;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class HttpClientSettings {
|
public class HttpClientSettings {
|
||||||
|
|
||||||
@Getter
|
private final Map<String, Object> params;
|
||||||
final Map<String, Object> params;
|
|
||||||
|
|
||||||
@Getter
|
private final Map<String, String> headers;
|
||||||
final Map<String, String> headers;
|
|
||||||
|
|
||||||
@Getter
|
private final Map<String, String> cookies;
|
||||||
final Map<String, String> cookies;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
ProxyClientSettings proxyClientSettings;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
Consumer<HttpClient.Builder> onClientCreating;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
Consumer<HttpRequest.Builder> onRequestCreating;
|
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
private ProxyClientSettings proxyClientSettings;
|
||||||
Duration timeout;
|
|
||||||
|
private Consumer<HttpClient.Builder> onClientCreating;
|
||||||
|
|
||||||
|
private Consumer<HttpRequest.Builder> onRequestCreating;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private Duration timeout;
|
||||||
|
|
||||||
public HttpClientSettings() {
|
public HttpClientSettings() {
|
||||||
this.params = new TreeMap<>();
|
this.params = new TreeMap<>();
|
||||||
@@ -65,10 +59,8 @@ public class HttpClientSettings {
|
|||||||
this.cookies = new HashMap<>();
|
this.cookies = new HashMap<>();
|
||||||
this.timeout = Duration.ofSeconds(2);
|
this.timeout = Duration.ofSeconds(2);
|
||||||
this.proxyClientSettings = new ProxyClientSettings();
|
this.proxyClientSettings = new ProxyClientSettings();
|
||||||
this.onClientCreating = (x) -> {
|
this.onClientCreating = (x) -> {};
|
||||||
};
|
this.onRequestCreating = (x) -> {};
|
||||||
this.onRequestCreating = (x) -> {
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -33,12 +33,17 @@ import java.util.logging.Level;
|
|||||||
@Data
|
@Data
|
||||||
public class LiveClientSettings {
|
public class LiveClientSettings {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets client to offline mode, prohibits connection to TikTok servers
|
||||||
|
* @apiNote Useful when testing client with custom events
|
||||||
|
*/
|
||||||
|
private boolean offline;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if gifts data is downloaded before TikTokLive starts,
|
* Fetch and download gifts data before TikTokLive starts
|
||||||
* when `false` then client.giftManager() does not contain initial gifts
|
* @apiNote If `false`, client.giftManager() does not contain initial gifts
|
||||||
*/
|
*/
|
||||||
private boolean fetchGifts;
|
private boolean fetchGifts = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ISO-Language for Client
|
* ISO-Language for Client
|
||||||
@@ -76,14 +81,22 @@ public class LiveClientSettings {
|
|||||||
private HttpClientSettings httpSettings;
|
private HttpClientSettings httpSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId
|
* Interval of time in milliseconds between pings to TikTok
|
||||||
* documentation how to obtain sessionId https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages
|
* @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;
|
private String sessionId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional: By default roomID is fetched before connect to live, but you can set it manually
|
* Optional: By default roomID is fetched before connect to live, but you can set it manually
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
private String roomId;
|
private String roomId;
|
||||||
|
|
||||||
@@ -92,8 +105,7 @@ public class LiveClientSettings {
|
|||||||
*/
|
*/
|
||||||
private String apiKey;
|
private String apiKey;
|
||||||
|
|
||||||
public static LiveClientSettings createDefault()
|
public static LiveClientSettings createDefault() {
|
||||||
{
|
|
||||||
var httpSettings = new HttpClientSettings();
|
var httpSettings = new HttpClientSettings();
|
||||||
httpSettings.getParams().putAll(DefaultClientParams());
|
httpSettings.getParams().putAll(DefaultClientParams());
|
||||||
httpSettings.getHeaders().putAll(DefaultRequestHeaders());
|
httpSettings.getHeaders().putAll(DefaultRequestHeaders());
|
||||||
|
|||||||
@@ -30,10 +30,14 @@ 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();
|
GiftsData.Response fetchGiftsData();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@link GiftsData.Response} list of gifts that are available in your region / livestream
|
||||||
|
*/
|
||||||
|
GiftsData.Response fetchRoomGiftsData(String room_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about user that is having a livestream
|
* Returns information about user that is having a livestream
|
||||||
|
|||||||
@@ -22,51 +22,50 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.listener;
|
package io.github.jwdeveloper.tiktok.listener;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* ListenersManager
|
||||||
* @see ListenersManager
|
* <p>
|
||||||
*
|
|
||||||
* TikTokEventListener is an alternative way of handing TikTok events.
|
* TikTokEventListener is an alternative way of handing TikTok events.
|
||||||
|
* <p>
|
||||||
|
* {@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
|
* @TikTokEventObserver
|
||||||
* that could be obtained by client.getListenerManager();
|
* public void onGiftMessage(LiveClient liveClient, TikTokGiftMessageEvent event)
|
||||||
*
|
* {
|
||||||
* Method in TikTokEventListener should meet 4 requirements to be detected
|
* System.out.println(event.getGift().getDescription());
|
||||||
* - 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 onAnyEvent(LiveClient liveClient, TikTokEvent event)
|
||||||
|
* {
|
||||||
|
* System.out.println(event.getClass().getSimpleName());
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public interface TikTokEventListener
|
public interface TikTokEventListener
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,134 @@
|
|||||||
|
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) {}
|
||||||
|
}
|
||||||
@@ -59,7 +59,16 @@ public interface LiveClient {
|
|||||||
/**
|
/**
|
||||||
* Use to manually invoke event
|
* 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
|
* Get information about gifts
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public interface LiveRoomInfo
|
|||||||
String getRoomId();
|
String getRoomId();
|
||||||
String getHostName();
|
String getHostName();
|
||||||
String getTitle();
|
String getTitle();
|
||||||
User getHostUser();
|
User getHost();
|
||||||
List<RankingUser> getUsersRanking();
|
List<RankingUser> getUsersRanking();
|
||||||
ConnectionState getConnectionState();
|
ConnectionState getConnectionState();
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,8 @@ message Text {
|
|||||||
|
|
||||||
// @Image
|
// @Image
|
||||||
message Image {
|
message Image {
|
||||||
repeated string urlList = 1;
|
repeated string url = 1;
|
||||||
|
string extras = 2;
|
||||||
bool isAnimated = 9;
|
bool isAnimated = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1061,9 +1062,9 @@ message CohostListChangeContent {
|
|||||||
|
|
||||||
|
|
||||||
message LinkerListChangeContent {
|
message LinkerListChangeContent {
|
||||||
repeated ListUser linkedUsersList = 1;
|
repeated ListUser linkedUsers = 1;
|
||||||
repeated ListUser appliedUsersList = 2;
|
repeated ListUser appliedUsers = 2;
|
||||||
repeated ListUser connectingUsersList = 3;
|
repeated ListUser connectingUsers = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message LinkerMediaChangeContent {
|
message LinkerMediaChangeContent {
|
||||||
|
|||||||
@@ -35,6 +35,14 @@ enum LinkmicApplierSortSetting {
|
|||||||
LINKMIC_APPLIER_SORT_SETTING_BY_GIFT_SCORE = 1;
|
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 {
|
enum HashtagNamespace {
|
||||||
GLOBAL = 0;
|
GLOBAL = 0;
|
||||||
GAMING = 1;
|
GAMING = 1;
|
||||||
@@ -242,21 +250,21 @@ enum CommonContentCase {
|
|||||||
|
|
||||||
|
|
||||||
enum LinkMessageType {
|
enum LinkMessageType {
|
||||||
TPYE_LINKER_UNKNOWN = 0;
|
TYPE_LINKER_UNKNOWN = 0;
|
||||||
TYPE_LINKER_CREATE = 1;
|
TYPE_LINKER_CREATE = 1;
|
||||||
TYPE_LINKER_CLOSE = 2;
|
TYPE_LINKER_CLOSE = 2;
|
||||||
TYPE_LINKER_INVITE = 3;
|
TYPE_LINKER_INVITE = 3;
|
||||||
TYPE_LINKER_APPLY = 4;
|
TYPE_LINKER_APPLY = 4;
|
||||||
TYPE_LINKER_REPLY = 5;
|
TYPE_LINKER_REPLY = 5;
|
||||||
TPYE_LINKER_ENTER = 6;
|
TYPE_LINKER_ENTER = 6;
|
||||||
TPYE_LINKER_LEAVE = 7;
|
TYPE_LINKER_LEAVE = 7;
|
||||||
TYPE_LINKER_PERMIT = 8;
|
TYPE_LINKER_PERMIT = 8;
|
||||||
TPYE_LINKER_CANCEL_INVITE = 9;
|
TYPE_LINKER_CANCEL_INVITE = 9;
|
||||||
TYPE_LINKER_WAITING_LIST_CHANGE = 10;
|
TYPE_LINKER_WAITING_LIST_CHANGE = 10;
|
||||||
TYPE_LINKER_LINKED_LIST_CHANGE = 11;
|
TYPE_LINKER_LINKED_LIST_CHANGE = 11;
|
||||||
TYPE_LINKER_UPDATE_USER = 12;
|
TYPE_LINKER_UPDATE_USER = 12;
|
||||||
TPYE_LINKER_KICK_OUT = 13;
|
TYPE_LINKER_KICK_OUT = 13;
|
||||||
TPYE_LINKER_CANCEL_APPLY = 14;
|
TYPE_LINKER_CANCEL_APPLY = 14;
|
||||||
TYPE_LINKER_MUTE = 15;
|
TYPE_LINKER_MUTE = 15;
|
||||||
TYPE_LINKER_MATCH = 16;
|
TYPE_LINKER_MATCH = 16;
|
||||||
TYPE_LINKER_UPDATE_USER_SETTING = 17;
|
TYPE_LINKER_UPDATE_USER_SETTING = 17;
|
||||||
@@ -267,8 +275,8 @@ enum LinkMessageType {
|
|||||||
TYPE_LINKER_COHOST_LIST_CHANGE = 22;
|
TYPE_LINKER_COHOST_LIST_CHANGE = 22;
|
||||||
TYPE_LINKER_MEDIA_CHANGE = 23;
|
TYPE_LINKER_MEDIA_CHANGE = 23;
|
||||||
TYPE_LINKER_ACCEPT_NOTICE = 24;
|
TYPE_LINKER_ACCEPT_NOTICE = 24;
|
||||||
TPYE_LINKER_SYS_KICK_OUT = 101;
|
TYPE_LINKER_SYS_KICK_OUT = 101;
|
||||||
TPYE_LINKMIC_USER_TOAST = 102;
|
TYPE_LINKMIC_USER_TOAST = 102;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MessageType {
|
enum MessageType {
|
||||||
|
|||||||
@@ -521,7 +521,7 @@ message WebcastLinkMicArmies {
|
|||||||
uint64 id2 = 4;
|
uint64 id2 = 4;
|
||||||
uint64 timeStamp1 = 5;
|
uint64 timeStamp1 = 5;
|
||||||
uint64 timeStamp2 = 6;
|
uint64 timeStamp2 = 6;
|
||||||
int32 battleStatus = 7; // SHOULD BE AN ENUM
|
LinkMicBattleStatus battleStatus = 7;
|
||||||
uint64 data1 = 8;
|
uint64 data1 = 8;
|
||||||
uint64 data2 = 9;
|
uint64 data2 = 9;
|
||||||
uint32 data3 = 10;
|
uint32 data3 = 10;
|
||||||
@@ -574,11 +574,26 @@ message WebcastLinkMicBattle {
|
|||||||
Common common = 1;
|
Common common = 1;
|
||||||
uint64 id = 2;
|
uint64 id = 2;
|
||||||
LinkMicBattleConfig battleConfig = 3;
|
LinkMicBattleConfig battleConfig = 3;
|
||||||
uint32 data2 = 4;
|
LinkMicBattleStatus battleStatus = 4;
|
||||||
repeated LinkMicBattleDetails details = 5;
|
repeated LinkMicBattleDetails details = 5;
|
||||||
repeated LinkMicBattleTeam teams1 = 9;
|
repeated LinkMicBattleTopViewers viewerTeam = 9;
|
||||||
repeated LinkMicBattleTeam teams2 = 10;
|
repeated LinkMicBattleHost hostTeam = 10;
|
||||||
repeated LinkMicBattleTeamData teamData = 13;
|
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 {
|
message LinkMicBattleConfig {
|
||||||
uint64 id1 = 1;
|
uint64 id1 = 1;
|
||||||
@@ -586,29 +601,69 @@ message WebcastLinkMicBattle {
|
|||||||
uint32 data1 = 3;
|
uint32 data1 = 3;
|
||||||
uint64 id2 = 4;
|
uint64 id2 = 4;
|
||||||
uint32 data2 = 5;
|
uint32 data2 = 5;
|
||||||
|
uint32 data3 = 6;
|
||||||
|
uint32 data4 = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
message LinkMicBattleTeamData {
|
||||||
|
uint64 teamId = 1;
|
||||||
|
LinkMicBattleData data = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message LinkMicBattleData {
|
message LinkMicBattleData {
|
||||||
uint64 id = 1;
|
uint64 id = 1;
|
||||||
uint32 data1 = 2;
|
uint32 data1 = 2;
|
||||||
uint32 data2 = 3;
|
uint32 winStreak = 3;
|
||||||
uint32 data3 = 5;
|
uint32 data3 = 5;
|
||||||
string url = 6;
|
string url = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message LinkMicBattleDetails {
|
message LinkMicBattleDetails {
|
||||||
uint64 id = 1;
|
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;
|
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 {
|
message LinkMicBattleHost {
|
||||||
uint64 teamId = 1;
|
uint64 id = 1;
|
||||||
LinkMicBattleData data = 2;
|
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;
|
LinkerListChangeContent ListChangeContent = 20;
|
||||||
CohostListChangeContent CohostListChangeContent = 21;
|
CohostListChangeContent CohostListChangeContent = 21;
|
||||||
LinkerMediaChangeContent MediaChangeContent = 22;
|
LinkerMediaChangeContent MediaChangeContent = 22;
|
||||||
LinkerAcceptNoticeContent ReplyAcceptNoticeContent = 23;
|
LinkerAcceptNoticeContent AcceptNoticeContent = 23;
|
||||||
LinkerSysKickOutContent SysKickOutContent = 101;
|
LinkerSysKickOutContent SysKickOutContent = 101;
|
||||||
LinkmicUserToastContent UserToastContent = 102;
|
LinkmicUserToastContent UserToastContent = 102;
|
||||||
string extra = 200;
|
string extra = 200;
|
||||||
@@ -793,5 +848,3 @@ message RoomVerifyMessage {
|
|||||||
int64 noticeType = 4;
|
int64 noticeType = 4;
|
||||||
bool closeRoom = 5;
|
bool closeRoom = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.3.0-Release</version>
|
<version>1.7.1-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
|
|||||||
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
||||||
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
|
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class TikTokLive {
|
public class TikTokLive {
|
||||||
@@ -92,8 +91,6 @@ public class TikTokLive {
|
|||||||
return new TikTokLiveHttpClient();
|
return new TikTokLiveHttpClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//I don't like it, but it is reasonable for now
|
|
||||||
private static GiftsManager giftsManager;
|
private static GiftsManager giftsManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,18 +99,11 @@ public class TikTokLive {
|
|||||||
* @return GiftsManager
|
* @return GiftsManager
|
||||||
*/
|
*/
|
||||||
public static GiftsManager gifts() {
|
public static GiftsManager gifts() {
|
||||||
if (giftsManager != null) {
|
if (giftsManager == null) {
|
||||||
return giftsManager;
|
synchronized (GiftsManager.class) {
|
||||||
}
|
giftsManager = new TikTokGiftsManager(requests().fetchGiftsData().getGifts());
|
||||||
synchronized (GiftsManager.class)
|
|
||||||
{
|
|
||||||
if (giftsManager == null)
|
|
||||||
{
|
|
||||||
return new TikTokGiftsManager(requests().fetchGiftsData().getGifts());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return giftsManager;
|
return giftsManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -22,48 +22,49 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokDisconnectedEvent;
|
import com.google.protobuf.ByteString;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
|
import io.github.jwdeveloper.tiktok.data.events.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokReconnectingEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.control.*;
|
import io.github.jwdeveloper.tiktok.data.events.control.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.http.TikTokRoomDataResponseEvent;
|
import io.github.jwdeveloper.tiktok.data.events.http.TikTokRoomDataResponseEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.room.TikTokRoomInfoEvent;
|
import io.github.jwdeveloper.tiktok.data.events.room.TikTokRoomInfoEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
|
import io.github.jwdeveloper.tiktok.data.requests.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.LiveData;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.LiveUserData;
|
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.*;
|
|
||||||
import io.github.jwdeveloper.tiktok.listener.ListenersManager;
|
|
||||||
import io.github.jwdeveloper.tiktok.listener.TikTokListenersManager;
|
|
||||||
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
|
||||||
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.settings.LiveClientSettings;
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
|
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.SocketClient;
|
import io.github.jwdeveloper.tiktok.websocket.SocketClient;
|
||||||
|
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class TikTokLiveClient implements LiveClient {
|
public class TikTokLiveClient implements LiveClient {
|
||||||
private final TikTokRoomInfo liveRoomInfo;
|
private final TikTokRoomInfo liveRoomInfo;
|
||||||
private final TikTokLiveHttpClient httpClient;
|
private final LiveHttpClient httpClient;
|
||||||
private final SocketClient webSocketClient;
|
private final SocketClient webSocketClient;
|
||||||
private final TikTokLiveEventHandler tikTokEventHandler;
|
private final TikTokLiveEventHandler tikTokEventHandler;
|
||||||
private final LiveClientSettings clientSettings;
|
private final LiveClientSettings clientSettings;
|
||||||
private final TikTokListenersManager listenersManager;
|
private final TikTokListenersManager listenersManager;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final GiftsManager giftsManager;
|
private final GiftsManager giftsManager;
|
||||||
|
private final TikTokLiveMessageHandler messageHandler;
|
||||||
|
|
||||||
public TikTokLiveClient(GiftsManager giftsManager,
|
public TikTokLiveClient(
|
||||||
TikTokRoomInfo tikTokLiveMeta,
|
TikTokLiveMessageHandler messageHandler,
|
||||||
TikTokLiveHttpClient tiktokHttpClient,
|
GiftsManager giftsManager,
|
||||||
SocketClient webSocketClient,
|
TikTokRoomInfo tikTokLiveMeta,
|
||||||
TikTokLiveEventHandler tikTokEventHandler,
|
LiveHttpClient tiktokHttpClient,
|
||||||
LiveClientSettings clientSettings,
|
SocketClient webSocketClient,
|
||||||
TikTokListenersManager listenersManager,
|
TikTokLiveEventHandler tikTokEventHandler,
|
||||||
Logger logger) {
|
LiveClientSettings clientSettings,
|
||||||
|
TikTokListenersManager listenersManager,
|
||||||
|
Logger logger) {
|
||||||
|
this.messageHandler = messageHandler;
|
||||||
this.giftsManager = giftsManager;
|
this.giftsManager = giftsManager;
|
||||||
this.liveRoomInfo = tikTokLiveMeta;
|
this.liveRoomInfo = tikTokLiveMeta;
|
||||||
this.httpClient = tiktokHttpClient;
|
this.httpClient = tiktokHttpClient;
|
||||||
@@ -127,6 +128,9 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
liveRoomInfo.setStartTime(userData.getStartedAtTimeStamp());
|
liveRoomInfo.setStartTime(userData.getStartedAtTimeStamp());
|
||||||
liveRoomInfo.setRoomId(userData.getRoomId());
|
liveRoomInfo.setRoomId(userData.getRoomId());
|
||||||
|
|
||||||
|
if (clientSettings.isFetchGifts())
|
||||||
|
giftsManager.attachGiftsList(httpClient.fetchRoomGiftsData(userData.getRoomId()).getGifts());
|
||||||
|
|
||||||
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
|
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
|
||||||
throw new TikTokLiveOfflineHostException("User is offline: " + liveRoomInfo.getHostName());
|
throw new TikTokLiveOfflineHostException("User is offline: " + liveRoomInfo.getHostName());
|
||||||
|
|
||||||
@@ -136,7 +140,7 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
var liveDataRequest = new LiveData.Request(userData.getRoomId());
|
var liveDataRequest = new LiveData.Request(userData.getRoomId());
|
||||||
var liveData = httpClient.fetchLiveData(liveDataRequest);
|
var liveData = httpClient.fetchLiveData(liveDataRequest);
|
||||||
|
|
||||||
if (liveData.isAgeRestricted())
|
if (liveData.isAgeRestricted() && clientSettings.isThrowOnAgeRestriction())
|
||||||
throw new TikTokLiveException("Livestream for " + liveRoomInfo.getHostName() + " is 18+ or age restricted!");
|
throw new TikTokLiveException("Livestream for " + liveRoomInfo.getHostName() + " is 18+ or age restricted!");
|
||||||
|
|
||||||
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostNotFound)
|
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostNotFound)
|
||||||
@@ -183,6 +187,20 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
tikTokEventHandler.publish(this, event);
|
tikTokEventHandler.publish(this, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Override
|
||||||
public GiftsManager getGiftManager() {
|
public GiftsManager getGiftManager() {
|
||||||
return giftsManager;
|
return giftsManager;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ 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.envelop.TikTokChestEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.gift.*;
|
import io.github.jwdeveloper.tiktok.data.events.gift.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.http.TikTokHttpResponseEvent;
|
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.poll.TikTokPollEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.room.*;
|
import io.github.jwdeveloper.tiktok.data.events.room.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.social.*;
|
import io.github.jwdeveloper.tiktok.data.events.social.*;
|
||||||
@@ -44,17 +45,19 @@ import io.github.jwdeveloper.tiktok.mappers.*;
|
|||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.handlers.*;
|
import io.github.jwdeveloper.tiktok.mappers.handlers.*;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
||||||
import io.github.jwdeveloper.tiktok.websocket.TikTokWebSocketClient;
|
import io.github.jwdeveloper.tiktok.websocket.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static io.github.jwdeveloper.tiktok.messages.enums.LinkMessageType.*;
|
||||||
|
|
||||||
public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
||||||
|
|
||||||
protected final LiveClientSettings clientSettings;
|
protected final LiveClientSettings clientSettings;
|
||||||
protected final TikTokLiveEventHandler tikTokEventHandler;
|
protected final TikTokLiveEventHandler eventHandler;
|
||||||
protected final List<TikTokEventListener> listeners;
|
protected final List<TikTokEventListener> listeners;
|
||||||
protected Consumer<TikTokMapper> onCustomMappings;
|
protected Consumer<TikTokMapper> onCustomMappings;
|
||||||
protected Logger logger;
|
protected Logger logger;
|
||||||
@@ -63,7 +66,7 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
public TikTokLiveClientBuilder(String userName) {
|
public TikTokLiveClientBuilder(String userName) {
|
||||||
this.clientSettings = LiveClientSettings.createDefault();
|
this.clientSettings = LiveClientSettings.createDefault();
|
||||||
this.clientSettings.setHostName(userName);
|
this.clientSettings.setHostName(userName);
|
||||||
this.tikTokEventHandler = new TikTokLiveEventHandler();
|
this.eventHandler = new TikTokLiveEventHandler();
|
||||||
this.listeners = new ArrayList<>();
|
this.listeners = new ArrayList<>();
|
||||||
this.onCustomMappings = (e) -> {
|
this.onCustomMappings = (e) -> {
|
||||||
};
|
};
|
||||||
@@ -95,6 +98,9 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
if (clientSettings.getHostName().startsWith("@"))
|
if (clientSettings.getHostName().startsWith("@"))
|
||||||
clientSettings.setHostName(clientSettings.getHostName().substring(1));
|
clientSettings.setHostName(clientSettings.getHostName().substring(1));
|
||||||
|
|
||||||
|
if (clientSettings.getPingInterval() < 250)
|
||||||
|
throw new TikTokLiveException("Minimum allowed ping interval is 250 millseconds");
|
||||||
|
|
||||||
var httpSettings = clientSettings.getHttpSettings();
|
var httpSettings = clientSettings.getHttpSettings();
|
||||||
httpSettings.getParams().put("app_language", clientSettings.getClientLanguage());
|
httpSettings.getParams().put("app_language", clientSettings.getClientLanguage());
|
||||||
httpSettings.getParams().put("webcast_language", clientSettings.getClientLanguage());
|
httpSettings.getParams().put("webcast_language", clientSettings.getClientLanguage());
|
||||||
@@ -109,27 +115,31 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
var tiktokRoomInfo = new TikTokRoomInfo();
|
var tiktokRoomInfo = new TikTokRoomInfo();
|
||||||
tiktokRoomInfo.setHostName(clientSettings.getHostName());
|
tiktokRoomInfo.setHostName(clientSettings.getHostName());
|
||||||
|
|
||||||
var listenerManager = new TikTokListenersManager(listeners, tikTokEventHandler);
|
var listenerManager = new TikTokListenersManager(listeners, eventHandler);
|
||||||
|
|
||||||
var httpClientFactory = new HttpClientFactory(clientSettings);
|
var httpClientFactory = new HttpClientFactory(clientSettings);
|
||||||
var tikTokLiveHttpClient = new TikTokLiveHttpClient(httpClientFactory, clientSettings);
|
|
||||||
|
|
||||||
|
var liveHttpClient = clientSettings.isOffline() ?
|
||||||
|
new TikTokLiveHttpOfflineClient() :
|
||||||
|
new TikTokLiveHttpClient(httpClientFactory, clientSettings);
|
||||||
|
|
||||||
var eventsMapper = createMapper(giftsManager, tiktokRoomInfo);
|
var eventsMapper = createMapper(giftsManager, tiktokRoomInfo);
|
||||||
var messageHandler = new TikTokLiveMessageHandler(tikTokEventHandler, eventsMapper);
|
var messageHandler = new TikTokLiveMessageHandler(eventHandler, eventsMapper);
|
||||||
|
|
||||||
|
var webSocketClient = clientSettings.isOffline() ?
|
||||||
var webSocketClient = new TikTokWebSocketClient(
|
new TikTokWebSocketOfflineClient(eventHandler) :
|
||||||
clientSettings,
|
new TikTokWebSocketClient(
|
||||||
messageHandler,
|
clientSettings,
|
||||||
tikTokEventHandler);
|
messageHandler,
|
||||||
|
eventHandler);
|
||||||
|
|
||||||
return new TikTokLiveClient(
|
return new TikTokLiveClient(
|
||||||
|
messageHandler,
|
||||||
giftsManager,
|
giftsManager,
|
||||||
tiktokRoomInfo,
|
tiktokRoomInfo,
|
||||||
tikTokLiveHttpClient,
|
liveHttpClient,
|
||||||
webSocketClient,
|
webSocketClient,
|
||||||
tikTokEventHandler,
|
eventHandler,
|
||||||
clientSettings,
|
clientSettings,
|
||||||
listenerManager,
|
listenerManager,
|
||||||
logger);
|
logger);
|
||||||
@@ -199,9 +209,42 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
|
|
||||||
|
|
||||||
//LinkMic events
|
//LinkMic events
|
||||||
// mapper.webcastObjectToConstructor(WebcastLinkMicBattle.class, TikTokLinkMicBattleEvent.class);
|
mapper.forMessage(WebcastLinkMicBattle.class, (inputBytes, messageName, mapperHelper) -> {
|
||||||
// mapper.webcastObjectToConstructor(WebcastLinkMicArmies.class, TikTokLinkMicArmiesEvent.class);
|
var message = mapperHelper.bytesToWebcastObject(inputBytes, WebcastLinkMicBattle.class);
|
||||||
// mapper.webcastObjectToConstructor(WebcastLinkMicMethod.class, TikTokLinkMicMethodEvent.class);
|
return MappingResult.of(message, new TikTokLinkMicBattleEvent(message));
|
||||||
|
});
|
||||||
|
mapper.forMessage(WebcastLinkMicArmies.class, (inputBytes, messageName, mapperHelper) -> {
|
||||||
|
var message = mapperHelper.bytesToWebcastObject(inputBytes, WebcastLinkMicArmies.class);
|
||||||
|
return MappingResult.of(message, new TikTokLinkMicArmiesEvent(message));
|
||||||
|
});
|
||||||
|
mapper.forMessage(WebcastLinkMessage.class, ((inputBytes, messageName, mapperHelper) -> {
|
||||||
|
var message = mapperHelper.bytesToWebcastObject(inputBytes, WebcastLinkMessage.class);
|
||||||
|
return MappingResult.of(message, switch (message.getMessageType()) {
|
||||||
|
case TYPE_LINKER_INVITE -> new TikTokLinkInviteEvent(message);
|
||||||
|
case TYPE_LINKER_REPLY -> new TikTokLinkReplyEvent(message);
|
||||||
|
case TYPE_LINKER_CREATE -> new TikTokLinkCreateEvent(message);
|
||||||
|
case TYPE_LINKER_CLOSE -> new TikTokLinkCloseEvent(message);
|
||||||
|
case TYPE_LINKER_ENTER -> new TikTokLinkEnterEvent(message);
|
||||||
|
case TYPE_LINKER_LEAVE -> new TikTokLinkLeaveEvent(message);
|
||||||
|
case TYPE_LINKER_CANCEL_INVITE, TYPE_LINKER_CANCEL_APPLY -> new TikTokLinkCancelEvent(message);
|
||||||
|
case TYPE_LINKER_KICK_OUT -> new TikTokLinkKickOutEvent(message);
|
||||||
|
case TYPE_LINKER_LINKED_LIST_CHANGE -> new TikTokLinkLinkedListChangeEvent(message);
|
||||||
|
case TYPE_LINKER_UPDATE_USER -> new TikTokLinkUpdateUserEvent(message);
|
||||||
|
case TYPE_LINKER_WAITING_LIST_CHANGE, TYPE_LINKER_WAITING_LIST_CHANGE_V2 -> new TikTokLinkWaitListChangeEvent(message);
|
||||||
|
case TYPE_LINKER_MUTE -> new TikTokLinkMuteEvent(message);
|
||||||
|
case TYPE_LINKER_MATCH -> new TikTokLinkRandomMatchEvent(message);
|
||||||
|
case TYPE_LINKER_UPDATE_USER_SETTING -> new TikTokLinkUpdateUserSettingEvent(message);
|
||||||
|
case TYPE_LINKER_MIC_IDX_UPDATE -> new TikTokLinkMicIdxUpdateEvent(message);
|
||||||
|
case TYPE_LINKER_LINKED_LIST_CHANGE_V2 -> new TikTokLinkListChangeEvent(message);
|
||||||
|
case TYPE_LINKER_COHOST_LIST_CHANGE -> new TikTokLinkCohostListChangeEvent(message);
|
||||||
|
case TYPE_LINKER_MEDIA_CHANGE -> new TikTokLinkMediaChangeEvent(message);
|
||||||
|
case TYPE_LINKER_ACCEPT_NOTICE -> new TikTokLinkAcceptNoticeEvent(message);
|
||||||
|
case TYPE_LINKER_SYS_KICK_OUT -> new TikTokLinkSysKickOutEvent(message);
|
||||||
|
case TYPE_LINKMIC_USER_TOAST -> new TikTokLinkUserToastEvent(message);
|
||||||
|
default -> new TikTokLinkEvent(message);
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
// mapper.webcastObjectToConstructor(WebcastLinkMicMethod.class, TikTokLinkMicMethodEvent.class);
|
||||||
// mapper.webcastObjectToConstructor(WebcastLinkMicFanTicketMethod.class, TikTokLinkMicFanTicketEvent.class);
|
// mapper.webcastObjectToConstructor(WebcastLinkMicFanTicketMethod.class, TikTokLinkMicFanTicketEvent.class);
|
||||||
|
|
||||||
//Rank events
|
//Rank events
|
||||||
@@ -235,255 +278,360 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onUnhandledSocial(EventConsumer<TikTokUnhandledSocialEvent> event) {
|
public TikTokLiveClientBuilder onUnhandledSocial(EventConsumer<TikTokUnhandledSocialEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokUnhandledSocialEvent.class, event);
|
eventHandler.subscribe(TikTokUnhandledSocialEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveClientBuilder onChest(EventConsumer<TikTokChestEvent> event) {
|
public LiveClientBuilder onChest(EventConsumer<TikTokChestEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokChestEvent.class, event);
|
eventHandler.subscribe(TikTokChestEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkMicFanTicket(EventConsumer<TikTokLinkMicFanTicketEvent> event) {
|
public TikTokLiveClientBuilder onLinkMicFanTicket(EventConsumer<TikTokLinkMicFanTicketEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokLinkMicFanTicketEvent.class, event);
|
eventHandler.subscribe(TikTokLinkMicFanTicketEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onEnvelope(EventConsumer<TikTokEnvelopeEvent> event) {
|
public TikTokLiveClientBuilder onEnvelope(EventConsumer<TikTokEnvelopeEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokEnvelopeEvent.class, event);
|
eventHandler.subscribe(TikTokEnvelopeEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onShop(EventConsumer<TikTokShopEvent> event) {
|
public TikTokLiveClientBuilder onShop(EventConsumer<TikTokShopEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokShopEvent.class, event);
|
eventHandler.subscribe(TikTokShopEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onDetect(EventConsumer<TikTokDetectEvent> event) {
|
public TikTokLiveClientBuilder onDetect(EventConsumer<TikTokDetectEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokDetectEvent.class, event);
|
eventHandler.subscribe(TikTokDetectEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkLayer(EventConsumer<TikTokLinkLayerEvent> event) {
|
public TikTokLiveClientBuilder onLinkLayer(EventConsumer<TikTokLinkLayerEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokLinkLayerEvent.class, event);
|
eventHandler.subscribe(TikTokLinkLayerEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onConnected(EventConsumer<TikTokConnectedEvent> event) {
|
public TikTokLiveClientBuilder onConnected(EventConsumer<TikTokConnectedEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokConnectedEvent.class, event);
|
eventHandler.subscribe(TikTokConnectedEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onPreConnection(EventConsumer<TikTokPreConnectionEvent> event) {
|
public TikTokLiveClientBuilder onPreConnection(EventConsumer<TikTokPreConnectionEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokPreConnectionEvent.class, event);
|
eventHandler.subscribe(TikTokPreConnectionEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onCaption(EventConsumer<TikTokCaptionEvent> event) {
|
public TikTokLiveClientBuilder onCaption(EventConsumer<TikTokCaptionEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokCaptionEvent.class, event);
|
eventHandler.subscribe(TikTokCaptionEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onQuestion(EventConsumer<TikTokQuestionEvent> event) {
|
public TikTokLiveClientBuilder onQuestion(EventConsumer<TikTokQuestionEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokQuestionEvent.class, event);
|
eventHandler.subscribe(TikTokQuestionEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onRoomPin(EventConsumer<TikTokRoomPinEvent> event) {
|
public TikTokLiveClientBuilder onRoomPin(EventConsumer<TikTokRoomPinEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokRoomPinEvent.class, event);
|
eventHandler.subscribe(TikTokRoomPinEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends TikTokEvent> LiveClientBuilder onEvent(Class<E> eventClass, EventConsumer<E> event) {
|
public <E extends TikTokEvent> LiveClientBuilder onEvent(Class<E> eventClass, EventConsumer<E> event) {
|
||||||
tikTokEventHandler.subscribe(eventClass, event);
|
eventHandler.subscribe(eventClass, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TikTokLiveClientBuilder onRoomInfo(EventConsumer<TikTokRoomInfoEvent> event) {
|
public TikTokLiveClientBuilder onRoomInfo(EventConsumer<TikTokRoomInfoEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokRoomInfoEvent.class, event);
|
eventHandler.subscribe(TikTokRoomInfoEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLivePaused(EventConsumer<TikTokLivePausedEvent> event) {
|
public TikTokLiveClientBuilder onLivePaused(EventConsumer<TikTokLivePausedEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokLivePausedEvent.class, event);
|
eventHandler.subscribe(TikTokLivePausedEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TikTokLiveClientBuilder onLiveUnpaused(EventConsumer<TikTokLiveUnpausedEvent> event) {
|
public TikTokLiveClientBuilder onLiveUnpaused(EventConsumer<TikTokLiveUnpausedEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokLiveUnpausedEvent.class, event);
|
eventHandler.subscribe(TikTokLiveUnpausedEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLike(EventConsumer<TikTokLikeEvent> event) {
|
public TikTokLiveClientBuilder onLike(EventConsumer<TikTokLikeEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokLikeEvent.class, event);
|
eventHandler.subscribe(TikTokLikeEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLink(EventConsumer<TikTokLinkEvent> event) {
|
public TikTokLiveClientBuilder onLink(EventConsumer<TikTokLinkEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokLinkEvent.class, event);
|
eventHandler.subscribe(TikTokLinkEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkInvite(EventConsumer<TikTokLinkInviteEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkInviteEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkReply(EventConsumer<TikTokLinkReplyEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkReplyEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkCreate(EventConsumer<TikTokLinkCreateEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkCreateEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkClose(EventConsumer<TikTokLinkCloseEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkCloseEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkEnter(EventConsumer<TikTokLinkEnterEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkEnterEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkLeave(EventConsumer<TikTokLinkLeaveEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkLeaveEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkCancel(EventConsumer<TikTokLinkCancelEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkCancelEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkKickOut(EventConsumer<TikTokLinkKickOutEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkKickOutEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkLinkedListChange(EventConsumer<TikTokLinkLinkedListChangeEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkLinkedListChangeEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkUpdateUser(EventConsumer<TikTokLinkUpdateUserEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkUpdateUserEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkWaitListChange(EventConsumer<TikTokLinkWaitListChangeEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkWaitListChangeEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkMute(EventConsumer<TikTokLinkMuteEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkMuteEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkRandomMatch(EventConsumer<TikTokLinkRandomMatchEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkRandomMatchEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkUpdateUserSettings(EventConsumer<TikTokLinkUpdateUserSettingEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkUpdateUserSettingEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkMicIdxUpdate(EventConsumer<TikTokLinkMicIdxUpdateEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkMicIdxUpdateEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkListChange(EventConsumer<TikTokLinkListChangeEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkListChangeEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkCohostListChange(EventConsumer<TikTokLinkCohostListChangeEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkCohostListChangeEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkMediaChange(EventConsumer<TikTokLinkMediaChangeEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkMediaChangeEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkAcceptNotice(EventConsumer<TikTokLinkAcceptNoticeEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkAcceptNoticeEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkSysKickOut(EventConsumer<TikTokLinkSysKickOutEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkSysKickOutEvent.class, event);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TikTokLiveClientBuilder onLinkUserToast(EventConsumer<TikTokLinkUserToastEvent> event) {
|
||||||
|
eventHandler.subscribe(TikTokLinkUserToastEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onBarrage(EventConsumer<TikTokBarrageEvent> event) {
|
public TikTokLiveClientBuilder onBarrage(EventConsumer<TikTokBarrageEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokBarrageEvent.class, event);
|
eventHandler.subscribe(TikTokBarrageEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onGift(EventConsumer<TikTokGiftEvent> event) {
|
public TikTokLiveClientBuilder onGift(EventConsumer<TikTokGiftEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokGiftEvent.class, event);
|
eventHandler.subscribe(TikTokGiftEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onGiftCombo(EventConsumer<TikTokGiftComboEvent> event) {
|
public TikTokLiveClientBuilder onGiftCombo(EventConsumer<TikTokGiftComboEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokGiftComboEvent.class, event);
|
eventHandler.subscribe(TikTokGiftComboEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkMicArmies(EventConsumer<TikTokLinkMicArmiesEvent> event) {
|
public TikTokLiveClientBuilder onLinkMicArmies(EventConsumer<TikTokLinkMicArmiesEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokLinkMicArmiesEvent.class, event);
|
eventHandler.subscribe(TikTokLinkMicArmiesEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onEmote(EventConsumer<TikTokEmoteEvent> event) {
|
public TikTokLiveClientBuilder onEmote(EventConsumer<TikTokEmoteEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokEmoteEvent.class, event);
|
eventHandler.subscribe(TikTokEmoteEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onUnauthorizedMember(EventConsumer<TikTokUnauthorizedMemberEvent> event) {
|
public TikTokLiveClientBuilder onUnauthorizedMember(EventConsumer<TikTokUnauthorizedMemberEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokUnauthorizedMemberEvent.class, event);
|
eventHandler.subscribe(TikTokUnauthorizedMemberEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onInRoomBanner(EventConsumer<TikTokInRoomBannerEvent> event) {
|
public TikTokLiveClientBuilder onInRoomBanner(EventConsumer<TikTokInRoomBannerEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokInRoomBannerEvent.class, event);
|
eventHandler.subscribe(TikTokInRoomBannerEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkMicMethod(EventConsumer<TikTokLinkMicMethodEvent> event) {
|
public TikTokLiveClientBuilder onLinkMicMethod(EventConsumer<TikTokLinkMicMethodEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokLinkMicMethodEvent.class, event);
|
eventHandler.subscribe(TikTokLinkMicMethodEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onSubscribe(EventConsumer<TikTokSubscribeEvent> event) {
|
public TikTokLiveClientBuilder onSubscribe(EventConsumer<TikTokSubscribeEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokSubscribeEvent.class, event);
|
eventHandler.subscribe(TikTokSubscribeEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onPoll(EventConsumer<TikTokPollEvent> event) {
|
public TikTokLiveClientBuilder onPoll(EventConsumer<TikTokPollEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokPollEvent.class, event);
|
eventHandler.subscribe(TikTokPollEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onFollow(EventConsumer<TikTokFollowEvent> event) {
|
public TikTokLiveClientBuilder onFollow(EventConsumer<TikTokFollowEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokFollowEvent.class, event);
|
eventHandler.subscribe(TikTokFollowEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onComment(EventConsumer<TikTokCommentEvent> event) {
|
public TikTokLiveClientBuilder onComment(EventConsumer<TikTokCommentEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokCommentEvent.class, event);
|
eventHandler.subscribe(TikTokCommentEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LiveClientBuilder onHttpResponse(EventConsumer<TikTokHttpResponseEvent> action) {
|
public LiveClientBuilder onHttpResponse(EventConsumer<TikTokHttpResponseEvent> action) {
|
||||||
tikTokEventHandler.subscribe(TikTokHttpResponseEvent.class, action);
|
eventHandler.subscribe(TikTokHttpResponseEvent.class, action);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onGoalUpdate(EventConsumer<TikTokGoalUpdateEvent> event) {
|
public TikTokLiveClientBuilder onGoalUpdate(EventConsumer<TikTokGoalUpdateEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokGoalUpdateEvent.class, event);
|
eventHandler.subscribe(TikTokGoalUpdateEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onRankUpdate(EventConsumer<TikTokRankUpdateEvent> event) {
|
public TikTokLiveClientBuilder onRankUpdate(EventConsumer<TikTokRankUpdateEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokRankUpdateEvent.class, event);
|
eventHandler.subscribe(TikTokRankUpdateEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onIMDelete(EventConsumer<TikTokIMDeleteEvent> event) {
|
public TikTokLiveClientBuilder onIMDelete(EventConsumer<TikTokIMDeleteEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokIMDeleteEvent.class, event);
|
eventHandler.subscribe(TikTokIMDeleteEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLiveEnded(EventConsumer<TikTokLiveEndedEvent> event) {
|
public TikTokLiveClientBuilder onLiveEnded(EventConsumer<TikTokLiveEndedEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokLiveEndedEvent.class, event);
|
eventHandler.subscribe(TikTokLiveEndedEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onError(EventConsumer<TikTokErrorEvent> event) {
|
public TikTokLiveClientBuilder onError(EventConsumer<TikTokErrorEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokErrorEvent.class, event);
|
eventHandler.subscribe(TikTokErrorEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onJoin(EventConsumer<TikTokJoinEvent> event) {
|
public TikTokLiveClientBuilder onJoin(EventConsumer<TikTokJoinEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokJoinEvent.class, event);
|
eventHandler.subscribe(TikTokJoinEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onRankText(EventConsumer<TikTokRankTextEvent> event) {
|
public TikTokLiveClientBuilder onRankText(EventConsumer<TikTokRankTextEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokRankTextEvent.class, event);
|
eventHandler.subscribe(TikTokRankTextEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onShare(EventConsumer<TikTokShareEvent> event) {
|
public TikTokLiveClientBuilder onShare(EventConsumer<TikTokShareEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokShareEvent.class, event);
|
eventHandler.subscribe(TikTokShareEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onUnhandledMember(EventConsumer<TikTokUnhandledMemberEvent> event) {
|
public TikTokLiveClientBuilder onUnhandledMember(EventConsumer<TikTokUnhandledMemberEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokUnhandledMemberEvent.class, event);
|
eventHandler.subscribe(TikTokUnhandledMemberEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onSubNotify(EventConsumer<TikTokSubNotifyEvent> event) {
|
public TikTokLiveClientBuilder onSubNotify(EventConsumer<TikTokSubNotifyEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokSubNotifyEvent.class, event);
|
eventHandler.subscribe(TikTokSubNotifyEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkMicBattle(EventConsumer<TikTokLinkMicBattleEvent> event) {
|
public TikTokLiveClientBuilder onLinkMicBattle(EventConsumer<TikTokLinkMicBattleEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokLinkMicBattleEvent.class, event);
|
eventHandler.subscribe(TikTokLinkMicBattleEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onDisconnected(EventConsumer<TikTokDisconnectedEvent> event) {
|
public TikTokLiveClientBuilder onDisconnected(EventConsumer<TikTokDisconnectedEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokDisconnectedEvent.class, event);
|
eventHandler.subscribe(TikTokDisconnectedEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onUnhandledControl(EventConsumer<TikTokUnhandledControlEvent> event) {
|
public TikTokLiveClientBuilder onUnhandledControl(EventConsumer<TikTokUnhandledControlEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokUnhandledControlEvent.class, event);
|
eventHandler.subscribe(TikTokUnhandledControlEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onEvent(EventConsumer<TikTokEvent> event) {
|
public TikTokLiveClientBuilder onEvent(EventConsumer<TikTokEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokEvent.class, event);
|
eventHandler.subscribe(TikTokEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TikTokLiveClientBuilder onWebsocketResponse(EventConsumer<TikTokWebsocketResponseEvent> event) {
|
public TikTokLiveClientBuilder onWebsocketResponse(EventConsumer<TikTokWebsocketResponseEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokWebsocketResponseEvent.class, event);
|
eventHandler.subscribe(TikTokWebsocketResponseEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TikTokLiveClientBuilder onWebsocketMessage(EventConsumer<TikTokWebsocketMessageEvent> event) {
|
public TikTokLiveClientBuilder onWebsocketMessage(EventConsumer<TikTokWebsocketMessageEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokWebsocketMessageEvent.class, event);
|
eventHandler.subscribe(TikTokWebsocketMessageEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TikTokLiveClientBuilder onWebsocketUnhandledMessage(EventConsumer<TikTokWebsocketUnhandledMessageEvent> event) {
|
public TikTokLiveClientBuilder onWebsocketUnhandledMessage(EventConsumer<TikTokWebsocketUnhandledMessageEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokWebsocketUnhandledMessageEvent.class, event);
|
eventHandler.subscribe(TikTokWebsocketUnhandledMessageEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TikTokLiveClientBuilder onReconnecting(EventConsumer<TikTokReconnectingEvent> event) {
|
public TikTokLiveClientBuilder onReconnecting(EventConsumer<TikTokReconnectingEvent> event) {
|
||||||
tikTokEventHandler.subscribe(TikTokReconnectingEvent.class, event);
|
eventHandler.subscribe(TikTokReconnectingEvent.class, event);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,6 +43,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
private static final String TIKTOK_URL_WEB = "https://www.tiktok.com/";
|
private static final String TIKTOK_URL_WEB = "https://www.tiktok.com/";
|
||||||
private static final String TIKTOK_URL_WEBCAST = "https://webcast.tiktok.com/webcast/";
|
private static final String TIKTOK_URL_WEBCAST = "https://webcast.tiktok.com/webcast/";
|
||||||
public static final String TIKTOK_GIFTS_URL = "https://raw.githubusercontent.com/TikTok-LIVE-Private/GiftsGenerator/master/page/public/gifts.json";
|
public static final String TIKTOK_GIFTS_URL = "https://raw.githubusercontent.com/TikTok-LIVE-Private/GiftsGenerator/master/page/public/gifts.json";
|
||||||
|
public static final String TIKTOK_ROOM_GIFTS_URL = TIKTOK_URL_WEBCAST+"gift/list/";
|
||||||
public static final int TIKTOK_AGE_RESTRICTED_CODE = 4003110;
|
public static final int TIKTOK_AGE_RESTRICTED_CODE = 4003110;
|
||||||
|
|
||||||
private final HttpClientFactory httpFactory;
|
private final HttpClientFactory httpFactory;
|
||||||
@@ -55,7 +56,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
public TikTokLiveHttpClient(HttpClientFactory factory, LiveClientSettings settings) {
|
public TikTokLiveHttpClient(HttpClientFactory factory, LiveClientSettings settings) {
|
||||||
this.httpFactory = factory;
|
this.httpFactory = factory;
|
||||||
this.clientSettings = settings;
|
this.clientSettings = settings;
|
||||||
this.logger = LoggerFactory.create("HttpClient", clientSettings);
|
this.logger = LoggerFactory.create("HttpClient-"+hashCode(), clientSettings);
|
||||||
liveUserDataMapper = new LiveUserDataMapper();
|
liveUserDataMapper = new LiveUserDataMapper();
|
||||||
liveDataMapper = new LiveDataMapper();
|
liveDataMapper = new LiveDataMapper();
|
||||||
giftsDataMapper = new GiftsDataMapper();
|
giftsDataMapper = new GiftsDataMapper();
|
||||||
@@ -65,6 +66,31 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
this(new HttpClientFactory(LiveClientSettings.createDefault()), LiveClientSettings.createDefault());
|
this(new HttpClientFactory(LiveClientSettings.createDefault()), LiveClientSettings.createDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GiftsData.Response fetchRoomGiftsData(String room_id) {
|
||||||
|
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
||||||
|
if (proxyClientSettings.isEnabled()) {
|
||||||
|
while (proxyClientSettings.hasNext()) {
|
||||||
|
try {
|
||||||
|
return getRoomGiftsData(room_id);
|
||||||
|
} catch (TikTokProxyRequestException ignored) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getRoomGiftsData(room_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GiftsData.Response getRoomGiftsData(String room_id) {
|
||||||
|
var result = httpFactory.client(TIKTOK_ROOM_GIFTS_URL)
|
||||||
|
.withParam("room_id", room_id)
|
||||||
|
.build()
|
||||||
|
.toJsonResponse();
|
||||||
|
|
||||||
|
if (result.isFailure())
|
||||||
|
throw new TikTokLiveRequestException("Unable to fetch gifts information's - "+result);
|
||||||
|
|
||||||
|
var json = result.getContent();
|
||||||
|
return giftsDataMapper.mapRoom(json);
|
||||||
|
}
|
||||||
|
|
||||||
public GiftsData.Response fetchGiftsData() {
|
public GiftsData.Response fetchGiftsData() {
|
||||||
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
||||||
if (proxyClientSettings.isEnabled()) {
|
if (proxyClientSettings.isEnabled()) {
|
||||||
@@ -83,7 +109,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
.toJsonResponse();
|
.toJsonResponse();
|
||||||
|
|
||||||
if (result.isFailure())
|
if (result.isFailure())
|
||||||
throw new TikTokLiveRequestException("Unable to fetch gifts information's"+result.toStack());
|
throw new TikTokLiveRequestException("Unable to fetch gifts information's - "+result);
|
||||||
|
|
||||||
var json = result.getContent();
|
var json = result.getContent();
|
||||||
return giftsDataMapper.map(json);
|
return giftsDataMapper.map(json);
|
||||||
@@ -111,10 +137,10 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
.toJsonResponse();
|
.toJsonResponse();
|
||||||
|
|
||||||
if (result.isFailure())
|
if (result.isFailure())
|
||||||
throw new TikTokLiveRequestException("Unable to get information's about user"+result.toStack());
|
throw new TikTokLiveRequestException("Unable to get information's about user - "+result);
|
||||||
|
|
||||||
var json = result.getContent();
|
var json = result.getContent();
|
||||||
return liveUserDataMapper.map(json);
|
return liveUserDataMapper.map(json, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -138,7 +164,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
.toJsonResponse();
|
.toJsonResponse();
|
||||||
|
|
||||||
if (result.isFailure())
|
if (result.isFailure())
|
||||||
throw new TikTokLiveRequestException("Unable to get info about live room"+result.toStack());
|
throw new TikTokLiveRequestException("Unable to get info about live room - "+result);
|
||||||
|
|
||||||
var json = result.getContent();
|
var json = result.getContent();
|
||||||
return liveDataMapper.map(json);
|
return liveDataMapper.map(json);
|
||||||
@@ -152,8 +178,8 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
try {
|
try {
|
||||||
var resultHeader = ActionResult.of(credentialsResponse.headers().firstValue("x-set-tt-cookie"));
|
var resultHeader = ActionResult.of(credentialsResponse.headers().firstValue("x-set-tt-cookie"));
|
||||||
if (resultHeader.isFailure()) {
|
if (resultHeader.isFailure()) {
|
||||||
logger.warning("SignServer Headers: "+request.getRoomId()+" - "+credentialsResponse.headers().map());
|
logger.warning("Sign Server Headers: "+request.getRoomId()+" - "+credentialsResponse.headers().map());
|
||||||
throw new TikTokSignServerException("Sign server did not return the x-set-tt-cookie header"+result.toStack());
|
throw new TikTokSignServerException("Sign server did not return the x-set-tt-cookie header - "+result);
|
||||||
}
|
}
|
||||||
var websocketCookie = resultHeader.getContent();
|
var websocketCookie = resultHeader.getContent();
|
||||||
var webcastResponse = WebcastResponse.parseFrom(credentialsResponse.body());
|
var webcastResponse = WebcastResponse.parseFrom(credentialsResponse.body());
|
||||||
@@ -169,7 +195,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
|
|
||||||
return new LiveConnectionData.Response(websocketCookie, webSocketUrl, webcastResponse);
|
return new LiveConnectionData.Response(websocketCookie, webSocketUrl, webcastResponse);
|
||||||
} catch (InvalidProtocolBufferException e) {
|
} catch (InvalidProtocolBufferException e) {
|
||||||
throw new TikTokSignServerException("Unable to parse websocket credentials response to WebcastResponse"+result.toStack());
|
throw new TikTokSignServerException("Unable to parse websocket credentials response to WebcastResponse - "+result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +223,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
var result = builder.build().toResponse();
|
var result = builder.build().toResponse();
|
||||||
|
|
||||||
if (result.isFailure())
|
if (result.isFailure())
|
||||||
throw new TikTokSignServerException("Unable to get websocket connection credentials"+result.toStack());
|
throw new TikTokSignServerException("Unable to get websocket connection credentials - "+result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.requests.GiftsData;
|
||||||
|
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.http.LiveHttpClient;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TikTokLiveHttpOfflineClient implements LiveHttpClient {
|
||||||
|
@Override
|
||||||
|
public GiftsData.Response fetchGiftsData() {
|
||||||
|
return new GiftsData.Response("", List.of());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GiftsData.Response fetchRoomGiftsData(String room_id) {
|
||||||
|
return new GiftsData.Response("", List.of());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiveUserData.Response fetchLiveUserData(LiveUserData.Request request) {
|
||||||
|
return new LiveUserData.Response("", LiveUserData.UserStatus.Live, "offline_room_id", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiveData.Response fetchLiveData(LiveData.Request request) {
|
||||||
|
return new LiveData.Response("",
|
||||||
|
LiveData.LiveStatus.HostOnline,
|
||||||
|
"offline live",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
false,
|
||||||
|
new User(0L, "offline user", new Picture("")),
|
||||||
|
LiveData.LiveType.SOLO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiveConnectionData.Response fetchLiveConnectionData(LiveConnectionData.Request request) {
|
||||||
|
return new LiveConnectionData.Response("",
|
||||||
|
URI.create("https://example.live"),
|
||||||
|
WebcastResponse.newBuilder().build());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -61,11 +61,6 @@ public class TikTokRoomInfo implements LiveRoomInfo {
|
|||||||
return connectionState == state;
|
return connectionState == state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public User getHostUser() {
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateRanking(List<RankingUser> rankingUsers) {
|
public void updateRanking(List<RankingUser> rankingUsers) {
|
||||||
usersRanking.clear();
|
usersRanking.clear();
|
||||||
usersRanking.addAll(rankingUsers);
|
usersRanking.addAll(rankingUsers);
|
||||||
|
|||||||
@@ -1,16 +1,27 @@
|
|||||||
package io.github.jwdeveloper.tiktok.common;
|
package io.github.jwdeveloper.tiktok.common;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.http.mappers.*;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.net.http.*;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ActionResult<T> {
|
public class ActionResult<T> {
|
||||||
|
|
||||||
|
private static final Gson gson = new Gson().newBuilder().disableHtmlEscaping()
|
||||||
|
.registerTypeHierarchyAdapter(HttpResponse.class, new HttpResponseJsonMapper())
|
||||||
|
.registerTypeHierarchyAdapter(HttpRequest.class, new HttpRequestJsonMapper())
|
||||||
|
.setPrettyPrinting().create();
|
||||||
|
|
||||||
private boolean success = true;
|
private boolean success = true;
|
||||||
private T content;
|
|
||||||
private String message;
|
private String message;
|
||||||
|
private T content;
|
||||||
|
@Accessors(chain = true, fluent = true)
|
||||||
|
private ActionResult<?> previous;
|
||||||
|
|
||||||
protected ActionResult(T object) {
|
protected ActionResult(T object) {
|
||||||
this.content = object;
|
this.content = object;
|
||||||
@@ -41,8 +52,9 @@ public class ActionResult<T> {
|
|||||||
public boolean hasMessage() {
|
public boolean hasMessage() {
|
||||||
return message != null;
|
return message != null;
|
||||||
}
|
}
|
||||||
public String toStack() {
|
|
||||||
return hasMessage() ? " - "+message : "";
|
public boolean hasPrevious() {
|
||||||
|
return previous != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasContent() {
|
public boolean hasContent() {
|
||||||
@@ -84,4 +96,18 @@ public class ActionResult<T> {
|
|||||||
public static <T> ActionResult<T> failure() {
|
public static <T> ActionResult<T> failure() {
|
||||||
return failure(null);
|
return failure(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JsonObject toJson() {
|
||||||
|
JsonObject map = new JsonObject();
|
||||||
|
map.addProperty("success", success);
|
||||||
|
map.addProperty("message", message);
|
||||||
|
map.add("content", gson.toJsonTree(content));
|
||||||
|
map.add("previous", hasPrevious() ? previous.toJson() : null);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ActionResult: "+gson.toJson(toJson());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
package io.github.jwdeveloper.tiktok.common;
|
package io.github.jwdeveloper.tiktok.common;
|
||||||
|
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -7,6 +10,8 @@ public class ActionResultBuilder<T>
|
|||||||
{
|
{
|
||||||
private final T content;
|
private final T content;
|
||||||
private String message;
|
private String message;
|
||||||
|
@Setter @Accessors(fluent = true, chain = true)
|
||||||
|
private ActionResult<?> previous;
|
||||||
|
|
||||||
public ActionResultBuilder(T content) {
|
public ActionResultBuilder(T content) {
|
||||||
this.content = content;
|
this.content = content;
|
||||||
@@ -18,10 +23,10 @@ public class ActionResultBuilder<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult<T> success() {
|
public ActionResult<T> success() {
|
||||||
return ActionResult.success(content, message);
|
return ActionResult.success(content, message).previous(previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult<T> failure() {
|
public ActionResult<T> failure() {
|
||||||
return ActionResult.success(content, message);
|
return ActionResult.success(content, message).previous(previous);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,10 @@
|
|||||||
package io.github.jwdeveloper.tiktok.gifts;
|
package io.github.jwdeveloper.tiktok.gifts;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
|
||||||
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.function.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TikTokGiftsManager implements GiftsManager {
|
public class TikTokGiftsManager implements GiftsManager {
|
||||||
@@ -16,7 +12,7 @@ public class TikTokGiftsManager implements GiftsManager {
|
|||||||
|
|
||||||
public TikTokGiftsManager(List<Gift> giftList)
|
public TikTokGiftsManager(List<Gift> giftList)
|
||||||
{
|
{
|
||||||
giftsByIdIndex = giftList.stream().collect(Collectors.toConcurrentMap(Gift::getId, e -> e));
|
giftsByIdIndex = giftList.stream().collect(Collectors.toConcurrentMap(Gift::getId, Function.identity()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void attachGift(Gift gift) {
|
public void attachGift(Gift gift) {
|
||||||
@@ -32,11 +28,7 @@ public class TikTokGiftsManager implements GiftsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Gift getById(int giftId) {
|
public Gift getById(int giftId) {
|
||||||
if (!giftsByIdIndex.containsKey(giftId)) {
|
return giftsByIdIndex.getOrDefault(giftId, Gift.UNDEFINED);
|
||||||
return Gift.UNDEFINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return giftsByIdIndex.get(giftId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gift getByFilter(Predicate<Gift> filter) {
|
public Gift getByFilter(Predicate<Gift> filter) {
|
||||||
@@ -44,7 +36,7 @@ public class TikTokGiftsManager implements GiftsManager {
|
|||||||
.stream()
|
.stream()
|
||||||
.filter(filter)
|
.filter(filter)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseGet(() -> Gift.UNDEFINED);
|
.orElse(Gift.UNDEFINED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.net.http.*;
|
import java.net.http.*;
|
||||||
import java.nio.charset.*;
|
import java.nio.charset.*;
|
||||||
|
import java.time.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -47,7 +48,21 @@ public class HttpClient {
|
|||||||
try {
|
try {
|
||||||
var response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
|
var response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
|
||||||
var result = ActionResult.of(response);
|
var result = ActionResult.of(response);
|
||||||
return response.statusCode() != 200 ? result.message("HttpResponse Code: ", response.statusCode()).failure() : result.success();
|
return switch (response.statusCode()) {
|
||||||
|
case 420 -> result.message("HttpResponse Code:", response.statusCode(), "| IP Cloudflare Blocked.").failure();
|
||||||
|
case 429 -> {
|
||||||
|
var wait = response.headers().firstValue("ratelimit-reset");
|
||||||
|
if (wait.isEmpty())
|
||||||
|
yield result.message("HttpResponse Code:", response.statusCode(), "| Sign server rate limit reached. Try again later.").failure();
|
||||||
|
Duration duration = Duration.ofSeconds(Long.parseLong(wait.get()));
|
||||||
|
yield result.message("HttpResponse Code:", response.statusCode(),
|
||||||
|
String.format("| Sign server rate limit reached. Try again in %02d:%02d.", duration.toMinutesPart(), duration.toSecondsPart())).failure();
|
||||||
|
}
|
||||||
|
case 500, 501, 502, 503 -> result.message("HttpResponse Code:", response.statusCode(), "| Sign server Error. Try again later.").failure();
|
||||||
|
case 504 -> result.message("HttpResponse Code:", response.statusCode(), "| Sign server Timeout. Try again later.").failure();
|
||||||
|
case 200 -> result.success();
|
||||||
|
default -> result.message("HttpResponse Code:", response.statusCode()).failure();
|
||||||
|
};
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new TikTokLiveRequestException(e);
|
throw new TikTokLiveRequestException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
socksConnection.setSSLSocketFactory(sc.getSocketFactory());
|
socksConnection.setSSLSocketFactory(sc.getSocketFactory());
|
||||||
socksConnection.setConnectTimeout(httpClientSettings.getTimeout().toMillisPart());
|
socksConnection.setConnectTimeout(httpClientSettings.getTimeout().toMillisPart());
|
||||||
socksConnection.setReadTimeout(httpClientSettings.getTimeout().toMillisPart());
|
socksConnection.setReadTimeout(httpClientSettings.getTimeout().toMillisPart());
|
||||||
|
httpClientSettings.getHeaders().forEach(socksConnection::setRequestProperty);
|
||||||
|
|
||||||
byte[] body = socksConnection.getInputStream().readAllBytes();
|
byte[] body = socksConnection.getInputStream().readAllBytes();
|
||||||
|
|
||||||
|
|||||||
@@ -22,15 +22,15 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.http.mappers;
|
package io.github.jwdeveloper.tiktok.http.mappers;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.*;
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.GiftsData;
|
import io.github.jwdeveloper.tiktok.data.requests.GiftsData;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
|
||||||
public class GiftsDataMapper {
|
public class GiftsDataMapper {
|
||||||
|
|
||||||
public GiftsData.Response map(String json) {
|
public GiftsData.Response map(String json) {
|
||||||
var parsedJson = JsonParser.parseString(json);
|
var parsedJson = JsonParser.parseString(json);
|
||||||
var jsonObject = parsedJson.getAsJsonObject();
|
var jsonObject = parsedJson.getAsJsonObject();
|
||||||
@@ -42,7 +42,6 @@ public class GiftsDataMapper {
|
|||||||
return new GiftsData.Response(json, gifts);
|
return new GiftsData.Response(json, gifts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Gift mapSingleGift(JsonElement jsonElement) {
|
private Gift mapSingleGift(JsonElement jsonElement) {
|
||||||
var jsonObject = jsonElement.getAsJsonObject();
|
var jsonObject = jsonElement.getAsJsonObject();
|
||||||
|
|
||||||
@@ -52,4 +51,34 @@ public class GiftsDataMapper {
|
|||||||
var image = jsonObject.get("image").getAsString();
|
var image = jsonObject.get("image").getAsString();
|
||||||
return new Gift(id, name, diamondCost, new Picture(image), jsonObject);
|
return new Gift(id, name, diamondCost, new Picture(image), jsonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GiftsData.Response mapRoom(String json) {
|
||||||
|
var parsedJson = JsonParser.parseString(json);
|
||||||
|
var jsonObject = parsedJson.getAsJsonObject();
|
||||||
|
if (jsonObject.get("data") instanceof JsonObject data && data.get("gifts") instanceof JsonArray giftArray) {
|
||||||
|
var gifts = giftArray.asList().parallelStream()
|
||||||
|
.map(this::mapSingleRoomGift)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return new GiftsData.Response(json, gifts);
|
||||||
|
}
|
||||||
|
return new GiftsData.Response("", List.of());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Gift mapSingleRoomGift(JsonElement jsonElement) {
|
||||||
|
var jsonObject = jsonElement.getAsJsonObject();
|
||||||
|
|
||||||
|
var id = jsonObject.get("id").getAsInt();
|
||||||
|
var name = jsonObject.get("name").getAsString();
|
||||||
|
var diamondCost = jsonObject.get("diamond_count").getAsInt();
|
||||||
|
Picture picture;
|
||||||
|
if (jsonObject.get("image") instanceof JsonObject image && image.get("url_list") instanceof JsonArray urls && !urls.isEmpty()) {
|
||||||
|
String url = urls.get(0).getAsString();
|
||||||
|
if (url.endsWith(".webp"))
|
||||||
|
url = url.substring(0, url.length()-4)+"png";
|
||||||
|
picture = new Picture(url);
|
||||||
|
} else
|
||||||
|
picture = Picture.empty();
|
||||||
|
return new Gift(id, name, diamondCost, picture, jsonObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.http.mappers;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
|
||||||
|
public class HttpRequestJsonMapper implements JsonSerializer<HttpRequest>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(HttpRequest src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
|
JsonObject object = new JsonObject();
|
||||||
|
object.addProperty("method", src.method());
|
||||||
|
object.add("timeout", context.serialize(src.timeout().toString()));
|
||||||
|
object.addProperty("expectContinue", src.expectContinue());
|
||||||
|
object.add("uri", context.serialize(src.uri()));
|
||||||
|
object.add("version", context.serialize(src.version().toString()));
|
||||||
|
object.add("headers", context.serialize(src.headers().map()));
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.http.mappers;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
|
||||||
|
public class HttpResponseJsonMapper implements JsonSerializer<HttpResponse>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(HttpResponse src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
|
JsonObject object = new JsonObject();
|
||||||
|
object.addProperty("statusCode", src.statusCode());
|
||||||
|
object.add("request", context.serialize(src.request()));
|
||||||
|
object.add("headers", context.serialize(src.headers().map()));
|
||||||
|
object.add("body", context.serialize(src.body()));
|
||||||
|
object.add("uri", context.serialize(src.uri().toString()));
|
||||||
|
object.add("version", context.serialize(src.version().toString()));
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,8 +65,7 @@ public class LiveDataMapper {
|
|||||||
default -> LiveData.LiveStatus.HostNotFound;
|
default -> LiveData.LiveStatus.HostNotFound;
|
||||||
};
|
};
|
||||||
response.setLiveStatus(statusValue);
|
response.setLiveStatus(statusValue);
|
||||||
} else if (data.has("prompts") && jsonObject.has("status_code") &&
|
} else if (data.has("prompts") && data.get("prompts").getAsString().isEmpty() && jsonObject.has("status_code")) {
|
||||||
data.get("prompts").getAsString().isEmpty() && jsonObject.get("status_code").isJsonPrimitive()) {
|
|
||||||
response.setAgeRestricted(jsonObject.get("status_code").getAsInt() == TikTokLiveHttpClient.TIKTOK_AGE_RESTRICTED_CODE);
|
response.setAgeRestricted(jsonObject.get("status_code").getAsInt() == TikTokLiveHttpClient.TIKTOK_AGE_RESTRICTED_CODE);
|
||||||
} else {
|
} else {
|
||||||
response.setLiveStatus(LiveData.LiveStatus.HostNotFound);
|
response.setLiveStatus(LiveData.LiveStatus.HostNotFound);
|
||||||
|
|||||||
@@ -22,45 +22,52 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.http.mappers;
|
package io.github.jwdeveloper.tiktok.http.mappers;
|
||||||
|
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.LiveUserData;
|
import io.github.jwdeveloper.tiktok.data.requests.LiveUserData;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class LiveUserDataMapper
|
public class LiveUserDataMapper
|
||||||
{
|
{
|
||||||
public LiveUserData.Response map(String json) {
|
public LiveUserData.Response map(String json, Logger logger) {
|
||||||
var jsonObject = JsonParser.parseString(json).getAsJsonObject();
|
try {
|
||||||
|
var jsonObject = JsonParser.parseString(json).getAsJsonObject();
|
||||||
|
|
||||||
var message = jsonObject.get("message").getAsString();
|
var message = jsonObject.get("message").getAsString();
|
||||||
|
|
||||||
if (message.equals("params_error")) {
|
if (message.equals("params_error")) {
|
||||||
throw new TikTokLiveRequestException("fetchRoomIdFromTiktokApi -> Unable to fetch roomID, contact the developer");
|
throw new TikTokLiveRequestException("fetchRoomIdFromTiktokApi -> Unable to fetch roomID, contact the developer");
|
||||||
}
|
}
|
||||||
if (message.equals("user_not_found")) {
|
if (message.equals("user_not_found")) {
|
||||||
|
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1);
|
||||||
|
}
|
||||||
|
//live -> status 2
|
||||||
|
//live paused -> 3
|
||||||
|
//not live -> status 4
|
||||||
|
var element = jsonObject.get("data");
|
||||||
|
if (element.isJsonNull()) {
|
||||||
|
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1);
|
||||||
|
}
|
||||||
|
var data = element.getAsJsonObject();
|
||||||
|
var user = data.getAsJsonObject("user");
|
||||||
|
var roomId = user.get("roomId").getAsString();
|
||||||
|
var status = user.get("status").getAsInt();
|
||||||
|
|
||||||
|
var liveRoom = data.getAsJsonObject("liveRoom");
|
||||||
|
long startTime = liveRoom.get("startTime").getAsLong();
|
||||||
|
|
||||||
|
var statusEnum = switch (status) {
|
||||||
|
case 2 -> LiveUserData.UserStatus.Live;
|
||||||
|
case 3 -> LiveUserData.UserStatus.LivePaused;
|
||||||
|
case 4 -> LiveUserData.UserStatus.Offline;
|
||||||
|
default -> LiveUserData.UserStatus.NotFound;
|
||||||
|
};
|
||||||
|
|
||||||
|
return new LiveUserData.Response(json, statusEnum, roomId, startTime);
|
||||||
|
} catch (JsonSyntaxException | IllegalStateException e) {
|
||||||
|
logger.warning("Malformed Json: '"+json+"' - Error Message: "+e.getMessage());
|
||||||
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1);
|
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1);
|
||||||
}
|
}
|
||||||
//live -> status 2
|
|
||||||
//live paused -> 3
|
|
||||||
//not live -> status 4
|
|
||||||
var element = jsonObject.get("data");
|
|
||||||
if (element.isJsonNull()) {
|
|
||||||
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1);
|
|
||||||
}
|
|
||||||
var data = element.getAsJsonObject();
|
|
||||||
var user = data.getAsJsonObject("user");
|
|
||||||
var roomId = user.get("roomId").getAsString();
|
|
||||||
var status = user.get("status").getAsInt();
|
|
||||||
|
|
||||||
var liveRoom = data.getAsJsonObject("liveRoom");
|
|
||||||
long startTime = liveRoom.get("startTime").getAsLong();
|
|
||||||
|
|
||||||
var statusEnum = switch (status) {
|
|
||||||
case 2 -> LiveUserData.UserStatus.Live;
|
|
||||||
case 3 -> LiveUserData.UserStatus.LivePaused;
|
|
||||||
case 4 -> LiveUserData.UserStatus.Offline;
|
|
||||||
default -> LiveUserData.UserStatus.NotFound;
|
|
||||||
};
|
|
||||||
|
|
||||||
return new LiveUserData.Response(json, statusEnum, roomId, startTime);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,16 +96,17 @@ public class TikTokListenersManager implements ListenersManager {
|
|||||||
m.isAnnotationPresent(TikTokEventObserver.class)).toList();
|
m.isAnnotationPresent(TikTokEventObserver.class)).toList();
|
||||||
var eventsMap = new HashMap<Class<?>, List<EventConsumer<?>>>();
|
var eventsMap = new HashMap<Class<?>, List<EventConsumer<?>>>();
|
||||||
for (var method : methods) {
|
for (var method : methods) {
|
||||||
var eventClazz = method.getParameterTypes()[1];
|
var liveclientClass = method.getParameterTypes()[0];
|
||||||
|
var eventClass = method.getParameterTypes()[1];
|
||||||
|
|
||||||
if (eventClazz.isAssignableFrom(LiveClient.class) &&
|
if (!LiveClient.class.isAssignableFrom(liveclientClass) && !liveclientClass.equals(LiveClient.class)) {
|
||||||
!eventClazz.equals(LiveClient.class)) {
|
throw new TikTokEventListenerMethodException("Method " + method.getName() + "() 1st parameter must be instance of " + LiveClient.class.getName()
|
||||||
throw new TikTokEventListenerMethodException("Method " + method.getName() + "() 1nd parameter must instance of " + LiveClient.class.getName());
|
+ " | Invalid parameter class: "+liveclientClass.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventClazz.isAssignableFrom(TikTokEvent.class) &&
|
if (!TikTokEvent.class.isAssignableFrom(eventClass) && !eventClass.equals(TikTokEvent.class)) {
|
||||||
!eventClazz.equals(TikTokEvent.class)) {
|
throw new TikTokEventListenerMethodException("Method " + method.getName() + "() 2nd parameter must be instance of " + TikTokEvent.class.getName()
|
||||||
throw new TikTokEventListenerMethodException("Method " + method.getName() + "() 2nd parameter must instance of " + TikTokEvent.class.getName());
|
+ " | Invalid parameter class: "+eventClass.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
EventConsumer eventMethodRef = (liveClient, event) ->
|
EventConsumer eventMethodRef = (liveClient, event) ->
|
||||||
@@ -117,7 +118,7 @@ public class TikTokListenersManager implements ListenersManager {
|
|||||||
throw new TikTokEventListenerMethodException(e);
|
throw new TikTokEventListenerMethodException(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
eventsMap.computeIfAbsent(eventClazz, (a) -> new ArrayList<>()).add(eventMethodRef);
|
eventsMap.computeIfAbsent(eventClass, (a) -> new ArrayList<>()).add(eventMethodRef);
|
||||||
}
|
}
|
||||||
return new ListenerBindingModel(listener, eventsMap);
|
return new ListenerBindingModel(listener, eventsMap);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,13 +27,11 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.gift.*;
|
import io.github.jwdeveloper.tiktok.data.events.gift.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
|
||||||
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.TikTokMapperHelper;
|
import io.github.jwdeveloper.tiktok.mappers.TikTokMapperHelper;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import sun.misc.Unsafe;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -58,40 +56,40 @@ public class TikTokGiftEventHandler {
|
|||||||
|
|
||||||
public List<TikTokEvent> handleGift(WebcastGiftMessage currentMessage) {
|
public List<TikTokEvent> handleGift(WebcastGiftMessage currentMessage) {
|
||||||
var userId = currentMessage.getUser().getId();
|
var userId = currentMessage.getUser().getId();
|
||||||
var currentType = GiftSendType.fromNumber(currentMessage.getSendType());
|
var currentType = GiftComboStateType.fromNumber(currentMessage.getSendType());
|
||||||
var containsPreviousMessage = giftsMessages.containsKey(userId);
|
var containsPreviousMessage = giftsMessages.containsKey(userId);
|
||||||
|
|
||||||
|
|
||||||
//If gift is not streakable just return onGift event
|
//If gift is not streakable just return onGift event
|
||||||
if (currentMessage.getGift().getType() != 1) {
|
if (currentMessage.getGift().getType() != 1) {
|
||||||
var comboEvent = getGiftComboEvent(currentMessage, GiftSendType.Finished);
|
var comboEvent = getGiftComboEvent(currentMessage, GiftComboStateType.Finished);
|
||||||
var giftEvent = getGiftEvent(currentMessage);
|
var giftEvent = getGiftEvent(currentMessage);
|
||||||
return List.of(comboEvent, giftEvent);
|
return List.of(comboEvent, giftEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!containsPreviousMessage) {
|
if (!containsPreviousMessage) {
|
||||||
if (currentType == GiftSendType.Finished) {
|
if (currentType == GiftComboStateType.Finished) {
|
||||||
return List.of(getGiftEvent(currentMessage));
|
return List.of(getGiftEvent(currentMessage));
|
||||||
} else {
|
} else {
|
||||||
giftsMessages.put(userId, currentMessage);
|
giftsMessages.put(userId, currentMessage);
|
||||||
return List.of(getGiftComboEvent(currentMessage, GiftSendType.Begin));
|
return List.of(getGiftComboEvent(currentMessage, GiftComboStateType.Begin));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var previousMessage = giftsMessages.get(userId);
|
var previousMessage = giftsMessages.get(userId);
|
||||||
var previousType = GiftSendType.fromNumber(previousMessage.getSendType());
|
var previousType = GiftComboStateType.fromNumber(previousMessage.getSendType());
|
||||||
if (currentType == GiftSendType.Active &&
|
if (currentType == GiftComboStateType.Active &&
|
||||||
previousType == GiftSendType.Active) {
|
previousType == GiftComboStateType.Active) {
|
||||||
giftsMessages.put(userId, currentMessage);
|
giftsMessages.put(userId, currentMessage);
|
||||||
return List.of(getGiftComboEvent(currentMessage, GiftSendType.Active));
|
return List.of(getGiftComboEvent(currentMessage, GiftComboStateType.Active));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (currentType == GiftSendType.Finished &&
|
if (currentType == GiftComboStateType.Finished &&
|
||||||
previousType == GiftSendType.Active) {
|
previousType == GiftComboStateType.Active) {
|
||||||
giftsMessages.clear();
|
giftsMessages.clear();
|
||||||
return List.of(
|
return List.of(
|
||||||
getGiftComboEvent(currentMessage, GiftSendType.Finished),
|
getGiftComboEvent(currentMessage, GiftComboStateType.Finished),
|
||||||
getGiftEvent(currentMessage));
|
getGiftEvent(currentMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +102,7 @@ public class TikTokGiftEventHandler {
|
|||||||
return new TikTokGiftEvent(gift, tikTokRoomInfo.getHost(), message);
|
return new TikTokGiftEvent(gift, tikTokRoomInfo.getHost(), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TikTokGiftEvent getGiftComboEvent(WebcastGiftMessage message, GiftSendType state) {
|
private TikTokGiftEvent getGiftComboEvent(WebcastGiftMessage message, GiftComboStateType state) {
|
||||||
var gift = getGiftObject(message);
|
var gift = getGiftObject(message);
|
||||||
return new TikTokGiftComboEvent(gift, tikTokRoomInfo.getHost(), message, state);
|
return new TikTokGiftComboEvent(gift, tikTokRoomInfo.getHost(), message, state);
|
||||||
}
|
}
|
||||||
@@ -124,36 +122,8 @@ public class TikTokGiftEventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gift.getPicture().getLink().endsWith(".webp"))
|
if (gift.getPicture().getLink().endsWith(".webp"))
|
||||||
{
|
gift.setPicture(Picture.map(giftMessage.getGift().getImage()));
|
||||||
updatePicture(gift, giftMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
return gift;
|
return gift;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO-kohlerpop1: I do not think this method is needed for any reason?
|
|
||||||
// TODO response:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Some generated gifts in JSON file contains .webp image format,
|
|
||||||
* that's bad since java by the defult is not supporing .webp and when URL is
|
|
||||||
* converted to Java.io.Image then image is null
|
|
||||||
*
|
|
||||||
* However, TikTok in GiftWebcast event always has image in .jpg format,
|
|
||||||
* so I take advantage of it and swap .webp url with .jpg url
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
private void updatePicture(Gift gift, WebcastGiftMessage webcastGiftMessage) {
|
|
||||||
try {
|
|
||||||
var picture = Picture.map(webcastGiftMessage.getGift().getImage());
|
|
||||||
var constructor = Unsafe.class.getDeclaredConstructors()[0];
|
|
||||||
constructor.setAccessible(true);
|
|
||||||
var field = Gift.class.getDeclaredField("picture");
|
|
||||||
field.setAccessible(true);
|
|
||||||
field.set(gift, picture);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new TikTokLiveException("Unable to update picture in gift: " + gift.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ public class TikTokWebSocketClient implements SocketClient {
|
|||||||
|
|
||||||
messageHandler.handle(liveClient, connectionData.getWebcastResponse());
|
messageHandler.handle(liveClient, connectionData.getWebcastResponse());
|
||||||
|
|
||||||
var headers = new HashMap<String, String>();
|
var headers = new HashMap<>(clientSettings.getHttpSettings().getHeaders());
|
||||||
headers.put("Cookie", connectionData.getWebsocketCookies());
|
headers.put("Cookie", connectionData.getWebsocketCookies());
|
||||||
webSocketClient = new TikTokWebSocketListener(connectionData.getWebsocketUrl(),
|
webSocketClient = new TikTokWebSocketListener(connectionData.getWebsocketUrl(),
|
||||||
headers,
|
headers,
|
||||||
@@ -82,7 +82,7 @@ public class TikTokWebSocketClient implements SocketClient {
|
|||||||
private void connectDefault() {
|
private void connectDefault() {
|
||||||
try {
|
try {
|
||||||
webSocketClient.connect();
|
webSocketClient.connect();
|
||||||
pingingTask.run(webSocketClient);
|
pingingTask.run(webSocketClient, clientSettings.getPingInterval());
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
@@ -112,7 +112,7 @@ public class TikTokWebSocketClient implements SocketClient {
|
|||||||
proxySettings.remove();
|
proxySettings.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pingingTask.run(webSocketClient);
|
pingingTask.run(webSocketClient, clientSettings.getPingInterval());
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
tikTokEventHandler.publish(tikTokLiveClient, new TikTokErrorEvent(e));
|
tikTokEventHandler.publish(tikTokLiveClient, new TikTokErrorEvent(e));
|
||||||
}
|
}
|
||||||
if (isNotClosing()) {
|
if (isOpen()) {
|
||||||
sendPing();
|
sendPing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,8 +79,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
pushFrameBuilder.setPayloadType("ack");
|
pushFrameBuilder.setPayloadType("ack");
|
||||||
pushFrameBuilder.setLogId(websocketPushFrame.getLogId());
|
pushFrameBuilder.setLogId(websocketPushFrame.getLogId());
|
||||||
pushFrameBuilder.setPayload(webcastResponse.getInternalExtBytes());
|
pushFrameBuilder.setPayload(webcastResponse.getInternalExtBytes());
|
||||||
if (isNotClosing())
|
if (isOpen()) {
|
||||||
{
|
|
||||||
this.send(pushFrameBuilder.build().toByteArray());
|
this.send(pushFrameBuilder.build().toByteArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,7 +89,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
@Override
|
@Override
|
||||||
public void onOpen(ServerHandshake serverHandshake) {
|
public void onOpen(ServerHandshake serverHandshake) {
|
||||||
tikTokEventHandler.publish(tikTokLiveClient, new TikTokConnectedEvent());
|
tikTokEventHandler.publish(tikTokLiveClient, new TikTokConnectedEvent());
|
||||||
if (isNotClosing()) {
|
if (isOpen()) {
|
||||||
sendPing();
|
sendPing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,7 +103,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
@Override
|
@Override
|
||||||
public void onError(Exception error) {
|
public void onError(Exception error) {
|
||||||
tikTokEventHandler.publish(tikTokLiveClient, new TikTokErrorEvent(error));
|
tikTokEventHandler.publish(tikTokLiveClient, new TikTokErrorEvent(error));
|
||||||
if (isNotClosing()) {
|
if (isOpen()) {
|
||||||
sendPing();
|
sendPing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,10 +128,6 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNotClosing() {
|
|
||||||
return !isClosed() && !isClosing();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(String s) {
|
public void onMessage(String s) {
|
||||||
// System.err.println(s);
|
// System.err.println(s);
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.websocket;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.TikTokLiveEventHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.TikTokConnectedEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.TikTokDisconnectedEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
|
||||||
|
public class TikTokWebSocketOfflineClient implements SocketClient {
|
||||||
|
|
||||||
|
private final TikTokLiveEventHandler handler;
|
||||||
|
private LiveClient liveClient;
|
||||||
|
|
||||||
|
public TikTokWebSocketOfflineClient(TikTokLiveEventHandler handler) {
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient) {
|
||||||
|
liveClient = tikTokLiveClient;
|
||||||
|
handler.publish(liveClient, new TikTokConnectedEvent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() {
|
||||||
|
if (liveClient == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handler.publish(liveClient, new TikTokDisconnectedEvent());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,13 +8,13 @@ public class TikTokWebSocketPingingTask
|
|||||||
{
|
{
|
||||||
private Thread thread;
|
private Thread thread;
|
||||||
private boolean isRunning = false;
|
private boolean isRunning = false;
|
||||||
private final int MIN_TIMEOUT = 250;
|
private final int MAX_TIMEOUT = 250;
|
||||||
private final int MAX_TIMEOUT = 500;
|
private final int SLEEP_TIME = 500;
|
||||||
|
|
||||||
public void run(WebSocket webSocket)
|
public void run(WebSocket webSocket, long pingTaskTime)
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
thread = new Thread(() -> pingTask(webSocket));
|
thread = new Thread(() -> pingTask(webSocket, pingTaskTime));
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
@@ -26,20 +26,18 @@ public class TikTokWebSocketPingingTask
|
|||||||
isRunning = false;
|
isRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void pingTask(WebSocket webSocket, long pingTaskTime)
|
||||||
private void pingTask(WebSocket webSocket)
|
|
||||||
{
|
{
|
||||||
var random = new Random();
|
var random = new Random();
|
||||||
while (isRunning) {
|
while (isRunning) {
|
||||||
try {
|
try {
|
||||||
if (!webSocket.isOpen()) {
|
if (!webSocket.isOpen()) {
|
||||||
Thread.sleep(100);
|
Thread.sleep(SLEEP_TIME);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
webSocket.sendPing();
|
webSocket.sendPing();
|
||||||
|
|
||||||
var timeout = random.nextInt(MAX_TIMEOUT)+MIN_TIMEOUT;
|
Thread.sleep(pingTaskTime+random.nextInt(MAX_TIMEOUT));
|
||||||
Thread.sleep(timeout);
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
|
|||||||
@@ -22,12 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.gifts;
|
package io.github.jwdeveloper.tiktok.gifts;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.GiftOld;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.InjectMocks;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftComboEvent;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftEvent;
|
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.GiftSendType;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.GiftComboStateType;
|
||||||
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftsManager;
|
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftsManager;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokGiftEventHandler;
|
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokGiftEventHandler;
|
||||||
import io.github.jwdeveloper.tiktok.messages.data.GiftStruct;
|
import io.github.jwdeveloper.tiktok.messages.data.GiftStruct;
|
||||||
@@ -40,7 +40,6 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.TestInstance;
|
import org.junit.jupiter.api.TestInstance;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
|
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
@@ -99,9 +98,9 @@ class TikTokGiftEventHandlerTest {
|
|||||||
Assertions.assertEquals(2, result3.size());
|
Assertions.assertEquals(2, result3.size());
|
||||||
var event3 = (TikTokGiftComboEvent) result3.get(0);
|
var event3 = (TikTokGiftComboEvent) result3.get(0);
|
||||||
|
|
||||||
Assertions.assertEquals(GiftSendType.Begin, event1.getComboState());
|
Assertions.assertEquals(GiftComboStateType.Begin, event1.getComboState());
|
||||||
Assertions.assertEquals(GiftSendType.Active, event2.getComboState());
|
Assertions.assertEquals(GiftComboStateType.Active, event2.getComboState());
|
||||||
Assertions.assertEquals(GiftSendType.Finished, event3.getComboState());
|
Assertions.assertEquals(GiftComboStateType.Finished, event3.getComboState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -118,7 +117,7 @@ class TikTokGiftEventHandlerTest {
|
|||||||
|
|
||||||
giftBuilder.setId(giftId);
|
giftBuilder.setId(giftId);
|
||||||
giftBuilder.setName(giftName);
|
giftBuilder.setName(giftName);
|
||||||
giftBuilder.setImage(Image.newBuilder().addUrlList(giftImage).build());
|
giftBuilder.setImage(Image.newBuilder().addUrl(giftImage).build());
|
||||||
giftBuilder.setType(streakable ? 1 : 0);
|
giftBuilder.setType(streakable ? 1 : 0);
|
||||||
userBuilder.setId(userId);
|
userBuilder.setId(userId);
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.3.0-Release</version>
|
<version>1.7.1-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>extension-collector</artifactId>
|
<artifactId>extension-collector</artifactId>
|
||||||
<version>1.3.0-Release</version>
|
<version>1.7.1-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
public class ChatMessageExample {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
|
|
||||||
var roomData = TikTokLive.requests()
|
|
||||||
.fetchLiveData("X");
|
|
||||||
|
|
||||||
var gifts = TikTokLive.requests().fetchGiftsData();
|
|
||||||
|
|
||||||
|
|
||||||
var user = TikTokLive.requests()
|
|
||||||
.fetchLiveUserData("mark");
|
|
||||||
|
|
||||||
TikTokLive.newClient(SimpleExample.TIKTOK_HOSTNAME)
|
|
||||||
.configure(clientSettings ->
|
|
||||||
{
|
|
||||||
clientSettings.setPrintToConsole(true);
|
|
||||||
clientSettings.getHttpSettings().setTimeout(Duration.ofSeconds(21));
|
|
||||||
})
|
|
||||||
.onComment((liveClient, event) ->
|
|
||||||
{
|
|
||||||
System.out.println("Chat message: " + event.getUser().getName() + " " + event.getText());
|
|
||||||
})
|
|
||||||
.onWebsocketUnhandledMessage((liveClient, event) ->
|
|
||||||
{
|
|
||||||
liveClient.getLogger().info(event.getMessage().getMethod());
|
|
||||||
}).buildAndConnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,27 +25,20 @@ package io.github.jwdeveloper.tiktok;
|
|||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.extension.collector.TikTokLiveCollector;
|
import io.github.jwdeveloper.tiktok.extension.collector.TikTokLiveCollector;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class CollectorExample {
|
public class CollectorExample {
|
||||||
|
|
||||||
|
|
||||||
private static String mongoUser;
|
|
||||||
|
|
||||||
private static String mongoPassword;
|
|
||||||
|
|
||||||
private static String mongoDatabase;
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
||||||
var collector = TikTokLiveCollector.use(settings ->
|
var path = "C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\Examples\\src\\main\\resources";
|
||||||
|
var collector = TikTokLiveCollector.useFile(settings ->
|
||||||
{
|
{
|
||||||
settings.setConnectionUrl("mongodb+srv://" + mongoUser + ":" + mongoPassword + "@" + mongoDatabase + "/?retryWrites=true&w=majority");
|
settings.setParentFile(new File(path));
|
||||||
settings.setDatabaseName("tiktok");
|
|
||||||
});
|
});
|
||||||
collector.connectDatabase();
|
collector.connect();
|
||||||
|
|
||||||
var users = List.of("tehila_723", "dino123597", "domaxyzx", "dash4214", "obserwacje_live");
|
var users = List.of("tehila_723", "dino123597", "domaxyzx", "dash4214", "obserwacje_live");
|
||||||
Map<String, Object> additionalDataFields = Map.of("sessionTag", "ExampleTag");
|
Map<String, Object> additionalDataFields = Map.of("sessionTag", "ExampleTag");
|
||||||
@@ -59,18 +52,11 @@ public class CollectorExample {
|
|||||||
{
|
{
|
||||||
event.getException().printStackTrace();
|
event.getException().printStackTrace();
|
||||||
})
|
})
|
||||||
.addListener(collector.newListener(additionalDataFields, document ->
|
.addListener(collector.newListener(additionalDataFields))
|
||||||
{
|
|
||||||
//filtering document data before it is inserted to database
|
|
||||||
if (document.get("dataType") == "message") {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}))
|
|
||||||
.buildAndConnectAsync();
|
.buildAndConnectAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.in.read();
|
System.in.read();
|
||||||
collector.disconnectDatabase();
|
collector.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ import java.io.IOException;
|
|||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class SimpleExample {
|
public class ConnectionExample {
|
||||||
public static String TIKTOK_HOSTNAME = "kvadromama_marina1";
|
public static String TIKTOK_HOSTNAME = "kvadromama_marina1";
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
@@ -40,10 +40,10 @@ public class SimpleExample {
|
|||||||
|
|
||||||
var gifts = TikTokLive.gifts();
|
var gifts = TikTokLive.gifts();
|
||||||
|
|
||||||
TikTokLive.newClient(SimpleExample.TIKTOK_HOSTNAME)
|
TikTokLive.newClient(ConnectionExample.TIKTOK_HOSTNAME)
|
||||||
.configure(clientSettings ->
|
.configure(clientSettings ->
|
||||||
{
|
{
|
||||||
clientSettings.setHostName(SimpleExample.TIKTOK_HOSTNAME); // This method is useful in case you want change hostname later
|
clientSettings.setHostName(ConnectionExample.TIKTOK_HOSTNAME); // This method is useful in case you want change hostname later
|
||||||
clientSettings.setClientLanguage("en"); // Language
|
clientSettings.setClientLanguage("en"); // Language
|
||||||
clientSettings.setLogLevel(Level.ALL); // Log level
|
clientSettings.setLogLevel(Level.ALL); // Log level
|
||||||
clientSettings.setPrintToConsole(true); // Printing all logs to console even if log level is Level.OFF
|
clientSettings.setPrintToConsole(true); // Printing all logs to console even if log level is Level.OFF
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user