Pass the socket.io variable around as a parameter to other files / components

var io = socket.io


require('./component1.js')(io)


...
// component1.js 

module.exports = function (io) {
// logic
} 

—
Sent from Mailbox for iPhone

On Sun, Jun 30, 2013 at 10:40 AM, Mike Chen <[email protected]> wrote:

> Hi guys,
> I'm pretty new to Node.JS and socket IO, so I was wondering if I could get 
> some guidance on project I'm working on. I would like to build a single 
> page multiplayer game that basically communicates solely through socket.IO. 
> However, I am quickly seeing that my socket.js file is getting very clumsy. 
> I am using express to manage the MVC side of things, but I feel like socket 
> connections don't really fit in the MVC paradigm. 
> I have read a bunch of tutorials on node JS and socket IO, but all of them 
> have small socket components. 
> Essentially I am wondering how to break down a large socket.js file into 
> smaller more manageable components? For example, I have a chat room in the 
> page, as well as the game part, and some meta game aspects. I don't feel 
> like these all belong in the same socket.js file, but it doesnt seem clean 
> to divide them in separate files either because you need access to the 
> client and the socket object ( to emit to all users in a room lets say) 
> Thanks
> -- 
> -- 
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: 
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
> --- 
> You received this message because you are subscribed to the Google Groups 
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to