I've been trying to send data through Google's FCM which will expire after 10 seconds. What I mean is that if the user wasn't connected to the internet during those 10 seconds, he won't receive it.
This is my Javascript
code for sending the request to the FCM:
var http = new XMLHttpRequest();
http.open("POST", "https://fcm.googleapis.com/fcm/send", true);
http.onreadystatechange = function() {};
http.setRequestHeader("Content-type", "application/json");
http.setRequestHeader("Authorization", "key=*****");
http.send(JSON.stringify({
"to": "/topics/all",
"data": {
"Title": "Test",
"areas": "Dan, Ayalon",
},
"android": {
"ttl": "10s" //I've tried also removing the s, and changing the ttl to TTL and time_to_leave
}
}));
The problem is that my android app still receives the data even 2 minutes later, after those 10 seconds passed. (What I did here is switching off the network ay my phone and turning it back on 2 minutes later)
I tried to send the request through the Firebase Console, and there it worked... I didn't receive the message a minute later. What am I doing wrong here?
Thank you!
Update: I thought about another solution. Maybe I'd send the current time manually, and then I'll make the client check how much time has passed? Does it sound like a good solution?
Update 2: I tried each and every example Google provided in their documentation and none of them worked. I also tried a million other ways to write the request and yet nothing worked. I'm starting to feel like it might be a bug. I reported Google and now I'm waiting for their response. I will update here their response.