FCM with Gdevelop (Firebase Cloud messaging)

Is there anyone who has already tried or succeeded in using FCM with Gdevelop? I would like to incorporate it. At this moment I have manually exported it to a cordova project and imported it into android studio. I am trying to do this :

Sending push notifications

I am stuck as where to put the code that gets the registration code and does the subscribing to a topic. I would guess that could be done in Gdevelop as Javascript but I do not know exactly where. I have used Firebase for many projects now and like very much what can be done with it. Is FCM planned to become a part of Gdevelop in the future too?

I can see that apply plugin: ‚Äėcom.google.gms.google-services‚Äô is already in the project thus would it be as simple as using

FirebaseInstanceId.getInstance().getInstanceId()
                        .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
        @Override
        public void onComplete(@NonNull Task<InstanceIdResult> task) {
            if (!task.isSuccessful()) {
                Log.w(TAG, "getInstanceId failed",
                task.getException());
                return;
            }

            // Get new Instance ID token
            String token = task.getResult().getToken();        
        }
    });

that code in Gdevelop? If so where would I do that best?

estoy en la mismo problema y sigo sin encontrarlo hallaste alguna manera

I did not solve it. The trouble is getting the device token. If there was a way to just get that I could sent it to my server and with a python script sent the notification messages. It has to do with the electron browser I believe. I also tried to compile it myself and change the code in android studio but I am just not savvy enough to get it to work unfortunatly. Hopefully one of the developers can come up with a solution one day. FCM would be the holy grail for my big two game as it would be able then to if users want to sent a message that their day dash is in danger for example.

It should look probably something like this

cordova.plugins.firebase.messaging.getToken().then(function(token) {
// Send the token to your server using a WebSocket or any other method
// …
console.log(‚ÄėFCM device token:‚Äô, token);
}).catch(function(error) {
console.error(‚ÄėError getting FCM device token:‚Äô, error);
});

But that requires a firebase plugin for cordova(cordova plugin add cordova-plugin-firebase). Then the project would need to be compiled using android studio that uses it to wrap all the html/css and javascript in it.

Is there anyone that can explain better why this is not working or if it at all one day will be?

FCM is tricky…

The Cordova plugin adds some interesting functionality, including this, crash analytics, native google/apple authentication…

The issue is that it is incompatibility with the web version, so you cannot for example authenticate with the mobile app then use that to access user data with the regular web SDK used for the rest of the Firebase integration… If we run both in parallel, it’ll also mess up the analytics, and possibly add other issues. Firebase is already one of the most absurdly big extensions for GDevelop, so adding support for the mobile ask would double the implementation count and therefore the amount of code to maintain… They also do not have feature parity leading to some features not working on mobile, some not working on the other platforms…

So we cannot easily integrate the mobile version of the sdk. Luckily, FCM also works on the web! There is a small problem though… It requires a service worker to handle notifications while your app is not open. GDevelop’s code generator is very generic, so that it can compile events to any programming language. Therefore it does not know about concepts such as a service worker, since it’s something specific to the web platform and therefore we cannot generate the necessary service worker code…

1 Like