Created
December 30, 2015 08:42
-
-
Save pegasuskim/be0f95d147e9fcb70f74 to your computer and use it in GitHub Desktop.
mqtt handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mqtt = require('mqtt'); | |
var EventEmitter = require('events').EventEmitter; | |
var inherits = require('util').inherits; | |
module.exports = MqttProvider; | |
function MqttProvider( pushSetting ) { | |
var self = this; | |
self._initPushConnection(pushSetting); | |
}; | |
inherits(MqttProvider, EventEmitter); | |
MqttProvider.prototype._initPushConnection = function( settings ) { | |
var self = this; | |
var options = { qos:2, retain: true }; | |
var port = settings.port; | |
var host = settings.host; | |
//var reconnectPeriod = 100; | |
this.connection = mqtt.createClient( port, host, options ); | |
this.connection.on('error', function(err) { | |
console.log("mqtt connection Error " + err); | |
self.emit('error', err); | |
}); | |
}; | |
MqttProvider.prototype.pushNotification = function( notification, deviceToken, appId ) { | |
var connection = this.connection; | |
connection.publish( appId+'/'+deviceToken , JSON.stringify(notification) ); | |
console.log("pushNotification DATA: " + appId+'/'+deviceToken , JSON.stringify(notification) ); | |
}; | |
MqttProvider.prototype._createMessage = function( notification ) { | |
var message = {}; | |
return message; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment