mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 08:49:40 -05:00
Fixed NPE - Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Thread.interrupt()" because "this.liveDownloadThread" is null
Moved websocketClient.setSocketFactory call up where it only needs called once not looped. Also added pingingTask.run for not used proxy connections.
This commit is contained in:
@@ -36,7 +36,6 @@ public class LiveClientSettings {
|
|||||||
/**
|
/**
|
||||||
* ISO-Language for Client
|
* ISO-Language for Client
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private String clientLanguage;
|
private String clientLanguage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +43,6 @@ public class LiveClientSettings {
|
|||||||
*/
|
*/
|
||||||
private boolean retryOnConnectionFailure;
|
private boolean retryOnConnectionFailure;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before retrying connect, wait for select amount of time
|
* Before retrying connect, wait for select amount of time
|
||||||
*/
|
*/
|
||||||
@@ -53,42 +51,35 @@ public class LiveClientSettings {
|
|||||||
/**
|
/**
|
||||||
* Whether to print Logs to Console
|
* Whether to print Logs to Console
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private boolean printToConsole = true;
|
private boolean printToConsole = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LoggingLevel for Logs
|
* LoggingLevel for Logs
|
||||||
*/
|
*/
|
||||||
private Level logLevel;
|
private Level logLevel;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional: Use it if you need to change TikTok live hostname in builder
|
* Optional: Use it if you need to change TikTok live hostname in builder
|
||||||
*/
|
*/
|
||||||
private String hostName;
|
private String hostName;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameters used in requests to TikTok api
|
* Parameters used in requests to TikTok api
|
||||||
*/
|
*/
|
||||||
private HttpClientSettings httpSettings;
|
private HttpClientSettings httpSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
/*
|
|
||||||
* Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId
|
* Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId
|
||||||
* documentation how to obtain sessionId https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages
|
* documentation how to obtain sessionId https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages
|
||||||
*/
|
*/
|
||||||
private String sessionId;
|
private String sessionId;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Optional: By default roomID is fetched before connect to live, but you can set it manually
|
* Optional: By default roomID is fetched before connect to live, but you can set it manually
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private String roomId;
|
private String roomId;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static LiveClientSettings createDefault()
|
public static LiveClientSettings createDefault()
|
||||||
{
|
{
|
||||||
var httpSettings = new HttpClientSettings();
|
var httpSettings = new HttpClientSettings();
|
||||||
@@ -103,12 +94,10 @@ public class LiveClientSettings {
|
|||||||
clientSettings.setPrintToConsole(false);
|
clientSettings.setPrintToConsole(false);
|
||||||
clientSettings.setLogLevel(Level.ALL);
|
clientSettings.setLogLevel(Level.ALL);
|
||||||
|
|
||||||
|
|
||||||
clientSettings.setHttpSettings(httpSettings);
|
clientSettings.setHttpSettings(httpSettings);
|
||||||
return clientSettings;
|
return clientSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Parameters for HTTP-Request
|
* Default Parameters for HTTP-Request
|
||||||
*/
|
*/
|
||||||
@@ -147,11 +136,9 @@ public class LiveClientSettings {
|
|||||||
clientParams.put("webcast_sdk_version", "1.3.0");
|
clientParams.put("webcast_sdk_version", "1.3.0");
|
||||||
clientParams.put("update_version_code", "1.3.0");
|
clientParams.put("update_version_code", "1.3.0");
|
||||||
|
|
||||||
|
|
||||||
return clientParams;
|
return clientParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Headers for HTTP-Request
|
* Default Headers for HTTP-Request
|
||||||
*/
|
*/
|
||||||
@@ -167,6 +154,4 @@ public class LiveClientSettings {
|
|||||||
headers.put("Accept-Language", "en-US,en; q=0.9");
|
headers.put("Accept-Language", "en-US,en; q=0.9");
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
proxyList.remove(index);
|
proxyList.remove(index);
|
||||||
|
lastSuccess = false; // index is no longer valid and lastSuccess needs falsified
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIndex(int index) {
|
public void setIndex(int index) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ 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.TikTokLiveException;
|
import io.github.jwdeveloper.tiktok.exceptions.*;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||||
import org.java_websocket.client.WebSocketClient;
|
import org.java_websocket.client.WebSocketClient;
|
||||||
|
|
||||||
@@ -91,6 +91,20 @@ public class TikTokWebSocketClient implements SocketClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void connectProxy(ProxyClientSettings proxySettings) {
|
public void connectProxy(ProxyClientSettings proxySettings) {
|
||||||
|
try {
|
||||||
|
if (proxySettings.getType() == Proxy.Type.SOCKS) {
|
||||||
|
SSLContext sc = SSLContext.getInstance("SSL");
|
||||||
|
sc.init(null, new TrustManager[]{new X509TrustManager() {
|
||||||
|
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {}
|
||||||
|
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {}
|
||||||
|
public X509Certificate[] getAcceptedIssuers() { return null; }
|
||||||
|
}}, null);
|
||||||
|
webSocketClient.setSocketFactory(sc.getSocketFactory());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// This will never be thrown.
|
||||||
|
throw new TikTokProxyRequestException("Unable to set Socks proxy SSL instance");
|
||||||
|
}
|
||||||
while (proxySettings.hasNext()) {
|
while (proxySettings.hasNext()) {
|
||||||
ProxyData proxyData = proxySettings.next();
|
ProxyData proxyData = proxySettings.next();
|
||||||
if (!tryProxyConnection(proxySettings, proxyData)) {
|
if (!tryProxyConnection(proxySettings, proxyData)) {
|
||||||
@@ -98,6 +112,7 @@ public class TikTokWebSocketClient implements SocketClient {
|
|||||||
proxySettings.remove();
|
proxySettings.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
pingingTask.run(webSocketClient);
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -107,21 +122,6 @@ public class TikTokWebSocketClient implements SocketClient {
|
|||||||
|
|
||||||
public boolean tryProxyConnection(ProxyClientSettings proxySettings, ProxyData proxyData) {
|
public boolean tryProxyConnection(ProxyClientSettings proxySettings, ProxyData proxyData) {
|
||||||
try {
|
try {
|
||||||
if (proxySettings.getType() == Proxy.Type.SOCKS) {
|
|
||||||
SSLContext sc = SSLContext.getInstance("SSL");
|
|
||||||
sc.init(null, new TrustManager[]{new X509TrustManager() {
|
|
||||||
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public X509Certificate[] getAcceptedIssuers() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}}, null);
|
|
||||||
webSocketClient.setSocketFactory(sc.getSocketFactory());
|
|
||||||
}
|
|
||||||
webSocketClient.setProxy(new Proxy(proxySettings.getType(), proxyData.toSocketAddress()));
|
webSocketClient.setProxy(new Proxy(proxySettings.getType(), proxyData.toSocketAddress()));
|
||||||
webSocketClient.connect();
|
webSocketClient.connect();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -128,11 +128,13 @@ public class RecorderListener implements LiveRecorder {
|
|||||||
|
|
||||||
@TikTokEventObserver
|
@TikTokEventObserver
|
||||||
private void onDisconnected(LiveClient liveClient, TikTokDisconnectedEvent event) {
|
private void onDisconnected(LiveClient liveClient, TikTokDisconnectedEvent event) {
|
||||||
|
if (isConnected())
|
||||||
liveDownloadThread.interrupt();
|
liveDownloadThread.interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@TikTokEventObserver
|
@TikTokEventObserver
|
||||||
private void onDisconnected(LiveClient liveClient, TikTokLiveEndedEvent event) {
|
private void onDisconnected(LiveClient liveClient, TikTokLiveEndedEvent event) {
|
||||||
|
if (isConnected())
|
||||||
liveDownloadThread.interrupt();
|
liveDownloadThread.interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,4 +196,8 @@ public class RecorderListener implements LiveRecorder {
|
|||||||
|
|
||||||
return new DownloadData(urlLink, sessionId);
|
return new DownloadData(urlLink, sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isConnected() {
|
||||||
|
return liveDownloadThread != null && liveDownloadThread.isAlive();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user