适用于网络的Firebase云消息传递

时间:2016-07-10 09:17:16

标签: firebase google-cloud-messaging messaging firebase-realtime-database firebase-cloud-messaging

我想使用Google的Firebase为网络构建一个消息传递应用。在此应用程序中,用户应向其他用户发送消息或从其他用户接收消息。我检查了Google的Firebase网站,但我迷路了。你能告诉我从哪里开始吗?你能告诉我任何与Firebase网络信息相关的教程或类似内容吗?我欢迎任何建议。感谢。

4 个答案:

答案 0 :(得分:6)

对于许多浏览器,Firebase Cloud Messaging for Web现在都是officially available

我们写了blogpost about our experience implementing it

答案 1 :(得分:3)

FCM(firebase云消息传递)只能通过Android,iOS和Web(指定的Google Chrome)实现。因此,要在所有浏览器的Web应用程序中使用它,我们必须实现firebase数据库。您可以看到此implementation of firebase database

答案 2 :(得分:3)

您还可以将Firebase Cloud Messaging用于带有Jquery的Web:

 $("#button").click(function(){

   var json = {
     "to": "dBbB2BFT-VY:APA91bHrvgfXbZa-K5eg9vVdUkIsHbMCwHRVc8dBAvoH_3ZxxxxxVVeMXP7Bm0iera5s37ChHmAVh29P8aAVa8HF0I0goZKPYdGT6lNl4MXN0na7xbmvF25c4ZLl0JkCDm_saXb51Vrte",
     "notification": {
       "title": "Push enviado com JQuery",
       "body": "Corpo de mensagem web!"
     },
     "data": {
       "titulo": "Título da mensagem de dados!",
       "descricao": "Corpo dos dados..."
     }
   };

   $.ajax({
    url: 'https://fcm.googleapis.com/fcm/send',
    type: "POST",
    processData : false,
    beforeSend: function (xhr) {
      xhr.setRequestHeader('Content-Type', 'application/json');
      xhr.setRequestHeader('Authorization', 'key=AIzaSyBShxxxxXevRq0trDbA9mhnY_2jqMoeChA');
    },
    data: JSON.stringify(json),
    success: function () {
      console.log("Mensagem enviada com sucesso!");
    },
    error: function(error) {
      console.log(error);
    }
  });
});

答案 3 :(得分:0)

您可以在这里看到它:https://github.com/ShaheerDev/RealtimeWebChatApp (我已经使用身份验证来登录用户,并使用实时数据库来获取消息并将消息发送到数据库。它也可以实时更新)