File tree Expand file tree Collapse file tree
app/src/main/java/com/sameerasw/airsync/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -343,6 +343,12 @@ object WebSocketUtil {
343343 reason : String
344344 ) {
345345 if (webSocket == WebSocketUtil .webSocket) {
346+ if (code != 1000 ) {
347+ CoroutineScope (Dispatchers .Main ).launch {
348+ val msg = reason.ifEmpty { " Unknown Server Disconnect" }
349+ android.widget.Toast .makeText(context, " Disconnected: $msg " , android.widget.Toast .LENGTH_SHORT ).show()
350+ }
351+ }
346352 isConnected.set(false )
347353 isSocketOpen.set(false )
348354 isConnecting.set(false )
@@ -377,8 +383,22 @@ object WebSocketUtil {
377383 ) {
378384 val totalToTry = ipList.size
379385 val failedCount = failedAttempts.incrementAndGet()
380-
381- if (webSocket == WebSocketUtil .webSocket || (! connectionStarted.get() && failedCount >= totalToTry)) {
386+ val wasActive = webSocket == WebSocketUtil .webSocket
387+ val isFinalManualAttempt = manualAttempt && ! connectionStarted.get() && failedCount >= totalToTry
388+
389+ if (wasActive || isFinalManualAttempt) {
390+ if (manualAttempt || isSocketOpen.get()) {
391+ CoroutineScope (Dispatchers .Main ).launch {
392+ val msg = when (t) {
393+ is java.net.ConnectException -> " Connection Refused (Is AirSync Mac running?)"
394+ is java.net.SocketTimeoutException -> " Could not discover your mac"
395+ is java.net.UnknownHostException -> " Could not reach your mac"
396+ is java.io.EOFException , is java.net.SocketException -> " Lost connection to your mac"
397+ else -> t.message ? : " Unknown connection error"
398+ }
399+ android.widget.Toast .makeText(context, " AirSync: $msg " , android.widget.Toast .LENGTH_LONG ).show()
400+ }
401+ }
382402 isConnected.set(false )
383403 isConnecting.set(false )
384404 isSocketOpen.set(false )
You can’t perform that action at this time.
0 commit comments