Skip to content

Commit

Permalink
Merge pull request #7 from Rasarts/Update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
jnguillerme authored Sep 4, 2017
2 parents e532ade + cc41fa4 commit 90b7201
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# See https://www.dartlang.org/tools/private-files.html

# Files and directories created by pub
.packages
.pub/
build/
# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock

# Directory created by dartdoc
# If you don't generate documentation locally you can remove this line.
doc/api/
20 changes: 17 additions & 3 deletions lib/mqtt_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class MqttClient<E extends VirtualMqttConnection> {
var onSubscribeData = null;
var onConnectionLost = null;
Map<int, Completer> _messagesToCompleteMap;

String userName;
String userPassword;

var _liveTimer;

Expand All @@ -20,7 +23,7 @@ class MqttClient<E extends VirtualMqttConnection> {
/**
* MqttClient constructor
*/
MqttClient(E mqttConnection, {String clientID: '', num qos: 0x0, bool cleanSession:true} )
MqttClient(E mqttConnection, {String clientID: '', num qos: 0x0, bool cleanSession:true, String this.userName, String this.userPassword} )
: _mqttConnection = mqttConnection, _clientID = clientID, _qos = qos, _cleanSession = cleanSession, debugMessage = false, _will = null;

/**
Expand All @@ -40,8 +43,11 @@ class MqttClient<E extends VirtualMqttConnection> {
* An optional callback can be provided to be called when
* the connection to the mqtt broker has been lost
*/
Future<int> connect([onConnectionLostCallback]) {
Future<int> connect([onConnectionLostCallback, String uName, String uPassword]) {
_connack = new Completer();

userName = uName != null ? uName : userName;
userPassword = uPassword != null ? uPassword : userPassword;

if (onConnectionLostCallback != null) onConnectionLost = onConnectionLostCallback;

Expand Down Expand Up @@ -164,6 +170,10 @@ class MqttClient<E extends VirtualMqttConnection> {
void _openSession() {
print("Opening session");
MqttMessageConnect m = new MqttMessageConnect.setOptions(_clientID, _qos, _cleanSession);

m._userName= userName;
m._password = userPassword;
m.setUserNameAndPassword(userName, userPassword);

// set will
m.setWill(_will);
Expand All @@ -190,7 +200,11 @@ class MqttClient<E extends VirtualMqttConnection> {
*
* Return the data that has not been processed
*/
List<int> _processMqttMessage(data) {
List<int> _processMqttMessage(dynamic details) {
var data = details;

if (details.runtimeType.toString() != 'Uint8List') data = details.asInt8List();

num type = data[0] >> 4;
int msgProcessedLength = data.length;

Expand Down
2 changes: 1 addition & 1 deletion lib/mqtt_message_suback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MqttMessageSuback extends MqttMessageAssured {
* byte 2 - Message ID LSB
*/
num decodeVariableHeader(List<int> data) {
assert(data.length == 3);
// assert(data.length == 3);

messageID = 256 * data[0] + data[1];

Expand Down
1 change: 1 addition & 0 deletions lib/mqtt_shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'mqtt_version_v3.dart' ;
import "package:ini/ini.dart";
import 'dart:io';
import 'dart:convert';
import 'dart:typed_data';

part 'mqtt_client.dart';
part 'mqtt_connection_shared.dart';
Expand Down

0 comments on commit 90b7201

Please sign in to comment.