Skip to content
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

Broadcast from request handler #75

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

Broadcast from request handler #75

hickford opened this issue Sep 10, 2011 · 1 comment

Comments

@hickford
Copy link

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
Copy link
Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant