mauricemach / zappa

Node development for the lazy.
zappajs.org
MIT License
951 stars 81 forks source link

Share the Express session with Socket.IO, if it exists #90

Closed timshadel closed 12 years ago

timshadel commented 13 years ago

Based on the following article. Read the comments, too. http://www.danielbaulig.de/socket-ioexpress/

This lets regular requests that hit Express actions emit messages back to clients over all socket.io connections they've established (with the same Express session id).

This is great for handling some work asynchronously in Node (like file parsing) by sending back a response immediately, then sending updates to the browser as events occur during your long task (like 'finished parsing', or 'error parsing').

timshadel commented 13 years ago

Sorry. I'm not sure what you're pointing out. Did you add something, or did you notice that it exists already? Perhaps if you link to a line in the GitHub source that'd be easiest for me to understand.

[link to a line in the GitHub source](https://github.com/mauricemach/zappa/blob/master/src/zappa.coffee#L114)

Thanks!

timshadel commented 13 years ago

Rebased this onto 0.3.1. Should pull cleanly now.

timshadel commented 13 years ago

Hmm.. Maybe configuring client-side use of namespacing is a cleaner way to do this:

<script>
var me = io.connect('http://localhost/my-username-or-session-id');

me.on('connect', function () {
  me.emit('hi!');
});
</script>

Let me play around with that idea before you go and put all these new session references in there...I think the less that Zappa can think about the presence or absence of session the better.

timshadel commented 13 years ago

@mauricemach - No good. I've tried a few different approaches to starting and using the socket. There are workarounds for some cases, but I just can't find a good workaround for some others -- I need my normal controller functions to be able to @emit messages to the user's "room". So, the commit still stands as is.

mansona commented 12 years ago

has this progressed in the last 5 months? has this been solved in a different way?

shimaore commented 12 years ago

FWIW we're trying to address this in zappajs/zappajs#32 ; it'd be great to have some use cases so that we can validate we are providing what is needed (I already took into account @timshadel 's original description).