mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-08-06 00:00:10 +00:00
Casting stability fixes to ChromeCast connection thread.
This commit is contained in:
parent
4cb1bf268f
commit
34d4d92289
3 changed files with 18 additions and 5 deletions
|
@ -138,7 +138,7 @@ class AirPlayCastingDevice : CastingDevice {
|
||||||
try {
|
try {
|
||||||
val connectedSocket = getConnectedSocket(adrs.toList(), port);
|
val connectedSocket = getConnectedSocket(adrs.toList(), port);
|
||||||
if (connectedSocket == null) {
|
if (connectedSocket == null) {
|
||||||
delay(3000);
|
delay(1000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ import org.json.JSONObject
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
import java.io.DataOutputStream
|
import java.io.DataOutputStream
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
|
import java.net.InetSocketAddress
|
||||||
|
import java.net.Socket
|
||||||
import java.security.cert.X509Certificate
|
import java.security.cert.X509Certificate
|
||||||
import javax.net.ssl.SSLContext
|
import javax.net.ssl.SSLContext
|
||||||
import javax.net.ssl.SSLSocket
|
import javax.net.ssl.SSLSocket
|
||||||
|
@ -303,17 +305,18 @@ class ChromecastCastingDevice : CastingDevice {
|
||||||
_thread = Thread {
|
_thread = Thread {
|
||||||
connectionState = CastConnectionState.CONNECTING;
|
connectionState = CastConnectionState.CONNECTING;
|
||||||
|
|
||||||
|
var connectedSocket: Socket? = null
|
||||||
while (_scopeIO?.isActive == true) {
|
while (_scopeIO?.isActive == true) {
|
||||||
try {
|
try {
|
||||||
val connectedSocket = getConnectedSocket(adrs.toList(), port);
|
val resultSocket = getConnectedSocket(adrs.toList(), port);
|
||||||
if (connectedSocket == null) {
|
if (resultSocket == null) {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connectedSocket = resultSocket
|
||||||
usedRemoteAddress = connectedSocket.inetAddress;
|
usedRemoteAddress = connectedSocket.inetAddress;
|
||||||
localAddress = connectedSocket.localAddress;
|
localAddress = connectedSocket.localAddress;
|
||||||
connectedSocket.close();
|
|
||||||
break;
|
break;
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
Logger.w(TAG, "Failed to get setup initial connection to ChromeCast device.", e)
|
Logger.w(TAG, "Failed to get setup initial connection to ChromeCast device.", e)
|
||||||
|
@ -332,7 +335,16 @@ class ChromecastCastingDevice : CastingDevice {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_socket?.close()
|
_socket?.close()
|
||||||
_socket = factory.createSocket(usedRemoteAddress, port) as SSLSocket;
|
if (connectedSocket != null) {
|
||||||
|
Logger.i(TAG, "Using connected socket.")
|
||||||
|
_socket = factory.createSocket(connectedSocket, connectedSocket.inetAddress.hostAddress, connectedSocket.port, true) as SSLSocket
|
||||||
|
connectedSocket = null
|
||||||
|
} else {
|
||||||
|
Logger.i(TAG, "Using new socket.")
|
||||||
|
val s = Socket().apply { this.connect(InetSocketAddress(usedRemoteAddress, port), 5000) }
|
||||||
|
_socket = factory.createSocket(s, s.inetAddress.hostAddress, s.port, true) as SSLSocket
|
||||||
|
}
|
||||||
|
|
||||||
_socket?.startHandshake();
|
_socket?.startHandshake();
|
||||||
Logger.i(TAG, "Successfully connected to Chromecast at $usedRemoteAddress:$port");
|
Logger.i(TAG, "Successfully connected to Chromecast at $usedRemoteAddress:$port");
|
||||||
|
|
||||||
|
|
|
@ -285,6 +285,7 @@ class FCastCastingDevice : CastingDevice {
|
||||||
connectionState = CastConnectionState.CONNECTING;
|
connectionState = CastConnectionState.CONNECTING;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
_socket?.close()
|
||||||
if (connectedSocket != null) {
|
if (connectedSocket != null) {
|
||||||
Logger.i(TAG, "Using connected socket.");
|
Logger.i(TAG, "Using connected socket.");
|
||||||
_socket = connectedSocket
|
_socket = connectedSocket
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue