Skip to content

Commit

Permalink
ver. 1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
efraespada committed Jun 24, 2017
1 parent 159be11 commit eae7e77
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
50 changes: 38 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ function FlamebaseDatabase(database, path) {
*/
this.syncFromDatabase = function() {
try {
console.log("####################### data path: " + path);
if (this.debugVal) {
logger.debug("####################### data path: " + path);
}
object.ref = object.db.getData(path);
this.lastStringReference = JSON.stringify(object.ref);
if (this.debugVal) {
logger.debug("####################### ref: " + JSON.stringify(object.ref));
}
object.syncNotifications();
} catch(e) {
console.log("####################### not found, generating {} ");
Expand Down Expand Up @@ -179,6 +185,8 @@ function FlamebaseDatabase(database, path) {
sen.notification = notification;
this.sendPushMessage(sen);
}
} else if (this.debugVal) {
logger.debug("no differences located");
}
}

Expand Down Expand Up @@ -211,6 +219,8 @@ function FlamebaseDatabase(database, path) {
s.notification = notification;
this.sendPushMessage(s);
}
} else if (this.debugVal) {
logger.debug("no differences located");
}
}
};
Expand Down Expand Up @@ -250,20 +260,36 @@ function FlamebaseDatabase(database, path) {
var notificationLength = JSON.stringify(notification).length;

var differences = JSON.stringify(diff(JSON.parse(this.lastStringReference), this.ref));
differences = this.string2Hex(differences);
var partsToSend = [];
var limit = os.indexOf(this.OS.IOS) !== -1 ? this.lengthLimit.IOS - notificationLength : this.lengthLimit.ANDROID - notificationLength;
if (differences.length > limit) {
var index = -1;
var pendingChars = differences.length;
while (pendingChars > 0) {
index++;
var part = differences.slice(index * limit, (pendingChars < limit ? index * limit + pendingChars : (index + 1) * limit));
pendingChars = pendingChars - part.length;
partsToSend.push(part);

if (this.debugVal) {
logger.debug("diff: " + differences);
}

if (differences === "false") {
var currentStringRef = JSON.stringify(this.ref);
if (this.lastStringReference.length != currentStringRef.length) {
logger.error("something went wrong; chars diff: " + (this.lastStringReference.length - currentStringRef.length));
}
if (this.debugVal) {
logger.debug("no differences");
}
} else {
partsToSend.push(differences);
differences = this.string2Hex(differences);

var limit = os.indexOf(this.OS.IOS) !== -1 ? this.lengthLimit.IOS - notificationLength : this.lengthLimit.ANDROID - notificationLength;
if (differences.length > limit) {
var index = -1;
var pendingChars = differences.length;
while (pendingChars > 0) {
index++;
var part = differences.slice(index * limit, (pendingChars < limit ? index * limit + pendingChars : (index + 1) * limit));
pendingChars = pendingChars - part.length;
partsToSend.push(part);
}
} else {
partsToSend.push(differences);
}
}

var result = {};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.1.0"
"version": "1.1.1"
}

0 comments on commit eae7e77

Please sign in to comment.