• Pl chevron_right

      Alexander Gnauck: Firebase Cloud Messaging with MatriX XMPP SDK

      news.movim.eu / PlanetJabber • 17 hours ago • 1 minute

    We get a lot of requests on howto use the MatriX XMPP SDK with Google Firebase Cloud Messaging.

    The following are the settings for your XmppClient object

    • The XMPP domain is: gcm.googleapis.com
    • The hostname is: fcm-xmpp.googleapis.com
    • It looks like there are no SRV records in place, this is why you need to set the hostname manual and disable SRV record lookups
    • Firebase does not support XMPP’s StartTls feature and requires to initiate a TLS connection. This is how we have done it in the old days when the protocol still was called Jabber. The OldStyleSsl property takes care of this in MatriX’s XmppClient.
    • Firebase is using a non standard XMPP port, because no SRV records are in place we have to set port 5236 manual in the code
    • the username is your Firebase Sender Id and the password is your server key. You find them in the Firebase portal under Settings => Cloud Messagging
    • the contact list and presence feature is not require. So we can disable it by setting AutoRoster and AutoPresence to false
    XmppClient xmppClient = new XmppClient
    {
        XmppDomain          = "gcm.googleapis.com",
        Hostname            = "fcm-xmpp.googleapis.com",
        Port                = 5236,
        ResolveSrvRecords   = false,
        OldStyleSsl         = true,
        Username            = "YOUR_FIREBASE_SENDER_ID",
        Password            = "YOUR_FIREBASE_SERVER_KEY",
        AutoRoster          = false,
        AutoPresence        = false
    };
    
    xmppClient.Open();
    

    You can find a basic example also here in our GIT repository:
    https://gitlab.com/matrix-xmpp/samples/tree/master/csharp/FirebaseClient

    See also:
    https://firebase.google.com/docs/cloud-messaging/server#implementing-the-xmpp-connection-server-protocol