Skip to content

Commit

Permalink
Changing to pass fullstack test
Browse files Browse the repository at this point in the history
  • Loading branch information
sandro-k committed Oct 29, 2015
1 parent aa36299 commit 849a692
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
37 changes: 31 additions & 6 deletions mqtt-connection.html
@@ -1,6 +1,5 @@
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="mqttjs.html">
<link rel="import" href="mqemitter.html">

<!--
The `<mqtt-connection>` element exposes MQTT connection functionality to the web.
Expand Down Expand Up @@ -47,7 +46,7 @@
/**
* Fired when a connection is connected.
*
* @event mqtt-connection-connected
* @mqtt-subscription-unregister mqtt-connection-connected
*/

/**
Expand Down Expand Up @@ -152,7 +151,7 @@
notify: true,
readOnly: true,
value: function () {
return new MQEmitter();
return require("MQEmitter")();
},
},

Expand Down Expand Up @@ -252,6 +251,13 @@
type: Boolean,
readOnly: false,
value: false,
},

packetQueue: {
type: Array,
value: function(){
return [];
}
}

},
Expand Down Expand Up @@ -339,6 +345,21 @@
if(this.client) {
// actually send the `publish` message to the MQTT broker
this.client.publish(topic, message, opts, opt_callback);
} else {
var nop = function () {};
var queuePacket = {
cb: opt_callback || nop,
packet: {
cmd: 'publish',
topic: topic,
payload: message,
qos: opt_qos || 0,
retain: opt_retained || false,
messageId: 1
}
};

this.push("packetQueue", queuePacket);
}
},

Expand Down Expand Up @@ -405,8 +426,10 @@
* @private
*/
_createClient: function () {
// require mqtt from bundled browserified dependencies
var mqtt = require("mqtt");
if(mqtt) {
this._createClientDebounce();
this._createClientDebounce(mqtt);
// return this.debounce('_createClient', this._createClientDebounce());
} else {
// failed to load mqtt.js
Expand All @@ -416,8 +439,10 @@
}
},

_createClientDebounce: function(){
_createClientDebounce: function(mqtt){
this.set("options.clientId", this._generateClientId());
this.options["queue"] = this.packetQueue;

this.client = mqtt.connect(this.url, this.options);
this.client.setMaxListeners(this.maxListeners);
},
Expand Down Expand Up @@ -676,7 +701,7 @@
var sub = event.detail.target;
if(sub) {
if(sub.topic && this.client) {
this.client.unsubscribe(sub.topic);
this.client.unsubscribe(sub.topic, sub._handelSubscriptionUnsubscribed.bind(sub));
this._removeSubFromEmmitter(sub);
}
this._unregisterElement("subscriptions", sub);
Expand Down
2 changes: 1 addition & 1 deletion mqtt-publish.html
Expand Up @@ -124,7 +124,7 @@
publish: function () {
if(this.topic && this.topic.length > 0 && this.payload && this.payload.length > 0 && this._parentConnection) {
this._setPublished(false);
this._parentConnection.publish(this.topic, this.payload, this.qos, this.retained);
this._parentConnection.publish(this.topic, this.payload, this.qos, this.retained, this._handelPublicationPublished.bind(this));
}
},

Expand Down
9 changes: 4 additions & 5 deletions mqtt-subscription.html
Expand Up @@ -178,7 +178,7 @@
value: function () {
return this._handelMessage.bind(this);
}
},
}
},

behaviors: [MqttElements.MqttSubscriptionRegestrationBehaviour],
Expand Down Expand Up @@ -217,7 +217,6 @@
break;
default:
this.payloadParseFunction = String.fromCharCode;

}
},

Expand Down Expand Up @@ -264,12 +263,12 @@
_storeMessage: function (message) {
message.parsedPayload = this._parseMessage(message);

this._setLastMessage(message);

if(this.messages.length >= this.numberOfMessages) {
this.shift("messages");
}
this.push("messages", message);

this._setLastMessage(message);
},

/**
Expand All @@ -284,7 +283,7 @@
if(cb) {
cb();
}
},
}
})
})(window);
</script>

0 comments on commit 849a692

Please sign in to comment.