Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple disconnect #563

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,12 @@ class MqttService : Service(), MqttTraceHandler {
* @param activityToken arbitrary identifier to be passed back to the Activity
*/
fun disconnect(clientHandle: String, invocationContext: String?, activityToken: String?) {
val client = getConnection(clientHandle)
client.disconnect(invocationContext, activityToken)
connections.remove(clientHandle)

if (isConnectionAvailable(clientHandle)) {
val client = getConnection(clientHandle)
client.disconnect(invocationContext, activityToken)
connections.remove(clientHandle)
} else
Timber.w("Connection is not available $clientHandle")

// the activity has finished using us, so we can stop the service
// the activities are bound with BIND_AUTO_CREATE, so the service will
Expand Down Expand Up @@ -507,6 +509,8 @@ class MqttService : Service(), MqttTraceHandler {
return connections[clientHandle] ?: throw IllegalArgumentException("Invalid ClientHandle >$clientHandle<")
}

private fun isConnectionAvailable(clientHandle: String) = connections.contains(clientHandle)

/**
* Called by the Activity when a message has been passed back to the application
*
Expand Down
Loading