-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcommon.js
38 lines (38 loc) · 1.18 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"use strict";
var EventHandler = (function () {
function EventHandler() {
this.handlers = [];
}
EventHandler.prototype.on = function (handler) {
this.handlers.push(handler);
};
EventHandler.prototype.off = function (handler) {
this.handlers = this.handlers.filter(function (h) { return h !== handler; });
};
EventHandler.prototype.trigger = function (data) {
this.handlers.slice(0).forEach(function (h) { return h(data); });
};
return EventHandler;
}());
exports.EventHandler = EventHandler;
var Message = (function () {
function Message(mqttMessage) {
this.payload = mqttMessage.payloadString || '';
this.bytes = mqttMessage.payloadBytes || null;
this.topic = mqttMessage.destinationName || '';
this.qos = mqttMessage.qos || 0;
}
return Message;
}());
exports.Message = Message;
var guid = function () {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
};
exports.guid = guid;
//# sourceMappingURL=common.js.map