4

I am trying to set up FCM functionalities into my app. At the moment, I would like to display a button such that when the user presses the button an upstream message is generated which is sent to Google's CCS. It is my understanding that this upstream message will be turned into an XMPP stanza by the Google CCS. Then, it will be delivered to the phone that has the id I set to when creating the upstream message. After reading the documentation on FCM from google, I see that it is very simple to create an upstream message:

FirebaseMessaging fm = FirebaseMessaging.getInstance();
fm.send(new RemoteMessage.Builder(SENDER_ID + "@gcm.googleapis.com")
.setMessageId(Integer.toString(msgId.incrementAndGet()))
.addData("my_message", "Hello World")
.addData("my_action","SAY_HELLO")
.addData()//somewhere in here must be a way to set the senderId of the phone
// i am trying to send the message to ??? 
.build());  

Now by looking at the code above, i see in no way XMPP being used to create this upstream message. No XMPP stanza creation. My question deals with where does this XMPP stanza be delivered to? Once it leaves Google's CCS. I see a method on the class that extends FirebaseMessagingService called onMessageReceived. It is my understanding that in this method is where the XMPP stanza will be delievered. Or, will it be delivered on the Smack library connection I intend to set up which will have a PacketListener. According to the example by "Gronkking Android", Google's CCS XMPP stanzas will be delivered here on this packetlistener. I do intend to follow this example to receive these coming stanzas and generate the required ack messages.

If anyone has any thoughts or ideas it would be great to hear your comments

Thank you

i_o
  • 777
  • 9
  • 25
  • Ok. So this app server resides on the application code or is it external to it. From the examples I've seen I could just get by with an xmpp interface that communicates with CCS and store relevant info on a web server such as GoDaddy. But, still I don't know how to implement these stanzas for communication with CCS via smack. According to the docs, I must authorize my connection with stanzas. Should I register a packet listener with my connection? I will try this to see what my connection receives from CCS. @arthurthompson – i_o Jul 01 '16 at 19:14
  • A very simple explanation: The app server could be your home server or some server you have access to (hosted server) and It must be running an xmpp server app. It keeps connected to FCM and when your upstream message arrives from the device, the FCM will send the message to your app server. – MisterWalrus Jul 30 '16 at 17:59
  • So how come the firebase docs say that CCS uses XMPP as an authenticated transport layer. It says i could use any XMPP library to manage the connection. Since Smack library provides all the support needed for TLS and aurhentication and its an XMPP library i could use it ti manage the connection to create an app server. But i choose to use it inside my code not external to it. Connection objects in Smack could process stanzas too. I've already set TLS with Smack inside my code. I am already getting connected with my code not with an app server. I am having problems with SASLauth. @MisterWalrus – i_o Jul 30 '16 at 19:53
  • Yes, I suppose you are right. I don't see why if you implement all necesary XMPP support your app server could not be a device. TBH, I did not look at the problem the way you are forcing me to look at. You might be right – MisterWalrus Jul 30 '16 at 20:18
  • Smack could manage the connection. Problem is that most of the Smack samples are outdated. Even the javadocs arent updated. Its a challenge trying to piece valid information. @MisterWalrus – i_o Jul 30 '16 at 22:16

2 Answers2

6

Device to device messaging is not supported by FCM. Upstream messages are designed to go from your mobile device through CCS to your XMPP app server. Once your XMPP app server receives the message it can decide to send a downstream message through CCS to a mobile device. The XMPP communication with stanzas is done between CCS and your XMPP app server.

Arthur Thompson
  • 9,087
  • 4
  • 29
  • 33
1

FCM cloud service is good for PUSH notifications downstream from a corporation system, or a bank system, etc. Otherwise, to do the job of upstream message, you need your own XMPP application server (usually on public IP), I don't see any way around it. The FCM cloud service will just forward all the messages received to it without even reading them; it will be the application server duty, to route all the messages to the correct mobile device, always by recalling the FCM cloud service. I guess it would be easier without FCM service in the middle, just using your own XMPP server at some public IP, and the mobile device app should work like an XMPP client.

Zanna
  • 676
  • 9
  • 13