Sunday, 15 April 2012

javascript - Separating several socket.io connections from same user -



javascript - Separating several socket.io connections from same user -

i'm developing simple web application using node.js, express , socket.io 1 user able type , other able view , can't head around using socket.io.

flow after login, user see conversations. able click on "edit" or "view" conversation. display conversation , type transmitted using socket.io server , had clicked "view".

every conversation has id , user can view conversation going "/:id/view" , edit going "/:id/edit". problem when user opens several conversations editing, don't know how separate them. have code:

app.get("/:id/edit", function(req, res) { res.render('editing'); });

problem can't figure out how tell, when socket.io connects (in io.on("connection")), conversation id belongs to. thought utilize session save id of opened conversation, problem when user opens 2 conversations @ same time - won't possible separate these. solution came render conversation id in res.render javascript - like:

<html> ... <body> ... <script> var socket = io(); socket.emit("conversation_id", "{% id %}"); ... </script> </body> </html>

but think rendering client-side javascript isn't nice , there huge security problem - 1 time restrict viewing documents people belongs to, user able alter document id (since client-side) , connect other documents.

is there simple, canonical way of how properly? in short, want alternative of:

app.get("/:id/edit", function(req, res) { res.render('editing'); var socket = socket_from_socketio_that_connects_because_of_this; socket.on("type", function (data) { objects[req.params.id].text.push(data); }); });

thanks!

javascript node.js express socket.io

No comments:

Post a Comment