aboutsummaryrefslogtreecommitdiff
path: root/firebase-io
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-05-24 21:04:16 +0200
committertomsmeding <tom.smeding@gmail.com>2017-05-24 21:04:16 +0200
commit096270b1d0ec09f0dbcfe8653957154a07a90de4 (patch)
treebbfaa58f0c2c83e9163bc9be01782f46bd5228a4 /firebase-io
parent438254db34608808f7d521fe871e21393542c556 (diff)
server: Fix firebase notifications
Diffstat (limited to 'firebase-io')
-rwxr-xr-xfirebase-io/firebase-io.js13
1 files changed, 10 insertions, 3 deletions
diff --git a/firebase-io/firebase-io.js b/firebase-io/firebase-io.js
index bfcca0f..e4e7305 100755
--- a/firebase-io/firebase-io.js
+++ b/firebase-io/firebase-io.js
@@ -10,6 +10,7 @@ firebase.initializeApp({
const fieldConverters=new Map([
["token",(b)=>b.toString()],
["user",(b)=>b.toString()],
+ ["to_user",(b)=>b.toString()],
["room",(b)=>b.toString()],
["message",(b)=>b.toString()],
["timestamp",(b)=>b.toString()], // Nanosecond timestamps are too close to 52-bit range
@@ -71,6 +72,7 @@ function processMessage(type,fields){
switch(type){
case "message":
const user=fields.get("user");
+ const to_user=fields.get("to_user");
const room=fields.get("room");
const token=fields.get("token");
const payload={
@@ -78,6 +80,10 @@ function processMessage(type,fields){
title: user+" ("+room+")",
body: fields.get("message"),
tag: room,
+ },
+ data: {
+ user: user,
+ room: room,
}
};
firebase.messaging().sendToDevice(token,payload)
@@ -85,10 +91,11 @@ function processMessage(type,fields){
const result=response.results[0];
const realToken=result.canonicalRegistrationToken;
if(result.error){
- console.error("JS: Send error:",result.error);
+ console.error("JS: Send error:",result.error.errorInfo);
+ console.log("delete_token "+to_user+" "+token);
} else if(realToken&&realToken!=token){
- console.log("delete_token "+user+" "+token);
- console.log("add_token "+user+" "+realToken);
+ console.log("delete_token "+to_user+" "+token);
+ console.log("add_token "+to_user+" "+realToken);
}
})
.catch((err)=>{