Created
April 2, 2011 02:25
-
-
Save ggoodman/899182 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ = require('jquery') | |
$ -> | |
$('#input').keypress (e) -> | |
if e.keyCode == 10 || e.keyCode == 13 | |
live.send 'relay', $('#input').val() | |
$('#input').val('').focus() | |
live = require('./live').client() | |
.expose | |
serverMessage: (name, message) -> | |
console.log "*** #{name} #{message}" | |
talk: (name, message) -> | |
$('<dt>', {text: name}).appendTo('#chat') | |
$('<dd>', {text: message}).appendTo('#chat') | |
getName: (cb) -> | |
name = prompt("What is your name") | |
if name then cb(false, name) | |
else cb(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get '/:page?', loadUser, (req, res) -> | |
page = req.params.page or 'index' | |
req.bidi | |
.send 'getName', (err, name) -> | |
req.bidi.name = name | |
req.bidi.broadcast 'serverMessage', name, "connected" | |
.expose | |
relay: (msg) -> | |
console.log "Relay called" | |
req.bidi.broadcast 'talk', @name, msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment