简体   繁体   English

GeddyJS(Node.js + Socket.io框架)实时选项

[英]GeddyJS (Node.js+Socket.io framework) realtime option

I have a Geddy app that has some realtime models (I remember using -rt to generate some models), and I'd like to revisit the realtime-ness of my Geddy app. 我有一个具有某些实时模型的Geddy应用程序(我记得使用-rt生成了一些模型),我想重新审视我的Geddy应用程序的实时性。

I don't need my models to be updated automatically (I'm not sharing models with the client; I am using Geddy only as a REST backend) 我不需要自动更新模型(我不与客户端共享模型;我仅将Geddy用作REST后端)

But I would like to explicitly emit events through socket.io and use its room functionality in my controllers, and I'll handle those events in the client side appropriately. 但是我想通过socket.io显式发出事件,并在控制器中使用其房间功能,我将在客户端适当地处理这些事件。

So, my questions are: 1. how do I clean up my existing code in that I don't want realtime models in my app 2. what would I need to do in order to explicitly events from my controllers? 因此,我的问题是:1.我不希望在应用程序中使用实时模型,因此如何清理现有的代码2.为了显式地从控制器中发生事件,我需要做什么?

I tried doing the following in after_start.js as shown here: https://github.com/geddy/geddy/wiki/Realtime-and-MVC in "Realtime for existing projects" section, but none of the messages get logged... 我尝试在after_start.js中执行以下操作,如下所示: https : //github.com/geddy/geddy/wiki/Realtime-and-MVC在“现有项目的实时”部分,但是没有消息被记录。 。

console.log('Here 1');
geddy.io.sockets.on('connection', function(socket) {
    console.log('Here 2');
    socket.emit('hello', {message: "world"});
    socket.on('message', function(message) {
        console.log('Message!');
    });
});

Any help is much appreciated. 任何帮助深表感谢。 Thanks! 谢谢!

Just found out that the after_start.js was a workaround for the lack of events from the application to know when the server had actually started (so you would know when you could attach Socket.io). 刚刚发现after_start.js是一种解决方法,因为它缺少应用程序中的事件,无法知道服务器的实际启动时间(因此,您知道何时可以附加Socket.io)。 Now the geddy object in the worker process emits a 'started' event you can use: 现在,工作进程中的geddy对象会发出一个“ started”事件,您可以使用:

http://geddyjs.org/reference#global http://geddyjs.org/reference#global

So set a listener in your init.js for that event, and set your RT code up in there. 因此,请在init.js中为该事件设置一个侦听器,然后在其中设置RT代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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