Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the user is offline and gets online he won't receive any of messages that was sent when he was offline unless a new message is sent #3807

Open
Stevemoretz opened this issue Sep 18, 2020 · 0 comments

Comments

@Stevemoretz
Copy link

[REQUIRED] Describe your environment

  • Operating System version: MacOS 10.15
  • Browser version: Opera 67.0.3575.97
  • Firebase SDK version: 7.20.0
  • Firebase Product: messaging

[REQUIRED] Describe the problem

Steps to reproduce:

I got the background and foreground and all working,But do this:

  1. Close the browser tab and disconnect internet from your browser (I use tripmode firewall to do this)
    2.Send a message to the client
    3.Connect back the browser and visit the website.
    4.You get no new messages.
    5.Send another message now.
    6.You'll see the old message also comes in with the new one.

So really?Shall I just send an empty message everytime the user gets in just to push the old messages which he didn't receive because he was offline?I don't think so.It sounds more like a bug to me.

Relevant Code:

firebase-messaging-sw.js

// Give the service worker access to Firebase Messaging.
// Note that you can only use Firebase Messaging here, other Firebase libraries
// are not available in the service worker.
importScripts('https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/7.20.0/firebase-messaging.js');

// Initialize the Firebase app in the service worker by passing in
// your app's Firebase config object.
// https://firebase.google.com/docs/web/setup#config-object
firebase.initializeApp({
//Stuff removed for no abusing
});

// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
const messaging = firebase.messaging();

messaging.setBackgroundMessageHandler(function(payload) {
    console.log('[firebase-messaging-sw.js] Received background message ', payload);
    // Customize notification here
    const notificationTitle = 'Background Message Title';
    const notificationOptions = {
        body: 'Background Message body.',
        // icon: '/firebase-logo.png'
    };

    return self.registration.showNotification(notificationTitle, notificationOptions);
});

bundle.js

import * as firebase from "firebase/app";

import "firebase/messaging";

var firebaseConfig = {
//removed
};

// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();
messaging.usePublicVapidKey("BC6x_n00j4PlXpAl4Dhuck7mkuBqPJ67AmB33YBGSgzsM2hPQUIlkdyqL94vmFNfb9pKAHiC1gM6D3l07O7RsUM");


// Get Instance ID token. Initially this makes a network call, once retrieved
// subsequent calls to getToken will return from cache.

const showToken = (msg) => {
    console.log(msg);
};

messaging.getToken().then((currentToken) => {
    if (currentToken) {
        // sendTokenToServer(currentToken);
        // updateUIForPushEnabled(currentToken);
        console.log(currentToken);
    } else {
        // Show permission request.
        console.log('No Instance ID token available. Request permission to generate one.');
        // Show permission UI.
        // updateUIForPushPermissionRequired();
        // setTokenSentToServer(false);
    }
}).catch((err) => {
    console.log('An error occurred while retrieving token. ', err);
    showToken('Error retrieving Instance ID token. ', err);
    // setTokenSentToServer(false);
});


// Callback fired if Instance ID token is updated.
messaging.onTokenRefresh(() => {
    messaging.getToken().then((refreshedToken) => {
        console.log('Token refreshed.');
        // Indicate that the new Instance ID token has not yet been sent to the
        // app server.
        // setTokenSentToServer(false);
        // Send Instance ID token to app server.
        // sendTokenToServer(refreshedToken);
        // ...
        console.log(refreshedToken);
    }).catch((err) => {
        console.log('Unable to retrieve refreshed token ', err);
        showToken('Unable to retrieve refreshed token ', err);
    });
});

messaging.onMessage((payload) => {
    console.log('Message received. ', payload);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants