in app/src/main/java/com/amazonaws/ivs/basicbroadcast/viewModel/MainViewModel.kt [124:145]
override fun onError(error: BroadcastException) {
Log.d(TAG, "Error is: ${error.detail} Error code: ${error.code} Error source: ${error.source}")
if (error.error == ErrorType.ERROR_DEVICE_DISCONNECTED && error.source == microphoneDevice?.urn) {
microphoneDevice?.let {
try {
session?.exchangeDevices(it, it) { microphone ->
Log.d(TAG, "Device with id ${microphoneDevice?.deviceId} reattached")
microphoneDevice = microphone.descriptor
}
} catch (e: BroadcastException) {
Log.d(TAG, "Camera exchange exception $e")
}
}
} else if (error.error == ErrorType.ERROR_DEVICE_DISCONNECTED && microphoneDevice == null) {
launchMain {
Toast.makeText(context, "External device ${error.source} disconnected", Toast.LENGTH_SHORT).show()
}
} else {
error.printStackTrace()
launchMain { errorHappened.value = Pair(error.code.toString(), error.detail) }
}
}