Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to subscribe to a FCM topic from a web client?

Tags:

I want to subscribe to a FCM (Firebase Cloud Messaging) topic from the front end (web) of an Angular application.

From what I've learned from here and here, it looks like subscription to topics can't be done via web from the front end. The client should send a token and a topic to the server, then the server should request the subscription to FCM.

I'd like to know if there's a way I can securely subscribe to topics directly via web.

like image 989
Marcelo Henrique Bittencourt Avatar asked Aug 14 '19 15:08

Marcelo Henrique Bittencourt


People also ask

How do I subscribe to a topic in FCM?

You can subscribe client app instances to any existing topic, or you can create a new topic. When you use the API to subscribe a client app to a new topic (one that does not already exist for your Firebase project), a new topic of that name is created in FCM and any client can subsequently subscribe to it.

How do I send notifications to topic FCM?

fun sendMessage(title: String, content: String,topic: String) — This method is used to send Messages as Push Notifications to devices that are subscribed to a particular topic. Let's see how this method works internally. It uses HttpUrlConnection internally to trigger an API. (i.e https://fcm.googleapis.com/fcm/send).

Does FCM work on web?

The FCM JavaScript API lets you receive notification messages in web apps running in browsers that support the Push API. This includes the browser versions listed in this support matrix and Chrome extensions via the Push API. The FCM SDK is supported only in pages served over HTTPS.


1 Answers

yes it can be done client side

this.push.subscribe(
  'your Topic',
  () => {
    console.log('success');
  },
  e => {
    console.log('error:', e);
  }
);

more information

https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/API.md

https://ionicframework.com/docs/native/push

this is related your topic

https://forum.ionicframework.com/t/firebase-push-notification-topic-subscription/95523/6

like image 98
Chanaka Weerasinghe Avatar answered Oct 15 '22 11:10

Chanaka Weerasinghe