Skip to content

Commit

Permalink
Merge pull request feedhenry#15 from witmicko/RHMAP-9474_lazy-load
Browse files Browse the repository at this point in the history
Rhmap 9474 lazy load
  • Loading branch information
witmicko authored Aug 26, 2016
2 parents d94ff54 + 78ab905 commit affe4c4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
20 changes: 14 additions & 6 deletions lib/push.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var AeroGear = require("unifiedpush-node-sender"),
assert = require('assert'),
futils = require('./fhutils');
var assert = require('assert'),
futils = require('./fhutils'),
aeroGearLoaded = false;

module.exports = function (cfg) {
assert.ok(cfg, 'cfg is undefined');
Expand All @@ -9,7 +9,7 @@ module.exports = function (cfg) {
var props = fhutils.getMillicoreProps();
var headers = {
'X-Project-Id': props.widget,
'X-App-Id': props.instance,
'X-App-Id': props.instance
};
fhutils.addAppApiKeyHeader(headers);
var settings = {
Expand All @@ -19,16 +19,24 @@ module.exports = function (cfg) {
headers: headers
};

var sender = AeroGear.Sender(settings);

// $fh.push
var sender;
return function push(message, options, callback) {
if (!aeroGearLoaded) {
var AeroGear = require("unifiedpush-node-sender");
sender = AeroGear.Sender(settings);
aeroGearLoaded = true;
}

if (!message) return callback(new Error("Missing required 'message' parameter"));
if (!options) return callback(new Error("Missing required 'options' parameter"));
if (!options.broadcast) {
if (!options.apps) return callback(new Error("Missing required 'options.apps' parameter while 'options.broadcast' not specified" + JSON.stringify(options)));
}
sender.send(message, options, callback);
if (sender){
sender.send(message, options, callback);
}
}
};

2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fh-mbaas-api",
"version": "5.13.8",
"version": "5.13.9",
"description": "FeedHenry MBAAS Cloud APIs",
"main": "lib/api.js",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sonar.projectKey=fh-mbaas-api
sonar.projectName=fh-mbaas-api-nightly-master
sonar.projectVersion=5.13.8
sonar.projectVersion=5.13.9

sonar.sources=./lib
sonar.tests=./test
Expand Down

0 comments on commit affe4c4

Please sign in to comment.