mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-28 01:09:40 -05:00
Created TikTokLiveUnknownHostException for use inside of TikTokLiveClient!
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.exceptions;
|
||||||
|
|
||||||
|
public class TikTokLiveUnknownHostException extends TikTokLiveException
|
||||||
|
{
|
||||||
|
public TikTokLiveUnknownHostException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -78,15 +78,10 @@ public class TikTokLiveClient implements LiveClient
|
|||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void connectAsync(Consumer<LiveClient> onConnection) {
|
public void connectAsync(Consumer<LiveClient> onConnection) {
|
||||||
CompletableFuture.runAsync(() -> {
|
connectAsync().thenAccept(onConnection);
|
||||||
connect();
|
|
||||||
onConnection.accept(this);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public CompletableFuture<LiveClient> connectAsync() {
|
public CompletableFuture<LiveClient> connectAsync() {
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
connect();
|
connect();
|
||||||
@@ -135,7 +130,7 @@ public class TikTokLiveClient implements LiveClient
|
|||||||
throw new TikTokLiveOfflineHostException("User is offline: " + roomInfo.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: " + roomInfo.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);
|
||||||
@@ -144,7 +139,7 @@ public class TikTokLiveClient implements LiveClient
|
|||||||
throw new TikTokLiveException("Livestream for " + roomInfo.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 " + roomInfo.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 " + roomInfo.getHostName() + " not found, is the Host offline?");
|
throw new TikTokLiveOfflineHostException("LiveStream for " + roomInfo.getHostName() + " not found, is the Host offline?");
|
||||||
|
|||||||
Reference in New Issue
Block a user