mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Compare commits
88 Commits
1.7.0-Rele
...
1.8.8-Rele
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8ac0f6fff | ||
|
|
732eda3d22 | ||
|
|
358954984b | ||
|
|
acb13ea58a | ||
|
|
e8129862d1 | ||
|
|
88e36e7e90 | ||
|
|
eef9d43d01 | ||
|
|
75f3896a86 | ||
|
|
e679ff23b7 | ||
|
|
e6211e69c5 | ||
|
|
1b3ee24aea | ||
|
|
c9309ee2cf | ||
|
|
a28df44cee | ||
|
|
ee866762a3 | ||
|
|
3cb7c83ef4 | ||
|
|
bf755bcb89 | ||
|
|
20bb05e527 | ||
|
|
d5a3213ad8 | ||
|
|
7e496373ef | ||
|
|
1f3c1c7d41 | ||
|
|
c160259863 | ||
|
|
fb458e7e7d | ||
|
|
5f5ada312a | ||
|
|
cb20c3dd3a | ||
|
|
bf42f65b3d | ||
|
|
05e18ef8e0 | ||
|
|
0f6ee58d7f | ||
|
|
511759960d | ||
|
|
617d1c381a | ||
|
|
6f8b4698cd | ||
|
|
2bc1993ea5 | ||
|
|
3d4a517adb | ||
|
|
ee0b559758 | ||
|
|
1c9573dc39 | ||
|
|
5b17c33236 | ||
|
|
b59373254c | ||
|
|
5524d9f8c4 | ||
|
|
aa56f8eaea | ||
|
|
e40bde8e7c | ||
|
|
b769eb9c1f | ||
|
|
3e555a502a | ||
|
|
316868818b | ||
|
|
36475c2cf6 | ||
|
|
2dbe81278c | ||
|
|
91fc32b20b | ||
|
|
fa855fa3aa | ||
|
|
cfea12dacc | ||
|
|
16cd819aaf | ||
|
|
290a4970fd | ||
|
|
660cb287e9 | ||
|
|
f5de7720cd | ||
|
|
f986efd2d5 | ||
|
|
1054453451 | ||
|
|
7005f58edd | ||
|
|
63672fe9eb | ||
|
|
fed9de3fd0 | ||
|
|
b223651a8f | ||
|
|
8d715d4f50 | ||
|
|
1736236ccf | ||
|
|
85d99ce4f1 | ||
|
|
87727070e9 | ||
|
|
71f744cf49 | ||
|
|
046d5f1756 | ||
|
|
c36b0f1f62 | ||
|
|
a2082ebee3 | ||
|
|
412c72c119 | ||
|
|
6728fd9963 | ||
|
|
47493d4955 | ||
|
|
4d4317d96c | ||
|
|
b1954a708c | ||
|
|
14317337e9 | ||
|
|
947c9c49a2 | ||
|
|
f2bd07377b | ||
|
|
3f268f3a1a | ||
|
|
55fcf83870 | ||
|
|
8d3828cca8 | ||
|
|
1c88491b8c | ||
|
|
47b050d0ba | ||
|
|
cfef082d3b | ||
|
|
34ddc74189 | ||
|
|
9a66d240bc | ||
|
|
d825803187 | ||
|
|
77c9cd6b52 | ||
|
|
0329d3cfeb | ||
|
|
26659bb37d | ||
|
|
0b9852c4d4 | ||
|
|
31618a16ba | ||
|
|
243791f6b8 |
2
.github/workflows/maven-publish.yml
vendored
2
.github/workflows/maven-publish.yml
vendored
@@ -53,7 +53,7 @@ jobs:
|
|||||||
restore-keys: ${{runner.os}}-m2
|
restore-keys: ${{runner.os}}-m2
|
||||||
|
|
||||||
- name: 7 Create Artifacts
|
- name: 7 Create Artifacts
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ steps.version.outputs.version_tag }}
|
name: ${{ steps.version.outputs.version_tag }}
|
||||||
path: staging
|
path: staging
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.6.4-Release</version>
|
<version>1.8.7-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.annotations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HIGHEST 1
|
||||||
|
* HIGH 2
|
||||||
|
* NORMAL 3
|
||||||
|
* LOW 4
|
||||||
|
* LOWEST 5
|
||||||
|
*/
|
||||||
|
public enum Priority {
|
||||||
|
LOWEST(2), LOW(1), NORMAL(0), HIGH(-1), HIGHEST(-2);
|
||||||
|
|
||||||
|
public final int value;
|
||||||
|
|
||||||
|
Priority(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,5 +28,14 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface TikTokEventObserver
|
public @interface TikTokEventObserver
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* When more than one method listen for certain Event, you can specify the method priority
|
||||||
|
* @see Priority
|
||||||
|
*/
|
||||||
|
Priority priority() default Priority.NORMAL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When true, action is invoked on a thread, from the threads pool
|
||||||
|
*/
|
||||||
|
boolean async() default false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,16 +50,12 @@ public class ProxyData
|
|||||||
|
|
||||||
return new ProxyData(address, port);
|
return new ProxyData(address, port);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new IllegalArgumentException("Port must be a valid integer!");
|
throw new IllegalArgumentException("Port must be a valid integer!", e);
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
throw new IllegalArgumentException("Address must be valid IPv4, IPv6, or domain name!");
|
throw new IllegalArgumentException("Address must be valid IPv4, IPv6, or domain name!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyData clone() {
|
|
||||||
return new ProxyData(address, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
public InetSocketAddress toSocketAddress() {
|
public InetSocketAddress toSocketAddress() {
|
||||||
return new InetSocketAddress(address, port);
|
return new InetSocketAddress(address, port);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,7 @@ import lombok.Getter;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered every time a new chat comment arrives.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokCommentEvent extends TikTokHeaderEvent {
|
public class TikTokCommentEvent extends TikTokHeaderEvent {
|
||||||
@@ -60,6 +58,7 @@ public class TikTokCommentEvent extends TikTokHeaderEvent {
|
|||||||
var builder = WebcastChatMessage.newBuilder();
|
var builder = WebcastChatMessage.newBuilder();
|
||||||
builder.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
builder.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
.setNickname(userName)
|
.setNickname(userName)
|
||||||
|
.setDisplayId(userName)
|
||||||
.build());
|
.build());
|
||||||
builder.setContentLanguage("en");
|
builder.setContentLanguage("en");
|
||||||
builder.setVisibleToSender(true);
|
builder.setVisibleToSender(true);
|
||||||
|
|||||||
@@ -25,11 +25,13 @@ import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
|||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when the connection is successfully established.
|
|
||||||
*/
|
|
||||||
@EventMeta(eventType = EventType.Control)
|
@EventMeta(eventType = EventType.Control)
|
||||||
public class TikTokConnectedEvent extends TikTokLiveClientEvent
|
public class TikTokConnectedEvent extends TikTokLiveClientEvent
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public static TikTokConnectedEvent of()
|
||||||
|
{
|
||||||
|
return new TikTokConnectedEvent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,7 @@ import io.github.jwdeveloper.tiktok.annotations.EventType;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when the connection gets disconnected. In that case you can call connect() again to have a reconnect logic.
|
|
||||||
* Note that you should wait a little bit before attempting a reconnect to to avoid being rate-limited.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Control)
|
@EventMeta(eventType = EventType.Control)
|
||||||
public class TikTokDisconnectedEvent extends TikTokLiveClientEvent {
|
public class TikTokDisconnectedEvent extends TikTokLiveClientEvent {
|
||||||
@@ -42,4 +39,10 @@ public class TikTokDisconnectedEvent extends TikTokLiveClientEvent {
|
|||||||
public TikTokDisconnectedEvent() {
|
public TikTokDisconnectedEvent() {
|
||||||
this("None");
|
this("None");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static TikTokDisconnectedEvent of(String reason)
|
||||||
|
{
|
||||||
|
return new TikTokDisconnectedEvent(reason);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -25,16 +25,18 @@ package io.github.jwdeveloper.tiktok.data.events;
|
|||||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
|
||||||
* General error event. You should handle this.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EventMeta(eventType = EventType.Control)
|
@EventMeta(eventType = EventType.Control)
|
||||||
public class TikTokErrorEvent extends TikTokLiveClientEvent
|
public class TikTokErrorEvent extends TikTokLiveClientEvent {
|
||||||
{
|
|
||||||
private final Throwable exception;
|
private final Throwable exception;
|
||||||
|
|
||||||
|
|
||||||
|
public static TikTokErrorEvent of(String message) {
|
||||||
|
return new TikTokErrorEvent(new TikTokLiveException(message));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,6 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
|||||||
true if battle is finished otherwise false
|
true if battle is finished otherwise false
|
||||||
*/
|
*/
|
||||||
private final boolean finished;
|
private final boolean finished;
|
||||||
@Getter(AccessLevel.NONE)
|
|
||||||
private final boolean oneVsOne;
|
|
||||||
private final List<Team> teams;
|
private final List<Team> teams;
|
||||||
|
|
||||||
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
||||||
@@ -55,7 +53,6 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
|||||||
if (msg.getHostTeamCount() == 2) { // 1v1 battle
|
if (msg.getHostTeamCount() == 2) { // 1v1 battle
|
||||||
teams.add(new Team1v1(msg.getHostTeam(0), msg));
|
teams.add(new Team1v1(msg.getHostTeam(0), msg));
|
||||||
teams.add(new Team1v1(msg.getHostTeam(1), msg));
|
teams.add(new Team1v1(msg.getHostTeam(1), msg));
|
||||||
oneVsOne = true;
|
|
||||||
} else { // 2v2 battle
|
} else { // 2v2 battle
|
||||||
if (isFinished()) {
|
if (isFinished()) {
|
||||||
teams.add(new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 1).findFirst().orElse(null), msg));
|
teams.add(new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 1).findFirst().orElse(null), msg));
|
||||||
@@ -64,7 +61,6 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
|||||||
teams.add(new Team2v2(msg.getHostTeam(0), msg.getHostTeam(1), msg));
|
teams.add(new Team2v2(msg.getHostTeam(0), msg.getHostTeam(1), msg));
|
||||||
teams.add(new Team2v2(msg.getHostTeam(2), msg.getHostTeam(3), msg));
|
teams.add(new Team2v2(msg.getHostTeam(2), msg.getHostTeam(3), msg));
|
||||||
}
|
}
|
||||||
oneVsOne = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info:
|
// Info:
|
||||||
@@ -74,10 +70,14 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean is1v1() {
|
public boolean is1v1() {
|
||||||
return oneVsOne;
|
return teams.get(0) instanceof Team1v1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean is2v2() {
|
public boolean is2v2() {
|
||||||
return !oneVsOne;
|
return teams.get(0) instanceof Team2v2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTie() {
|
||||||
|
return isFinished() && teams.get(0).getTotalPoints() == teams.get(1).getTotalPoints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,11 +24,14 @@ package io.github.jwdeveloper.tiktok.data.events;
|
|||||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.control.TikTokConnectingEvent;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when the live stream gets terminated by the host. Will also trigger the TikTokDisconnectedEvent event.
|
|
||||||
*/
|
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLiveEndedEvent extends TikTokEvent {
|
public class TikTokLiveEndedEvent extends TikTokEvent {
|
||||||
|
|
||||||
|
|
||||||
|
public static TikTokLiveEndedEvent of() {
|
||||||
|
return new TikTokLiveEndedEvent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,7 @@ import io.github.jwdeveloper.tiktok.data.models.users.User;
|
|||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastQuestionNewMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastQuestionNewMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/*
|
|
||||||
Triggered every time someone asks a new question via the question feature.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokQuestionEvent extends TikTokHeaderEvent {
|
public class TikTokQuestionEvent extends TikTokHeaderEvent {
|
||||||
|
|||||||
@@ -31,9 +31,7 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastMemberMessage;
|
|||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSubNotifyMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSubNotifyMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers when a user creates a subscription.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokSubscribeEvent extends TikTokHeaderEvent {
|
public class TikTokSubscribeEvent extends TikTokHeaderEvent {
|
||||||
@@ -55,6 +53,7 @@ public class TikTokSubscribeEvent extends TikTokHeaderEvent {
|
|||||||
public static TikTokSubscribeEvent of(String userName) {
|
public static TikTokSubscribeEvent of(String userName) {
|
||||||
return new TikTokSubscribeEvent(WebcastMemberMessage.newBuilder()
|
return new TikTokSubscribeEvent(WebcastMemberMessage.newBuilder()
|
||||||
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
|
.setDisplayId(userName)
|
||||||
.setNickname(userName)
|
.setNickname(userName)
|
||||||
.build())
|
.build())
|
||||||
.build());
|
.build());
|
||||||
|
|||||||
@@ -26,9 +26,6 @@ package io.github.jwdeveloper.tiktok.data.events.common;
|
|||||||
import io.github.jwdeveloper.tiktok.utils.JsonUtil;
|
import io.github.jwdeveloper.tiktok.utils.JsonUtil;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class for all events
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
public abstract class TikTokEvent {
|
public abstract class TikTokEvent {
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
|||||||
* Triggered when client is connecting to live is successfully established.
|
* Triggered when client is connecting to live is successfully established.
|
||||||
*/
|
*/
|
||||||
@EventMeta(eventType = EventType.Control)
|
@EventMeta(eventType = EventType.Control)
|
||||||
public class TikTokConnectingEvent extends TikTokLiveClientEvent
|
public class TikTokConnectingEvent extends TikTokLiveClientEvent {
|
||||||
{
|
|
||||||
|
|
||||||
|
public static TikTokConnectingEvent of() {
|
||||||
|
return new TikTokConnectingEvent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,7 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokLiveClientEvent;
|
|||||||
import io.github.jwdeveloper.tiktok.data.requests.*;
|
import io.github.jwdeveloper.tiktok.data.requests.*;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered before the connection is established.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Control)
|
@EventMeta(eventType = EventType.Control)
|
||||||
public class TikTokPreConnectionEvent extends TikTokLiveClientEvent
|
public class TikTokPreConnectionEvent extends TikTokLiveClientEvent
|
||||||
|
|||||||
@@ -29,20 +29,6 @@ import io.github.jwdeveloper.tiktok.data.models.users.User;
|
|||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered every time gift is sent
|
|
||||||
*
|
|
||||||
* @see GiftComboStateType it has 3 states
|
|
||||||
*
|
|
||||||
* <p>Example when user sends gift with combo</p>
|
|
||||||
* <p>>Combo: 1 -> comboState = GiftSendType.Begin</p>
|
|
||||||
* <p>Combo: 4 -> comboState = GiftSendType.Active</p>
|
|
||||||
* <p>Combo: 8 -> comboState = GiftSendType.Active</p>
|
|
||||||
* <p>Combo: 12 -> comboState = GiftSendType.Finsihed</p>
|
|
||||||
* <p>
|
|
||||||
* Remember if comboState is Finsihed both TikTokGiftComboEvent and TikTokGiftEvent event gets triggered
|
|
||||||
*/
|
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
@Getter
|
@Getter
|
||||||
public class TikTokGiftComboEvent extends TikTokGiftEvent {
|
public class TikTokGiftComboEvent extends TikTokGiftEvent {
|
||||||
@@ -55,12 +41,9 @@ public class TikTokGiftComboEvent extends TikTokGiftEvent {
|
|||||||
|
|
||||||
public static TikTokGiftComboEvent of(Gift gift, int combo, GiftComboStateType comboState) {
|
public static TikTokGiftComboEvent of(Gift gift, int combo, GiftComboStateType comboState) {
|
||||||
return new TikTokGiftComboEvent(
|
return new TikTokGiftComboEvent(
|
||||||
gift,
|
gift,
|
||||||
new User(0L, "Test", new Picture("")),
|
new User(0L, "Test", new Picture("")),
|
||||||
WebcastGiftMessage
|
WebcastGiftMessage.newBuilder().setComboCount(combo).build(),
|
||||||
.newBuilder()
|
comboState);
|
||||||
.setComboCount(combo)
|
|
||||||
.build(),
|
|
||||||
comboState);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.events.gift;
|
package io.github.jwdeveloper.tiktok.data.events.gift;
|
||||||
|
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
@@ -31,12 +30,6 @@ import io.github.jwdeveloper.tiktok.data.models.users.User;
|
|||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when user sends gifts that has
|
|
||||||
* no combo (most of expensive gifts)
|
|
||||||
* or if combo has finished
|
|
||||||
*/
|
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
@Getter
|
@Getter
|
||||||
public class TikTokGiftEvent extends TikTokHeaderEvent {
|
public class TikTokGiftEvent extends TikTokHeaderEvent {
|
||||||
|
|||||||
@@ -1,38 +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.data.events.http;
|
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.LiveData;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EventMeta(eventType = EventType.Debug)
|
|
||||||
public class TikTokRoomDataResponseEvent extends TikTokEvent
|
|
||||||
{
|
|
||||||
private final LiveData.Response liveData;
|
|
||||||
}
|
|
||||||
@@ -30,9 +30,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Triggered when LiveRoomInfo got updated such as likes, viewers, ranking ....
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
|
|||||||
@@ -29,13 +29,10 @@ import io.github.jwdeveloper.tiktok.data.models.users.User;
|
|||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers when a user follows the streamer. Based on social event.
|
|
||||||
*/
|
|
||||||
@Value
|
@Value
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokFollowEvent extends TikTokHeaderEvent
|
public class TikTokFollowEvent extends TikTokHeaderEvent {
|
||||||
{
|
|
||||||
User user;
|
User user;
|
||||||
int totalFollowers;
|
int totalFollowers;
|
||||||
|
|
||||||
@@ -45,12 +42,12 @@ public class TikTokFollowEvent extends TikTokHeaderEvent
|
|||||||
totalFollowers = msg.getFollowCount();
|
totalFollowers = msg.getFollowCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TikTokFollowEvent of(String userName)
|
public static TikTokFollowEvent of(String userName) {
|
||||||
{
|
|
||||||
return new TikTokFollowEvent(WebcastSocialMessage.newBuilder()
|
return new TikTokFollowEvent(WebcastSocialMessage.newBuilder()
|
||||||
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
.setNickname(userName)
|
.setDisplayId(userName)
|
||||||
.build())
|
.setNickname(userName)
|
||||||
.build());
|
.build())
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,6 +53,7 @@ public class TikTokJoinEvent extends TikTokHeaderEvent {
|
|||||||
{
|
{
|
||||||
return new TikTokJoinEvent(WebcastMemberMessage.newBuilder()
|
return new TikTokJoinEvent(WebcastMemberMessage.newBuilder()
|
||||||
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
|
.setDisplayId(userName)
|
||||||
.setNickname(userName)
|
.setNickname(userName)
|
||||||
.build())
|
.build())
|
||||||
.build());
|
.build());
|
||||||
|
|||||||
@@ -31,9 +31,7 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when a viewer sends likes to the streamer. For streams with many viewers, this event is not always triggered by TikTok.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLikeEvent extends TikTokHeaderEvent
|
public class TikTokLikeEvent extends TikTokHeaderEvent
|
||||||
@@ -64,6 +62,7 @@ public class TikTokLikeEvent extends TikTokHeaderEvent
|
|||||||
.setCount(likes)
|
.setCount(likes)
|
||||||
.setTotal(likes)
|
.setTotal(likes)
|
||||||
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
|
.setDisplayId(userName)
|
||||||
.setNickname(userName)
|
.setNickname(userName)
|
||||||
.build())
|
.build())
|
||||||
.build());
|
.build());
|
||||||
|
|||||||
@@ -26,27 +26,35 @@ 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.WebcastSocialMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers when a user shares the stream. Based on social event.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokShareEvent extends TikTokHeaderEvent {
|
public class TikTokShareEvent extends TikTokHeaderEvent {
|
||||||
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) {
|
public TikTokShareEvent(WebcastSocialMessage msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
user = User.map(msg.getUser());
|
user = User.map(msg.getUser());
|
||||||
totalShares = 1;
|
totalShares = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TikTokShareEvent of(String userName, int shaders) {
|
||||||
|
return new TikTokShareEvent(WebcastSocialMessage.newBuilder()
|
||||||
|
.setUser(io.github.jwdeveloper.tiktok.messages.data.User.newBuilder()
|
||||||
|
.setDisplayId(userName)
|
||||||
|
.setNickname(userName)
|
||||||
|
.build())
|
||||||
|
.build(), shaders);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -35,10 +35,7 @@ import lombok.Value;
|
|||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered every time TikTok sends data. Data incoming as protobuf message.
|
|
||||||
* You can deserialize the binary object depending on the use case.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EventMeta(eventType = EventType.Debug)
|
@EventMeta(eventType = EventType.Debug)
|
||||||
|
|||||||
@@ -29,9 +29,7 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered every time a protobuf encoded webcast message arrives. You can deserialize the binary object depending on the use case.
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Debug)
|
@EventMeta(eventType = EventType.Debug)
|
||||||
public class TikTokWebsocketUnhandledMessageEvent extends TikTokUnhandledEvent<WebcastResponse.Message>
|
public class TikTokWebsocketUnhandledMessageEvent extends TikTokUnhandledEvent<WebcastResponse.Message>
|
||||||
|
|||||||
@@ -1,6 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.battles;
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
public abstract class Team {
|
public abstract class Team {
|
||||||
|
/** Value >= 0 when finished otherwise -1 */
|
||||||
|
@Getter protected int totalPoints;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a check for verifying if this team represents a 1v1 Team.
|
* Provides a check for verifying if this team represents a 1v1 Team.
|
||||||
* @return true if this team is of type {@link Team1v1}, false otherwise.
|
* @return true if this team is of type {@link Team1v1}, false otherwise.
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.battles;
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
@@ -7,10 +29,7 @@ import lombok.Getter;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class Team1v1 extends Team
|
public class Team1v1 extends Team {
|
||||||
{
|
|
||||||
/** Value >= 0 when finished otherwise -1 */
|
|
||||||
private final int totalPoints;
|
|
||||||
private final int winStreak;
|
private final int winStreak;
|
||||||
private final User host;
|
private final User host;
|
||||||
private final List<Viewer> viewers;
|
private final List<Viewer> viewers;
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.battles;
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
@@ -8,9 +30,6 @@ import java.util.*;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class Team2v2 extends Team {
|
public class Team2v2 extends Team {
|
||||||
/** Value >= 0 when finished otherwise -1 */
|
|
||||||
private final int totalPoints;
|
|
||||||
|
|
||||||
private final List<User> hosts;
|
private final List<User> hosts;
|
||||||
private final List<Viewer> viewers;
|
private final List<Viewer> viewers;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.battles;
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.gifts;
|
package io.github.jwdeveloper.tiktok.data.models.gifts;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|||||||
@@ -23,9 +23,9 @@
|
|||||||
package io.github.jwdeveloper.tiktok.data.models.gifts;
|
package io.github.jwdeveloper.tiktok.data.models.gifts;
|
||||||
|
|
||||||
public enum GiftComboStateType {
|
public enum GiftComboStateType {
|
||||||
Finished,
|
|
||||||
Begin,
|
Begin,
|
||||||
Active;
|
Active,
|
||||||
|
Finished;
|
||||||
|
|
||||||
public static GiftComboStateType fromNumber(long number) {
|
public static GiftComboStateType fromNumber(long number) {
|
||||||
return switch ((int) number) {
|
return switch ((int) number) {
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.users;
|
package io.github.jwdeveloper.tiktok.data.models.users;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -31,4 +53,19 @@ public class ListUser
|
|||||||
AUDIO,
|
AUDIO,
|
||||||
VIDEO
|
VIDEO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ListUser{" +
|
||||||
|
"user=" + user +
|
||||||
|
", linkType=" + linkType +
|
||||||
|
", linkMicId=" + linkMicId +
|
||||||
|
", linkStatus=" + linkStatus +
|
||||||
|
", modifyTime=" + modifyTime +
|
||||||
|
", linkerId=" + linkerId +
|
||||||
|
", userPosition=" + userPosition +
|
||||||
|
", silenceStatus=" + silenceStatus +
|
||||||
|
", roleType=" + roleType +
|
||||||
|
"}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -22,16 +22,12 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.models.users;
|
package io.github.jwdeveloper.tiktok.data.models.users;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.badges.Badge;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.badges.Badge;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
||||||
import lombok.AccessLevel;
|
import lombok.*;
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class User {
|
public class User {
|
||||||
@@ -49,12 +45,12 @@ public class User {
|
|||||||
return attributes.stream().toList();
|
return attributes.stream().toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAttribute(UserAttribute userFlag) {
|
public boolean hasAttribute(UserAttribute attribute) {
|
||||||
return attributes.contains(userFlag);
|
return attributes.contains(attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAttribute(UserAttribute... flags) {
|
public void addAttribute(UserAttribute... attributes) {
|
||||||
this.attributes.addAll(Arrays.stream(flags).toList());
|
this.attributes.addAll(List.of(attributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGiftGiver() {
|
public boolean isGiftGiver() {
|
||||||
@@ -168,11 +164,11 @@ 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()));
|
||||||
|
|
||||||
public static User map(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
public static User map(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
||||||
return new User(user);
|
return new User(user);
|
||||||
@@ -209,12 +205,12 @@ public class User {
|
|||||||
|
|
||||||
public static User map(WebcastEnvelopeMessage.EnvelopeInfo envelopeInfo) {
|
public static User map(WebcastEnvelopeMessage.EnvelopeInfo envelopeInfo) {
|
||||||
return new User(0L,
|
return new User(0L,
|
||||||
//envelopeInfo.getSendUserId(),
|
//envelopeInfo.getSendUserId(),
|
||||||
envelopeInfo.getSendUserName(),
|
envelopeInfo.getSendUserName(),
|
||||||
Picture.map(envelopeInfo.getSendUserAvatar()),
|
Picture.map(envelopeInfo.getSendUserAvatar()),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
List.of(Badge.empty()));
|
List.of(Badge.empty()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,23 +22,30 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.requests;
|
package io.github.jwdeveloper.tiktok.data.requests;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
public class LiveUserData {
|
public class LiveUserData {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
|
||||||
public static class Request {
|
public static class Request {
|
||||||
private String userName;
|
private final String userName;
|
||||||
|
|
||||||
|
public Request(String userName) {
|
||||||
|
if (userName == null || userName.isBlank())
|
||||||
|
throw new IllegalArgumentException("Invalid empty username!");
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class Response {
|
public static class Response {
|
||||||
private String json;
|
private final String json;
|
||||||
private UserStatus userStatus;
|
private final UserStatus userStatus;
|
||||||
private String roomId;
|
private final String roomId;
|
||||||
private long startedAtTimeStamp;
|
private final long startTime;
|
||||||
|
private final User user;
|
||||||
|
|
||||||
public boolean isLiveOnline() {
|
public boolean isLiveOnline() {
|
||||||
return userStatus == LiveUserData.UserStatus.Live || userStatus == LiveUserData.UserStatus.LivePaused;
|
return userStatus == LiveUserData.UserStatus.Live || userStatus == LiveUserData.UserStatus.LivePaused;
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ public class HttpClientSettings {
|
|||||||
newSettings.getHeaders().putAll(new TreeMap<>(this.headers));
|
newSettings.getHeaders().putAll(new TreeMap<>(this.headers));
|
||||||
newSettings.getCookies().putAll(new TreeMap<>(this.cookies));
|
newSettings.getCookies().putAll(new TreeMap<>(this.cookies));
|
||||||
newSettings.getParams().putAll(new TreeMap<>(this.params));
|
newSettings.getParams().putAll(new TreeMap<>(this.params));
|
||||||
newSettings.proxyClientSettings = this.proxyClientSettings;
|
newSettings.setProxyClientSettings(this.proxyClientSettings);
|
||||||
|
|
||||||
return newSettings;
|
return newSettings;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,9 +82,9 @@ public class LiveClientSettings {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Interval of time in milliseconds between pings to TikTok
|
* Interval of time in milliseconds between pings to TikTok
|
||||||
* @apiNote Min: 250 (0.25 seconds), Default: 5000 (5 seconds)
|
* @apiNote Min: 250 (0.25 seconds), Default: 10000 (10 seconds - TikTok Default)
|
||||||
*/
|
*/
|
||||||
private long pingInterval = 5000;
|
private long pingInterval = 10000;
|
||||||
|
|
||||||
/** Throw an exception on 18+ Age Restriction */
|
/** Throw an exception on 18+ Age Restriction */
|
||||||
private boolean throwOnAgeRestriction;
|
private boolean throwOnAgeRestriction;
|
||||||
|
|||||||
@@ -31,17 +31,17 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class ProxyClientSettings implements Iterator<ProxyData>
|
public class ProxyClientSettings implements Iterator<ProxyData>, Iterable<ProxyData>
|
||||||
{
|
{
|
||||||
private boolean enabled, autoDiscard = true, fallback = true;
|
private boolean enabled, autoDiscard = true, fallback = true;
|
||||||
private Rotation rotation = Rotation.CONSECUTIVE;
|
private Rotation rotation = Rotation.CONSECUTIVE;
|
||||||
private final List<ProxyData> proxyList = new ArrayList<>();
|
private final List<ProxyData> proxyList = new ArrayList<>();
|
||||||
private int index = -1;
|
private int index;
|
||||||
private Proxy.Type type = Proxy.Type.DIRECT;
|
private Proxy.Type type = Proxy.Type.DIRECT;
|
||||||
private Consumer<ProxyData> onProxyUpdated = x -> {};
|
private Consumer<ProxyData> onProxyUpdated = x -> {};
|
||||||
|
|
||||||
public boolean addProxy(String addressPort) {
|
public boolean addProxy(String addressPort) {
|
||||||
return proxyList.add(ProxyData.map(addressPort));
|
return addProxy(ProxyData.map(addressPort).toSocketAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addProxy(String address, int port) {
|
public boolean addProxy(String address, int port) {
|
||||||
@@ -57,33 +57,27 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public synchronized boolean hasNext() {
|
||||||
return !proxyList.isEmpty();
|
return !proxyList.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProxyData next() {
|
public synchronized ProxyData next() {
|
||||||
var nextProxy = switch (rotation)
|
try {
|
||||||
{
|
var nextProxy = proxyList.get(index);
|
||||||
case CONSECUTIVE -> {
|
onProxyUpdated.accept(nextProxy);
|
||||||
index = (index+1) % proxyList.size();
|
return nextProxy;
|
||||||
yield proxyList.get(index).clone();
|
} finally {
|
||||||
|
switch (rotation) {
|
||||||
|
case CONSECUTIVE -> index = ++index % proxyList.size();
|
||||||
|
case RANDOM -> index = (int) (Math.random() * proxyList.size());
|
||||||
|
case NONE -> index = Math.max(index, 0);
|
||||||
}
|
}
|
||||||
case RANDOM -> {
|
}
|
||||||
index = new Random().nextInt(proxyList.size());
|
}
|
||||||
yield proxyList.get(index).clone();
|
|
||||||
}
|
|
||||||
case NONE -> {
|
|
||||||
index = Math.max(index, 0);
|
|
||||||
yield proxyList.get(index).clone();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
onProxyUpdated.accept(nextProxy);
|
|
||||||
return nextProxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public synchronized void remove() {
|
||||||
proxyList.remove(index);
|
proxyList.remove(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,8 +91,8 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyClientSettings clone()
|
@Override
|
||||||
{
|
public ProxyClientSettings clone() {
|
||||||
ProxyClientSettings settings = new ProxyClientSettings();
|
ProxyClientSettings settings = new ProxyClientSettings();
|
||||||
settings.setEnabled(enabled);
|
settings.setEnabled(enabled);
|
||||||
settings.setRotation(rotation);
|
settings.setRotation(rotation);
|
||||||
@@ -109,6 +103,27 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ProxyClientSettings{" +
|
||||||
|
"enabled=" + enabled +
|
||||||
|
", autoDiscard=" + autoDiscard +
|
||||||
|
", fallback=" + fallback +
|
||||||
|
", rotation=" + rotation +
|
||||||
|
", proxyList=" + proxyList +
|
||||||
|
", index=" + index +
|
||||||
|
", type=" + type +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* With {@code Iterable<ProxyData>} interface, you can use this object inside for loop!
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Iterator<ProxyData> iterator() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public enum Rotation
|
public enum Rotation
|
||||||
{
|
{
|
||||||
/** Rotate addresses consecutively, from proxy 0 -> 1 -> 2 -> ...etc. */
|
/** Rotate addresses consecutively, from proxy 0 -> 1 -> 2 -> ...etc. */
|
||||||
|
|||||||
@@ -20,7 +20,11 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.mappers.handlers;
|
package io.github.jwdeveloper.tiktok.exceptions;
|
||||||
|
|
||||||
public class TikTokChestEventHandler {
|
public class TikTokLiveUnknownHostException extends TikTokLiveException
|
||||||
}
|
{
|
||||||
|
public TikTokLiveUnknownHostException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,15 +25,13 @@ package io.github.jwdeveloper.tiktok.listener;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You can dynamically add or removing TikTokEventListener
|
* Manage events listeners objects
|
||||||
*
|
|
||||||
* @see TikTokEventListener
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface ListenersManager
|
public interface ListenersManager
|
||||||
{
|
{
|
||||||
List<TikTokEventListener> getListeners();
|
List<Object> getListeners();
|
||||||
void addListener(TikTokEventListener listener);
|
|
||||||
|
|
||||||
void removeListener(TikTokEventListener listener);
|
void addListener(Object listener);
|
||||||
|
|
||||||
|
void removeListener(Object listener);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,9 +38,9 @@ import io.github.jwdeveloper.tiktok.live.LiveClient;
|
|||||||
* <p>- 2 parameters of (LiveClient, Class extending TikTokEvent)
|
* <p>- 2 parameters of (LiveClient, Class extending TikTokEvent)
|
||||||
* <pre>
|
* <pre>
|
||||||
* {@code
|
* {@code
|
||||||
* public static class CustomListener implements TikTokEventListener
|
* public static class CustomListener
|
||||||
* {
|
* {
|
||||||
* @TikTokEventObserver
|
* @TikTokEventObserver
|
||||||
* public void onError(LiveClient liveClient, TikTokErrorEvent event)
|
* public void onError(LiveClient liveClient, TikTokErrorEvent event)
|
||||||
* {
|
* {
|
||||||
* System.out.println(event.getException().getMessage());
|
* System.out.println(event.getException().getMessage());
|
||||||
@@ -67,7 +67,7 @@ import io.github.jwdeveloper.tiktok.live.LiveClient;
|
|||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public interface TikTokEventListener
|
@Deprecated(forRemoval = true, since = "1.8.1 (This interface is not longer needed, please remove it from your class) | Removing in 1.9.0")
|
||||||
{
|
public interface TikTokEventListener {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.listener;
|
package io.github.jwdeveloper.tiktok.listener;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.*;
|
import io.github.jwdeveloper.tiktok.data.events.*;
|
||||||
@@ -13,7 +35,7 @@ import io.github.jwdeveloper.tiktok.data.events.social.*;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.websocket.*;
|
import io.github.jwdeveloper.tiktok.data.events.websocket.*;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
|
||||||
public abstract class TikTokEventListenerBase implements TikTokEventListener
|
public abstract class TikTokEventListenerBase
|
||||||
{
|
{
|
||||||
public void onUnhandledSocial(LiveClient client, TikTokUnhandledSocialEvent event) {}
|
public void onUnhandledSocial(LiveClient client, TikTokUnhandledSocialEvent event) {}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ package io.github.jwdeveloper.tiktok.live;
|
|||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
import io.github.jwdeveloper.tiktok.listener.ListenersManager;
|
import io.github.jwdeveloper.tiktok.listener.ListenersManager;
|
||||||
import io.github.jwdeveloper.tiktok.listener.TikTokEventListener;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -81,9 +80,7 @@ public interface LiveClient {
|
|||||||
LiveRoomInfo getRoomInfo();
|
LiveRoomInfo getRoomInfo();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage TikTokEventListener
|
* Manage TikTokEvent Listeners
|
||||||
*
|
|
||||||
* @see TikTokEventListener
|
|
||||||
*/
|
*/
|
||||||
ListenersManager getListenersManager();
|
ListenersManager getListenersManager();
|
||||||
|
|
||||||
@@ -91,4 +88,4 @@ public interface LiveClient {
|
|||||||
* Logger
|
* Logger
|
||||||
*/
|
*/
|
||||||
Logger getLogger();
|
Logger getLogger();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.live;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.builder.EventConsumer;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface LiveEventsHandler {
|
||||||
|
void publish(LiveClient tikTokLiveClient, TikTokEvent tikTokEvent);
|
||||||
|
|
||||||
|
<T extends TikTokEvent> void subscribe(Class<?> clazz, EventConsumer<T> event);
|
||||||
|
|
||||||
|
<T extends TikTokEvent> void unsubscribeAll(Class<?> clazz);
|
||||||
|
|
||||||
|
<T extends TikTokEvent> void unsubscribe(EventConsumer<T> consumer);
|
||||||
|
|
||||||
|
<T extends TikTokEvent> void unsubscribe(Class<?> clazz, EventConsumer<T> consumer);
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.live;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.dto.MessageMetaData;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketMessageEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketResponseEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveMessageException;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||||
|
import io.github.jwdeveloper.tiktok.utils.Stopwatch;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
public interface LiveMessagesHandler {
|
||||||
|
void handle(LiveClient client, WebcastResponse webcastResponse);
|
||||||
|
|
||||||
|
void handleSingleMessage(LiveClient client, WebcastResponse.Message message);
|
||||||
|
}
|
||||||
@@ -25,7 +25,13 @@ package io.github.jwdeveloper.tiktok.live.builder;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
public interface EventConsumer<T extends TikTokEvent>
|
public interface EventConsumer<T extends TikTokEvent>
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param liveClient TikTok live client
|
||||||
|
* @param event event data object
|
||||||
|
*/
|
||||||
void onEvent(LiveClient liveClient, T event);
|
void onEvent(LiveClient liveClient, T event);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.live.builder;
|
package io.github.jwdeveloper.tiktok.live.builder;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.*;
|
import io.github.jwdeveloper.tiktok.data.events.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.control.TikTokConnectingEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.control.TikTokPreConnectionEvent;
|
import io.github.jwdeveloper.tiktok.data.events.control.TikTokPreConnectionEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftComboEvent;
|
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftComboEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftEvent;
|
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftEvent;
|
||||||
@@ -36,6 +37,7 @@ import io.github.jwdeveloper.tiktok.data.events.social.TikTokShareEvent;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketMessageEvent;
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketMessageEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketResponseEvent;
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketResponseEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.gifts.GiftComboStateType;
|
||||||
|
|
||||||
|
|
||||||
public interface EventsBuilder<T> {
|
public interface EventsBuilder<T> {
|
||||||
@@ -52,131 +54,269 @@ public interface EventsBuilder<T> {
|
|||||||
/**
|
/**
|
||||||
* Invoked whenever any event is triggered
|
* Invoked whenever any event is triggered
|
||||||
*
|
*
|
||||||
* @param action
|
* @param action consumable action
|
||||||
* @return
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onEvent(EventConsumer<TikTokEvent> action);
|
default T onEvent(EventConsumer<TikTokEvent> action) {
|
||||||
|
return onEvent(TikTokEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* As a first event after method `LiveClient::connect()` is performed
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onConnecting(EventConsumer<TikTokConnectingEvent> action)
|
||||||
|
{
|
||||||
|
return onEvent(TikTokConnectingEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when information about room (live) got updated such as viewer count, etc..
|
* Invoked when information about room (live) got updated such as viewer count, etc..
|
||||||
*
|
*
|
||||||
* @param action
|
* @param action consumable action
|
||||||
* @return
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onRoomInfo(EventConsumer<TikTokRoomInfoEvent> action);
|
default T onRoomInfo(EventConsumer<TikTokRoomInfoEvent> action) {
|
||||||
|
return onEvent(TikTokRoomInfoEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when someone send message to chat
|
* Invoked when someone send message to chat
|
||||||
*
|
*
|
||||||
* @param action
|
* @param action consumable action
|
||||||
* @return
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onComment(EventConsumer<TikTokCommentEvent> action);
|
default T onComment(EventConsumer<TikTokCommentEvent> action) {
|
||||||
|
return onEvent(TikTokCommentEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when TikTokLiveJava makes http request and getting response
|
* Invoked when TikTokLiveJava makes http request and getting response
|
||||||
*
|
*
|
||||||
* @param action
|
* @param action consumable action
|
||||||
* @return
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onHttpResponse(EventConsumer<TikTokHttpResponseEvent> action);
|
default T onHttpResponse(EventConsumer<TikTokHttpResponseEvent> action) {
|
||||||
|
return onEvent(TikTokHttpResponseEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when TikTok protocolBuffer data "message" was successfully mapped to event
|
* Invoked when TikTok protocolBuffer data "message" was successfully mapped to event
|
||||||
* events contains protocol-buffer "Message" and TikTokLiveJava "Event"
|
* events contains protocol-buffer "Message" and TikTokLiveJava "Event"
|
||||||
*
|
*
|
||||||
* @param action
|
* @param action consumable action
|
||||||
* @return
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onWebsocketMessage(EventConsumer<TikTokWebsocketMessageEvent> action);
|
default T onWebsocketMessage(EventConsumer<TikTokWebsocketMessageEvent> action) {
|
||||||
|
return onEvent(TikTokWebsocketMessageEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when there was not found event mapper for TikTok protocolBuffer data "message"
|
* Triggered every time a protobuf encoded webcast message arrives. You can deserialize the binary object depending on the use case.
|
||||||
*
|
*
|
||||||
* @param action
|
* @param action consumable action
|
||||||
* @return
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onWebsocketUnhandledMessage(EventConsumer<TikTokWebsocketUnhandledMessageEvent> action);
|
default T onWebsocketUnhandledMessage(EventConsumer<TikTokWebsocketUnhandledMessageEvent> action) {
|
||||||
|
return onEvent(TikTokWebsocketUnhandledMessageEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked every time TikTok sends protocolBuffer data to websocket
|
* Invoked every time TikTok sends protocolBuffer data to websocket
|
||||||
* Response contains list of messages that are later mapped to events
|
* Response contains list of messages that are later mapped to events
|
||||||
* @param action
|
*
|
||||||
* @return
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onWebsocketResponse(EventConsumer<TikTokWebsocketResponseEvent> action);
|
default T onWebsocketResponse(EventConsumer<TikTokWebsocketResponseEvent> action) {
|
||||||
|
return onEvent(TikTokWebsocketResponseEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked for gifts that has no combo, or when combo finishes
|
* Triggers for these different reasons:
|
||||||
* @param action
|
* <ol>
|
||||||
* @return
|
* <li>User sends gifts that have no combo (most of expensive gifts)</li>
|
||||||
|
* <li>{@link TikTokGiftComboEvent} has combaState = {@link GiftComboStateType#Finished}</li>
|
||||||
|
* </ol>
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onGift(EventConsumer<TikTokGiftEvent> action);
|
default T onGift(EventConsumer<TikTokGiftEvent> action) {
|
||||||
|
return onEvent(TikTokGiftEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked for gifts that has combo options such as roses
|
* Triggered every time a gift is sent
|
||||||
* @param action
|
* <p>Example when user sends gift with combo</p>
|
||||||
* @return
|
* <ul>
|
||||||
|
* <li>Combo: 1 -> comboState = {@link GiftComboStateType#Begin}</li>
|
||||||
|
* <li>Combo: 4 -> comboState = {@link GiftComboStateType#Active}</li>
|
||||||
|
* <li>Combo: 8 -> comboState = {@link GiftComboStateType#Active}</li>
|
||||||
|
* <li>Combo: 12 -> comboState = {@link GiftComboStateType#Finished}</li>
|
||||||
|
* </ul>
|
||||||
|
* Both {@link TikTokGiftComboEvent} and {@link TikTokGiftEvent} events are triggered when comboState is Finished
|
||||||
|
*
|
||||||
|
* @apiNote {@link GiftComboStateType} has 3 states: {@link GiftComboStateType#Begin Begin}, {@link GiftComboStateType#Active Active}, & {@link GiftComboStateType#Finished Finished}
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onGiftCombo(EventConsumer<TikTokGiftComboEvent> action);
|
default T onGiftCombo(EventConsumer<TikTokGiftComboEvent> action) {
|
||||||
|
return onEvent(TikTokGiftComboEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered every time someone asks a new question via the question feature.
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onQuestion(EventConsumer<TikTokQuestionEvent> action) {
|
||||||
|
return onEvent(TikTokQuestionEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onQuestion(EventConsumer<TikTokQuestionEvent> action);
|
/**
|
||||||
|
* Triggers when a user subscribe the streamer.
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onSubscribe(EventConsumer<TikTokSubscribeEvent> action) {
|
||||||
|
return onEvent(TikTokSubscribeEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onSubscribe(EventConsumer<TikTokSubscribeEvent> action);
|
/**
|
||||||
|
* Triggers when a user follows the streamer. Based on social event.
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onFollow(EventConsumer<TikTokFollowEvent> action) {
|
||||||
|
return onEvent(TikTokFollowEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onFollow(EventConsumer<TikTokFollowEvent> action);
|
/**
|
||||||
|
* Triggered when a viewer sends likes to the streamer. For streams with many viewers, this event is not always triggered by TikTok.
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onLike(EventConsumer<TikTokLikeEvent> action) {
|
||||||
|
return onEvent(TikTokLikeEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onLike(EventConsumer<TikTokLikeEvent> action);
|
/**
|
||||||
|
* Triggers when a user sends emote
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onEmote(EventConsumer<TikTokEmoteEvent> action) {
|
||||||
|
return onEvent(TikTokEmoteEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onEmote(EventConsumer<TikTokEmoteEvent> action);
|
/**
|
||||||
|
* Triggers when a user joins to the live
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onJoin(EventConsumer<TikTokJoinEvent> action) {
|
||||||
|
return onEvent(TikTokJoinEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onJoin(EventConsumer<TikTokJoinEvent> action);
|
/**
|
||||||
|
* Triggers when a user shares the stream.
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onShare(EventConsumer<TikTokShareEvent> action) {
|
||||||
|
return onEvent(TikTokShareEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onShare(EventConsumer<TikTokShareEvent> action);
|
/**
|
||||||
|
* Triggered when the live stream gets paused
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onLivePaused(EventConsumer<TikTokLivePausedEvent> action) {
|
||||||
|
return onEvent(TikTokLivePausedEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onLivePaused(EventConsumer<TikTokLivePausedEvent> action);
|
/**
|
||||||
|
* Triggered when the live stream gets unpaused
|
||||||
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onLiveUnpaused(EventConsumer<TikTokLiveUnpausedEvent> action) {
|
||||||
|
return onEvent(TikTokLiveUnpausedEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
T onLiveUnpaused(EventConsumer<TikTokLiveUnpausedEvent> action);
|
/**
|
||||||
|
* Triggered when the live stream gets terminated by the host. Will also trigger the TikTokDisconnectedEvent event.
|
||||||
T onLiveEnded(EventConsumer<TikTokLiveEndedEvent> action);
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
|
*/
|
||||||
|
default T onLiveEnded(EventConsumer<TikTokLiveEndedEvent> action) {
|
||||||
|
return onEvent(TikTokLiveEndedEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when client has been successfully connected to live
|
* Invoked when client has been successfully connected to live
|
||||||
* @param action
|
*
|
||||||
* @return
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onConnected(EventConsumer<TikTokConnectedEvent> action);
|
default T onConnected(EventConsumer<TikTokConnectedEvent> action) {
|
||||||
|
return onEvent(TikTokConnectedEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked before client has been successfully connected to live
|
* Invoked before client has been successfully connected to live
|
||||||
* @param action
|
*
|
||||||
* @return
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onPreConnection(EventConsumer<TikTokPreConnectionEvent> action);
|
default T onPreConnection(EventConsumer<TikTokPreConnectionEvent> action) {
|
||||||
|
return onEvent(TikTokPreConnectionEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when client tries to reconnect
|
* Invoked when client tries to reconnect
|
||||||
* @param action
|
*
|
||||||
* @return
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onReconnecting(EventConsumer<TikTokReconnectingEvent> action);
|
default T onReconnecting(EventConsumer<TikTokReconnectingEvent> action) {
|
||||||
|
return onEvent(TikTokReconnectingEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when client disconnected
|
* Triggered when the connection gets disconnected. In that case you can call connect() again to have a reconnect logic.
|
||||||
* @param action
|
* Note that you should wait a little bit before attempting a reconnect to avoid being rate-limited.
|
||||||
* @return
|
*
|
||||||
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onDisconnected(EventConsumer<TikTokDisconnectedEvent> action);
|
default T onDisconnected(EventConsumer<TikTokDisconnectedEvent> action) {
|
||||||
|
return onEvent(TikTokDisconnectedEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when exception was throed inside client or event handler
|
* Invoked when exception was throed inside client or event handler
|
||||||
* @param action
|
*
|
||||||
* @return
|
* @param action consumable action
|
||||||
|
* @return self instance
|
||||||
*/
|
*/
|
||||||
T onError(EventConsumer<TikTokErrorEvent> action);
|
default T onError(EventConsumer<TikTokErrorEvent> action) {
|
||||||
|
return onEvent(TikTokErrorEvent.class, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO Figure out how those events works
|
// TODO Figure out how those events works
|
||||||
@@ -223,4 +363,10 @@ public interface EventsBuilder<T> {
|
|||||||
//T onLinkMicBattle(TikTokEventConsumer<TikTokLinkMicBattleEvent> event);
|
//T onLinkMicBattle(TikTokEventConsumer<TikTokLinkMicBattleEvent> event);
|
||||||
|
|
||||||
//T onUnhandledControl(TikTokEventConsumer<TikTokUnhandledControlEvent> event);
|
//T onUnhandledControl(TikTokEventConsumer<TikTokUnhandledControlEvent> event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To do figure out how to use Annotation processor.
|
||||||
|
* Goal is to generates methods for all possible events, everytime library is compiled
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -22,59 +22,73 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.live.builder;
|
package io.github.jwdeveloper.tiktok.live.builder;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.dependance.implementation.DependanceContainerBuilder;
|
||||||
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
import io.github.jwdeveloper.tiktok.listener.TikTokEventListener;
|
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.TikTokMapper;
|
import io.github.jwdeveloper.tiktok.mappers.LiveMapper;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
|
public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is triggered after default mappings are registered
|
* This method is triggered after default mappings are registered
|
||||||
* It could be used to OVERRIDE behaviour of mappings and implement custom behaviour
|
* It could be used to OVERRIDE behaviour of mappings and implement custom behaviour
|
||||||
*
|
* <p>
|
||||||
* Be aware if for example you override WebcastGiftEvent, onGiftEvent() will not be working
|
* Be aware if for example you override WebcastGiftEvent, onGiftEvent() will not be working
|
||||||
*
|
*
|
||||||
* @param onCustomMappings lambda method
|
* @param onCustomMappings lambda method
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
LiveClientBuilder onMapping(Consumer<TikTokMapper> onCustomMappings);
|
LiveClientBuilder mappings(Consumer<LiveMapper> onCustomMappings);
|
||||||
|
|
||||||
|
@Deprecated(forRemoval = true, since = "1.8.2 use `mappings` method instead")
|
||||||
|
LiveClientBuilder onMappings(Consumer<LiveMapper> onCustomMappings);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration of client settings
|
* Configuration of client settings
|
||||||
* @see LiveClientSettings
|
*
|
||||||
* @param onConfigure
|
* @param onConfigure
|
||||||
* @return
|
* @return
|
||||||
|
* @see LiveClientSettings
|
||||||
*/
|
*/
|
||||||
LiveClientBuilder configure(Consumer<LiveClientSettings> onConfigure);
|
LiveClientBuilder configure(Consumer<LiveClientSettings> onConfigure);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TikTokEventListener
|
* Adds events listener class, its fancy way to register events without using lamda method
|
||||||
* Adding events listener class, its fancy way to register events without using lamda method
|
*
|
||||||
* but actual method in class that implements TikTokEventListener
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
LiveClientBuilder addListener(TikTokEventListener listener);
|
LiveClientBuilder addListener(Object listener);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Allows you to use own implementation of internal TikTokLive dependencies,
|
||||||
|
* when the default implementation does not meet your needs
|
||||||
|
*
|
||||||
|
* @param onCustomizeDependencies access to dependency container
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
LiveClientBuilder customize(Consumer<DependanceContainerBuilder> onCustomizeDependencies);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds new instance of the LiveClient
|
||||||
*
|
*
|
||||||
* @return LiveClient object
|
* @return LiveClient object
|
||||||
*/
|
*/
|
||||||
LiveClient build();
|
LiveClient build();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Builds new instance of the LiveClient and connects to live
|
||||||
*
|
*
|
||||||
* @return LiveClient object and connects to TikTok live
|
* @return LiveClient object
|
||||||
*/
|
*/
|
||||||
LiveClient buildAndConnect();
|
LiveClient buildAndConnect();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return LiveClient object and connects to TikTok live asynchronously
|
* @return LiveClient object and connects to TikTok live asynchronously
|
||||||
*/
|
*/
|
||||||
CompletableFuture<LiveClient> buildAndConnectAsync();
|
CompletableFuture<LiveClient> buildAndConnectAsync();
|
||||||
}
|
}
|
||||||
@@ -27,18 +27,23 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
|||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingAction;
|
import io.github.jwdeveloper.tiktok.mappers.data.MappingAction;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public interface TikTokMapper {
|
public interface LiveMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * if mapper is not found for messageName, TikTokLiveException is thrown
|
* when mapper is not found for messageName, TikTokLiveException is thrown
|
||||||
*
|
*
|
||||||
* @param messageName
|
* @param messageName
|
||||||
* @return TikTokMapperModel
|
* @return TikTokMapperModel
|
||||||
*/
|
*/
|
||||||
TikTokMapperModel forMessage(String messageName);
|
TikTokMapperModel forMessage(String messageName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mapperName protocol buffer class type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
TikTokMapperModel forMessage(Class<? extends GeneratedMessageV3> mapperName);
|
TikTokMapperModel forMessage(Class<? extends GeneratedMessageV3> mapperName);
|
||||||
|
|
||||||
TikTokMapperModel forMessage(String mapperName, MappingAction<MappingResult> onMapping);
|
TikTokMapperModel forMessage(String mapperName, MappingAction<MappingResult> onMapping);
|
||||||
@@ -49,10 +54,9 @@ public interface TikTokMapper {
|
|||||||
|
|
||||||
TikTokMapperModel forAnyMessage();
|
TikTokMapperModel forAnyMessage();
|
||||||
|
|
||||||
|
List<TikTokEvent> handleMapping(String messageName, byte[] bytes);
|
||||||
|
|
||||||
boolean isRegistered(String mapperName);
|
boolean isRegistered(String mapperName);
|
||||||
|
|
||||||
<T extends GeneratedMessageV3> boolean isRegistered(Class<T> mapperName);
|
<T extends GeneratedMessageV3> boolean isRegistered(Class<T> mapperName);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ import com.google.protobuf.GeneratedMessageV3;
|
|||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokMessageMappingException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokMessageMappingException;
|
||||||
import io.github.jwdeveloper.tiktok.utils.ProtoBufferObject;
|
import io.github.jwdeveloper.tiktok.utils.ProtoBufferObject;
|
||||||
|
|
||||||
public interface TikTokMapperHelper {
|
public interface LiveMapperHelper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bytes protocol buffer data bytes
|
* @param bytes protocol buffer data bytes
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.mappers.data;
|
package io.github.jwdeveloper.tiktok.mappers.data;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.mappers.TikTokMapperHelper;
|
import io.github.jwdeveloper.tiktok.mappers.LiveMapperHelper;
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface MappingAction<T> {
|
public interface MappingAction<T> {
|
||||||
@@ -33,6 +33,6 @@ public interface MappingAction<T> {
|
|||||||
* @param mapperHelper utils and helper methods that can be use to debbug/display/deserialize protocol buffer data
|
* @param mapperHelper utils and helper methods that can be use to debbug/display/deserialize protocol buffer data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
T onMapping(byte[] inputBytes, String messageName, TikTokMapperHelper mapperHelper);
|
T onMapping(byte[] inputBytes, String messageName, LiveMapperHelper mapperHelper);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,8 @@ package io.github.jwdeveloper.tiktok.websocket;
|
|||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
|
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
|
||||||
|
|
||||||
public interface SocketClient {
|
public interface LiveSocketClient {
|
||||||
void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient);
|
void start(LiveConnectionData.Response webcastResponse, LiveClient tikTokLiveClient);
|
||||||
void stop();
|
void stop();
|
||||||
}
|
}
|
||||||
@@ -155,8 +155,9 @@ enum MemberMessageAction {
|
|||||||
enum ControlAction {
|
enum ControlAction {
|
||||||
ControlActionUNKNOWN = 0;
|
ControlActionUNKNOWN = 0;
|
||||||
STREAM_PAUSED = 1; // Stream Paused by Host
|
STREAM_PAUSED = 1; // Stream Paused by Host
|
||||||
STREAM_UNPAUSED = 2;
|
STREAM_UNPAUSED = 2; // Stream Unpaused by Host
|
||||||
STREAM_ENDED = 3; // Stream Ended by Host
|
STREAM_ENDED = 3; // Stream Ended by Host
|
||||||
|
STREAM_SUSPENDED = 4; // Stream Ended by TikTok
|
||||||
}
|
}
|
||||||
|
|
||||||
enum LinkLayerMessageType
|
enum LinkLayerMessageType
|
||||||
|
|||||||
@@ -5,13 +5,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.6.4-Release</version>
|
<version>1.8.7-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>Client</artifactId>
|
<artifactId>Client</artifactId>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
|||||||
@@ -23,19 +23,21 @@
|
|||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftsManager;
|
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftsManager;
|
||||||
import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
|
import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
|
||||||
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
||||||
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
|
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class TikTokLive {
|
public class TikTokLive {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of Tiktok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return LiveClientBuilder
|
* @return LiveClientBuilder
|
||||||
*/
|
*/
|
||||||
public static LiveClientBuilder newClient(String hostName) {
|
public static LiveClientBuilder newClient(String hostName) {
|
||||||
@@ -45,7 +47,7 @@ public class TikTokLive {
|
|||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of Tiktok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return true if live is Online, false if is offline
|
* @return true if live is Online, false if is offline
|
||||||
*/
|
*/
|
||||||
public static boolean isLiveOnline(String hostName) {
|
public static boolean isLiveOnline(String hostName) {
|
||||||
@@ -55,7 +57,7 @@ public class TikTokLive {
|
|||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of Tiktok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return true if live is Online, false if is offline
|
* @return true if live is Online, false if is offline
|
||||||
*/
|
*/
|
||||||
public static CompletableFuture<Boolean> isLiveOnlineAsync(String hostName) {
|
public static CompletableFuture<Boolean> isLiveOnlineAsync(String hostName) {
|
||||||
@@ -65,7 +67,7 @@ public class TikTokLive {
|
|||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of Tiktok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return true is hostName name is valid and exists, false if not
|
* @return true is hostName name is valid and exists, false if not
|
||||||
*/
|
*/
|
||||||
public static boolean isHostNameValid(String hostName) {
|
public static boolean isHostNameValid(String hostName) {
|
||||||
@@ -75,20 +77,29 @@ public class TikTokLive {
|
|||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of Tiktok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return true is hostName name is valid and exists, false if not
|
* @return true is hostName name is valid and exists, false if not
|
||||||
*/
|
*/
|
||||||
public static CompletableFuture<Boolean> isHostNameValidAsync(String hostName) {
|
public static CompletableFuture<Boolean> isHostNameValidAsync(String hostName) {
|
||||||
return CompletableFuture.supplyAsync(() -> isHostNameValid(hostName));
|
return CompletableFuture.supplyAsync(() -> isHostNameValid(hostName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use to get some data from TikTok about users are lives
|
||||||
|
*
|
||||||
|
* @return LiveHttpClient
|
||||||
|
*/
|
||||||
|
public static LiveHttpClient requests(Consumer<LiveClientSettings> consumer) {
|
||||||
|
return new TikTokLiveHttpClient(consumer);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use to get some data from TikTok about users are lives
|
* Use to get some data from TikTok about users are lives
|
||||||
*
|
*
|
||||||
* @return LiveHttpClient
|
* @return LiveHttpClient
|
||||||
*/
|
*/
|
||||||
public static LiveHttpClient requests() {
|
public static LiveHttpClient requests() {
|
||||||
return new TikTokLiveHttpClient();
|
return requests(liveClientSettings -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GiftsManager giftsManager;
|
private static GiftsManager giftsManager;
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import com.google.protobuf.ByteString;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.*;
|
import io.github.jwdeveloper.tiktok.data.events.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.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.room.TikTokRoomInfoEvent;
|
import io.github.jwdeveloper.tiktok.data.events.room.TikTokRoomInfoEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.*;
|
import io.github.jwdeveloper.tiktok.data.requests.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
@@ -36,37 +35,40 @@ import io.github.jwdeveloper.tiktok.listener.*;
|
|||||||
import io.github.jwdeveloper.tiktok.live.*;
|
import io.github.jwdeveloper.tiktok.live.*;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||||
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
||||||
import io.github.jwdeveloper.tiktok.websocket.SocketClient;
|
import io.github.jwdeveloper.tiktok.websocket.LiveSocketClient;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class TikTokLiveClient implements LiveClient {
|
@Getter
|
||||||
private final TikTokRoomInfo liveRoomInfo;
|
public class TikTokLiveClient implements LiveClient
|
||||||
|
{
|
||||||
|
private final TikTokRoomInfo roomInfo;
|
||||||
private final LiveHttpClient httpClient;
|
private final LiveHttpClient httpClient;
|
||||||
private final SocketClient webSocketClient;
|
private final LiveSocketClient webSocketClient;
|
||||||
private final TikTokLiveEventHandler tikTokEventHandler;
|
private final LiveEventsHandler tikTokEventHandler;
|
||||||
private final LiveClientSettings clientSettings;
|
private final LiveClientSettings clientSettings;
|
||||||
private final TikTokListenersManager listenersManager;
|
private final ListenersManager listenersManager;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final GiftsManager giftsManager;
|
private final GiftsManager giftManager;
|
||||||
private final TikTokLiveMessageHandler messageHandler;
|
private final LiveMessagesHandler messageHandler;
|
||||||
|
|
||||||
public TikTokLiveClient(
|
public TikTokLiveClient(
|
||||||
TikTokLiveMessageHandler messageHandler,
|
LiveMessagesHandler messageHandler,
|
||||||
GiftsManager giftsManager,
|
GiftsManager giftsManager,
|
||||||
TikTokRoomInfo tikTokLiveMeta,
|
TikTokRoomInfo tikTokLiveMeta,
|
||||||
LiveHttpClient tiktokHttpClient,
|
LiveHttpClient tiktokHttpClient,
|
||||||
SocketClient webSocketClient,
|
LiveSocketClient webSocketClient,
|
||||||
TikTokLiveEventHandler tikTokEventHandler,
|
LiveEventsHandler tikTokEventHandler,
|
||||||
LiveClientSettings clientSettings,
|
LiveClientSettings clientSettings,
|
||||||
TikTokListenersManager listenersManager,
|
ListenersManager listenersManager,
|
||||||
Logger logger) {
|
Logger logger) {
|
||||||
this.messageHandler = messageHandler;
|
this.messageHandler = messageHandler;
|
||||||
this.giftsManager = giftsManager;
|
this.giftManager = giftsManager;
|
||||||
this.liveRoomInfo = tikTokLiveMeta;
|
this.roomInfo = tikTokLiveMeta;
|
||||||
this.httpClient = tiktokHttpClient;
|
this.httpClient = tiktokHttpClient;
|
||||||
this.webSocketClient = webSocketClient;
|
this.webSocketClient = webSocketClient;
|
||||||
this.tikTokEventHandler = tikTokEventHandler;
|
this.tikTokEventHandler = tikTokEventHandler;
|
||||||
@@ -75,22 +77,6 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void connectAsync(Consumer<LiveClient> onConnection) {
|
|
||||||
CompletableFuture.runAsync(() -> {
|
|
||||||
connect();
|
|
||||||
onConnection.accept(this);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public CompletableFuture<LiveClient> connectAsync() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
|
||||||
connect();
|
|
||||||
return this;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void connect() {
|
public void connect() {
|
||||||
try {
|
try {
|
||||||
tryConnect();
|
tryConnect();
|
||||||
@@ -102,8 +88,7 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
if (e instanceof TikTokLiveOfflineHostException && clientSettings.isRetryOnConnectionFailure()) {
|
if (e instanceof TikTokLiveOfflineHostException && clientSettings.isRetryOnConnectionFailure()) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(clientSettings.getRetryConnectionTimeout().toMillis());
|
Thread.sleep(clientSettings.getRetryConnectionTimeout().toMillis());
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {}
|
||||||
}
|
|
||||||
logger.info("Reconnecting");
|
logger.info("Reconnecting");
|
||||||
tikTokEventHandler.publish(this, new TikTokReconnectingEvent());
|
tikTokEventHandler.publish(this, new TikTokReconnectingEvent());
|
||||||
this.connect();
|
this.connect();
|
||||||
@@ -117,61 +102,59 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void tryConnect() {
|
public void tryConnect() {
|
||||||
if (!liveRoomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) {
|
if (!roomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) {
|
||||||
throw new TikTokLiveException("Already connected");
|
throw new TikTokLiveException("Already connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(ConnectionState.CONNECTING);
|
setState(ConnectionState.CONNECTING);
|
||||||
tikTokEventHandler.publish(this, new TikTokConnectingEvent());
|
tikTokEventHandler.publish(this, new TikTokConnectingEvent());
|
||||||
var userDataRequest = new LiveUserData.Request(liveRoomInfo.getHostName());
|
var userDataRequest = new LiveUserData.Request(roomInfo.getHostName());
|
||||||
var userData = httpClient.fetchLiveUserData(userDataRequest);
|
var userData = httpClient.fetchLiveUserData(userDataRequest);
|
||||||
liveRoomInfo.setStartTime(userData.getStartedAtTimeStamp());
|
roomInfo.setStartTime(userData.getStartTime());
|
||||||
liveRoomInfo.setRoomId(userData.getRoomId());
|
roomInfo.setRoomId(userData.getRoomId());
|
||||||
|
|
||||||
if (clientSettings.isFetchGifts())
|
|
||||||
giftsManager.attachGiftsList(httpClient.fetchRoomGiftsData(userData.getRoomId()).getGifts());
|
|
||||||
|
|
||||||
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
|
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
|
||||||
throw new TikTokLiveOfflineHostException("User is offline: " + liveRoomInfo.getHostName());
|
throw new TikTokLiveOfflineHostException("User is offline: " + roomInfo.getHostName());
|
||||||
|
|
||||||
if (userData.getUserStatus() == LiveUserData.UserStatus.NotFound)
|
if (userData.getUserStatus() == LiveUserData.UserStatus.NotFound)
|
||||||
throw new TikTokLiveOfflineHostException("User not found: " + liveRoomInfo.getHostName());
|
throw new TikTokLiveUnknownHostException("User not found: " + roomInfo.getHostName());
|
||||||
|
|
||||||
var liveDataRequest = new LiveData.Request(userData.getRoomId());
|
var liveDataRequest = new LiveData.Request(userData.getRoomId());
|
||||||
var liveData = httpClient.fetchLiveData(liveDataRequest);
|
var liveData = httpClient.fetchLiveData(liveDataRequest);
|
||||||
|
|
||||||
if (liveData.isAgeRestricted() && clientSettings.isThrowOnAgeRestriction())
|
if (liveData.isAgeRestricted() && clientSettings.isThrowOnAgeRestriction())
|
||||||
throw new TikTokLiveException("Livestream for " + liveRoomInfo.getHostName() + " is 18+ or age restricted!");
|
throw new TikTokLiveException("Livestream for " + roomInfo.getHostName() + " is 18+ or age restricted!");
|
||||||
|
|
||||||
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostNotFound)
|
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostNotFound)
|
||||||
throw new TikTokLiveOfflineHostException("LiveStream for " + liveRoomInfo.getHostName() + " could not be found.");
|
throw new TikTokLiveUnknownHostException("LiveStream for " + roomInfo.getHostName() + " could not be found.");
|
||||||
|
|
||||||
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostOffline)
|
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostOffline)
|
||||||
throw new TikTokLiveOfflineHostException("LiveStream for " + liveRoomInfo.getHostName() + " not found, is the Host offline?");
|
throw new TikTokLiveOfflineHostException("LiveStream for " + roomInfo.getHostName() + " not found, is the Host offline?");
|
||||||
|
|
||||||
tikTokEventHandler.publish(this, new TikTokRoomDataResponseEvent(liveData));
|
roomInfo.setTitle(liveData.getTitle());
|
||||||
|
roomInfo.setViewersCount(liveData.getViewers());
|
||||||
liveRoomInfo.setTitle(liveData.getTitle());
|
roomInfo.setTotalViewersCount(liveData.getTotalViewers());
|
||||||
liveRoomInfo.setViewersCount(liveData.getViewers());
|
roomInfo.setAgeRestricted(liveData.isAgeRestricted());
|
||||||
liveRoomInfo.setTotalViewersCount(liveData.getTotalViewers());
|
roomInfo.setHost(liveData.getHost());
|
||||||
liveRoomInfo.setAgeRestricted(liveData.isAgeRestricted());
|
|
||||||
liveRoomInfo.setHost(liveData.getHost());
|
|
||||||
|
|
||||||
var preconnectEvent = new TikTokPreConnectionEvent(userData, liveData);
|
var preconnectEvent = new TikTokPreConnectionEvent(userData, liveData);
|
||||||
tikTokEventHandler.publish(this, preconnectEvent);
|
tikTokEventHandler.publish(this, preconnectEvent);
|
||||||
if (preconnectEvent.isCancelConnection())
|
if (preconnectEvent.isCancelConnection())
|
||||||
throw new TikTokLiveException("TikTokPreConnectionEvent cancelled connection!");
|
throw new TikTokLiveException("TikTokPreConnectionEvent cancelled connection!");
|
||||||
|
|
||||||
|
if (clientSettings.isFetchGifts())
|
||||||
|
giftManager.attachGiftsList(httpClient.fetchRoomGiftsData(userData.getRoomId()).getGifts());
|
||||||
|
|
||||||
var liveConnectionRequest = new LiveConnectionData.Request(userData.getRoomId());
|
var liveConnectionRequest = new LiveConnectionData.Request(userData.getRoomId());
|
||||||
var liveConnectionData = httpClient.fetchLiveConnectionData(liveConnectionRequest);
|
var liveConnectionData = httpClient.fetchLiveConnectionData(liveConnectionRequest);
|
||||||
webSocketClient.start(liveConnectionData, this);
|
webSocketClient.start(liveConnectionData, this);
|
||||||
|
|
||||||
setState(ConnectionState.CONNECTED);
|
setState(ConnectionState.CONNECTED);
|
||||||
tikTokEventHandler.publish(this, new TikTokRoomInfoEvent(liveRoomInfo));
|
tikTokEventHandler.publish(this, new TikTokRoomInfoEvent(roomInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
if (liveRoomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) {
|
if (roomInfo.hasConnectionState(ConnectionState.DISCONNECTED)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setState(ConnectionState.DISCONNECTED);
|
setState(ConnectionState.DISCONNECTED);
|
||||||
@@ -180,7 +163,7 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
|
|
||||||
private void setState(ConnectionState connectionState) {
|
private void setState(ConnectionState connectionState) {
|
||||||
logger.info("TikTokLive client state: " + connectionState.name());
|
logger.info("TikTokLive client state: " + connectionState.name());
|
||||||
liveRoomInfo.setConnectionState(connectionState);
|
roomInfo.setConnectionState(connectionState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void publishEvent(TikTokEvent event) {
|
public void publishEvent(TikTokEvent event) {
|
||||||
@@ -201,22 +184,15 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
messageHandler.handleSingleMessage(this, message);
|
messageHandler.handleSingleMessage(this, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public GiftsManager getGiftManager() {
|
public void connectAsync(Consumer<LiveClient> onConnection) {
|
||||||
return giftsManager;
|
connectAsync().thenAccept(onConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveRoomInfo getRoomInfo() {
|
public CompletableFuture<LiveClient> connectAsync() {
|
||||||
return liveRoomInfo;
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
}
|
connect();
|
||||||
|
return this;
|
||||||
@Override
|
});
|
||||||
public ListenersManager getListenersManager() {
|
|
||||||
return listenersManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Logger getLogger() {
|
|
||||||
return logger;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,29 +22,25 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.dependance.Dependance;
|
||||||
|
import io.github.jwdeveloper.dependance.api.DependanceContainer;
|
||||||
|
import io.github.jwdeveloper.dependance.implementation.DependanceContainerBuilder;
|
||||||
|
import io.github.jwdeveloper.tiktok.mappers.MessagesMapperFactory;
|
||||||
import io.github.jwdeveloper.tiktok.common.LoggerFactory;
|
import io.github.jwdeveloper.tiktok.common.LoggerFactory;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.*;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.control.TikTokPreConnectionEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.envelop.TikTokChestEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.gift.*;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.http.TikTokHttpResponseEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.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.data.settings.LiveClientSettings;
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
||||||
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftsManager;
|
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftsManager;
|
||||||
import io.github.jwdeveloper.tiktok.http.HttpClientFactory;
|
import io.github.jwdeveloper.tiktok.http.HttpClientFactory;
|
||||||
|
import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
|
||||||
import io.github.jwdeveloper.tiktok.listener.*;
|
import io.github.jwdeveloper.tiktok.listener.*;
|
||||||
import io.github.jwdeveloper.tiktok.live.*;
|
import io.github.jwdeveloper.tiktok.live.*;
|
||||||
import io.github.jwdeveloper.tiktok.live.builder.*;
|
import io.github.jwdeveloper.tiktok.live.builder.*;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.*;
|
import io.github.jwdeveloper.tiktok.mappers.*;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokCommonEventHandler;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.handlers.*;
|
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokGiftEventHandler;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokRoomInfoEventHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokSocialMediaEventHandler;
|
||||||
import io.github.jwdeveloper.tiktok.websocket.*;
|
import io.github.jwdeveloper.tiktok.websocket.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -52,28 +48,31 @@ 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 eventHandler;
|
protected final LiveEventsHandler eventHandler;
|
||||||
protected final List<TikTokEventListener> listeners;
|
protected final List<Object> listeners;
|
||||||
protected Consumer<TikTokMapper> onCustomMappings;
|
protected final List<Consumer<LiveMapper>> onCustomMappings;
|
||||||
protected Logger logger;
|
protected final List<Consumer<DependanceContainerBuilder>> onCustomDependencies;
|
||||||
protected GiftsManager giftsManager;
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder(String userName) {
|
public TikTokLiveClientBuilder(String userName) {
|
||||||
this.clientSettings = LiveClientSettings.createDefault();
|
this.clientSettings = LiveClientSettings.createDefault();
|
||||||
this.clientSettings.setHostName(userName);
|
this.clientSettings.setHostName(userName);
|
||||||
this.eventHandler = new TikTokLiveEventHandler();
|
this.eventHandler = new TikTokLiveEventHandler();
|
||||||
this.listeners = new ArrayList<>();
|
this.listeners = new ArrayList<>();
|
||||||
this.onCustomMappings = (e) -> {
|
this.onCustomMappings = new ArrayList<>();
|
||||||
};
|
this.onCustomDependencies = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveClientBuilder onMapping(Consumer<TikTokMapper> onCustomMappings) {
|
public LiveClientBuilder mappings(Consumer<LiveMapper> consumer) {
|
||||||
this.onCustomMappings = onCustomMappings;
|
this.onCustomMappings.add(consumer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiveClientBuilder onMappings(Consumer<LiveMapper> onCustomMappings) {
|
||||||
|
mappings(onCustomMappings);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,12 +81,18 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder addListener(TikTokEventListener listener) {
|
public TikTokLiveClientBuilder addListener(Object listener) {
|
||||||
if (listener != null)
|
if (listener != null)
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiveClientBuilder customize(Consumer<DependanceContainerBuilder> onCustomizeDependencies) {
|
||||||
|
this.onCustomDependencies.add(onCustomizeDependencies);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
protected void validate() {
|
protected void validate() {
|
||||||
if (clientSettings.getClientLanguage() == null || clientSettings.getClientLanguage().isEmpty())
|
if (clientSettings.getClientLanguage() == null || clientSettings.getClientLanguage().isEmpty())
|
||||||
clientSettings.setClientLanguage("en");
|
clientSettings.setClientLanguage("en");
|
||||||
@@ -98,175 +103,92 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
if (clientSettings.getHostName().startsWith("@"))
|
if (clientSettings.getHostName().startsWith("@"))
|
||||||
clientSettings.setHostName(clientSettings.getHostName().substring(1));
|
clientSettings.setHostName(clientSettings.getHostName().substring(1));
|
||||||
|
|
||||||
|
//TODO 250 Magic number
|
||||||
if (clientSettings.getPingInterval() < 250)
|
if (clientSettings.getPingInterval() < 250)
|
||||||
throw new TikTokLiveException("Minimum allowed ping interval is 250 millseconds");
|
throw new TikTokLiveException("Minimum allowed ping interval is 250 milliseconds");
|
||||||
|
|
||||||
var httpSettings = clientSettings.getHttpSettings();
|
var httpSettings = clientSettings.getHttpSettings();
|
||||||
httpSettings.getParams().put("app_language", clientSettings.getClientLanguage());
|
httpSettings.getParams().put("app_language", clientSettings.getClientLanguage());
|
||||||
httpSettings.getParams().put("webcast_language", clientSettings.getClientLanguage());
|
httpSettings.getParams().put("webcast_language", clientSettings.getClientLanguage());
|
||||||
|
|
||||||
this.logger = LoggerFactory.create(clientSettings.getHostName(), clientSettings);
|
|
||||||
this.giftsManager = clientSettings.isFetchGifts() ? TikTokLive.gifts() : new TikTokGiftsManager(List.of());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO each class registered to container should implement own interface,
|
||||||
public LiveClient build() {
|
public LiveClient build() {
|
||||||
validate();
|
validate();
|
||||||
|
|
||||||
var tiktokRoomInfo = new TikTokRoomInfo();
|
//Docs: https://github.com/jwdeveloper/DepenDance?tab=readme-ov-file#01-basic
|
||||||
tiktokRoomInfo.setHostName(clientSettings.getHostName());
|
var dependance = Dependance.newContainer();
|
||||||
|
|
||||||
var listenerManager = new TikTokListenersManager(listeners, eventHandler);
|
//config
|
||||||
|
dependance.registerSingleton(LiveClientSettings.class, clientSettings);
|
||||||
|
dependance.registerSingleton(Logger.class, LoggerFactory.create(clientSettings.getHostName(), clientSettings));
|
||||||
|
dependance.registerSingleton(TikTokRoomInfo.class, container ->
|
||||||
|
{
|
||||||
|
var roomInfo = new TikTokRoomInfo();
|
||||||
|
roomInfo.setHostName(clientSettings.getHostName());
|
||||||
|
return roomInfo;
|
||||||
|
});
|
||||||
|
|
||||||
var httpClientFactory = new HttpClientFactory(clientSettings);
|
//messages
|
||||||
|
dependance.registerSingleton(LiveEventsHandler.class, eventHandler);
|
||||||
|
dependance.registerSingleton(LiveMessagesHandler.class, TikTokLiveMessageHandler.class);
|
||||||
|
|
||||||
var liveHttpClient = clientSettings.isOffline() ?
|
//listeners
|
||||||
new TikTokLiveHttpOfflineClient() :
|
dependance.registerSingleton(ListenersManager.class, TikTokListenersManager.class);
|
||||||
new TikTokLiveHttpClient(httpClientFactory, clientSettings);
|
|
||||||
|
|
||||||
var eventsMapper = createMapper(giftsManager, tiktokRoomInfo);
|
//networking
|
||||||
var messageHandler = new TikTokLiveMessageHandler(eventHandler, eventsMapper);
|
dependance.registerSingleton(HttpClientFactory.class);
|
||||||
|
dependance.registerSingleton(WebSocketHeartbeatTask.class);
|
||||||
|
if (clientSettings.isOffline()) {
|
||||||
|
dependance.registerSingleton(LiveSocketClient.class, TikTokWebSocketOfflineClient.class);
|
||||||
|
dependance.registerSingleton(LiveHttpClient.class, TikTokLiveHttpOfflineClient.class);
|
||||||
|
} else {
|
||||||
|
dependance.registerSingleton(LiveSocketClient.class, TikTokWebSocketClient.class);
|
||||||
|
dependance.registerSingleton(LiveHttpClient.class, TikTokLiveHttpClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
var webSocketClient = clientSettings.isOffline() ?
|
/* TODO in future, custom proxy implementation that can be provided via builder
|
||||||
new TikTokWebSocketOfflineClient(eventHandler) :
|
* if(customProxy != null)
|
||||||
new TikTokWebSocketClient(
|
* dependance.registerSingleton(TikTokProxyProvider.class,customProxy);
|
||||||
clientSettings,
|
* else
|
||||||
messageHandler,
|
* dependance.registerSingleton(TikTokProxyProvider.class,DefaultProxyProvider.class);
|
||||||
eventHandler);
|
*/
|
||||||
|
|
||||||
return new TikTokLiveClient(
|
//gifts
|
||||||
messageHandler,
|
if (clientSettings.isFetchGifts()) {
|
||||||
giftsManager,
|
dependance.registerSingleton(GiftsManager.class, TikTokLive.gifts());
|
||||||
tiktokRoomInfo,
|
} else {
|
||||||
liveHttpClient,
|
dependance.registerSingleton(GiftsManager.class, new TikTokGiftsManager(List.of()));
|
||||||
webSocketClient,
|
}
|
||||||
eventHandler,
|
|
||||||
clientSettings,
|
//mapper
|
||||||
listenerManager,
|
dependance.registerSingleton(TikTokGenericEventMapper.class);
|
||||||
logger);
|
dependance.registerSingleton(LiveMapperHelper.class, TikTokLiveMapperHelper.class);
|
||||||
|
dependance.registerSingleton(LiveMapper.class, (container) ->
|
||||||
|
{
|
||||||
|
var dependace = (DependanceContainer) container.find(DependanceContainer.class);
|
||||||
|
var mapper = MessagesMapperFactory.create(dependace);
|
||||||
|
onCustomMappings.forEach(action -> action.accept(mapper));
|
||||||
|
return mapper;
|
||||||
|
});
|
||||||
|
|
||||||
|
//mapper handlers
|
||||||
|
dependance.registerSingleton(TikTokCommonEventHandler.class);
|
||||||
|
dependance.registerSingleton(TikTokGiftEventHandler.class);
|
||||||
|
dependance.registerSingleton(TikTokRoomInfoEventHandler.class);
|
||||||
|
dependance.registerSingleton(TikTokSocialMediaEventHandler.class);
|
||||||
|
|
||||||
|
//client
|
||||||
|
dependance.registerSingleton(LiveClient.class, TikTokLiveClient.class);
|
||||||
|
|
||||||
|
onCustomDependencies.forEach(action -> action.accept(dependance));
|
||||||
|
var container = dependance.build();
|
||||||
|
|
||||||
|
var listenerManager = container.find(ListenersManager.class);
|
||||||
|
listeners.forEach(listenerManager::addListener);
|
||||||
|
return container.find(LiveClient.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveMapper createMapper(GiftsManager giftsManager, TikTokRoomInfo roomInfo) {
|
|
||||||
|
|
||||||
|
|
||||||
var eventMapper = new TikTokGenericEventMapper();
|
|
||||||
var mapper = new TikTokLiveMapper(new TikTokLiveMapperHelper(eventMapper));
|
|
||||||
|
|
||||||
//ConnectionEvents events
|
|
||||||
var commonHandler = new TikTokCommonEventHandler();
|
|
||||||
var giftHandler = new TikTokGiftEventHandler(giftsManager, roomInfo);
|
|
||||||
var roomInfoHandler = new TikTokRoomInfoEventHandler(roomInfo);
|
|
||||||
var socialHandler = new TikTokSocialMediaEventHandler(roomInfo);
|
|
||||||
|
|
||||||
|
|
||||||
mapper.forMessage(WebcastControlMessage.class, commonHandler::handleWebcastControlMessage);
|
|
||||||
|
|
||||||
//Room status events
|
|
||||||
mapper.forMessage(WebcastLiveIntroMessage.class, roomInfoHandler::handleIntro);
|
|
||||||
mapper.forMessage(WebcastRoomUserSeqMessage.class, roomInfoHandler::handleUserRanking);
|
|
||||||
mapper.forMessage(WebcastCaptionMessage.class, (inputBytes, messageName, mapperHelper) ->
|
|
||||||
{
|
|
||||||
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastCaptionMessage.class);
|
|
||||||
return MappingResult.of(messageObject, new TikTokCaptionEvent(messageObject));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
//User Interactions events
|
|
||||||
mapper.forMessage(WebcastChatMessage.class, (inputBytes, messageName, mapperHelper) ->
|
|
||||||
{
|
|
||||||
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastChatMessage.class);
|
|
||||||
return MappingResult.of(messageObject, new TikTokCommentEvent(messageObject));
|
|
||||||
});
|
|
||||||
mapper.forMessage(WebcastSubNotifyMessage.class, (inputBytes, messageName, mapperHelper) ->
|
|
||||||
{
|
|
||||||
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastSubNotifyMessage.class);
|
|
||||||
return MappingResult.of(messageObject, new TikTokSubscribeEvent(messageObject));
|
|
||||||
});
|
|
||||||
mapper.forMessage(WebcastEmoteChatMessage.class, (inputBytes, messageName, mapperHelper) ->
|
|
||||||
{
|
|
||||||
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastEmoteChatMessage.class);
|
|
||||||
return MappingResult.of(messageObject, new TikTokEmoteEvent(messageObject));
|
|
||||||
});
|
|
||||||
mapper.forMessage(WebcastQuestionNewMessage.class, (inputBytes, messageName, mapperHelper) ->
|
|
||||||
{
|
|
||||||
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastQuestionNewMessage.class);
|
|
||||||
return MappingResult.of(messageObject, new TikTokQuestionEvent(messageObject));
|
|
||||||
});
|
|
||||||
|
|
||||||
mapper.forMessage(WebcastLikeMessage.class, roomInfoHandler::handleLike);
|
|
||||||
mapper.forMessage(WebcastGiftMessage.class, giftHandler::handleGifts);
|
|
||||||
mapper.forMessage(WebcastSocialMessage.class, socialHandler::handle);
|
|
||||||
mapper.forMessage(WebcastMemberMessage.class, roomInfoHandler::handleMemberMessage);
|
|
||||||
|
|
||||||
|
|
||||||
//Host Interaction events
|
|
||||||
mapper.forMessage(WebcastPollMessage.class, commonHandler::handlePollEvent);
|
|
||||||
mapper.forMessage(WebcastRoomPinMessage.class, commonHandler::handlePinMessage);
|
|
||||||
mapper.forMessage(WebcastChatMessage.class, (inputBytes, messageName, mapperHelper) ->
|
|
||||||
{
|
|
||||||
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastChatMessage.class);
|
|
||||||
return MappingResult.of(messageObject, new TikTokCommentEvent(messageObject));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
//LinkMic events
|
|
||||||
mapper.forMessage(WebcastLinkMicBattle.class, (inputBytes, messageName, mapperHelper) -> {
|
|
||||||
var message = mapperHelper.bytesToWebcastObject(inputBytes, WebcastLinkMicBattle.class);
|
|
||||||
return MappingResult.of(message, new TikTokLinkMicBattleEvent(message));
|
|
||||||
});
|
|
||||||
mapper.forMessage(WebcastLinkMicArmies.class, (inputBytes, messageName, mapperHelper) -> {
|
|
||||||
var message = mapperHelper.bytesToWebcastObject(inputBytes, WebcastLinkMicArmies.class);
|
|
||||||
return MappingResult.of(message, new TikTokLinkMicArmiesEvent(message));
|
|
||||||
});
|
|
||||||
mapper.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);
|
|
||||||
|
|
||||||
//Rank events
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastRankTextMessage.class, TikTokRankTextEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastRankUpdateMessage.class, TikTokRankUpdateEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastHourlyRankMessage.class, TikTokRankUpdateEvent.class);
|
|
||||||
|
|
||||||
//Others events
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastInRoomBannerMessage.class, TikTokInRoomBannerEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastMsgDetectMessage.class, TikTokDetectEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastBarrageMessage.class, TikTokBarrageEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastUnauthorizedMemberMessage.class, TikTokUnauthorizedMemberEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastOecLiveShoppingMessage.class, TikTokShopEvent.class);
|
|
||||||
// mapper.webcastObjectToConstructor(WebcastImDeleteMessage.class, TikTokIMDeleteEvent.class);
|
|
||||||
// mapper.bytesToEvents(WebcastEnvelopeMessage.class, commonHandler::handleEnvelop);
|
|
||||||
|
|
||||||
|
|
||||||
onCustomMappings.accept(mapper);
|
|
||||||
return mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public LiveClient buildAndConnect() {
|
public LiveClient buildAndConnect() {
|
||||||
var client = build();
|
var client = build();
|
||||||
client.connect();
|
client.connect();
|
||||||
@@ -277,361 +199,9 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
return build().connectAsync();
|
return build().connectAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onUnhandledSocial(EventConsumer<TikTokUnhandledSocialEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokUnhandledSocialEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiveClientBuilder onChest(EventConsumer<TikTokChestEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokChestEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkMicFanTicket(EventConsumer<TikTokLinkMicFanTicketEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLinkMicFanTicketEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onEnvelope(EventConsumer<TikTokEnvelopeEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokEnvelopeEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onShop(EventConsumer<TikTokShopEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokShopEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onDetect(EventConsumer<TikTokDetectEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokDetectEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkLayer(EventConsumer<TikTokLinkLayerEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLinkLayerEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onConnected(EventConsumer<TikTokConnectedEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokConnectedEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onPreConnection(EventConsumer<TikTokPreConnectionEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokPreConnectionEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onCaption(EventConsumer<TikTokCaptionEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokCaptionEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onQuestion(EventConsumer<TikTokQuestionEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokQuestionEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onRoomPin(EventConsumer<TikTokRoomPinEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokRoomPinEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends TikTokEvent> LiveClientBuilder onEvent(Class<E> eventClass, EventConsumer<E> event) {
|
public <E extends TikTokEvent> LiveClientBuilder onEvent(Class<E> eventClass, EventConsumer<E> action) {
|
||||||
eventHandler.subscribe(eventClass, event);
|
eventHandler.subscribe(eventClass, action);
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TikTokLiveClientBuilder onRoomInfo(EventConsumer<TikTokRoomInfoEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokRoomInfoEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLivePaused(EventConsumer<TikTokLivePausedEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLivePausedEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TikTokLiveClientBuilder onLiveUnpaused(EventConsumer<TikTokLiveUnpausedEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLiveUnpausedEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLike(EventConsumer<TikTokLikeEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLikeEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLink(EventConsumer<TikTokLinkEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLinkEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onBarrage(EventConsumer<TikTokBarrageEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokBarrageEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onGift(EventConsumer<TikTokGiftEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokGiftEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onGiftCombo(EventConsumer<TikTokGiftComboEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokGiftComboEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkMicArmies(EventConsumer<TikTokLinkMicArmiesEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLinkMicArmiesEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onEmote(EventConsumer<TikTokEmoteEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokEmoteEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onUnauthorizedMember(EventConsumer<TikTokUnauthorizedMemberEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokUnauthorizedMemberEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onInRoomBanner(EventConsumer<TikTokInRoomBannerEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokInRoomBannerEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkMicMethod(EventConsumer<TikTokLinkMicMethodEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLinkMicMethodEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onSubscribe(EventConsumer<TikTokSubscribeEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokSubscribeEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onPoll(EventConsumer<TikTokPollEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokPollEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onFollow(EventConsumer<TikTokFollowEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokFollowEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onComment(EventConsumer<TikTokCommentEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokCommentEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LiveClientBuilder onHttpResponse(EventConsumer<TikTokHttpResponseEvent> action) {
|
|
||||||
eventHandler.subscribe(TikTokHttpResponseEvent.class, action);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onGoalUpdate(EventConsumer<TikTokGoalUpdateEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokGoalUpdateEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onRankUpdate(EventConsumer<TikTokRankUpdateEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokRankUpdateEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onIMDelete(EventConsumer<TikTokIMDeleteEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokIMDeleteEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLiveEnded(EventConsumer<TikTokLiveEndedEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLiveEndedEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onError(EventConsumer<TikTokErrorEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokErrorEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onJoin(EventConsumer<TikTokJoinEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokJoinEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onRankText(EventConsumer<TikTokRankTextEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokRankTextEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onShare(EventConsumer<TikTokShareEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokShareEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onUnhandledMember(EventConsumer<TikTokUnhandledMemberEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokUnhandledMemberEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onSubNotify(EventConsumer<TikTokSubNotifyEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokSubNotifyEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onLinkMicBattle(EventConsumer<TikTokLinkMicBattleEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokLinkMicBattleEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onDisconnected(EventConsumer<TikTokDisconnectedEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokDisconnectedEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onUnhandledControl(EventConsumer<TikTokUnhandledControlEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokUnhandledControlEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder onEvent(EventConsumer<TikTokEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TikTokLiveClientBuilder onWebsocketResponse(EventConsumer<TikTokWebsocketResponseEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokWebsocketResponseEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TikTokLiveClientBuilder onWebsocketMessage(EventConsumer<TikTokWebsocketMessageEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokWebsocketMessageEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TikTokLiveClientBuilder onWebsocketUnhandledMessage(EventConsumer<TikTokWebsocketUnhandledMessageEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokWebsocketUnhandledMessageEvent.class, event);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TikTokLiveClientBuilder onReconnecting(EventConsumer<TikTokReconnectingEvent> event) {
|
|
||||||
eventHandler.subscribe(TikTokReconnectingEvent.class, event);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,15 +23,13 @@
|
|||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveEventsHandler;
|
||||||
import io.github.jwdeveloper.tiktok.live.builder.EventConsumer;
|
import io.github.jwdeveloper.tiktok.live.builder.EventConsumer;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class TikTokLiveEventHandler {
|
public class TikTokLiveEventHandler implements LiveEventsHandler {
|
||||||
private final Map<Class<?>, Set<EventConsumer>> events;
|
private final Map<Class<?>, Set<EventConsumer>> events;
|
||||||
|
|
||||||
public TikTokLiveEventHandler() {
|
public TikTokLiveEventHandler() {
|
||||||
@@ -39,21 +37,8 @@ public class TikTokLiveEventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void publish(LiveClient tikTokLiveClient, TikTokEvent tikTokEvent) {
|
public void publish(LiveClient tikTokLiveClient, TikTokEvent tikTokEvent) {
|
||||||
if (events.containsKey(TikTokEvent.class)) {
|
Optional.ofNullable(events.get(TikTokEvent.class)).ifPresent(handlers -> handlers.forEach(handler -> handler.onEvent(tikTokLiveClient, tikTokEvent)));
|
||||||
var handlers = events.get(TikTokEvent.class);
|
Optional.ofNullable(events.get(tikTokEvent.getClass())).ifPresent(handlers -> handlers.forEach(handler -> handler.onEvent(tikTokLiveClient, tikTokEvent)));
|
||||||
for (var handle : handlers) {
|
|
||||||
handle.onEvent(tikTokLiveClient, tikTokEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!events.containsKey(tikTokEvent.getClass())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var handlers = events.get(tikTokEvent.getClass());
|
|
||||||
for (var handler : handlers) {
|
|
||||||
handler.onEvent(tikTokLiveClient, tikTokEvent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends TikTokEvent> void subscribe(Class<?> clazz, EventConsumer<T> event) {
|
public <T extends TikTokEvent> void subscribe(Class<?> clazz, EventConsumer<T> event) {
|
||||||
@@ -65,22 +50,10 @@ public class TikTokLiveEventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <T extends TikTokEvent> void unsubscribe(EventConsumer<T> consumer) {
|
public <T extends TikTokEvent> void unsubscribe(EventConsumer<T> consumer) {
|
||||||
for (var entry : events.entrySet()) {
|
events.forEach((key, value) -> value.remove(consumer));
|
||||||
entry.getValue().remove(consumer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends TikTokEvent> void unsubscribe(Class<?> clazz, EventConsumer<T> consumer) {
|
public <T extends TikTokEvent> void unsubscribe(Class<?> clazz, EventConsumer<T> consumer) {
|
||||||
if (clazz == null) {
|
Optional.ofNullable(clazz).map(events::get).ifPresent(consumers -> consumers.remove(consumer));
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!events.containsKey(clazz)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var eventSet = events.get(clazz);
|
|
||||||
eventSet.remove(consumer);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import io.github.jwdeveloper.dependance.injector.api.annotations.Inject;
|
||||||
import io.github.jwdeveloper.tiktok.common.*;
|
import io.github.jwdeveloper.tiktok.common.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.*;
|
import io.github.jwdeveloper.tiktok.data.requests.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
@@ -32,6 +33,7 @@ import io.github.jwdeveloper.tiktok.http.mappers.*;
|
|||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||||
|
|
||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class TikTokLiveHttpClient implements LiveHttpClient
|
public class TikTokLiveHttpClient implements LiveHttpClient
|
||||||
@@ -53,17 +55,19 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
private final GiftsDataMapper giftsDataMapper;
|
private final GiftsDataMapper giftsDataMapper;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
public TikTokLiveHttpClient(HttpClientFactory factory, LiveClientSettings settings) {
|
@Inject
|
||||||
|
public TikTokLiveHttpClient(HttpClientFactory factory) {
|
||||||
this.httpFactory = factory;
|
this.httpFactory = factory;
|
||||||
this.clientSettings = settings;
|
this.clientSettings = factory.getLiveClientSettings();
|
||||||
this.logger = LoggerFactory.create("HttpClient-"+hashCode(), clientSettings);
|
this.logger = LoggerFactory.create("HttpClient-"+hashCode(), clientSettings);
|
||||||
liveUserDataMapper = new LiveUserDataMapper();
|
liveUserDataMapper = new LiveUserDataMapper();
|
||||||
liveDataMapper = new LiveDataMapper();
|
liveDataMapper = new LiveDataMapper();
|
||||||
giftsDataMapper = new GiftsDataMapper();
|
giftsDataMapper = new GiftsDataMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokLiveHttpClient() {
|
public TikTokLiveHttpClient(Consumer<LiveClientSettings> consumer) {
|
||||||
this(new HttpClientFactory(LiveClientSettings.createDefault()), LiveClientSettings.createDefault());
|
this(new HttpClientFactory(LiveClientSettings.createDefault()));
|
||||||
|
consumer.accept(clientSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GiftsData.Response fetchRoomGiftsData(String room_id) {
|
public GiftsData.Response fetchRoomGiftsData(String room_id) {
|
||||||
@@ -103,6 +107,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
return getGiftsData();
|
return getGiftsData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(since = "1.8.6", forRemoval = true)
|
||||||
public GiftsData.Response getGiftsData() {
|
public GiftsData.Response getGiftsData() {
|
||||||
var result = httpFactory.client(TIKTOK_GIFTS_URL)
|
var result = httpFactory.client(TIKTOK_GIFTS_URL)
|
||||||
.build()
|
.build()
|
||||||
@@ -132,7 +137,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
var url = TIKTOK_URL_WEB + "api-live/user/room";
|
var url = TIKTOK_URL_WEB + "api-live/user/room";
|
||||||
var result = httpFactory.client(url)
|
var result = httpFactory.client(url)
|
||||||
.withParam("uniqueId", request.getUserName())
|
.withParam("uniqueId", request.getUserName())
|
||||||
.withParam("sourceType", "54")
|
.withParam("sourceType", "54") //MAGIC NUMBER, WHAT 54 means?
|
||||||
.build()
|
.build()
|
||||||
.toJsonResponse();
|
.toJsonResponse();
|
||||||
|
|
||||||
@@ -191,7 +196,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
.withParam("internal_ext", webcastResponse.getInternalExt())
|
.withParam("internal_ext", webcastResponse.getInternalExt())
|
||||||
.withParams(webcastResponse.getRouteParamsMapMap())
|
.withParams(webcastResponse.getRouteParamsMapMap())
|
||||||
.build()
|
.build()
|
||||||
.toUrl();
|
.toUri();
|
||||||
|
|
||||||
return new LiveConnectionData.Response(websocketCookie, webSocketUrl, webcastResponse);
|
return new LiveConnectionData.Response(websocketCookie, webSocketUrl, webcastResponse);
|
||||||
} catch (InvalidProtocolBufferException e) {
|
} catch (InvalidProtocolBufferException e) {
|
||||||
@@ -199,7 +204,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActionResult<HttpResponse<byte[]>> getStartingPayload(LiveConnectionData.Request request) {
|
protected ActionResult<HttpResponse<byte[]>> getStartingPayload(LiveConnectionData.Request request) {
|
||||||
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
||||||
if (proxyClientSettings.isEnabled()) {
|
if (proxyClientSettings.isEnabled()) {
|
||||||
while (proxyClientSettings.hasNext()) {
|
while (proxyClientSettings.hasNext()) {
|
||||||
@@ -211,10 +216,10 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
return getByteResponse(request.getRoomId());
|
return getByteResponse(request.getRoomId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActionResult<HttpResponse<byte[]>> getByteResponse(String room_id) {
|
protected ActionResult<HttpResponse<byte[]>> getByteResponse(String room_id) {
|
||||||
HttpClientBuilder builder = httpFactory.client(TIKTOK_SIGN_API)
|
HttpClientBuilder builder = httpFactory.client(TIKTOK_SIGN_API)
|
||||||
.withParam("client", "ttlive-java")
|
.withParam("client", "ttlive-java")
|
||||||
.withParam("uuc", "1")
|
.withParam("uuc", "1") //MAGIC NUMBER!
|
||||||
.withParam("room_id", room_id);
|
.withParam("room_id", room_id);
|
||||||
|
|
||||||
if (clientSettings.getApiKey() != null)
|
if (clientSettings.getApiKey() != null)
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
@@ -25,7 +47,7 @@ public class TikTokLiveHttpOfflineClient implements LiveHttpClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LiveUserData.Response fetchLiveUserData(LiveUserData.Request request) {
|
public LiveUserData.Response fetchLiveUserData(LiveUserData.Request request) {
|
||||||
return new LiveUserData.Response("", LiveUserData.UserStatus.Live, "offline_room_id", 0);
|
return new LiveUserData.Response("", LiveUserData.UserStatus.Live, "offline_room_id", 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,18 +30,20 @@ import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketRespons
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
|
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveMessageException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveMessageException;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.TikTokLiveMapper;
|
import io.github.jwdeveloper.tiktok.live.LiveEventsHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveMessagesHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.mappers.LiveMapper;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||||
import io.github.jwdeveloper.tiktok.utils.Stopwatch;
|
import io.github.jwdeveloper.tiktok.utils.Stopwatch;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
||||||
public class TikTokLiveMessageHandler {
|
public class TikTokLiveMessageHandler implements LiveMessagesHandler {
|
||||||
|
|
||||||
private final TikTokLiveEventHandler tikTokEventHandler;
|
private final LiveEventsHandler tikTokEventHandler;
|
||||||
private final TikTokLiveMapper mapper;
|
private final LiveMapper mapper;
|
||||||
|
|
||||||
public TikTokLiveMessageHandler(TikTokLiveEventHandler tikTokEventHandler, TikTokLiveMapper mapper) {
|
public TikTokLiveMessageHandler(LiveEventsHandler tikTokEventHandler, LiveMapper mapper) {
|
||||||
this.tikTokEventHandler = tikTokEventHandler;
|
this.tikTokEventHandler = tikTokEventHandler;
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
}
|
}
|
||||||
@@ -58,13 +60,13 @@ public class TikTokLiveMessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleSingleMessage(LiveClient client, WebcastResponse.Message message)
|
public void handleSingleMessage(LiveClient client, WebcastResponse.Message message) {
|
||||||
{
|
|
||||||
var messageClassName = message.getMethod();
|
var messageClassName = message.getMethod();
|
||||||
if (!mapper.isRegistered(messageClassName)) {
|
if (!mapper.isRegistered(messageClassName)) {
|
||||||
tikTokEventHandler.publish(client, new TikTokWebsocketUnhandledMessageEvent(message));
|
tikTokEventHandler.publish(client, new TikTokWebsocketUnhandledMessageEvent(message));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var stopwatch = new Stopwatch();
|
var stopwatch = new Stopwatch();
|
||||||
stopwatch.start();
|
stopwatch.start();
|
||||||
var events = mapper.handleMapping(messageClassName, message.getPayload().toByteArray());
|
var events = mapper.handleMapping(messageClassName, message.getPayload().toByteArray());
|
||||||
@@ -76,5 +78,4 @@ public class TikTokLiveMessageHandler {
|
|||||||
tikTokEventHandler.publish(client, event);
|
tikTokEventHandler.publish(client, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.common;
|
package io.github.jwdeveloper.tiktok.common;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
@@ -100,8 +122,8 @@ public class ActionResult<T> {
|
|||||||
public JsonObject toJson() {
|
public JsonObject toJson() {
|
||||||
JsonObject map = new JsonObject();
|
JsonObject map = new JsonObject();
|
||||||
map.addProperty("success", success);
|
map.addProperty("success", success);
|
||||||
map.add("content", gson.toJsonTree(content));
|
|
||||||
map.addProperty("message", message);
|
map.addProperty("message", message);
|
||||||
|
map.add("content", gson.toJsonTree(content));
|
||||||
map.add("previous", hasPrevious() ? previous.toJson() : null);
|
map.add("previous", hasPrevious() ? previous.toJson() : null);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.common;
|
package io.github.jwdeveloper.tiktok.common;
|
||||||
|
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.common;
|
package io.github.jwdeveloper.tiktok.common;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.gifts;
|
package io.github.jwdeveloper.tiktok.gifts;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||||
@@ -7,6 +29,7 @@ import java.util.*;
|
|||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
//TODO I should've been called it TikTokGiftsRepository
|
||||||
public class TikTokGiftsManager implements GiftsManager {
|
public class TikTokGiftsManager implements GiftsManager {
|
||||||
private final Map<Integer, Gift> giftsByIdIndex;
|
private final Map<Integer, Gift> giftsByIdIndex;
|
||||||
|
|
||||||
|
|||||||
@@ -90,14 +90,14 @@ public class HttpClient {
|
|||||||
return toResponse().map(HttpResponse::body);
|
return toResponse().map(HttpResponse::body);
|
||||||
}
|
}
|
||||||
|
|
||||||
public URI toUrl() {
|
public URI toUri() {
|
||||||
var stringUrl = prepareUrlWithParameters(url, httpClientSettings.getParams());
|
var stringUrl = prepareUrlWithParameters(url, httpClientSettings.getParams());
|
||||||
return URI.create(stringUrl);
|
return URI.create(stringUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpRequest prepareGetRequest() {
|
protected HttpRequest prepareGetRequest() {
|
||||||
var requestBuilder = HttpRequest.newBuilder().GET();
|
var requestBuilder = HttpRequest.newBuilder().GET();
|
||||||
requestBuilder.uri(toUrl());
|
requestBuilder.uri(toUri());
|
||||||
requestBuilder.timeout(httpClientSettings.getTimeout());
|
requestBuilder.timeout(httpClientSettings.getTimeout());
|
||||||
httpClientSettings.getHeaders().forEach(requestBuilder::setHeader);
|
httpClientSettings.getHeaders().forEach(requestBuilder::setHeader);
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,9 @@
|
|||||||
package io.github.jwdeveloper.tiktok.http;
|
package io.github.jwdeveloper.tiktok.http;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.settings.*;
|
import io.github.jwdeveloper.tiktok.data.settings.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class HttpClientFactory {
|
public class HttpClientFactory {
|
||||||
private final LiveClientSettings liveClientSettings;
|
private final LiveClientSettings liveClientSettings;
|
||||||
|
|
||||||
@@ -34,11 +36,4 @@ public class HttpClientFactory {
|
|||||||
public HttpClientBuilder client(String url) {
|
public HttpClientBuilder client(String url) {
|
||||||
return new HttpClientBuilder(url, liveClientSettings.getHttpSettings().clone());
|
return new HttpClientBuilder(url, liveClientSettings.getHttpSettings().clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Does not contains default httpClientSettings, Params, headers, etd
|
|
||||||
public HttpClientBuilder clientEmpty(String url) {
|
|
||||||
var settings = new HttpClientSettings();
|
|
||||||
settings.setProxyClientSettings(liveClientSettings.getHttpSettings().getProxyClientSettings());
|
|
||||||
return new HttpClientBuilder(url, settings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
public X509Certificate[] getAcceptedIssuers() { return null; }
|
public X509Certificate[] getAcceptedIssuers() { return null; }
|
||||||
}}, null);
|
}}, null);
|
||||||
|
|
||||||
URL url = toUrl().toURL();
|
URL url = toUri().toURL();
|
||||||
|
|
||||||
if (proxySettings.hasNext()) {
|
if (proxySettings.hasNext()) {
|
||||||
try {
|
try {
|
||||||
@@ -117,7 +117,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
|
|
||||||
var responseInfo = createResponseInfo(socksConnection.getResponseCode(), headers);
|
var responseInfo = createResponseInfo(socksConnection.getResponseCode(), headers);
|
||||||
|
|
||||||
var response = createHttpResponse(body, toUrl(), responseInfo);
|
var response = createHttpResponse(body, toUri(), responseInfo);
|
||||||
|
|
||||||
return ActionResult.success(response);
|
return ActionResult.success(response);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ 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;
|
import java.util.List;
|
||||||
|
|
||||||
public class GiftsDataMapper {
|
public class GiftsDataMapper {
|
||||||
@@ -56,9 +57,13 @@ public class GiftsDataMapper {
|
|||||||
var parsedJson = JsonParser.parseString(json);
|
var parsedJson = JsonParser.parseString(json);
|
||||||
var jsonObject = parsedJson.getAsJsonObject();
|
var jsonObject = parsedJson.getAsJsonObject();
|
||||||
if (jsonObject.get("data") instanceof JsonObject data && data.get("gifts") instanceof JsonArray giftArray) {
|
if (jsonObject.get("data") instanceof JsonObject data && data.get("gifts") instanceof JsonArray giftArray) {
|
||||||
var gifts = giftArray.asList().parallelStream()
|
var gifts = new ArrayList<Gift>();
|
||||||
.map(this::mapSingleRoomGift)
|
|
||||||
.toList();
|
for(int i = 0; i < giftArray.size(); i++) {
|
||||||
|
JsonElement element = giftArray.get(i);
|
||||||
|
Gift gift = mapSingleRoomGift(element);
|
||||||
|
gifts.add(gift);
|
||||||
|
}
|
||||||
|
|
||||||
return new GiftsData.Response(json, gifts);
|
return new GiftsData.Response(json, gifts);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.http.mappers;
|
package io.github.jwdeveloper.tiktok.http.mappers;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.http.mappers;
|
package io.github.jwdeveloper.tiktok.http.mappers;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ public class LiveDataMapper {
|
|||||||
var link = pictureElement.getAsJsonArray("url_list").get(1).getAsString();
|
var link = pictureElement.getAsJsonArray("url_list").get(1).getAsString();
|
||||||
var picture = new Picture(link);
|
var picture = new Picture(link);
|
||||||
|
|
||||||
var user = new User(id, name, profileName, picture, followers, followingCount, new ArrayList<>());
|
var user = new User(id, name, profileName, picture, followingCount, followers, new ArrayList<>());
|
||||||
user.addAttribute(UserAttribute.LiveHost);
|
user.addAttribute(UserAttribute.LiveHost);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,12 @@
|
|||||||
package io.github.jwdeveloper.tiktok.http.mappers;
|
package io.github.jwdeveloper.tiktok.http.mappers;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
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.List;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class LiveUserDataMapper
|
public class LiveUserDataMapper
|
||||||
@@ -40,17 +43,18 @@ public class LiveUserDataMapper
|
|||||||
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);
|
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1, null);
|
||||||
}
|
}
|
||||||
//live -> status 2
|
//live -> status 2
|
||||||
//live paused -> 3
|
//live paused -> 3
|
||||||
//not live -> status 4
|
//not live -> status 4
|
||||||
var element = jsonObject.get("data");
|
var element = jsonObject.get("data");
|
||||||
if (element.isJsonNull()) {
|
if (element.isJsonNull()) {
|
||||||
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1);
|
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1, null);
|
||||||
}
|
}
|
||||||
var data = element.getAsJsonObject();
|
var data = element.getAsJsonObject();
|
||||||
var user = data.getAsJsonObject("user");
|
var user = data.getAsJsonObject("user");
|
||||||
|
var stats = data.getAsJsonObject("stats");
|
||||||
var roomId = user.get("roomId").getAsString();
|
var roomId = user.get("roomId").getAsString();
|
||||||
var status = user.get("status").getAsInt();
|
var status = user.get("status").getAsInt();
|
||||||
|
|
||||||
@@ -64,10 +68,19 @@ public class LiveUserDataMapper
|
|||||||
default -> LiveUserData.UserStatus.NotFound;
|
default -> LiveUserData.UserStatus.NotFound;
|
||||||
};
|
};
|
||||||
|
|
||||||
return new LiveUserData.Response(json, statusEnum, roomId, startTime);
|
User foundUser = new User(
|
||||||
|
Long.parseLong(user.get("id").getAsString()),
|
||||||
|
user.get("uniqueId").getAsString(),
|
||||||
|
user.get("nickname").getAsString(),
|
||||||
|
new Picture(user.get("avatarLarger").getAsString()),
|
||||||
|
stats.get("followingCount").getAsLong(),
|
||||||
|
stats.get("followerCount").getAsLong(),
|
||||||
|
List.of());
|
||||||
|
|
||||||
|
return new LiveUserData.Response(json, statusEnum, roomId, startTime, foundUser);
|
||||||
} catch (JsonSyntaxException | IllegalStateException e) {
|
} catch (JsonSyntaxException | IllegalStateException e) {
|
||||||
logger.warning("Malformed Json: '"+json+"' - Error Message: "+e.getMessage());
|
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, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,19 +22,26 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.listener;
|
package io.github.jwdeveloper.tiktok.listener;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.Priority;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.live.builder.EventConsumer;
|
import io.github.jwdeveloper.tiktok.live.builder.EventConsumer;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
import lombok.Value;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
@Value
|
@Data
|
||||||
public class ListenerBindingModel
|
public class ListenerMethodInfo {
|
||||||
{
|
private Object listener;
|
||||||
|
|
||||||
TikTokEventListener listener;
|
private Class eventType;
|
||||||
|
|
||||||
Map<Class<?>, List<EventConsumer<?>>> events;
|
private Method method;
|
||||||
|
|
||||||
|
private Priority priority;
|
||||||
|
|
||||||
|
private boolean async;
|
||||||
|
|
||||||
|
private EventConsumer action = (a, b) -> {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -23,103 +23,135 @@
|
|||||||
package io.github.jwdeveloper.tiktok.listener;
|
package io.github.jwdeveloper.tiktok.listener;
|
||||||
|
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.TikTokLiveEventHandler;
|
import io.github.jwdeveloper.dependance.api.DependanceContainer;
|
||||||
import io.github.jwdeveloper.tiktok.annotations.TikTokEventObserver;
|
import io.github.jwdeveloper.tiktok.annotations.TikTokEventObserver;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokEventListenerMethodException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokEventListenerMethodException;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveEventsHandler;
|
||||||
import io.github.jwdeveloper.tiktok.live.builder.EventConsumer;
|
import io.github.jwdeveloper.tiktok.live.builder.EventConsumer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.List;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
public class TikTokListenersManager implements ListenersManager {
|
public class TikTokListenersManager implements ListenersManager {
|
||||||
private final TikTokLiveEventHandler eventObserver;
|
|
||||||
private final List<ListenerBindingModel> bindingModels;
|
|
||||||
|
|
||||||
public TikTokListenersManager(List<TikTokEventListener> listeners, TikTokLiveEventHandler tikTokEventHandler) {
|
private final Map<Object, List<ListenerMethodInfo>> listeners;
|
||||||
this.eventObserver = tikTokEventHandler;
|
private final LiveEventsHandler eventsHandler;
|
||||||
this.bindingModels = new ArrayList<>(listeners.size());
|
private final ExecutorService executorService;
|
||||||
for (var listener : listeners) {
|
private final DependanceContainer dependanceContainer;
|
||||||
addListener(listener);
|
|
||||||
}
|
|
||||||
|
public TikTokListenersManager(LiveEventsHandler tikTokEventHandler,
|
||||||
|
DependanceContainer dependanceContainer) {
|
||||||
|
this.eventsHandler = tikTokEventHandler;
|
||||||
|
this.dependanceContainer = dependanceContainer;
|
||||||
|
this.listeners = new HashMap<>();
|
||||||
|
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TikTokEventListener> getListeners() {
|
public List<Object> getListeners() {
|
||||||
return bindingModels.stream().map(ListenerBindingModel::getListener).toList();
|
return listeners.keySet().stream().toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addListener(TikTokEventListener listener) {
|
public void addListener(Object listener) {
|
||||||
var alreadyExists = bindingModels.stream().filter(e -> e.getListener() == listener).findAny();
|
if (listeners.containsKey(listener)) {
|
||||||
if (alreadyExists.isPresent()) {
|
|
||||||
throw new TikTokLiveException("Listener " + listener.getClass() + " has already been registered");
|
throw new TikTokLiveException("Listener " + listener.getClass() + " has already been registered");
|
||||||
}
|
}
|
||||||
var bindingModel = bindToEvents(listener);
|
|
||||||
|
|
||||||
for (var eventEntrySet : bindingModel.getEvents().entrySet()) {
|
var methodsInfo = getMethodsInfo(listener);
|
||||||
var eventType = eventEntrySet.getKey();
|
for (var methodInfo : methodsInfo) {
|
||||||
for (var methods : eventEntrySet.getValue()) {
|
eventsHandler.subscribe(methodInfo.getEventType(), methodInfo.getAction());
|
||||||
eventObserver.subscribe(eventType, methods);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
bindingModels.add(bindingModel);
|
listeners.put(listener, methodsInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeListener(TikTokEventListener listener) {
|
public void removeListener(Object listener) {
|
||||||
var optional = bindingModels.stream().filter(e -> e.getListener() == listener).findAny();
|
if (!listeners.containsKey(listener)) {
|
||||||
if (optional.isEmpty()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var methodsInfo = listeners.get(listener);
|
||||||
var bindingModel = optional.get();
|
for (var methodInfo : methodsInfo) {
|
||||||
|
eventsHandler.unsubscribe(methodInfo.getEventType(), methodInfo.getAction());
|
||||||
for (var eventEntrySet : bindingModel.getEvents().entrySet()) {
|
|
||||||
var eventType = eventEntrySet.getKey();
|
|
||||||
for (var methods : eventEntrySet.getValue()) {
|
|
||||||
eventObserver.unsubscribe(eventType, methods);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
bindingModels.remove(optional.get());
|
listeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenerBindingModel bindToEvents(TikTokEventListener listener) {
|
private List<ListenerMethodInfo> getMethodsInfo(Object listener) {
|
||||||
|
return Arrays.stream(listener.getClass().getDeclaredMethods())
|
||||||
|
.filter(e -> e.isAnnotationPresent(TikTokEventObserver.class))
|
||||||
|
.filter(e -> e.getParameterCount() >= 1)
|
||||||
|
.map(method -> getSingleMethodInfo(listener, method))
|
||||||
|
.sorted(Comparator.comparingInt(a -> a.getPriority().value))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
var clazz = listener.getClass();
|
private ListenerMethodInfo getSingleMethodInfo(Object listener, Method method) {
|
||||||
var methods = Arrays.stream(clazz.getDeclaredMethods()).filter(m ->
|
|
||||||
m.getParameterCount() == 2 &&
|
|
||||||
m.isAnnotationPresent(TikTokEventObserver.class)).toList();
|
|
||||||
var eventsMap = new HashMap<Class<?>, List<EventConsumer<?>>>();
|
|
||||||
for (var method : methods) {
|
|
||||||
var liveclientClass = method.getParameterTypes()[0];
|
|
||||||
var eventClass = method.getParameterTypes()[1];
|
|
||||||
|
|
||||||
if (!LiveClient.class.isAssignableFrom(liveclientClass) && !liveclientClass.equals(LiveClient.class)) {
|
method.setAccessible(true);
|
||||||
throw new TikTokEventListenerMethodException("Method " + method.getName() + "() 1st parameter must be instance of " + LiveClient.class.getName()
|
var annotation = method.getAnnotation(TikTokEventObserver.class);
|
||||||
+ " | Invalid parameter class: "+liveclientClass.getName());
|
var tiktokEventType = Arrays.stream(method.getParameterTypes())
|
||||||
}
|
.filter(TikTokEvent.class::isAssignableFrom)
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new TikTokEventListenerMethodException("Method " + method.getName() + "() must have only one parameter that inherits from class " + TikTokEvent.class.getName()));
|
||||||
|
|
||||||
if (!TikTokEvent.class.isAssignableFrom(eventClass) && !eventClass.equals(TikTokEvent.class)) {
|
var info = new ListenerMethodInfo();
|
||||||
throw new TikTokEventListenerMethodException("Method " + method.getName() + "() 2nd parameter must be instance of " + TikTokEvent.class.getName()
|
info.setListener(listener);
|
||||||
+ " | Invalid parameter class: "+eventClass.getName());
|
info.setAsync(annotation.async());
|
||||||
}
|
info.setPriority(annotation.priority());
|
||||||
|
info.setEventType(tiktokEventType);
|
||||||
|
info.setAction(createAction(listener, method, tiktokEventType));
|
||||||
|
|
||||||
EventConsumer eventMethodRef = (liveClient, event) ->
|
if (info.isAsync()) {
|
||||||
|
var action = info.getAction();
|
||||||
|
info.setAction((liveClient, event) ->
|
||||||
{
|
{
|
||||||
try {
|
executorService.submit(() ->
|
||||||
method.setAccessible(true);
|
{
|
||||||
method.invoke(listener, liveClient, event);
|
action.onEvent(liveClient, event);
|
||||||
} catch (Exception e) {
|
});
|
||||||
throw new TikTokEventListenerMethodException(e);
|
});
|
||||||
}
|
|
||||||
};
|
|
||||||
eventsMap.computeIfAbsent(eventClass, (a) -> new ArrayList<>()).add(eventMethodRef);
|
|
||||||
}
|
}
|
||||||
return new ListenerBindingModel(listener, eventsMap);
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//I know, implementation of this might look complicated
|
||||||
|
private EventConsumer createAction(Object listener, Method method, Class tiktokEventType) {
|
||||||
|
AtomicReference<Object> eventObjectRef = new AtomicReference<>();
|
||||||
|
var methodContainer = dependanceContainer.createChildContainer()
|
||||||
|
.configure(configuration ->
|
||||||
|
{
|
||||||
|
//Modifying container, so it returns TikTokEvent object instance,
|
||||||
|
//when TikTokEvent type is encountered in the methods parameters
|
||||||
|
configuration.onInjection(injectionEvent ->
|
||||||
|
{
|
||||||
|
if (injectionEvent.input().isAssignableFrom(tiktokEventType)) {
|
||||||
|
return eventObjectRef.get();
|
||||||
|
}
|
||||||
|
return injectionEvent.output();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return (liveClient, event) ->
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
eventObjectRef.set(event);
|
||||||
|
//Creating list of input objects based on method parameters
|
||||||
|
//Objects are received from container
|
||||||
|
var parameters = methodContainer.resolveParameters(method);
|
||||||
|
method.invoke(listener, parameters);
|
||||||
|
} catch (Exception e) {
|
||||||
|
eventsHandler.publish(liveClient, new TikTokErrorEvent(new TikTokEventListenerMethodException(e)));
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* 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.mappers;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.dependance.api.DependanceContainer;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.link.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
||||||
|
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokCommonEventHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokGiftEventHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokRoomInfoEventHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.mappers.handlers.TikTokSocialMediaEventHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
||||||
|
|
||||||
|
import static io.github.jwdeveloper.tiktok.messages.enums.LinkMessageType.*;
|
||||||
|
|
||||||
|
public class MessagesMapperFactory {
|
||||||
|
public static TikTokLiveMapper create(DependanceContainer container) {
|
||||||
|
|
||||||
|
var helper = container.find(LiveMapperHelper.class);
|
||||||
|
var mapper = new TikTokLiveMapper(helper);
|
||||||
|
|
||||||
|
//ConnectionEvents events
|
||||||
|
var commonHandler = container.find(TikTokCommonEventHandler.class);
|
||||||
|
var giftHandler = container.find(TikTokGiftEventHandler.class);
|
||||||
|
var roomInfoHandler = container.find(TikTokRoomInfoEventHandler.class);
|
||||||
|
var socialHandler = container.find(TikTokSocialMediaEventHandler.class);
|
||||||
|
|
||||||
|
|
||||||
|
mapper.forMessage(WebcastControlMessage.class, commonHandler::handleWebcastControlMessage);
|
||||||
|
|
||||||
|
//Room status events
|
||||||
|
mapper.forMessage(WebcastLiveIntroMessage.class, roomInfoHandler::handleIntro);
|
||||||
|
mapper.forMessage(WebcastRoomUserSeqMessage.class, roomInfoHandler::handleUserRanking);
|
||||||
|
mapper.forMessage(WebcastCaptionMessage.class, (inputBytes, messageName, mapperHelper) ->
|
||||||
|
{
|
||||||
|
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastCaptionMessage.class);
|
||||||
|
return MappingResult.of(messageObject, new TikTokCaptionEvent(messageObject));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//User Interactions events
|
||||||
|
mapper.forMessage(WebcastChatMessage.class, (inputBytes, messageName, mapperHelper) ->
|
||||||
|
{
|
||||||
|
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastChatMessage.class);
|
||||||
|
return MappingResult.of(messageObject, new TikTokCommentEvent(messageObject));
|
||||||
|
});
|
||||||
|
mapper.forMessage(WebcastSubNotifyMessage.class, (inputBytes, messageName, mapperHelper) ->
|
||||||
|
{
|
||||||
|
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastSubNotifyMessage.class);
|
||||||
|
return MappingResult.of(messageObject, new TikTokSubscribeEvent(messageObject));
|
||||||
|
});
|
||||||
|
mapper.forMessage(WebcastEmoteChatMessage.class, (inputBytes, messageName, mapperHelper) ->
|
||||||
|
{
|
||||||
|
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastEmoteChatMessage.class);
|
||||||
|
return MappingResult.of(messageObject, new TikTokEmoteEvent(messageObject));
|
||||||
|
});
|
||||||
|
mapper.forMessage(WebcastQuestionNewMessage.class, (inputBytes, messageName, mapperHelper) ->
|
||||||
|
{
|
||||||
|
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastQuestionNewMessage.class);
|
||||||
|
return MappingResult.of(messageObject, new TikTokQuestionEvent(messageObject));
|
||||||
|
});
|
||||||
|
|
||||||
|
mapper.forMessage(WebcastLikeMessage.class, roomInfoHandler::handleLike);
|
||||||
|
mapper.forMessage(WebcastGiftMessage.class, giftHandler::handleGifts);
|
||||||
|
mapper.forMessage(WebcastSocialMessage.class, socialHandler::handle);
|
||||||
|
mapper.forMessage(WebcastMemberMessage.class, roomInfoHandler::handleMemberMessage);
|
||||||
|
|
||||||
|
//Host Interaction events
|
||||||
|
mapper.forMessage(WebcastPollMessage.class, commonHandler::handlePollEvent);
|
||||||
|
mapper.forMessage(WebcastRoomPinMessage.class, commonHandler::handlePinMessage);
|
||||||
|
mapper.forMessage(WebcastChatMessage.class, (inputBytes, messageName, mapperHelper) ->
|
||||||
|
{
|
||||||
|
var messageObject = mapperHelper.bytesToWebcastObject(inputBytes, WebcastChatMessage.class);
|
||||||
|
return MappingResult.of(messageObject, new TikTokCommentEvent(messageObject));
|
||||||
|
});
|
||||||
|
|
||||||
|
//LinkMic events
|
||||||
|
mapper.forMessage(WebcastLinkMicBattle.class, (inputBytes, messageName, mapperHelper) -> {
|
||||||
|
var message = mapperHelper.bytesToWebcastObject(inputBytes, WebcastLinkMicBattle.class);
|
||||||
|
return MappingResult.of(message, new TikTokLinkMicBattleEvent(message));
|
||||||
|
});
|
||||||
|
mapper.forMessage(WebcastLinkMicArmies.class, (inputBytes, messageName, mapperHelper) -> {
|
||||||
|
var message = mapperHelper.bytesToWebcastObject(inputBytes, WebcastLinkMicArmies.class);
|
||||||
|
return MappingResult.of(message, new TikTokLinkMicArmiesEvent(message));
|
||||||
|
});
|
||||||
|
mapper.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_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);
|
||||||
|
|
||||||
|
//Rank events
|
||||||
|
// mapper.webcastObjectToConstructor(WebcastRankTextMessage.class, TikTokRankTextEvent.class);
|
||||||
|
// mapper.webcastObjectToConstructor(WebcastRankUpdateMessage.class, TikTokRankUpdateEvent.class);
|
||||||
|
// mapper.webcastObjectToConstructor(WebcastHourlyRankMessage.class, TikTokRankUpdateEvent.class);
|
||||||
|
|
||||||
|
//Others events
|
||||||
|
// mapper.webcastObjectToConstructor(WebcastInRoomBannerMessage.class, TikTokInRoomBannerEvent.class);
|
||||||
|
// mapper.webcastObjectToConstructor(WebcastMsgDetectMessage.class, TikTokDetectEvent.class);
|
||||||
|
// mapper.webcastObjectToConstructor(WebcastBarrageMessage.class, TikTokBarrageEvent.class);
|
||||||
|
// mapper.webcastObjectToConstructor(WebcastUnauthorizedMemberMessage.class, TikTokUnauthorizedMemberEvent.class);
|
||||||
|
// mapper.webcastObjectToConstructor(WebcastOecLiveShoppingMessage.class, TikTokShopEvent.class);
|
||||||
|
// mapper.webcastObjectToConstructor(WebcastImDeleteMessage.class, TikTokIMDeleteEvent.class);
|
||||||
|
// mapper.bytesToEvents(WebcastEnvelopeMessage.class, commonHandler::handleEnvelop);
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,26 +27,24 @@ import io.github.jwdeveloper.tiktok.exceptions.TikTokMessageMappingException;
|
|||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Goal of this class is to map ProtocolBuffer objects to TikTok Event in generic way
|
* Goal of this class is to map ProtocolBuffer objects to TikTok Event in generic way
|
||||||
*
|
* <ul>
|
||||||
* First parameter is ProtocolBuffer class type
|
* <li>First parameter is ProtocolBuffer class type</li>
|
||||||
* Second parameters is TikTokEvent class type
|
* <li>Second parameters is TikTokEvent class type</li>
|
||||||
* Third parameters is bytes payload
|
* <li>Third parameters is bytes payload</li>
|
||||||
*
|
* </ul>
|
||||||
* mapToEvent(WebcastGiftMessage.class, TikTokGiftEvent.class, payload)
|
* <p>mapToEvent(WebcastGiftMessage.class, TikTokGiftEvent.class, payload)</p>
|
||||||
*
|
* <p>How does it work?</p>
|
||||||
* How does it work?
|
* <ol>
|
||||||
* 1. Finds method `parseFrom(byte[] bytes)` inside ProtocolBuffer class
|
* <li>Finds method `parseFrom(byte[] bytes)` inside ProtocolBuffer class</li>
|
||||||
* 2. put payload to the method methods and create new instance of ProtcolBuffer object
|
* <li>Put payload to the method methods and create new instance of ProtcolBuffer object</li>
|
||||||
* 3. Finds in TikTokEvent constructor that takes ProtocolBuffer type as parameter
|
* <li>Finds in TikTokEvent constructor that takes ProtocolBuffer type as parameter</li>
|
||||||
* 4. create new Instance in TikTokEvents using object from step 2 and constructor from step 3
|
* <li>Create new Instance in TikTokEvents using object from step 2 and constructor from step 3</li>
|
||||||
*
|
* </ol>
|
||||||
* methodCache and constructorCache are used to boost performance
|
* methodCache and constructorCache are used to boost performance
|
||||||
*/
|
*/
|
||||||
public class TikTokGenericEventMapper {
|
public class TikTokGenericEventMapper {
|
||||||
|
|
||||||
@@ -55,7 +53,7 @@ public class TikTokGenericEventMapper {
|
|||||||
|
|
||||||
private final Map<Class<?>, Method> methodCache;
|
private final Map<Class<?>, Method> methodCache;
|
||||||
private final Map<TypePair, Constructor<?>> constructorCache;
|
private final Map<TypePair, Constructor<?>> constructorCache;
|
||||||
|
private static final String PARSE_FIELD = "parseFrom";
|
||||||
public TikTokGenericEventMapper() {
|
public TikTokGenericEventMapper() {
|
||||||
this.methodCache = new HashMap<>();
|
this.methodCache = new HashMap<>();
|
||||||
this.constructorCache = new HashMap<>();
|
this.constructorCache = new HashMap<>();
|
||||||
@@ -74,34 +72,27 @@ public class TikTokGenericEventMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Method getParsingMethod(Class<?> input) throws NoSuchMethodException {
|
public Method getParsingMethod(Class<?> input) throws RuntimeException {
|
||||||
if (methodCache.containsKey(input)) {
|
return methodCache.computeIfAbsent(input, aClass -> {
|
||||||
return methodCache.get(input);
|
try {
|
||||||
}
|
return aClass.getDeclaredMethod(PARSE_FIELD, byte[].class);
|
||||||
var method = input.getDeclaredMethod("parseFrom", byte[].class);
|
} catch (NoSuchMethodException e) {
|
||||||
methodCache.put(input, method);
|
throw new RuntimeException(e);
|
||||||
return method;
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Constructor<?> getParsingConstructor(Class<?> input, Class<?> output) {
|
private Constructor<?> getParsingConstructor(Class<?> input, Class<?> output) {
|
||||||
var pair = new TypePair(input, output);
|
return constructorCache.computeIfAbsent(new TypePair(input, output), pair -> {
|
||||||
if (constructorCache.containsKey(pair)) {
|
var optional = Arrays.stream(output.getConstructors())
|
||||||
return constructorCache.get(pair);
|
|
||||||
}
|
|
||||||
|
|
||||||
var optional = Arrays.stream(output.getConstructors())
|
|
||||||
.filter(ea -> Arrays.stream(ea.getParameterTypes())
|
.filter(ea -> Arrays.stream(ea.getParameterTypes())
|
||||||
.toList()
|
.toList()
|
||||||
.contains(input))
|
.contains(input))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
if (optional.isEmpty()) {
|
if (optional.isEmpty())
|
||||||
throw new TikTokMessageMappingException(input, output, "Unable to find constructor with input class type");
|
throw new TikTokMessageMappingException(input, output, "Unable to find constructor with input class type");
|
||||||
}
|
return optional.get();
|
||||||
|
});
|
||||||
constructorCache.put(pair, optional.get());
|
|
||||||
return optional.get();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -23,35 +23,28 @@
|
|||||||
package io.github.jwdeveloper.tiktok.mappers;
|
package io.github.jwdeveloper.tiktok.mappers;
|
||||||
|
|
||||||
import com.google.protobuf.GeneratedMessageV3;
|
import com.google.protobuf.GeneratedMessageV3;
|
||||||
import io.github.jwdeveloper.tiktok.TikTokLive;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingAction;
|
import io.github.jwdeveloper.tiktok.mappers.data.*;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class TikTokLiveMapper implements TikTokMapper {
|
public class TikTokLiveMapper implements LiveMapper {
|
||||||
|
|
||||||
private final Map<String, TikTokLiveMapperModel> mappers;
|
private final Map<String, TikTokLiveMapperModel> mappers;
|
||||||
private final TikTokMapperHelper mapperUtils;
|
private final LiveMapperHelper mapperUtils;
|
||||||
private final TikTokLiveMapperModel globalMapperModel;
|
private final TikTokLiveMapperModel globalMapperModel;
|
||||||
|
private static final String GLOBAL_MESSAGE = "GLOBAL MESSAGE";
|
||||||
|
|
||||||
public TikTokLiveMapper(TikTokMapperHelper mapperUtils) {
|
public TikTokLiveMapper(LiveMapperHelper mapperUtils) {
|
||||||
this.mappers = new HashMap<>();
|
this.mappers = new HashMap<>();
|
||||||
this.mapperUtils = mapperUtils;
|
this.mapperUtils = mapperUtils;
|
||||||
this.globalMapperModel = new TikTokLiveMapperModel("any message");
|
this.globalMapperModel = new TikTokLiveMapperModel(GLOBAL_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TikTokMapperModel forMessage(String messageName) {
|
public TikTokMapperModel forMessage(String messageName) {
|
||||||
if (!isRegistered(messageName)) {
|
return mappers.computeIfAbsent(messageName, TikTokLiveMapperModel::new);
|
||||||
var model = new TikTokLiveMapperModel(messageName);
|
|
||||||
mappers.put(messageName, model);
|
|
||||||
}
|
|
||||||
return mappers.get(messageName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -66,7 +59,6 @@ public class TikTokLiveMapper implements TikTokMapper {
|
|||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TikTokMapperModel forMessage(Class<? extends GeneratedMessageV3> mapperName, MappingAction<MappingResult> onMapping) {
|
public TikTokMapperModel forMessage(Class<? extends GeneratedMessageV3> mapperName, MappingAction<MappingResult> onMapping) {
|
||||||
var model = forMessage(mapperName);
|
var model = forMessage(mapperName);
|
||||||
@@ -84,7 +76,6 @@ public class TikTokLiveMapper implements TikTokMapper {
|
|||||||
return globalMapperModel;
|
return globalMapperModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isRegistered(String mapperName) {
|
public boolean isRegistered(String mapperName) {
|
||||||
return mappers.containsKey(mapperName);
|
return mappers.containsKey(mapperName);
|
||||||
}
|
}
|
||||||
@@ -94,23 +85,19 @@ public class TikTokLiveMapper implements TikTokMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<TikTokEvent> handleMapping(String messageName, byte[] bytes) {
|
public List<TikTokEvent> handleMapping(String messageName, byte[] bytes) {
|
||||||
if (!isRegistered(messageName)) {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
var mapperModel = mappers.get(messageName);
|
var mapperModel = mappers.get(messageName);
|
||||||
|
if (mapperModel == null)
|
||||||
|
return List.of();
|
||||||
|
|
||||||
var inputBytes = mapperModel.getOnBeforeMapping().onMapping(bytes, messageName, mapperUtils);
|
var inputBytes = mapperModel.getOnBeforeMapping().onMapping(bytes, messageName, mapperUtils);
|
||||||
var globalInputBytes = globalMapperModel.getOnBeforeMapping().onMapping(inputBytes, messageName, mapperUtils);
|
var globalInputBytes = globalMapperModel.getOnBeforeMapping().onMapping(inputBytes, messageName, mapperUtils);
|
||||||
|
|
||||||
|
|
||||||
var mappingResult = mapperModel.getOnMapping().onMapping(globalInputBytes, messageName, mapperUtils);
|
var mappingResult = mapperModel.getOnMapping().onMapping(globalInputBytes, messageName, mapperUtils);
|
||||||
|
|
||||||
if (mappingResult == null) {
|
if (mappingResult == null)
|
||||||
mappingResult = globalMapperModel.getOnMapping().onMapping(globalInputBytes, messageName, mapperUtils);
|
mappingResult = globalMapperModel.getOnMapping().onMapping(globalInputBytes, messageName, mapperUtils);
|
||||||
}
|
|
||||||
|
|
||||||
var afterMappingResult = mapperModel.getOnAfterMapping().apply(mappingResult);
|
var afterMappingResult = mapperModel.getOnAfterMapping().apply(mappingResult);
|
||||||
var globalAfterMappingResult = globalMapperModel.getOnAfterMapping().apply(MappingResult.of(mappingResult.getSource(), afterMappingResult));
|
return globalMapperModel.getOnAfterMapping().apply(MappingResult.of(mappingResult.getSource(), afterMappingResult));
|
||||||
return globalAfterMappingResult;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,10 @@ import io.github.jwdeveloper.tiktok.utils.JsonUtil;
|
|||||||
import io.github.jwdeveloper.tiktok.utils.ProtoBufferObject;
|
import io.github.jwdeveloper.tiktok.utils.ProtoBufferObject;
|
||||||
import io.github.jwdeveloper.tiktok.utils.ProtocolUtils;
|
import io.github.jwdeveloper.tiktok.utils.ProtocolUtils;
|
||||||
|
|
||||||
public class TikTokLiveMapperHelper implements TikTokMapperHelper {
|
public class TikTokLiveMapperHelper implements LiveMapperHelper {
|
||||||
|
|
||||||
|
private static final String PACKAGE_PREFIX = "io.github.jwdeveloper.tiktok.messages.webcast.";
|
||||||
|
|
||||||
private final TikTokGenericEventMapper genericMapper;
|
private final TikTokGenericEventMapper genericMapper;
|
||||||
|
|
||||||
public TikTokLiveMapperHelper(TikTokGenericEventMapper genericMapper) {
|
public TikTokLiveMapperHelper(TikTokGenericEventMapper genericMapper) {
|
||||||
@@ -39,6 +42,7 @@ public class TikTokLiveMapperHelper implements TikTokMapperHelper {
|
|||||||
public <T extends GeneratedMessageV3> T bytesToWebcastObject(byte[] bytes, Class<T> messageClass) {
|
public <T extends GeneratedMessageV3> T bytesToWebcastObject(byte[] bytes, Class<T> messageClass) {
|
||||||
try {
|
try {
|
||||||
var parsingMethod = genericMapper.getParsingMethod(messageClass);
|
var parsingMethod = genericMapper.getParsingMethod(messageClass);
|
||||||
|
//NULL is passed, since Parsing method is Static
|
||||||
var sourceObject = parsingMethod.invoke(null, bytes);
|
var sourceObject = parsingMethod.invoke(null, bytes);
|
||||||
return (T) sourceObject;
|
return (T) sourceObject;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -49,7 +53,7 @@ public class TikTokLiveMapperHelper implements TikTokMapperHelper {
|
|||||||
@Override
|
@Override
|
||||||
public Object bytesToWebcastObject(byte[] bytes, String messageName) {
|
public Object bytesToWebcastObject(byte[] bytes, String messageName) {
|
||||||
try {
|
try {
|
||||||
var packageName = "io.github.jwdeveloper.tiktok.messages.webcast." + messageName;
|
var packageName = PACKAGE_PREFIX + messageName;
|
||||||
var clazz = Class.forName(packageName);
|
var clazz = Class.forName(packageName);
|
||||||
return bytesToWebcastObject(bytes, (Class<? extends GeneratedMessageV3>) clazz);
|
return bytesToWebcastObject(bytes, (Class<? extends GeneratedMessageV3>) clazz);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -60,7 +64,7 @@ public class TikTokLiveMapperHelper implements TikTokMapperHelper {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isMessageHasProtoClass(String messageName) {
|
public boolean isMessageHasProtoClass(String messageName) {
|
||||||
try {
|
try {
|
||||||
var packageName = "io.github.jwdeveloper.tiktok.messages.webcast." + messageName;
|
var packageName = PACKAGE_PREFIX + messageName;
|
||||||
Class.forName(packageName);
|
Class.forName(packageName);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -75,5 +75,4 @@ public class TikTokLiveMapperModel implements TikTokMapperModel {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class TikTokCommonEventHandler
|
|||||||
var message = WebcastControlMessage.parseFrom(msg);
|
var message = WebcastControlMessage.parseFrom(msg);
|
||||||
return switch (message.getAction()) {
|
return switch (message.getAction()) {
|
||||||
case STREAM_PAUSED -> new TikTokLivePausedEvent();
|
case STREAM_PAUSED -> new TikTokLivePausedEvent();
|
||||||
case STREAM_ENDED -> new TikTokLiveEndedEvent();
|
case STREAM_ENDED, STREAM_SUSPENDED -> new TikTokLiveEndedEvent();
|
||||||
case STREAM_UNPAUSED -> new TikTokLiveUnpausedEvent();
|
case STREAM_UNPAUSED -> new TikTokLiveUnpausedEvent();
|
||||||
default -> new TikTokUnhandledControlEvent(message);
|
default -> new TikTokUnhandledControlEvent(message);
|
||||||
};
|
};
|
||||||
@@ -85,4 +85,4 @@ public class TikTokCommonEventHandler
|
|||||||
return List.of(new TikTokChestEvent(chest, msg));
|
return List.of(new TikTokChestEvent(chest, msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ 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.live.GiftsManager;
|
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.TikTokMapperHelper;
|
import io.github.jwdeveloper.tiktok.mappers.LiveMapperHelper;
|
||||||
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;
|
||||||
@@ -38,7 +38,6 @@ import java.util.*;
|
|||||||
public class TikTokGiftEventHandler {
|
public class TikTokGiftEventHandler {
|
||||||
private final Map<Long, WebcastGiftMessage> giftsMessages;
|
private final Map<Long, WebcastGiftMessage> giftsMessages;
|
||||||
private final TikTokRoomInfo tikTokRoomInfo;
|
private final TikTokRoomInfo tikTokRoomInfo;
|
||||||
|
|
||||||
private final GiftsManager giftsManager;
|
private final GiftsManager giftsManager;
|
||||||
|
|
||||||
public TikTokGiftEventHandler(GiftsManager giftsManager, TikTokRoomInfo tikTokRoomInfo) {
|
public TikTokGiftEventHandler(GiftsManager giftsManager, TikTokRoomInfo tikTokRoomInfo) {
|
||||||
@@ -48,18 +47,13 @@ public class TikTokGiftEventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public MappingResult handleGifts(byte[] msg, String name, TikTokMapperHelper helper) {
|
public MappingResult handleGifts(byte[] msg, String name, LiveMapperHelper helper) {
|
||||||
var currentMessage = WebcastGiftMessage.parseFrom(msg);
|
var currentMessage = WebcastGiftMessage.parseFrom(msg);
|
||||||
var gifts = handleGift(currentMessage);
|
var gifts = handleGift(currentMessage);
|
||||||
return MappingResult.of(currentMessage, gifts);
|
return MappingResult.of(currentMessage, gifts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TikTokEvent> handleGift(WebcastGiftMessage currentMessage) {
|
public List<TikTokEvent> handleGift(WebcastGiftMessage currentMessage) {
|
||||||
var userId = currentMessage.getUser().getId();
|
|
||||||
var currentType = GiftComboStateType.fromNumber(currentMessage.getSendType());
|
|
||||||
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, GiftComboStateType.Finished);
|
var comboEvent = getGiftComboEvent(currentMessage, GiftComboStateType.Finished);
|
||||||
@@ -67,7 +61,11 @@ public class TikTokGiftEventHandler {
|
|||||||
return List.of(comboEvent, giftEvent);
|
return List.of(comboEvent, giftEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!containsPreviousMessage) {
|
var userId = currentMessage.getUser().getId();
|
||||||
|
var currentType = GiftComboStateType.fromNumber(currentMessage.getSendType());
|
||||||
|
var previousMessage = giftsMessages.get(userId);
|
||||||
|
|
||||||
|
if (previousMessage == null) {
|
||||||
if (currentType == GiftComboStateType.Finished) {
|
if (currentType == GiftComboStateType.Finished) {
|
||||||
return List.of(getGiftEvent(currentMessage));
|
return List.of(getGiftEvent(currentMessage));
|
||||||
} else {
|
} else {
|
||||||
@@ -76,7 +74,6 @@ public class TikTokGiftEventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var previousMessage = giftsMessages.get(userId);
|
|
||||||
var previousType = GiftComboStateType.fromNumber(previousMessage.getSendType());
|
var previousType = GiftComboStateType.fromNumber(previousMessage.getSendType());
|
||||||
if (currentType == GiftComboStateType.Active &&
|
if (currentType == GiftComboStateType.Active &&
|
||||||
previousType == GiftComboStateType.Active) {
|
previousType == GiftComboStateType.Active) {
|
||||||
@@ -114,9 +111,9 @@ public class TikTokGiftEventHandler {
|
|||||||
gift = giftsManager.getByName(giftMessage.getGift().getName());
|
gift = giftsManager.getByName(giftMessage.getGift().getName());
|
||||||
if (gift == Gift.UNDEFINED) {
|
if (gift == Gift.UNDEFINED) {
|
||||||
gift = new Gift(giftId,
|
gift = new Gift(giftId,
|
||||||
giftMessage.getGift().getName(),
|
giftMessage.getGift().getName(),
|
||||||
giftMessage.getGift().getDiamondCount(),
|
giftMessage.getGift().getDiamondCount(),
|
||||||
Picture.map(giftMessage.getGift().getImage()));
|
Picture.map(giftMessage.getGift().getImage()));
|
||||||
|
|
||||||
giftsManager.attachGift(gift);
|
giftsManager.attachGift(gift);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import io.github.jwdeveloper.tiktok.data.events.social.TikTokJoinEvent;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.social.TikTokLikeEvent;
|
import io.github.jwdeveloper.tiktok.data.events.social.TikTokLikeEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.RankingUser;
|
import io.github.jwdeveloper.tiktok.data.models.RankingUser;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.TikTokMapperHelper;
|
import io.github.jwdeveloper.tiktok.mappers.LiveMapperHelper;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLikeMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLikeMessage;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLiveIntroMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLiveIntroMessage;
|
||||||
@@ -58,6 +58,7 @@ public class TikTokRoomInfoEventHandler {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public TikTokEvent handleUserRanking(byte[] msg) {
|
public TikTokEvent handleUserRanking(byte[] msg) {
|
||||||
var message = WebcastRoomUserSeqMessage.parseFrom(msg);
|
var message = WebcastRoomUserSeqMessage.parseFrom(msg);
|
||||||
|
var currentViewers = (int) message.getTotal();
|
||||||
var totalUsers = message.getTotalUser();
|
var totalUsers = message.getTotalUser();
|
||||||
var userRanking = message.getRanksListList().stream().map(RankingUser::new)
|
var userRanking = message.getRanksListList().stream().map(RankingUser::new)
|
||||||
.sorted((ru1, ru2) -> Integer.compare(ru2.getScore(), ru1.getScore()))
|
.sorted((ru1, ru2) -> Integer.compare(ru2.getScore(), ru1.getScore()))
|
||||||
@@ -65,6 +66,7 @@ public class TikTokRoomInfoEventHandler {
|
|||||||
|
|
||||||
return handleRoomInfo(tikTokRoomInfo ->
|
return handleRoomInfo(tikTokRoomInfo ->
|
||||||
{
|
{
|
||||||
|
tikTokRoomInfo.setViewersCount(currentViewers);
|
||||||
tikTokRoomInfo.setTotalViewersCount(totalUsers);
|
tikTokRoomInfo.setTotalViewersCount(totalUsers);
|
||||||
tikTokRoomInfo.updateRanking(userRanking);
|
tikTokRoomInfo.updateRanking(userRanking);
|
||||||
});
|
});
|
||||||
@@ -86,7 +88,7 @@ public class TikTokRoomInfoEventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public MappingResult handleMemberMessage(byte[] msg, String name, TikTokMapperHelper helper) {
|
public MappingResult handleMemberMessage(byte[] msg, String name, LiveMapperHelper helper) {
|
||||||
var message = WebcastMemberMessage.parseFrom(msg);
|
var message = WebcastMemberMessage.parseFrom(msg);
|
||||||
|
|
||||||
var event = switch (message.getAction()) {
|
var event = switch (message.getAction()) {
|
||||||
@@ -103,7 +105,7 @@ public class TikTokRoomInfoEventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public MappingResult handleLike(byte[] msg, String name, TikTokMapperHelper helper) {
|
public MappingResult handleLike(byte[] msg, String name, LiveMapperHelper helper) {
|
||||||
var message = WebcastLikeMessage.parseFrom(msg);
|
var message = WebcastLikeMessage.parseFrom(msg);
|
||||||
var event = new TikTokLikeEvent(message);
|
var event = new TikTokLikeEvent(message);
|
||||||
var roomInfoEvent = this.handleRoomInfo(tikTokRoomInfo ->
|
var roomInfoEvent = this.handleRoomInfo(tikTokRoomInfo ->
|
||||||
@@ -112,4 +114,4 @@ public class TikTokRoomInfoEventHandler {
|
|||||||
});
|
});
|
||||||
return MappingResult.of(message, List.of(event, roomInfoEvent));
|
return MappingResult.of(message, List.of(event, roomInfoEvent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,12 +22,13 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.websocket;
|
package io.github.jwdeveloper.tiktok.websocket;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.*;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.dto.ProxyData;
|
import io.github.jwdeveloper.tiktok.data.dto.ProxyData;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
|
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
|
||||||
import io.github.jwdeveloper.tiktok.data.settings.*;
|
import io.github.jwdeveloper.tiktok.data.settings.*;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.*;
|
import io.github.jwdeveloper.tiktok.exceptions.*;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveEventsHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveMessagesHandler;
|
||||||
import org.java_websocket.client.WebSocketClient;
|
import org.java_websocket.client.WebSocketClient;
|
||||||
|
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
@@ -35,24 +36,25 @@ import java.net.Proxy;
|
|||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class TikTokWebSocketClient implements SocketClient {
|
public class TikTokWebSocketClient implements LiveSocketClient {
|
||||||
private final LiveClientSettings clientSettings;
|
private final LiveClientSettings clientSettings;
|
||||||
private final TikTokLiveMessageHandler messageHandler;
|
private final LiveMessagesHandler messageHandler;
|
||||||
private final TikTokLiveEventHandler tikTokEventHandler;
|
private final LiveEventsHandler tikTokEventHandler;
|
||||||
|
private final WebSocketHeartbeatTask heartbeatTask;
|
||||||
private WebSocketClient webSocketClient;
|
private WebSocketClient webSocketClient;
|
||||||
|
|
||||||
private final TikTokWebSocketPingingTask pingingTask;
|
|
||||||
private boolean isConnected;
|
private boolean isConnected;
|
||||||
|
|
||||||
public TikTokWebSocketClient(
|
public TikTokWebSocketClient(
|
||||||
LiveClientSettings clientSettings,
|
LiveClientSettings clientSettings,
|
||||||
TikTokLiveMessageHandler messageHandler,
|
LiveMessagesHandler messageHandler,
|
||||||
TikTokLiveEventHandler tikTokEventHandler) {
|
LiveEventsHandler tikTokEventHandler,
|
||||||
|
WebSocketHeartbeatTask heartbeatTask)
|
||||||
|
{
|
||||||
this.clientSettings = clientSettings;
|
this.clientSettings = clientSettings;
|
||||||
this.messageHandler = messageHandler;
|
this.messageHandler = messageHandler;
|
||||||
this.tikTokEventHandler = tikTokEventHandler;
|
this.tikTokEventHandler = tikTokEventHandler;
|
||||||
|
this.heartbeatTask = heartbeatTask;
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
pingingTask = new TikTokWebSocketPingingTask();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,7 +65,7 @@ public class TikTokWebSocketClient implements SocketClient {
|
|||||||
|
|
||||||
messageHandler.handle(liveClient, connectionData.getWebcastResponse());
|
messageHandler.handle(liveClient, connectionData.getWebcastResponse());
|
||||||
|
|
||||||
var headers = new HashMap<>(clientSettings.getHttpSettings().getHeaders());
|
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 +84,7 @@ public class TikTokWebSocketClient implements SocketClient {
|
|||||||
private void connectDefault() {
|
private void connectDefault() {
|
||||||
try {
|
try {
|
||||||
webSocketClient.connect();
|
webSocketClient.connect();
|
||||||
pingingTask.run(webSocketClient, clientSettings.getPingInterval());
|
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
@@ -95,9 +97,15 @@ public class TikTokWebSocketClient implements SocketClient {
|
|||||||
if (proxySettings.getType() == Proxy.Type.SOCKS) {
|
if (proxySettings.getType() == Proxy.Type.SOCKS) {
|
||||||
SSLContext sc = SSLContext.getInstance("SSL");
|
SSLContext sc = SSLContext.getInstance("SSL");
|
||||||
sc.init(null, new TrustManager[]{new X509TrustManager() {
|
sc.init(null, new TrustManager[]{new X509TrustManager() {
|
||||||
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {}
|
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {
|
||||||
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {}
|
}
|
||||||
public X509Certificate[] getAcceptedIssuers() { return null; }
|
|
||||||
|
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}}, null);
|
}}, null);
|
||||||
webSocketClient.setSocketFactory(sc.getSocketFactory());
|
webSocketClient.setSocketFactory(sc.getSocketFactory());
|
||||||
}
|
}
|
||||||
@@ -112,7 +120,7 @@ public class TikTokWebSocketClient implements SocketClient {
|
|||||||
proxySettings.remove();
|
proxySettings.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pingingTask.run(webSocketClient, clientSettings.getPingInterval());
|
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -133,7 +141,7 @@ public class TikTokWebSocketClient implements SocketClient {
|
|||||||
public void stop() {
|
public void stop() {
|
||||||
if (isConnected && webSocketClient != null && webSocketClient.isOpen()) {
|
if (isConnected && webSocketClient != null && webSocketClient.isOpen()) {
|
||||||
webSocketClient.closeConnection(0, "");
|
webSocketClient.closeConnection(0, "");
|
||||||
pingingTask.stop();
|
heartbeatTask.stop();
|
||||||
}
|
}
|
||||||
webSocketClient = null;
|
webSocketClient = null;
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
|
|||||||
@@ -23,10 +23,11 @@
|
|||||||
package io.github.jwdeveloper.tiktok.websocket;
|
package io.github.jwdeveloper.tiktok.websocket;
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import io.github.jwdeveloper.tiktok.*;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.*;
|
import io.github.jwdeveloper.tiktok.data.events.*;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokProtocolBufferException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokProtocolBufferException;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveEventsHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveMessagesHandler;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
||||||
import org.java_websocket.client.WebSocketClient;
|
import org.java_websocket.client.WebSocketClient;
|
||||||
import org.java_websocket.drafts.Draft_6455;
|
import org.java_websocket.drafts.Draft_6455;
|
||||||
@@ -38,20 +39,20 @@ import java.util.*;
|
|||||||
|
|
||||||
public class TikTokWebSocketListener extends WebSocketClient {
|
public class TikTokWebSocketListener extends WebSocketClient {
|
||||||
|
|
||||||
private final TikTokLiveMessageHandler messageHandler;
|
private final LiveMessagesHandler messagesHandler;
|
||||||
private final TikTokLiveEventHandler tikTokEventHandler;
|
private final LiveEventsHandler eventHandler;
|
||||||
private final LiveClient tikTokLiveClient;
|
private final LiveClient liveClient;
|
||||||
|
|
||||||
public TikTokWebSocketListener(URI serverUri,
|
public TikTokWebSocketListener(URI serverUri,
|
||||||
Map<String, String> httpHeaders,
|
Map<String, String> httpHeaders,
|
||||||
int connectTimeout,
|
int connectTimeout,
|
||||||
TikTokLiveMessageHandler messageHandler,
|
LiveMessagesHandler messageHandler,
|
||||||
TikTokLiveEventHandler tikTokEventHandler,
|
LiveEventsHandler tikTokEventHandler,
|
||||||
LiveClient tikTokLiveClient) {
|
LiveClient tikTokLiveClient) {
|
||||||
super(serverUri, new Draft_6455(), httpHeaders, connectTimeout);
|
super(serverUri, new Draft_6455(), httpHeaders, connectTimeout);
|
||||||
this.messageHandler = messageHandler;
|
this.messagesHandler = messageHandler;
|
||||||
this.tikTokEventHandler = tikTokEventHandler;
|
this.eventHandler = tikTokEventHandler;
|
||||||
this.tikTokLiveClient = tikTokLiveClient;
|
this.liveClient = tikTokLiveClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -59,7 +60,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
try {
|
try {
|
||||||
handleBinary(bytes.array());
|
handleBinary(bytes.array());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
tikTokEventHandler.publish(tikTokLiveClient, new TikTokErrorEvent(e));
|
eventHandler.publish(liveClient, new TikTokErrorEvent(e));
|
||||||
}
|
}
|
||||||
if (isOpen()) {
|
if (isOpen()) {
|
||||||
sendPing();
|
sendPing();
|
||||||
@@ -83,12 +84,12 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
this.send(pushFrameBuilder.build().toByteArray());
|
this.send(pushFrameBuilder.build().toByteArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
messageHandler.handle(tikTokLiveClient, webcastResponse);
|
messagesHandler.handle(liveClient, webcastResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOpen(ServerHandshake serverHandshake) {
|
public void onOpen(ServerHandshake serverHandshake) {
|
||||||
tikTokEventHandler.publish(tikTokLiveClient, new TikTokConnectedEvent());
|
eventHandler.publish(liveClient, new TikTokConnectedEvent());
|
||||||
if (isOpen()) {
|
if (isOpen()) {
|
||||||
sendPing();
|
sendPing();
|
||||||
}
|
}
|
||||||
@@ -96,13 +97,13 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose(int code, String reason, boolean remote) {
|
public void onClose(int code, String reason, boolean remote) {
|
||||||
tikTokEventHandler.publish(tikTokLiveClient, new TikTokDisconnectedEvent(reason));
|
eventHandler.publish(liveClient, new TikTokDisconnectedEvent(reason));
|
||||||
tikTokLiveClient.disconnect();
|
liveClient.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Exception error) {
|
public void onError(Exception error) {
|
||||||
tikTokEventHandler.publish(tikTokLiveClient, new TikTokErrorEvent(error));
|
eventHandler.publish(liveClient, new TikTokErrorEvent(error));
|
||||||
if (isOpen()) {
|
if (isOpen()) {
|
||||||
sendPing();
|
sendPing();
|
||||||
}
|
}
|
||||||
@@ -130,6 +131,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(String s) {
|
public void onMessage(String s) {
|
||||||
// System.err.println(s);
|
//TODO we are not using this method, however I wounder if there might be
|
||||||
|
//so messages that are send as String from TikTok, for example some Jsons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +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.websocket;
|
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.TikTokConnectedEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokDisconnectedEvent;
|
import io.github.jwdeveloper.tiktok.data.events.TikTokDisconnectedEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
|
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveEventsHandler;
|
||||||
|
|
||||||
public class TikTokWebSocketOfflineClient implements SocketClient {
|
public class TikTokWebSocketOfflineClient implements LiveSocketClient {
|
||||||
|
|
||||||
private final TikTokLiveEventHandler handler;
|
private final LiveEventsHandler handler;
|
||||||
private LiveClient liveClient;
|
private LiveClient liveClient;
|
||||||
|
|
||||||
public TikTokWebSocketOfflineClient(TikTokLiveEventHandler handler) {
|
public TikTokWebSocketOfflineClient(LiveEventsHandler handler) {
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
package io.github.jwdeveloper.tiktok.websocket;
|
|
||||||
|
|
||||||
import org.java_websocket.WebSocket;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class TikTokWebSocketPingingTask
|
|
||||||
{
|
|
||||||
private Thread thread;
|
|
||||||
private boolean isRunning = false;
|
|
||||||
private final int MAX_TIMEOUT = 250;
|
|
||||||
private final int SLEEP_TIME = 500;
|
|
||||||
|
|
||||||
public void run(WebSocket webSocket, long pingTaskTime)
|
|
||||||
{
|
|
||||||
stop();
|
|
||||||
thread = new Thread(() -> pingTask(webSocket, pingTaskTime));
|
|
||||||
isRunning = true;
|
|
||||||
thread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop()
|
|
||||||
{
|
|
||||||
if (thread != null)
|
|
||||||
thread.interrupt();
|
|
||||||
isRunning = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void pingTask(WebSocket webSocket, long pingTaskTime)
|
|
||||||
{
|
|
||||||
var random = new Random();
|
|
||||||
while (isRunning) {
|
|
||||||
try {
|
|
||||||
if (!webSocket.isOpen()) {
|
|
||||||
Thread.sleep(SLEEP_TIME);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
webSocket.sendPing();
|
|
||||||
|
|
||||||
Thread.sleep(pingTaskTime+random.nextInt(MAX_TIMEOUT));
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
isRunning = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* 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.websocket;
|
||||||
|
|
||||||
|
import org.java_websocket.WebSocket;
|
||||||
|
|
||||||
|
public class WebSocketHeartbeatTask
|
||||||
|
{
|
||||||
|
private Thread thread;
|
||||||
|
private boolean isRunning = false;
|
||||||
|
private final int MAX_TIMEOUT = 250;
|
||||||
|
private final int SLEEP_TIME = 500;
|
||||||
|
private final byte[] heartbeatBytes = {58, 2, 104, 98}; // Byte Array of "3A026862" which is TikTok's custom heartbeat value
|
||||||
|
|
||||||
|
public void run(WebSocket webSocket, long pingTaskTime) {
|
||||||
|
stop();
|
||||||
|
thread = new Thread(() -> heartbeatTask(webSocket, pingTaskTime), "heartbeat-task");
|
||||||
|
isRunning = true;
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
if (thread != null)
|
||||||
|
thread.interrupt();
|
||||||
|
isRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void heartbeatTask(WebSocket webSocket, long pingTaskTime) {
|
||||||
|
while (isRunning) {
|
||||||
|
try {
|
||||||
|
if (webSocket.isOpen()) {
|
||||||
|
webSocket.send(heartbeatBytes);
|
||||||
|
Thread.sleep(pingTaskTime + (int) (Math.random() * MAX_TIMEOUT));
|
||||||
|
} else
|
||||||
|
Thread.sleep(SLEEP_TIME);
|
||||||
|
} catch (Exception e) {
|
||||||
|
//TODO we should display some kind of error message
|
||||||
|
isRunning = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.dependance.implementation.DependanceContainerBuilder;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.TikTokConnectedEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.TikTokDisconnectedEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.control.TikTokConnectingEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.control.TikTokPreConnectionEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.room.TikTokRoomInfoEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
|
||||||
|
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TikTokLiveClientTests extends TikTokTestBase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBeforeEachTest(LiveClientBuilder liveClientBuilder,
|
||||||
|
DependanceContainerBuilder containerBuilder) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldThrownWhenAlreadyConnected() {
|
||||||
|
roomInfoMock().setConnectionState(ConnectionState.CONNECTED);
|
||||||
|
Assert.assertThrows(TikTokLiveException.class, () ->
|
||||||
|
{
|
||||||
|
liveClient().connect();
|
||||||
|
});
|
||||||
|
Assert.assertEquals(ConnectionState.DISCONNECTED, roomInfoMock().getConnectionState());
|
||||||
|
AssertEvents(
|
||||||
|
TikTokErrorEvent.class,
|
||||||
|
TikTokDisconnectedEvent.class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldConnect() {
|
||||||
|
liveClient().connect();
|
||||||
|
Assert.assertEquals(ConnectionState.CONNECTED, roomInfoMock().getConnectionState());
|
||||||
|
AssertEvents(
|
||||||
|
TikTokConnectingEvent.class,
|
||||||
|
TikTokPreConnectionEvent.class,
|
||||||
|
TikTokConnectedEvent.class,
|
||||||
|
TikTokRoomInfoEvent.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.dependance.implementation.DependanceContainerBuilder;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveEventsHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
|
||||||
|
import io.github.jwdeveloper.tiktok.mocks.EventsHandlerMock;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for the unit tests
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
public abstract class TikTokTestBase {
|
||||||
|
|
||||||
|
private LiveClient liveClient;
|
||||||
|
|
||||||
|
private EventsHandlerMock eventsHandlerMock;
|
||||||
|
|
||||||
|
private TikTokRoomInfo roomInfoMock;
|
||||||
|
|
||||||
|
public void AssertEvents(Class<? extends TikTokEvent>... events) {
|
||||||
|
eventsHandlerMock.assertEvents(events);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
|
||||||
|
var builder = TikTokLive.newClient("test");
|
||||||
|
eventsHandlerMock = new EventsHandlerMock();
|
||||||
|
roomInfoMock = new TikTokRoomInfo();
|
||||||
|
roomInfoMock.setHostName("test");
|
||||||
|
liveClient = builder
|
||||||
|
.configure(liveClientSettings ->
|
||||||
|
{
|
||||||
|
liveClientSettings.setOffline(true);
|
||||||
|
liveClientSettings.setFetchGifts(false);
|
||||||
|
})
|
||||||
|
.customize(containerBuilder ->
|
||||||
|
{
|
||||||
|
containerBuilder.registerSingleton(LiveEventsHandler.class, eventsHandlerMock);
|
||||||
|
containerBuilder.registerSingleton(TikTokRoomInfo.class, roomInfoMock);
|
||||||
|
onBeforeEachTest(builder, containerBuilder);
|
||||||
|
}).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void onBeforeEachTest(LiveClientBuilder liveClientBuilder, DependanceContainerBuilder containerBuilder);
|
||||||
|
}
|
||||||
@@ -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.common;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
public class TikTokBaseTest
|
|
||||||
{
|
|
||||||
public byte[] getFileBytes(String path)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
var stream = getClass().getClassLoader().getResourceAsStream(path);
|
|
||||||
var bytes= stream.readAllBytes();
|
|
||||||
stream.close();
|
|
||||||
return bytes;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getFileBytesUtf(String path)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
var stream = getClass().getClassLoader().getResourceAsStream(path);
|
|
||||||
var bytes= stream.readAllBytes();
|
|
||||||
stream.close();
|
|
||||||
return Base64.getDecoder().decode(bytes);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +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.gifts;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
|
||||||
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
|
||||||
|
|
||||||
public class TikTokGiftManagerTest {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,10 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.listener;
|
package io.github.jwdeveloper.tiktok.listener;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.dependance.Dependance;
|
||||||
|
import io.github.jwdeveloper.dependance.api.DependanceContainer;
|
||||||
import io.github.jwdeveloper.tiktok.TikTokLiveEventHandler;
|
import io.github.jwdeveloper.tiktok.TikTokLiveEventHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.annotations.Priority;
|
||||||
import io.github.jwdeveloper.tiktok.annotations.TikTokEventObserver;
|
import io.github.jwdeveloper.tiktok.annotations.TikTokEventObserver;
|
||||||
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.gift.TikTokGiftEvent;
|
import io.github.jwdeveloper.tiktok.data.events.gift.TikTokGiftEvent;
|
||||||
@@ -44,27 +47,34 @@ class TikTokListenersManagerTest {
|
|||||||
|
|
||||||
private TikTokLiveEventHandler eventObserver;
|
private TikTokLiveEventHandler eventObserver;
|
||||||
private TikTokListenersManager tikTokListenersManager;
|
private TikTokListenersManager tikTokListenersManager;
|
||||||
|
private DependanceContainer dependanceContainer;
|
||||||
|
private LiveClient liveClient;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
eventObserver = Mockito.mock(TikTokLiveEventHandler.class);
|
|
||||||
List<TikTokEventListener> listeners = new ArrayList<>();
|
liveClient = Mockito.mock(LiveClient.class);
|
||||||
tikTokListenersManager = new TikTokListenersManager(listeners, eventObserver);
|
eventObserver = new TikTokLiveEventHandler();
|
||||||
|
|
||||||
|
dependanceContainer = Dependance.newContainer()
|
||||||
|
.registerSingleton(LiveClient.class, liveClient)
|
||||||
|
.build();
|
||||||
|
tikTokListenersManager = new TikTokListenersManager(eventObserver, dependanceContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void addListener() {
|
void addListener() {
|
||||||
TikTokEventListener listener =new TikTokEventListenerTest();
|
Object listener = new TikTokEventListenerTest();
|
||||||
tikTokListenersManager.addListener(listener);
|
tikTokListenersManager.addListener(listener);
|
||||||
|
|
||||||
List<TikTokEventListener> listeners = tikTokListenersManager.getListeners();
|
List<Object> listeners = tikTokListenersManager.getListeners();
|
||||||
assertEquals(1, listeners.size());
|
assertEquals(1, listeners.size());
|
||||||
assertSame(listener, listeners.get(0));
|
assertSame(listener, listeners.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void addListener_alreadyRegistered_throwsException() {
|
void addListener_alreadyRegistered_throwsException() {
|
||||||
TikTokEventListener listener = new TikTokEventListenerTest();
|
Object listener = new TikTokEventListenerTest();
|
||||||
tikTokListenersManager.addListener(listener);
|
tikTokListenersManager.addListener(listener);
|
||||||
|
|
||||||
Exception exception = assertThrows(TikTokLiveException.class, () -> {
|
Exception exception = assertThrows(TikTokLiveException.class, () -> {
|
||||||
@@ -76,39 +86,56 @@ class TikTokListenersManagerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void removeListener() {
|
void removeListener() {
|
||||||
TikTokEventListener listener = new TikTokEventListenerTest();
|
Object listener = new TikTokEventListenerTest();
|
||||||
tikTokListenersManager.addListener(listener);
|
tikTokListenersManager.addListener(listener);
|
||||||
tikTokListenersManager.removeListener(listener);
|
tikTokListenersManager.removeListener(listener);
|
||||||
|
|
||||||
List<TikTokEventListener> listeners = tikTokListenersManager.getListeners();
|
List<Object> listeners = tikTokListenersManager.getListeners();
|
||||||
assertTrue(listeners.isEmpty());
|
assertTrue(listeners.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldTriggerEvents() {
|
||||||
|
|
||||||
|
Object listener = new TikTokEventListenerTest();
|
||||||
|
tikTokListenersManager.addListener(listener);
|
||||||
|
|
||||||
|
|
||||||
|
var fakeGiftEvent = TikTokGiftEvent.of("TestRosa", 1, 1);
|
||||||
|
eventObserver.publish(liveClient, fakeGiftEvent);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void removeListener_notRegistered_doesNotThrow() {
|
void removeListener_notRegistered_doesNotThrow() {
|
||||||
TikTokEventListener listener = new TikTokEventListenerTest();
|
Object listener = new TikTokEventListenerTest();
|
||||||
assertDoesNotThrow(() -> tikTokListenersManager.removeListener(listener));
|
assertDoesNotThrow(() -> tikTokListenersManager.removeListener(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class TikTokEventListenerTest implements TikTokEventListener
|
public static class TikTokEventListenerTest {
|
||||||
{
|
|
||||||
@TikTokEventObserver
|
@TikTokEventObserver
|
||||||
public void onJoin(LiveClient client, TikTokJoinEvent joinEvent)
|
public void onJoin(LiveClient client, TikTokJoinEvent joinEvent) {
|
||||||
{
|
System.out.println("Hello from on join" + client + " " + joinEvent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TikTokEventObserver
|
@TikTokEventObserver(priority = Priority.LOWEST)
|
||||||
public void onGift(LiveClient client, TikTokGiftEvent giftMessageEvent)
|
public void onGift(LiveClient client, TikTokGiftEvent giftMessageEvent) {
|
||||||
{
|
System.out.println("Hello from onGift lowest priority" + client + " " + giftMessageEvent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TikTokEventObserver
|
@TikTokEventObserver(priority = Priority.NORMAL)
|
||||||
public void onEvent(LiveClient client, TikTokEvent event)
|
public void onGift2(LiveClient client, TikTokGiftEvent giftMessageEvent) {
|
||||||
{
|
System.out.println("Hello from onGift normal priority " + client + " " + giftMessageEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TikTokEventObserver(priority = Priority.HIGHEST)
|
||||||
|
public void onGift3(LiveClient client, TikTokGiftEvent giftMessageEvent) {
|
||||||
|
System.out.println("Hello from onGift highest priority " + client + " " + giftMessageEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TikTokEventObserver(async = true)
|
||||||
|
public void onEvent(LiveClient client, TikTokEvent event) {
|
||||||
|
System.out.println("Hello from onEvent im running on the thread " + Thread.currentThread().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.mocks;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.TikTokLiveEventHandler;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache published events,
|
||||||
|
*/
|
||||||
|
public class EventsHandlerMock extends TikTokLiveEventHandler {
|
||||||
|
private final List<TikTokEvent> publishedEvents = new ArrayList<TikTokEvent>();
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publish(LiveClient tikTokLiveClient, TikTokEvent tikTokEvent) {
|
||||||
|
super.publish(tikTokLiveClient, tikTokEvent);
|
||||||
|
publishedEvents.add(tikTokEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
public final void assertEvents(Class<? extends TikTokEvent>... events) {
|
||||||
|
|
||||||
|
if (events.length == 0 && !publishedEvents.isEmpty()) {
|
||||||
|
var classNames = publishedEvents.stream()
|
||||||
|
.map(e -> e.getClass().getSimpleName())
|
||||||
|
.toList();
|
||||||
|
var invokedEvents = String.join("\n", classNames);
|
||||||
|
throw new IllegalArgumentException("Not events should be invoked but there was: \n" + invokedEvents);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (var i = 0; i < events.length; i++) {
|
||||||
|
var expectedEvent = events[i];
|
||||||
|
var invokedEvent = publishedEvents.get(i);
|
||||||
|
if (expectedEvent.equals(invokedEvent.getClass())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw new RuntimeException("Expected event was " + expectedEvent + " but acctuall was " + invokedEvent.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
12
README.md
12
README.md
@@ -70,7 +70,7 @@ Maven
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
||||||
<artifactId>Client</artifactId>
|
<artifactId>Client</artifactId>
|
||||||
<version>1.7.0-Release</version>
|
<version>1.8.7-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -87,7 +87,7 @@ dependencyResolutionManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.5.0-Release'
|
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.8.5-Release'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -426,9 +426,9 @@ Triggered every time gift is sent
|
|||||||
<p>>Combo: 1 -> comboState = GiftSendType.Begin</p>
|
<p>>Combo: 1 -> comboState = GiftSendType.Begin</p>
|
||||||
<p>Combo: 4 -> comboState = GiftSendType.Active</p>
|
<p>Combo: 4 -> comboState = GiftSendType.Active</p>
|
||||||
<p>Combo: 8 -> comboState = GiftSendType.Active</p>
|
<p>Combo: 8 -> comboState = GiftSendType.Active</p>
|
||||||
<p>Combo: 12 -> comboState = GiftSendType.Finsihed</p>
|
<p>Combo: 12 -> comboState = GiftSendType.Finished</p>
|
||||||
<p>
|
<p>
|
||||||
Remember if comboState is Finsihed both TikTokGiftComboEvent and TikTokGiftEvent event gets triggered
|
Remember if comboState is Finished both TikTokGiftComboEvent and TikTokGiftEvent event gets triggered
|
||||||
|
|
||||||
|
|
||||||
```java
|
```java
|
||||||
@@ -707,7 +707,7 @@ public static void main(String[] args) throws IOException {
|
|||||||
* - second must be class that extending TikTokEvent
|
* - second must be class that extending TikTokEvent
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static class CustomListener implements TikTokEventListener {
|
public static class CustomListener {
|
||||||
|
|
||||||
@TikTokEventObserver
|
@TikTokEventObserver
|
||||||
public void onLike(LiveClient liveClient, TikTokLikeEvent event) {
|
public void onLike(LiveClient liveClient, TikTokLikeEvent event) {
|
||||||
@@ -754,4 +754,4 @@ public static class CustomListener implements TikTokEventListener {
|
|||||||
|
|
||||||
[Library documentation for contributors](https://github.com/jwdeveloper/TikTokLiveJava/wiki)
|
[Library documentation for contributors](https://github.com/jwdeveloper/TikTokLiveJava/wiki)
|
||||||
|
|
||||||
Your improvements are welcome! Feel free to open an <a href="https://github.com/jwdeveloper/TikTok-Live-Java/issues">issue</a> or <a href="https://github.com/jwdeveloper/TikTok-Live-Java/pulls">pull request</a>.
|
Your improvements are welcome! Feel free to open an <a href="https://github.com/jwdeveloper/TikTok-Live-Java/issues">issue</a> or <a href="https://github.com/jwdeveloper/TikTok-Live-Java/pulls">pull request</a>.
|
||||||
@@ -41,12 +41,12 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.6.4-Release</version>
|
<version>1.8.7-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>Examples</artifactId>
|
<artifactId>examples</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
@@ -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.6.4-Release</version>
|
<version>${project.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -32,14 +32,11 @@ import java.time.Duration;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class ConnectionExample {
|
public class ConnectionExample {
|
||||||
public static String TIKTOK_HOSTNAME = "kvadromama_marina1";
|
public static String TIKTOK_HOSTNAME = "yttvandroid";
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
||||||
showLogo();
|
showLogo();
|
||||||
|
|
||||||
var gifts = TikTokLive.gifts();
|
|
||||||
|
|
||||||
TikTokLive.newClient(ConnectionExample.TIKTOK_HOSTNAME)
|
TikTokLive.newClient(ConnectionExample.TIKTOK_HOSTNAME)
|
||||||
.configure(clientSettings ->
|
.configure(clientSettings ->
|
||||||
{
|
{
|
||||||
@@ -30,7 +30,7 @@ public class CustomMappingExample {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
TikTokLive.newClient("saszareznikow")
|
TikTokLive.newClient("saszareznikow")
|
||||||
.onMapping(mapper ->
|
.mappings(mapper ->
|
||||||
{
|
{
|
||||||
mapper.forMessage(WebcastChatMessage.class)
|
mapper.forMessage(WebcastChatMessage.class)
|
||||||
.onBeforeMapping((inputBytes, messageName, mapperHelper) ->
|
.onBeforeMapping((inputBytes, messageName, mapperHelper) ->
|
||||||
@@ -56,7 +56,6 @@ public class CustomMappingExample {
|
|||||||
System.out.println("onAfter mapping, " + source.getClass().getSimpleName() + " was mapped to " + events.size() + " events");
|
System.out.println("onAfter mapping, " + source.getClass().getSimpleName() + " was mapped to " + events.size() + " events");
|
||||||
return events;
|
return events;
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
There might be cast that we don't have Webcast class for incoming message from TikTok
|
There might be cast that we don't have Webcast class for incoming message from TikTok
|
||||||
`mapperHelper.bytesToProtoBufferStructure` but you can still investigate message structure
|
`mapperHelper.bytesToProtoBufferStructure` but you can still investigate message structure
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user