问题
I am really rookie and need an advice.
I have read documentation, and as far as i understood if you need send direct message, follow next steps:
- Make authentification, eventually you get
Firebase TokenId
anduserId
- Send them to your server side and store it in DB
- When you are going to send a message you need create
json
and put insidetopic
text
andresipent userId
so on... - Send this
json
via HTTP to your server side - When server retrive this
json
, it should use Firebase API to create new message blocchild
with random name in firebase - Eventually server have to find recipent user in DB by userId that we get from message.
- After server will find current recipent user by userId , next we should take
firebase tokenId
In order to sent notification . - And send recipent user notification with such data - name of new
message bloc
child
- Recipent will connect to this current bloc and retrive data
It is as i understood this consept, fix me please if smth wrong?
回答1:
Your suggested approach sounds good. The most important thing to realize is that you require an app server to send a downstream message to a device. Using the database as the communication mechanism between the app and the app server is a popular approach.
You could also use Cloud Messaging's upstream capabilities. But I've never tried that approach, because the database works fine for me and I had little interest in learning yet another protocol (XMPP).
You can read how I implemented it in this Firebase blog post Sending notifications between Android devices with Firebase Database and Cloud Messaging.
来源:https://stackoverflow.com/questions/39244994/how-to-send-direct-message-via-firebase-from-user-to-user