diff options
Diffstat (limited to 'firebase-io')
-rwxr-xr-x | firebase-io/firebase-io.js | 13 |
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)=>{ |