Giter Site home page Giter Site logo

fcmstream's Introduction

FCMStream

FCMStream is app server to send or receive messages from Firebase Cloud Messaging (FCM) using XMPP Protocol.

Usage

FCMStream will stream the Firebase Cloud Messaging (FCM) server through XMPP protocol for incoming messages and registers callback functions to handle the messages and acknowledgements when the messages arrive.

Issues

Firebase Cloud Messaging server sometimes has delayed issue on deliver messages to the app server or client apps, so the messages will be received on user end after at an average 2 minutes.

Start Service

To start the service from the shell:

php FCMStream/service.php

(You may need to prefix "php" with the full path of the executable.)

The service will registers callback functions through stream.php to handle the messages and acknowledgements when the messages arrive.

Make sure you configure the code for your project, fill the Sender ID and API key with credentials obtained from Firebase Console. Default server address and port have values intended for development; the production version have different endpoints port (fcm-xmpp.googleapis.com and 5235) see XMPP server references. Please assure also that no firewall blocks the port specified.

When FCMStream lost connection to the FCM server, it will retry to reconnect (configurable options).

fcmstream's People

Contributors

sourc7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fcmstream's Issues

Can not make it work with latest Server key (long one)

Looks like this project does not work anymore with new FCM server key.

Running at PHP 7 and fixing incorrect "?>" in one of scripts I was finally getting some output from service.php like below.

As for service.php variable 'api_key' - looks like FCM is expecting new "Server key" (like AAAAfJORI48:APA91...), not "Legacy server key" (like AIzaSyDX..) from its console - Cloud messaging. With new key I have no output at all.

With old key I got error
=== Connecting to fcm-xmpp.googleapis.com:5235... === 07:33:32 === === Sent 129 bytes === 07:33:32 === === Read 152 bytes === 07:33:32 === === Read 197 bytes === 07:33:32 === X-OAUTH2X-GOOGLE-TOKENPLAIN === Sent 169 bytes === 07:33:32 === ADUzNTA1MTcwNzI3OUBnY20uZ29vZ2xlYXBpcy5jb20AQUl6YVN5QzFNOHJUa2tMVnBYb0NPT055bklodmJr === Read 194 bytes === 07:33:32 === Received BROWSER API key. Only SERVER API keys are accepted. === Read 16 bytes === 07:33:32

I got in touch with FB support and got reply:
Based off the error, looks like you're using the wrong key. You should be using the FCM server key. This can be found in the Firebase Console under the Project Settings -> Cloud Messaging.

see details at https://stackoverflow.com/questions/50004547/firebase-cloud-messaging-returns-received-browser-api-key-only-server-api-keys

Gets stuck at Maximum execution time of 30 seconds exceeded

private function read($socket) {
$response = fread($socket, 1389);
echo 'read function';

After getting auth it goes in loop , i think its read function where it stuck.

=== Connecting to fcm-xmpp.googleapis.com:5236... === 08:24:18 === === Sent 129 bytes === 08:24:19 === read function=== Read 152 bytes === 08:24:20 === read function=== Read 197 bytes === 08:24:20 === X-OAUTH2X-GOOGLE-TOKENPLAIN === Sent 321 bytes === 08:24:20 === XXXXXX............................XXXXXXXXXXXXXXXXW9ORHh4N29aV0w1eGJRd0JweXZDckljRDliS3dGMUg= read function=== Read 51 bytes === 08:24:20 === === Sent 129 bytes === 08:24:20 === read function=== Read 152 bytes === 08:24:20 === read function=== Read 137 bytes === 08:24:20 === === Sent 173 bytes === 08:24:20 === test === Sent 148 bytes === 08:24:20 === read function=== Read 207 bytes === 08:24:21 === [email protected]/test403BFA94 === Streaming FCM Cloud Connection Server... === 08:24:21 === read function=== Read character 32 === 08:24:21 === === Keepalive exchange === 08:24:21 === === Sent 2 bytes === 08:24:21 === read function=== Read 94 bytes === 08:24:21 ===
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\FCMStream-master\stream.php on line 193

This is What i Got.

Sasl authentification failure

Hi, I am trying to convert my project from using the http to xmpp protocol to receive upstream messages and decided to try out your code. I used the sender_id and api_key which I already had from my working project. When starting the service from the shell the sasl authentification fails. Here is the log from my shell:

$ php FCMStream/service.php === Connecting to fcm-xmpp.googleapis.com:5235... === 11:42:40 === === Sent 129 bytes === 11:42:41 === <stream:stream to="fcm-xmpp.googleapis.com" version="1.0" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams"> === Read 152 bytes === 11:42:41 === <stream:stream from="fcm-xmpp.googleapis.com" id="/*id.....*/" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client"> === Read 197 bytes === 11:42:41 === <stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features> === Sent 321 bytes === 11:42:41 === <auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">/*authentification_id....*/==</auth> === Read 77 bytes === 11:42:41 === <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure> === Read 16 bytes === 11:42:41 === </stream:stream> === Read 0 bytes === 11:42:41 === === Read 0 bytes === 11:42:41 === === Read 0 bytes === 11:42:41 === === Read 0 bytes === 11:42:41 === === Read 0 bytes === 11:42:41 === === Read 0 bytes === 11:42:41 === === Read 0 bytes === 11:42:41 ===

any updates?

i tried running it today and it immediately exited with error ..

PHP Parse error: syntax error, unexpected 'exit' (T_EXIT), expecting identifier (T_STRING) in /home/user/bin/garagejs/FCMStream/stream.php on line 118

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.