Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Broadcast from request handler #75

Open
hickford opened this Issue Sep 10, 2011 · 1 comment

Comments

Projects
None yet
1 participant

Hi. In Zappa, the server should be able to broadcast an event during a request handler. Presently (Zappa 0.2.0) the shortcut broadcast is only accessible in event handlers.

Example use case: When a tweet is HTTP posted, the server broadcasts an event to notify other browsers connected.

post '/': ->
    t = new tweet({body: @text, date: new Date})
    t.save()
    broadcast 'tweet', {tweet: t}

client '/t.js': ->
    connect()    # an aside: connect() is neglected in the documentation
    at tweet: ->
        alert @tweet.body

Proposed solution: make broadcast a shortcut for io.sockets.emit in request handlers (and elsewhere).

Workaround: def io: io in the app's scope and then io.sockets.emit in the request handler.

hickford commented Nov 1, 2011

Now I'm using 0.3.1 . The bug still exists. Here's the updated workaround: io = @io in the app's scope and then io.sockets.emit in the request handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment