-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How would be the best way to integrate Socket.io? #26
Comments
Thank you for your message, Carlos. Couple questions:
I think the clean way here is to restructure things so that such extensions are possible in a modular way and I am very open to doing it. Thanks |
Hi @inadarei, Thank you for your quick answer. I still did not find the best way to really modularise the application, and this is the point where I am stuck. These are the modifications I did on the nodebootstrap-server/app.js: ...
, http = require('http');
...
if (is_http_thread) {
http = http.createServer(app);
http.listen(CONF.app.port);
}
... ...
callback(app, http);
... Then, in the var io = require('socket.io')(http);
// Use example directly from the server.js file. It should be used in the modules.
io.on('connection', function(socket){
console.log('a user connected');
socket.on('disconnect', function(){
console.log('a user disconnected')
})
}); However, now the problem that I am facing is that I would like to use my socket.io
How would you get socket.io to work in the modules? Thank you, |
Thank you Carlos. Work on making NodeBootstrap to be more modular is well on its way and I hope to be able to support your use case soon. Appreciate all your information. |
+1 |
1 similar comment
+1 |
how does something like the following look: https://github.com/inadarei/nodebootstrap/blob/master/server.js#L13 Since websockets are not URL-path-driven and are event-driven, we don't actually need to do as much "magic" as we had with the callback support for HTTP routes. Each module just needs access to socketio instance and it can be passed-through during module initialization. Multiple modules can/should share the same instance as in the event-driven workflow, multiple modules are "allowed" to respond to the same event. All you should need is: pass websockets instance to the module, during inclusion. Sounds OK? |
Exactly what I have been doing. However, I think you may have meant to write On Mon, Apr 13, 2015, 00:03 Irakli Nadareishvili notifications@github.com
|
Hi @inadarei, This is the way I was doing too, passing the io object around. I am glad this idea made all its way to master :D. |
Awesome! Sounds great. Glad that websockets it nicely supported now. Thanks, guys! @feynmanliang, yes the code sample was supposed to have |
As part of my project, I need to integrate socket.io.
The way I found the cleanest was to modify the nodebootstrap-server to use the http library when listening the port and exposing the http handle to the callback so I could use that http handler in the server.js file to bind socket.io.
Any ideas on how to do this better? To be honest I don't like to depend on the nodebootstrap-server module. Maybe it could be a better aproach to expose those files in the project folder so they could be modified when needed (like my case)?
Thank you for this great bootstrap project.
Carlos.
The text was updated successfully, but these errors were encountered: