Added convenience methods back to TikTokLive and changed sing to sign where misspelled!

This commit is contained in:
kohlerpop1
2024-01-05 13:57:29 -05:00
committed by Jacek W
parent 548a585e90
commit fa5385d893
2 changed files with 54 additions and 8 deletions

View File

@@ -23,9 +23,12 @@
package io.github.jwdeveloper.tiktok; 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.http.LiveHttpClient;
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder; import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
import java.util.concurrent.CompletableFuture;
public class TikTokLive { public class TikTokLive {
/** /**
@@ -37,6 +40,52 @@ public class TikTokLive {
return new TikTokLiveClientBuilder(hostName); 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<Boolean> 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<Boolean> isHostNameValidAsync(String hostName)
{
return CompletableFuture.supplyAsync(()-> isHostNameValid(hostName));
}
/** /**
* Use to get some data from TikTok about users are lives * Use to get some data from TikTok about users are lives
@@ -44,9 +93,6 @@ public class TikTokLive {
* @return LiveHttpClient * @return LiveHttpClient
*/ */
public static LiveHttpClient requests() { public static LiveHttpClient requests() {
return new TikTokLiveHttpClient(); return new TikTokLiveHttpClient();
} }
}
}

View File

@@ -50,14 +50,14 @@ public class TikTokLiveHttpClient implements LiveHttpClient {
private final HttpClientFactory httpFactory; private final HttpClientFactory httpFactory;
private final LiveUserDataMapper liveUserDataMapper; private final LiveUserDataMapper liveUserDataMapper;
private final LiveDataMapper liveDataMapper; private final LiveDataMapper liveDataMapper;
private final SignServerResponseMapper singServerResponseMapper; private final SignServerResponseMapper signServerResponseMapper;
private final GiftsDataMapper giftsDataMapper; private final GiftsDataMapper giftsDataMapper;
public TikTokLiveHttpClient(HttpClientFactory factory) { public TikTokLiveHttpClient(HttpClientFactory factory) {
this.httpFactory = factory; this.httpFactory = factory;
liveUserDataMapper = new LiveUserDataMapper(); liveUserDataMapper = new LiveUserDataMapper();
liveDataMapper = new LiveDataMapper(); liveDataMapper = new LiveDataMapper();
singServerResponseMapper = new SignServerResponseMapper(); signServerResponseMapper = new SignServerResponseMapper();
giftsDataMapper = new GiftsDataMapper(); giftsDataMapper = new GiftsDataMapper();
} }
@@ -180,7 +180,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient {
} }
var json = optional.get(); var json = optional.get();
return singServerResponseMapper.map(json); return signServerResponseMapper.map(json);
} }
HttpResponse<byte[]> getWebsocketCredentialsResponse(String signedUrl) { HttpResponse<byte[]> getWebsocketCredentialsResponse(String signedUrl) {
@@ -194,4 +194,4 @@ public class TikTokLiveHttpClient implements LiveHttpClient {
return optionalResponse.get(); return optionalResponse.get();
} }
} }