简体   繁体   中英

Device-Device communication in react native app based on firebase

I have just started learning react-native and thinking of integrating firebase to it. Now consider my question scenario:

There are two users A & Bwho have the react app running in their device( none of them are admin). Now I have studied that when we connect our react native app to firebase, every instance of the app running on a device gets a unique token and that token is stored in firebase itself.

Now suppose user A wants to send a " notification or message" to user B. Now see the below code I saw on firebase official website:

// This registration token comes from the client FCM SDKs.
var registrationToken = 'YOUR_REGISTRATION_TOKEN';

var message = {
  data: {
    score: '850',
    time: '2:45'
  },
  token: registrationToken
};

// Send a message to the device corresponding to the provided
// registration token.
admin.messaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

This method seems quite straightforward, but is there really any method using which user A can know the unique token of user B like this:

const token= firebase.getToken('B');

And then use this token in the above code to send notification to user B. Is it poosible to do it using firebase?

Thank You.

The code you found uses the Firebase Admin SDK to send messages. This SDK grants its users full administrative access to the Firebase project, so can only be used in trusted environments, such as your development machine, a server you control, or Cloud Functions. It cannot be used in the app you send to your users.

You will need a trusted environment to send the messages to the users. For more on this, see:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM