Crashfix in nsdmanager. StateSync reconnects less often. Channels are closed when sending fails in sync.

This commit is contained in:
Koen J 2025-05-01 21:53:48 +02:00
commit 9f78e9b7dd
3 changed files with 12 additions and 3 deletions

View file

@ -176,7 +176,11 @@ class StateCasting {
fun stopDiscovering() {
_nsdManager?.apply {
_discoveryListeners.forEach {
stopServiceDiscovery(it.value)
try {
stopServiceDiscovery(it.value)
} catch (e: Throwable) {
//Ignored
}
}
}
}

View file

@ -460,10 +460,10 @@ class StateSync {
Log.i(TAG, "Started relay session.")
} catch (e: Throwable) {
Log.e(TAG, "Relay session failed.", e)
Thread.sleep(5000)
} finally {
_relaySession?.stop()
_relaySession = null
Thread.sleep(5000)
}
}
}.apply { start() }
@ -737,6 +737,9 @@ class StateSync {
val json = String(dataBody, Charsets.UTF_8);
val history = Serializer.json.decodeFromString<List<HistoryVideo>>(json);
Logger.i(TAG, "SyncHistory received ${history.size} videos from ${remotePublicKey}");
if (history.size == 1) {
Logger.i(TAG, "SyncHistory received update video '${history[0].video.name}' (url: ${history[0].video.url}) at timestamp ${history[0].position}");
}
var lastHistory = OffsetDateTime.MIN;
for(video in history){

View file

@ -218,7 +218,9 @@ class SyncSession : IAuthorizable {
sent = true
break
} catch (e: Throwable) {
Logger.w(TAG, "Packet failed to send (opcode = $opcode, subOpcode = $subOpcode)", e)
Logger.w(TAG, "Packet failed to send (opcode = $opcode, subOpcode = $subOpcode), closing channel", e)
channel.close()
removeChannel(channel)
}
}