问题
i would like to use socket.io along with Geddy. I just followed the instructions in the below link:
https://github.com/mde/geddy/wiki/Getting-started-with-Geddy,-Socket.io,-and-Authentication
Suggest me how to catch the 'connection' event on specific model in server-side.
Also find below the glimpse of what i have did so far with this model...
geddy scaffold -rt LiveUpdate stat:string category:string
And found the following auto-generated scripts related to socket.io in "show.html.ejs" of
geddy.io.addListenersForModels(['LiveUpdate']);
geddy.model.LiveUpdate.on('update', function (chat) {
....
What i actually need is to know how to catch or emit events for this model from the server-side.
回答1:
Emitting socket.io events from models and controllers in Geddy is pretty simple:
geddy.io.sockets.emit
will emit an event to all connected clients
If you want to listen for events from, or send events to specific clients, you'll need to create an after_start.js
file in your app's config directory, and use geddy.io
like you would normally use socket.io
:
geddy.io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
来源:https://stackoverflow.com/questions/13644551/geddyjs-socket-io-catching-and-emitting-events-from-server-side