From fa5385d8939311e923ef2174c6a22daadf0ea471 Mon Sep 17 00:00:00 2001 From: kohlerpop1 Date: Fri, 5 Jan 2024 13:57:29 -0500 Subject: [PATCH] Added convenience methods back to TikTokLive and changed sing to sign where misspelled! --- .../github/jwdeveloper/tiktok/TikTokLive.java | 54 +++++++++++++++++-- .../tiktok/TikTokLiveHttpClient.java | 8 +-- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLive.java b/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLive.java index 38260b4..9eea3f2 100644 --- a/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLive.java +++ b/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLive.java @@ -23,9 +23,12 @@ package io.github.jwdeveloper.tiktok; +import io.github.jwdeveloper.tiktok.data.requests.LiveUserData; import io.github.jwdeveloper.tiktok.http.LiveHttpClient; import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder; +import java.util.concurrent.CompletableFuture; + public class TikTokLive { /** @@ -37,6 +40,52 @@ public class TikTokLive { return new TikTokLiveClientBuilder(hostName); } + /** + * + * @param hostName profile name of Tiktok user could be found in profile link + * example: https://www.tiktok.com/@dostawcavideo hostName would be dostawcavideo + * @return true if live is Online, false if is offline + */ + public static boolean isLiveOnline(String hostName) + { + LiveUserData.UserStatus status = requests().fetchLiveUserData(hostName).getUserStatus(); + return status == LiveUserData.UserStatus.Live || status == LiveUserData.UserStatus.LivePaused; + } + + + /** + * + * @param hostName profile name of Tiktok user could be found in profile link + * example: https://www.tiktok.com/@dostawcavideo hostName would be dostawcavideo + * @return true if live is Online, false if is offline + */ + public static CompletableFuture isLiveOnlineAsync(String hostName) + { + return CompletableFuture.supplyAsync(()-> isLiveOnline(hostName)); + } + + /** + * + * @param hostName profile name of Tiktok user could be found in profile link + * example: https://www.tiktok.com/@dostawcavideo hostName would be dostawcavideo + * @return true is hostName name is valid and exists, false if not + */ + public static boolean isHostNameValid(String hostName) + { + LiveUserData.UserStatus status = requests().fetchLiveUserData(hostName).getUserStatus(); + return status != LiveUserData.UserStatus.NotFound; + } + + /** + * + * @param hostName profile name of Tiktok user could be found in profile link + * example: https://www.tiktok.com/@dostawcavideo hostName would be dostawcavideo + * @return true is hostName name is valid and exists, false if not + */ + public static CompletableFuture isHostNameValidAsync(String hostName) + { + return CompletableFuture.supplyAsync(()-> isHostNameValid(hostName)); + } /** * Use to get some data from TikTok about users are lives @@ -44,9 +93,6 @@ public class TikTokLive { * @return LiveHttpClient */ public static LiveHttpClient requests() { - - return new TikTokLiveHttpClient(); } - -} +} \ No newline at end of file diff --git a/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLiveHttpClient.java b/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLiveHttpClient.java index 027be0a..66ad2aa 100644 --- a/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLiveHttpClient.java +++ b/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLiveHttpClient.java @@ -50,14 +50,14 @@ public class TikTokLiveHttpClient implements LiveHttpClient { private final HttpClientFactory httpFactory; private final LiveUserDataMapper liveUserDataMapper; private final LiveDataMapper liveDataMapper; - private final SignServerResponseMapper singServerResponseMapper; + private final SignServerResponseMapper signServerResponseMapper; private final GiftsDataMapper giftsDataMapper; public TikTokLiveHttpClient(HttpClientFactory factory) { this.httpFactory = factory; liveUserDataMapper = new LiveUserDataMapper(); liveDataMapper = new LiveDataMapper(); - singServerResponseMapper = new SignServerResponseMapper(); + signServerResponseMapper = new SignServerResponseMapper(); giftsDataMapper = new GiftsDataMapper(); } @@ -180,7 +180,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient { } var json = optional.get(); - return singServerResponseMapper.map(json); + return signServerResponseMapper.map(json); } HttpResponse getWebsocketCredentialsResponse(String signedUrl) { @@ -194,4 +194,4 @@ public class TikTokLiveHttpClient implements LiveHttpClient { return optionalResponse.get(); } -} +} \ No newline at end of file