CFenner/MMM-LocalTransport

View on GitHub
node_helper.js

Summary

Maintainability
A
0 mins
Test Coverage
/* MagicMirror²
 * Module: localtransport
 *
 * By Christopher Fenner https://github.com/CFenner
 * MIT Licensed.
 */
var NodeHelper = require('node_helper');
var request = require('request');

module.exports = NodeHelper.create({
  start: function () {
    console.log(this.name + ' helper started ...');
  },
  socketNotificationReceived: function(notification, payload) {
    //console.log(notification);
    if (notification === 'LOCAL_TRANSPORT_REQUEST') {
      var that = this;
      request({
          url: payload.url,
          method: 'GET'
        }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
          that.sendSocketNotification('LOCAL_TRANSPORT_RESPONSE', {
            id: payload.id,
            data: JSON.parse(body)
          });
        }
      });
    }
  }
});