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

Refactor connection handling and add support for WebSocket #112

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions lib/mqtt5_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ library mqtt5_client;

import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:meta/meta.dart';
import 'package:typed_data/typed_data.dart' as typed;
Expand Down
23 changes: 20 additions & 3 deletions lib/src/connectionhandling/mqtt_connection_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,27 @@ class MqttConnectionBase {
void _disconnect() {
// On disconnect clean(discard) anything in the message stream
messageStream.clean();
if (client != null) {
client.destroy();
client = null;

// Close the client
if (client == null) {
return;
}

if (client is WebSocket) {
final wsClient = client as WebSocket;
wsClient.close();
} else if (client is Socket) {
final socketClient = client as Socket;
socketClient.destroy();
} else {
try {
client.destroy();
} catch (e) {
MqttLogger.log('MqttConnectionBase::_disconnect - exception raised $e');
}
}

client = null;
}

/// User requested or auto disconnect disconnection
Expand Down
Loading