Rails faye实时通知系统
我正在尝试构建一个简单的基于 faye 实时的通知系统,以便我可以在某些操作上执行特定的 javascript。这个想法相对简单,尽管我在实现它时遇到了问题,但在阅读 faye 的文档后不确定采取哪条路。
目前的想法是
- 每个登录用户都有一个独特的 faye 通道,因此您可以仅将操作(弹出窗口、设置文本)推送给特定用户
- 我的应用程序布局中的一个 div,我可以将文本写入
- 保存布局的应用程序中的一个 div 。
现在我已经看过关于 faye 的 Railscast 教程,但 ryan 从控制器/操作方法创建工作 我不想在数据库中插入东西,只需从任何地方调用 JS 函数(我认为构建一个应用程序助手将是一个好主意),我只想做一些类似“执行 javascript 'set_text'” 的事情并执行javascript 'show_popup'
使用 Faye 构建此类功能的最佳方法是什么,基本上我只需
- 在某个 Faye 通道上执行 javascript 函数
即可完成弹出窗口和短信。 对此有点迷失,任何人都可以为我指出正确的方向,或者也许已经构建了这样的功能?谢谢!
Im trying to build a simple faye realtime based notification system so I can execute a certain javascript on certain actions.The idea is relatively simple though Im having problems implementing it, not sure wich road to take on this after reading the documentation of faye.
Current thoughts are
- One unique faye channel per logged-in user, so you can push a action (popup, set text) to a certain user only
- One div in my app layout that I can write text to
- One div in my app that holds layout for a popup
Now I've seen the railscast tutorial about faye but ryan works from a controller/action method create. I don't want to insert stuff in the db, just call the JS function from anywhere ( building an application helper would be a good idea I think ), I would just want to do something like "execute javascript 'set_text'" and execute javascript 'show_popup'
What would be the best way to build such functionality with Faye, Basically I only have to
- Execute a javascript function on a certain Faye channel
To accomplish the popup and text message.
A bit lost on this anyone can point me in the right direction or maybe have build such functionality already? thx in advanche!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在服务器端,您可以执行以下操作(这需要 eventmachine):
或者通过 HTTP:
然后在客户端,您可以对数据执行任何操作。
只需将
alert(1);
替换为您想要执行的任何 JS 即可。On the server side, you can just do (this needs eventmachine):
Or via HTTP:
Then on the client side, you can then do anything with the data.
Just replace
alert(1);
with whatever JS you want to execute.