Compare commits

...

19 Commits

Author SHA1 Message Date
kohlerpop1
03892390fa Optimize for loop! 2025-02-11 16:39:44 -05:00
kohlerpop1
71602d5513 Updates for example gifts classes! 2025-02-11 16:36:20 -05:00
kohlerpop1
20db7cb773 Removal of deprecated methods and addition of information in TikTokLiveUnknownHostException and TikTokLiveOfflineHostException! 2025-02-11 16:34:27 -05:00
GitHub Action
3fda7fe446 Update version in pom.xml 2025-02-11 04:35:54 +00:00
David Kohler
8fcbb4b20f Update README.md 2025-02-10 23:33:40 -05:00
David Kohler
d90ab60e52 Merge pull request #118 from jwdeveloper/develop-1.8.14
Add signature to user class and remove no longer UUC param!
2025-02-10 23:32:51 -05:00
kohlerpop1
33f9862758 Add signature to user class and remove no longer UUC param! 2025-02-10 23:32:11 -05:00
GitHub Action
d74c294323 Update version in pom.xml 2024-12-24 03:44:34 +00:00
David Kohler
31f0e4210d Update README.md 2024-12-23 22:42:53 -05:00
David Kohler
2e22da1fbe Merge pull request #115 from jwdeveloper/develop-1.8.13
Develop 1.8.13
2024-12-23 22:41:01 -05:00
kohlerpop1
4b4874d33e Update bytes required for ping task! 2024-12-23 22:17:27 -05:00
kohlerpop1
9c7b24f33e Add settings for allowing proxies to be used for working through Websockets. 2024-12-23 22:16:49 -05:00
kohlerpop1
7476a11ae0 Optimized TikTokLinkMicBattleEvent and added helper methods! 2024-12-23 22:14:55 -05:00
GitHub Action
125e421ea9 Update version in pom.xml 2024-12-19 18:48:50 +00:00
David Kohler
5d84e28bdb Merge pull request #114 from jwdeveloper/develop-1.8.12
Develop 1.8.12
2024-12-19 13:47:09 -05:00
kohlerpop1
a9003f4296 Add details to Disconnect events, removed unused imports, and not needed blank lines! 2024-12-10 19:25:20 -05:00
kohlerpop1
8cd640f8eb Converted list of teams to just 2 teams as we know the size is always 2 and updated methods accordingly. 2024-12-03 09:43:17 -05:00
kohlerpop1
ca741ed931 Add helper methods to get TikTokLinkMicBattleEvent teams by battleHostName! 2024-12-02 23:46:16 -05:00
GitHub Action
96872e27b5 Update version in pom.xml 2024-11-29 02:20:32 +00:00
34 changed files with 152 additions and 290 deletions

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>TikTokLiveJava</artifactId>
<groupId>io.github.jwdeveloper.tiktok</groupId>
<version>1.8.10-Release</version>
<version>1.8.14-Release</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>API</artifactId>

View File

@@ -36,11 +36,6 @@ public class TikTokDisconnectedEvent extends TikTokLiveClientEvent {
this.reason = reason.isBlank() ? "None" : reason;
}
public TikTokDisconnectedEvent() {
this("None");
}
public static TikTokDisconnectedEvent of(String reason)
{
return new TikTokDisconnectedEvent(reason);

View File

@@ -25,11 +25,12 @@ package io.github.jwdeveloper.tiktok.data.events;
import io.github.jwdeveloper.tiktok.annotations.*;
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
import io.github.jwdeveloper.tiktok.data.models.battles.*;
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
import io.github.jwdeveloper.tiktok.messages.enums.LinkMicBattleStatus;
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
import lombok.*;
import lombok.Getter;
import java.util.*;
import java.util.List;
/**
* Triggered every time a battle starts & ends
@@ -43,23 +44,22 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
true if battle is finished otherwise false
*/
private final boolean finished;
private final List<Team> teams;
private final Team team1, team2;
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
super(msg.getCommon());
battleId = msg.getId();
finished = msg.getBattleStatus() == LinkMicBattleStatus.BATTLE_FINISHED;
teams = new ArrayList<>();
if (msg.getHostTeamCount() == 2) { // 1v1 battle
teams.add(new Team1v1(msg.getHostTeam(0), msg));
teams.add(new Team1v1(msg.getHostTeam(1), msg));
team1 = new Team1v1(msg.getHostTeam(0), msg);
team2 = new Team1v1(msg.getHostTeam(1), msg);
} else { // 2v2 battle
if (isFinished()) {
teams.add(new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 1).findFirst().orElse(null), msg));
teams.add(new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 2).findFirst().orElse(null), msg));
team1 = new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 1).findFirst().orElse(null), msg);
team2 = new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 2).findFirst().orElse(null), msg);
} else {
teams.add(new Team2v2(msg.getHostTeam(0), msg.getHostTeam(1), msg));
teams.add(new Team2v2(msg.getHostTeam(2), msg.getHostTeam(3), msg));
team1 = new Team2v2(msg.getHostTeam(0), msg.getHostTeam(1), msg);
team2 = new Team2v2(msg.getHostTeam(2), msg.getHostTeam(3), msg);
}
}
@@ -69,15 +69,69 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
// - msg.getHostTeamCount() always is 2 for 1v1 or 4 for 2v2
}
/**
* @param battleHostName name of host to search
* @return Team1v1 instance containing name of host or null if no team found */
public Team1v1 get1v1Team(String battleHostName) {
if (!is1v1())
throw new TikTokLiveException("Teams are not instance of 1v1 battle!");
List<Team> list = getTeams(battleHostName);
return list.isEmpty() ? null : list.get(0).getAs1v1Team();
}
public Team2v2 get2v2Team(String battleHostName) {
if (!is2v2())
throw new TikTokLiveException("Teams are not instance of 2v2 battle!");
List<Team> list = getTeams(battleHostName);
return list.isEmpty() ? null : list.get(0).getAs2v2Team();
}
/**
* @param battleHostName name of host to search
* @return Team1v1 instance not containing name of host */
public Team1v1 get1v1OpponentTeam(String battleHostName) {
if (!is1v1())
throw new TikTokLiveException("Teams are not instance of 1v1 battle!");
List<Team> list = getTeams(battleHostName);
return list.isEmpty() ? null : list.get(1).getAs1v1Team();
}
public Team2v2 get2x2OpponentTeam(String battleHostName) {
if (!is2v2())
throw new TikTokLiveException("Teams are not instance of 2v2 battle!");
List<Team> list = getTeams(battleHostName);
return list.isEmpty() ? null : list.get(1).getAs2v2Team();
}
/**
* @param battleHostName name of host to search
* @return {@link List<Team>} with host team first, then opponent team
* <p> Empty if host is in neither otherwise always 2 in length;
*/
public List<Team> getTeams(String battleHostName) {
if (is1v1()) {
if (team1.getAs1v1Team().getHost().getName().equals(battleHostName))
return List.of(team1, team2);
if (team2.getAs1v1Team().getHost().getName().equals(battleHostName))
return List.of(team2, team1);
} else {
if (team1.getAs2v2Team().getHosts().stream().anyMatch(user -> user.getName().equals(battleHostName)))
return List.of(team1, team2);
if (team2.getAs2v2Team().getHosts().stream().anyMatch(user -> user.getName().equals(battleHostName)))
return List.of(team2, team1);
}
return List.of();
}
public boolean is1v1() {
return teams.get(0) instanceof Team1v1;
return team1.is1v1Team() || team2.is1v1Team();
}
public boolean is2v2() {
return teams.get(0) instanceof Team2v2;
return team1.is2v2Team() || team2.is2v2Team();
}
public boolean isTie() {
return isFinished() && teams.get(0).getTotalPoints() == teams.get(1).getTotalPoints();
return isFinished() && team1.getTotalPoints() == team2.getTotalPoints();
}
}

View File

@@ -35,4 +35,4 @@ public class TikTokUnhandledMemberEvent extends TikTokUnhandledEvent<WebcastMemb
public TikTokUnhandledMemberEvent(WebcastMemberMessage data) {
super(data);
}
}
}

View File

@@ -26,7 +26,6 @@ import io.github.jwdeveloper.tiktok.annotations.EventMeta;
import io.github.jwdeveloper.tiktok.annotations.EventType;
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
import io.github.jwdeveloper.tiktok.data.models.users.User;
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLikeMessage;
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastMemberMessage;
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
import lombok.Getter;
@@ -58,4 +57,4 @@ public class TikTokJoinEvent extends TikTokHeaderEvent {
.build())
.build());
}
}
}

View File

@@ -48,7 +48,6 @@ public class Gift {
this.properties = properties;
}
public Gift(int id, String name, int diamondCost, String pictureLink) {
this(id, name, diamondCost, new Picture(pictureLink), new JsonObject());
}

View File

@@ -33,6 +33,7 @@ import java.util.*;
public class User {
private final Long id;
private final String name;
private String signature;
private String profileName;
private Picture picture;
private long following;
@@ -106,6 +107,7 @@ public class User {
public User(Long id,
String name,
String profileName,
String signature,
Picture picture,
long following,
long followers,
@@ -113,6 +115,7 @@ public class User {
this.id = id;
this.name = name;
this.profileName = profileName;
this.signature = signature;
this.picture = picture;
this.following = following;
this.followers = followers;
@@ -133,7 +136,7 @@ public class User {
}
public User(long id, String name, String profileId, Picture picture) {
this(id, name, profileId, picture, 0, 0, List.of(Badge.empty()));
this(id, name, profileId, null, picture, 0, 0, List.of(Badge.empty()));
}
public User(WebcastLinkMicBattle.LinkMicBattleHost.HostGroup.Host host) {
@@ -142,6 +145,7 @@ public class User {
public User(io.github.jwdeveloper.tiktok.messages.data.User user) {
this(user.getId(), user.getDisplayId(), Picture.map(user.getAvatarThumb()));
signature = user.getBioDescription();
profileName = user.getNickname();
following = user.getFollowInfo().getFollowingCount();
followers = user.getFollowInfo().getFollowerCount();

View File

@@ -33,7 +33,7 @@ import java.util.function.Consumer;
@Setter
public class ProxyClientSettings implements Iterator<ProxyData>, Iterable<ProxyData>
{
private boolean enabled, autoDiscard = true, fallback = true;
private boolean enabled, autoDiscard = true, fallback = true, allowWebsocket = true;
private Rotation rotation = Rotation.CONSECUTIVE;
private final List<ProxyData> proxyList = new ArrayList<>();
private int index;

View File

@@ -22,9 +22,18 @@
*/
package io.github.jwdeveloper.tiktok.exceptions;
import io.github.jwdeveloper.tiktok.data.requests.*;
import lombok.Getter;
@Getter
public class TikTokLiveOfflineHostException extends TikTokLiveException
{
public TikTokLiveOfflineHostException(String message) {
private final LiveUserData.Response userData;
private final LiveData.Response liveData;
public TikTokLiveOfflineHostException(String message, LiveUserData.Response userData, LiveData.Response liveData) {
super(message);
this.userData = userData;
this.liveData = liveData;
}
}
}

View File

@@ -22,9 +22,18 @@
*/
package io.github.jwdeveloper.tiktok.exceptions;
import io.github.jwdeveloper.tiktok.data.requests.*;
import lombok.Getter;
@Getter
public class TikTokLiveUnknownHostException extends TikTokLiveException
{
public TikTokLiveUnknownHostException(String message) {
private final LiveUserData.Response userData;
private final LiveData.Response liveData;
public TikTokLiveUnknownHostException(String message, LiveUserData.Response userData, LiveData.Response liveData) {
super(message);
this.userData = userData;
this.liveData = liveData;
}
}

View File

@@ -29,11 +29,6 @@ import io.github.jwdeveloper.tiktok.data.requests.LiveUserData;
public interface LiveHttpClient
{
/**
* @return {@link GiftsData.Response} list of gifts that are compiled and available on github
*/
GiftsData.Response fetchGiftsData();
/**
* @return {@link GiftsData.Response} list of gifts that are available in your region / livestream
*/

View File

@@ -1,73 +0,0 @@
/*
* Copyright (c) 2023-2024 jwdeveloper jacekwoln@gmail.com
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package io.github.jwdeveloper.tiktok.listener;
import io.github.jwdeveloper.tiktok.live.LiveClient;
/**
* ListenersManager
* <p>
* TikTokEventListener is an alternative way of handing TikTok events.
* <p>
* {@code TikTokLive.newClient("someuser").addListener(listener);}
* <p>
* After registertion, all listeners are kept in Listener manager - {@link LiveClient#getListenersManager()}
* <p>
* Method in TikTokEventListener should meet requirements below to be detected
* <p>- @TikTokEventObserver annotation
* <p>- 2 parameters of (LiveClient, Class extending TikTokEvent)
* <pre>
* {@code
* public static class CustomListener
* {
* @TikTokEventObserver
* public void onError(LiveClient liveClient, TikTokErrorEvent event)
* {
* System.out.println(event.getException().getMessage());
* }
*
* @TikTokEventObserver
* public void onCommentMessage(LiveClient liveClient, TikTokCommentEvent event)
* {
* System.out.println(event.getText());
* }
*
* @TikTokEventObserver
* public void onGiftMessage(LiveClient liveClient, TikTokGiftMessageEvent event)
* {
* System.out.println(event.getGift().getDescription());
* }
*
* @TikTokEventObserver
* public void onAnyEvent(LiveClient liveClient, TikTokEvent event)
* {
* System.out.println(event.getClass().getSimpleName());
* }
* }
* }
* </pre>
*/
@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 {
}

View File

@@ -22,12 +22,8 @@
*/
package io.github.jwdeveloper.tiktok.live;
import com.google.gson.JsonObject;
import io.github.jwdeveloper.tiktok.data.models.Picture;
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;

View File

@@ -30,9 +30,8 @@ import io.github.jwdeveloper.tiktok.mappers.LiveMapper;
import java.util.concurrent.CompletableFuture;
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
* It could be used to OVERRIDE behaviour of mappings and implement custom behaviour
@@ -40,18 +39,15 @@ public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
* Be aware if for example you override WebcastGiftEvent, onGiftEvent() will not be working
*
* @param onCustomMappings lambda method
* @return
* @return {@link LiveClientBuilder}
*/
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
*
* @param onConfigure
* @return
* @param onConfigure Consumer for {@link LiveClientSettings}
* @return {@link LiveClientBuilder}
* @see LiveClientSettings
*/
LiveClientBuilder configure(Consumer<LiveClientSettings> onConfigure);
@@ -59,7 +55,7 @@ public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
/**
* Adds events listener class, its fancy way to register events without using lamda method
*
* @return
* @return {@link LiveClientBuilder}
*/
LiveClientBuilder addListener(Object listener);
@@ -69,7 +65,7 @@ public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
* when the default implementation does not meet your needs
*
* @param onCustomizeDependencies access to dependency container
* @return
* @return {@link LiveClientBuilder}
*/
LiveClientBuilder customize(Consumer<DependanceContainerBuilder> onCustomizeDependencies);

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>TikTokLiveJava</artifactId>
<groupId>io.github.jwdeveloper.tiktok</groupId>
<version>1.8.10-Release</version>
<version>1.8.14-Release</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -22,20 +22,18 @@
*/
package io.github.jwdeveloper.tiktok;
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftsManager;
import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
import io.github.jwdeveloper.tiktok.live.GiftsManager;
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
public class TikTokLive {
public class TikTokLive
{
/**
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
* Example: {@code https://www.tiktok.com/@dostawcavideo} - hostName would be 'dostawcavideo'
*
* @param hostName profile name of TikTok user could be found in profile link
* @return LiveClientBuilder
@@ -45,7 +43,7 @@ public class TikTokLive {
}
/**
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
* Example: {@code https://www.tiktok.com/@dostawcavideo} - hostName would be 'dostawcavideo'
*
* @param hostName profile name of TikTok user could be found in profile link
* @return true if live is Online, false if is offline
@@ -55,17 +53,17 @@ public class TikTokLive {
}
/**
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
* Example: {@code https://www.tiktok.com/@dostawcavideo} - hostName would be 'dostawcavideo'
*
* @param hostName profile name of TikTok user could be found in profile link
* @return true if live is Online, false if is offline
* @return {@link CompletableFuture} of true if live is Online, false if is offline
*/
public static CompletableFuture<Boolean> isLiveOnlineAsync(String hostName) {
return CompletableFuture.supplyAsync(() -> isLiveOnline(hostName));
}
/**
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
* Example: {@code https://www.tiktok.com/@dostawcavideo} - hostName would be 'dostawcavideo'
*
* @param hostName profile name of TikTok user could be found in profile link
* @return true is hostName name is valid and exists, false if not
@@ -75,7 +73,7 @@ public class TikTokLive {
}
/**
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
* Example: {@code https://www.tiktok.com/@dostawcavideo} - hostName would be 'dostawcavideo'
*
* @param hostName profile name of TikTok user could be found in profile link
* @return true is hostName name is valid and exists, false if not
@@ -101,20 +99,4 @@ public class TikTokLive {
public static LiveHttpClient requests() {
return requests(liveClientSettings -> {});
}
private static GiftsManager giftsManager;
/**
* Fetch gifts from endpoint and returns GiftManager
*
* @return GiftsManager
*/
public static GiftsManager gifts() {
if (giftsManager == null) {
synchronized (GiftsManager.class) {
giftsManager = new TikTokGiftsManager(requests().fetchGiftsData().getGifts());
}
}
return giftsManager;
}
}

View File

@@ -83,7 +83,7 @@ public class TikTokLiveClient implements LiveClient
} catch (TikTokLiveException e) {
setState(ConnectionState.DISCONNECTED);
tikTokEventHandler.publish(this, new TikTokErrorEvent(e));
tikTokEventHandler.publish(this, new TikTokDisconnectedEvent());
tikTokEventHandler.publish(this, new TikTokDisconnectedEvent("Exception: "+e.getMessage()));
if (e instanceof TikTokLiveOfflineHostException && clientSettings.isRetryOnConnectionFailure()) {
try {
@@ -114,10 +114,10 @@ public class TikTokLiveClient implements LiveClient
roomInfo.setRoomId(userData.getRoomId());
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
throw new TikTokLiveOfflineHostException("User is offline: " + roomInfo.getHostName());
throw new TikTokLiveOfflineHostException("User is offline: " + roomInfo.getHostName(), userData, null);
if (userData.getUserStatus() == LiveUserData.UserStatus.NotFound)
throw new TikTokLiveUnknownHostException("User not found: " + roomInfo.getHostName());
throw new TikTokLiveUnknownHostException("User not found: " + roomInfo.getHostName(), userData, null);
var liveDataRequest = new LiveData.Request(userData.getRoomId());
var liveData = httpClient.fetchLiveData(liveDataRequest);
@@ -126,10 +126,10 @@ public class TikTokLiveClient implements LiveClient
throw new TikTokLiveException("Livestream for " + roomInfo.getHostName() + " is 18+ or age restricted!");
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostNotFound)
throw new TikTokLiveUnknownHostException("LiveStream for " + roomInfo.getHostName() + " could not be found.");
throw new TikTokLiveUnknownHostException("LiveStream for " + roomInfo.getHostName() + " could not be found.", userData, liveData);
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostOffline)
throw new TikTokLiveOfflineHostException("LiveStream for " + roomInfo.getHostName() + " not found, is the Host offline?");
throw new TikTokLiveOfflineHostException("LiveStream for " + roomInfo.getHostName() + " not found, is the Host offline?", userData, liveData);
roomInfo.setTitle(liveData.getTitle());
roomInfo.setViewersCount(liveData.getViewers());

View File

@@ -70,12 +70,6 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
return this;
}
@Override
public LiveClientBuilder onMappings(Consumer<LiveMapper> onCustomMappings) {
mappings(onCustomMappings);
return this;
}
public TikTokLiveClientBuilder configure(Consumer<LiveClientSettings> onConfigure) {
onConfigure.accept(clientSettings);
return this;
@@ -155,11 +149,7 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
*/
//gifts
if (clientSettings.isFetchGifts()) {
dependance.registerSingleton(GiftsManager.class, TikTokLive.gifts());
} else {
dependance.registerSingleton(GiftsManager.class, new TikTokGiftsManager(List.of()));
}
dependance.registerSingleton(GiftsManager.class, new TikTokGiftsManager(List.of()));
//mapper
dependance.registerSingleton(TikTokGenericEventMapper.class);

View File

@@ -44,7 +44,6 @@ public class TikTokLiveHttpClient implements LiveHttpClient
private static final String TIKTOK_SIGN_API = "https://tiktok.eulerstream.com/webcast/fetch";
private static final String TIKTOK_URL_WEB = "https://www.tiktok.com/";
private static final String TIKTOK_URL_WEBCAST = "https://webcast.tiktok.com/webcast/";
public static final String TIKTOK_GIFTS_URL = "https://raw.githubusercontent.com/TikTok-LIVE-Private/GiftsGenerator/master/page/public/gifts.json";
public static final String TIKTOK_ROOM_GIFTS_URL = TIKTOK_URL_WEBCAST+"gift/list/";
public static final int TIKTOK_AGE_RESTRICTED_CODE = 4003110;
@@ -95,31 +94,6 @@ public class TikTokLiveHttpClient implements LiveHttpClient
return giftsDataMapper.mapRoom(json);
}
public GiftsData.Response fetchGiftsData() {
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
if (proxyClientSettings.isEnabled()) {
while (proxyClientSettings.hasNext()) {
try {
return getGiftsData();
} catch (TikTokProxyRequestException ignored) {}
}
}
return getGiftsData();
}
@Deprecated(since = "1.8.6", forRemoval = true)
public GiftsData.Response getGiftsData() {
var result = httpFactory.client(TIKTOK_GIFTS_URL)
.build()
.toJsonResponse();
if (result.isFailure())
throw new TikTokLiveRequestException("Unable to fetch gifts information's - "+result);
var json = result.getContent();
return giftsDataMapper.map(json);
}
@Override
public LiveUserData.Response fetchLiveUserData(LiveUserData.Request request) {
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
@@ -219,7 +193,6 @@ public class TikTokLiveHttpClient implements LiveHttpClient
protected ActionResult<HttpResponse<byte[]>> getByteResponse(String room_id) {
HttpClientBuilder builder = httpFactory.client(TIKTOK_SIGN_API)
.withParam("client", "ttlive-java")
.withParam("uuc", "1") //MAGIC NUMBER!
.withParam("room_id", room_id);
if (clientSettings.getApiKey() != null)

View File

@@ -35,11 +35,6 @@ import java.net.URI;
import java.util.List;
public class TikTokLiveHttpOfflineClient implements LiveHttpClient {
@Override
public GiftsData.Response fetchGiftsData() {
return new GiftsData.Response("", List.of());
}
@Override
public GiftsData.Response fetchRoomGiftsData(String room_id) {
return new GiftsData.Response("", List.of());

View File

@@ -59,8 +59,7 @@ public class GiftsDataMapper {
if (jsonObject.get("data") instanceof JsonObject data && data.get("gifts") instanceof JsonArray giftArray) {
var gifts = new ArrayList<Gift>();
for(int i = 0; i < giftArray.size(); i++) {
JsonElement element = giftArray.get(i);
for (JsonElement element : giftArray) {
Gift gift = mapSingleRoomGift(element);
gifts.add(gift);
}

View File

@@ -131,6 +131,7 @@ public class LiveDataMapper {
var id = jsonElement.get("id").getAsLong();
var name = jsonElement.get("display_id").getAsString();
var profileName = jsonElement.get("nickname").getAsString();
var signature = jsonElement.get("bio_description").getAsString();
var followElement = jsonElement.getAsJsonObject("follow_info");
@@ -142,7 +143,7 @@ public class LiveDataMapper {
var link = pictureElement.getAsJsonArray("url_list").get(1).getAsString();
var picture = new Picture(link);
var user = new User(id, name, profileName, picture, followingCount, followers, new ArrayList<>());
var user = new User(id, name, profileName, signature, picture, followingCount, followers, new ArrayList<>());
user.addAttribute(UserAttribute.LiveHost);
return user;
}

View File

@@ -72,6 +72,7 @@ public class LiveUserDataMapper
Long.parseLong(user.get("id").getAsString()),
user.get("uniqueId").getAsString(),
user.get("nickname").getAsString(),
user.get("signature").getAsString(),
new Picture(user.get("avatarLarger").getAsString()),
stats.get("followingCount").getAsLong(),
stats.get("followerCount").getAsLong(),

View File

@@ -74,11 +74,11 @@ public class TikTokWebSocketClient implements LiveSocketClient {
tikTokEventHandler,
liveClient);
// ProxyClientSettings proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
// if (proxyClientSettings.isEnabled())
// connectProxy(proxyClientSettings);
// else
connectDefault();
ProxyClientSettings proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
if (proxyClientSettings.isEnabled() && proxyClientSettings.isAllowWebsocket())
connectProxy(proxyClientSettings);
else
connectDefault();
}
private void connectDefault() {
@@ -115,15 +115,14 @@ public class TikTokWebSocketClient implements LiveSocketClient {
}
while (proxySettings.hasNext()) {
ProxyData proxyData = proxySettings.next();
if (!tryProxyConnection(proxySettings, proxyData)) {
if (proxySettings.isAutoDiscard())
proxySettings.remove();
continue;
}
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
isConnected = true;
break;
}
if (tryProxyConnection(proxySettings, proxyData)) {
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
isConnected = true;
break;
}
if (proxySettings.isAutoDiscard())
proxySettings.remove();
}
if (!isConnected)
throw new TikTokLiveException("Failed to connect to the websocket");
}

View File

@@ -48,6 +48,6 @@ public class TikTokWebSocketOfflineClient implements LiveSocketClient {
if (liveClient == null) {
return;
}
handler.publish(liveClient, new TikTokDisconnectedEvent());
handler.publish(liveClient, new TikTokDisconnectedEvent("Stopping"));
}
}
}

View File

@@ -24,13 +24,15 @@ package io.github.jwdeveloper.tiktok.websocket;
import org.java_websocket.WebSocket;
import java.util.Base64;
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
private final byte[] heartbeatBytes = Base64.getDecoder().decode("MgJwYjoCaGI="); // Used to be '3A026862' aka ':\x02hb', now is '2\x02pb:\x02hb'.
public void run(WebSocket webSocket, long pingTaskTime) {
stop();
@@ -58,6 +60,5 @@ public class WebSocketHeartbeatTask
isRunning = false;
}
}
}
}

View File

@@ -70,7 +70,7 @@ Maven
<dependency>
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
<artifactId>Client</artifactId>
<version>1.8.7-Release</version>
<version>1.8.14-Release</version>
<scope>compile</scope>
</dependency>
</dependencies>
@@ -87,7 +87,7 @@ dependencyResolutionManagement {
}
dependencies {
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.8.5-Release'
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.8.14-Release'
}
```
@@ -754,4 +754,4 @@ public static class CustomListener {
[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>.

View File

@@ -41,7 +41,7 @@
<parent>
<artifactId>TikTokLiveJava</artifactId>
<groupId>io.github.jwdeveloper.tiktok</groupId>
<version>1.8.10-Release</version>
<version>1.8.14-Release</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -64,8 +64,7 @@ public class Events_And_Gifts_Testing_Example
})
.build();
var gifts = TikTokLive.gifts();
var roseGift = gifts.getByName("Rose");
var roseGift = client.getGiftManager().getByName("Rose");
var fakeGift = TikTokGiftEvent.of(roseGift);
var fakeComboGift = TikTokGiftComboEvent.of(roseGift, 12, GiftComboStateType.Begin);
@@ -91,4 +90,4 @@ public class Events_And_Gifts_Testing_Example
}
private static final String webcastLikeMessageBase64 = "SAFSBRABGKwCUgcIAhABGKwCCv8BUAFYAbABA7gBARCflqWWo8Ha72UgzoPZhd8xQrwBGg4gkAMKCSNmZmZmZmZmZiJ/qgF6CngIhYjjgPWJv7RgGhDwnZKm8J2TjvCdk47wk4WTsgIKa3lsbGVlaGFsbPICTE1TNHdMakFCQUFBQXUyX21LNEw4WGJYa3lNaUFvZzJUTnNmVjk5N09WM2tpQ3NCTkNjYWkwcWxIcUt0Q3B0UGU1N2RLYVhxb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jvCdk47wk4WTsgIKa3lsbGVlaGFsbPICTE1TNHdMakFCQUFBQXUyX21LNEw4WGJYa3lNaUFvZzJUTnNmVjk5N09WM2tpQ3NCTkNjYWkwcWxIcUt0Q3B0UGU1N2RLYVhxb0xWSXo=";
}
}

View File

@@ -1,61 +0,0 @@
/*
* Copyright (c) 2023-2024 jwdeveloper jacekwoln@gmail.com
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package io.github.jwdeveloper.tiktok;
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
public class GiftsExample {
public static void main(String[] args) {
var giftsManager = TikTokLive.gifts();
var giftsList = giftsManager.toList();
for (var gift : giftsList) {
System.out.println("Gift: " + gift);
}
var giftsMap = giftsManager.toMap();
for (var entry : giftsMap.entrySet()) {
System.out.println("GiftId: " + entry.getKey() + " Gift: " + entry.getValue());
}
System.out.println("total number of gifts: " + giftsManager.toList().size());
var giftRose = giftsManager.getById(5655);
var giftRoseByName = giftsManager.getByName("Rose");
var giftByFilter = giftsManager.getByFilter(e -> e.getDiamondCost() > 50);
var giftsByFilter = giftsManager.getManyByFilter(e -> e.getDiamondCost() > 100);
System.out.println("total number of gifts with cost higher then 100: " + giftsByFilter.size());
/**
* In case searched gift not exists getByName returns you Gift.UNDEFINED
*/
var undefiedGift = giftsManager.getByName("GIFT WITH WRONG NAME");
var customGift = new Gift(123213213, "Custom gift", 50, "https://images.pexels.com/photos/2071882/pexels-photo-2071882.jpeg?cs=srgb&dl=pexels-wojciech-kumpicki-2071882.jpg&fm=jpg");
giftsManager.attachGift(customGift);
}
}

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>io.github.jwdeveloper.tiktok</groupId>
<artifactId>TikTokLiveJava</artifactId>
<version>1.8.10-Release</version>
<version>1.8.14-Release</version>
</parent>
@@ -33,7 +33,7 @@
<dependency>
<groupId>io.github.jwdeveloper.tiktok</groupId>
<artifactId>API</artifactId>
<version>1.8.10-Release</version>
<version>1.8.14-Release</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>TikTokLiveJava</artifactId>
<groupId>io.github.jwdeveloper.tiktok</groupId>
<version>1.8.10-Release</version>
<version>1.8.14-Release</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>extension-recorder</artifactId>

View File

@@ -7,7 +7,7 @@
<groupId>io.github.jwdeveloper.tiktok</groupId>
<artifactId>TikTokLiveJava</artifactId>
<packaging>pom</packaging>
<version>1.8.10-Release</version>
<version>1.8.14-Release</version>
<modules>
<module>API</module>
<module>Client</module>

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>TikTokLiveJava</artifactId>
<groupId>io.github.jwdeveloper.tiktok</groupId>
<version>1.8.10-Release</version>
<version>1.8.14-Release</version>
</parent>
<modelVersion>4.0.0</modelVersion>