如何建立像Facebook这样的实时推送通知功能? [英] How to build realtime push notification feature like facebook does?

查看:248
本文介绍了如何建立像Facebook这样的实时推送通知功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要为我的Web应用程序(一个小型​​社交网络)构建实时推送通知功能,而且我不知道从哪里开始.

I'm going to build realtime push notification feature for my web application ( a small social network) and I don't know where to start.

这就是我要构建的:有类似按钮,注释表单,……用户单击喜欢,写下他们的注释,并(相对)立即在所有者的浏览器上显示新的喜欢和注释的数量,..那样的东西.

This is what I want to build: there are like buttons, comment forms, ... Users click like, write their comments and (relatively) immediately, on the owner's browser shows the number of new likes and comments, ... Something like that.

我已经阅读了有关nodeJs,MeteorJS上的socketIo的信息,但是不幸的是,它们需要现代浏览器支持的WebSocket.我刚刚阅读了Comet技术,发现它很容易应用.但是我不确定它是否会运行良好,因为Comet依赖长轮询连接(如果我错了,请纠正我).

I've read about socketIo on nodeJs, MeteorJS but unfortunately, they need WebSocket supported by mordern browsers. I've just read about Comet technic and find it pretty easy to apply. But i'm not sure it will performs well because Comet relies on long-polling connection (correct me if I'm wrong).

此外,我认为Facebook正在将Comet用于其推送通知功能.通过firebug插件上的控制台选项卡,我可以看到始终与Facebook保持连接. 因此,有人可以向我展示一种开发这种功能的技术和模型吗?

In addition, I think facebook is using Comet for its push notification feature. Through console tab on firebug plugin I can see there's alway a holding connection to facebook. So can anybody show me a technic, a model to develop a feature like that?

推荐答案

一个有前途的想法是使用HTML5通知API.如果您希望只要他的浏览器正在运行就在用户屏幕上弹出通知,那将是一个完美的选择(即使您正在浏览其他网站或所有窗口都已关闭).

A promising idea is to work with the HTML5 notification API; it's perfect if you want notifications to pop on the user screen as long as his browser is running (even if you're surfing another website or if all windows are closed).

http://www.paulund.co.uk/html5-notifications

但是,如果要异步更新页面的不同部分(无需刷新或按下按钮),则应一起使用:

However, if what you want is to update different parts of your page asynchronously (without refreshing or pushing a button), you should use together :

  • Ajax调用;
  • 听众和观察者.

当您Ajax调用以检索特定类型的json数据(例如)时,它可以触发带有许多新通知的徽章(侦听器)的出现,等等.

When you Ajax calls retrieve particular types of json data (for example), it can trigger appearance of a badge (listener) with a number of new notifications, or so...

安装了JQuery后,您应该没事...

With JQuery installed, you should be fine...

即使通常不是这种情况,有时,对于简单的调整,编写完成的工作也更容易...

Even though it's often not the case, sometimes, for simple tweaks, it's easier to code the job done...

您可以从这里开始:

如何实现观察者"在没有插件的Jquery中?(虽然很老,但是很有趣)

How implement a "observer" in Jquery without plugins? (it's old, but interesting)

或查看此页面:

使用ajax/jquery浏览器即时更新

(令人难以置信的google查询多久返回一次stacko的页面)

(incredible how often google queries return stacko' pages)

这篇关于如何建立像Facebook这样的实时推送通知功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆