This repository has been archived by the owner on Aug 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Damon Oehlman
committed
May 21, 2012
1 parent
cbf6840
commit 3d56ded
Showing
14 changed files
with
291 additions
and
71 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.DS_Store | ||
node_modules | ||
node_modules | ||
config/development.json |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
var socket = new WebSocket('ws://localhost:8001'); | ||
var socket = new WebSocket('{{ wsurl }}'); | ||
|
||
socket.onopen = function() { | ||
console.log('ready'); | ||
socket.send('hi'); | ||
}; | ||
|
||
socket.onmessage = function(evt) { | ||
// log what we received from the server | ||
demoshell.info(evt.data); | ||
|
||
// close the socket | ||
socket.close(); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var socket = new WebSocket('{{ wsurl }}'); | ||
|
||
socket.onopen = function() { | ||
socket.send('twitter'); | ||
}; | ||
|
||
socket.onmessage = function(evt) { | ||
var tweet = JSON.parse(evt.data); | ||
|
||
console.log(tweet); | ||
|
||
// log what we received from the server | ||
demoshell.info(tweet.text); | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var debug = require('debug')('tweets-demo'), | ||
config = require('config'), | ||
WebSocketServer = require('ws').Server, | ||
Twitter = require('ntwitter'), | ||
util = require('util'), | ||
reInvalidChars = /[\\\"\x00-\x1f\ud800-\udfff\ufffe\uffff\u2000-\u20ff]/g; | ||
|
||
exports.run = function(opts) { | ||
// create the demo server | ||
var client = new Twitter(config), | ||
wss = new WebSocketServer(opts), | ||
clients = []; | ||
|
||
wss.on('connection', function(ws) { | ||
ws.on('message', function(topic) { | ||
debug('tracking topic: ' + topic); | ||
client.stream('statuses/filter', { track: topic }, function(stream) { | ||
stream.on('data', function(data) { | ||
var tweet = { | ||
user: data.user.screen_name, | ||
text: (data.text || '').replace(reInvalidChars, '') | ||
}; | ||
|
||
debug('captured tweet: ' + tweet.user + ': ' + tweet.text); | ||
|
||
try { | ||
ws.send(JSON.stringify(tweet)); | ||
} | ||
catch (e) { | ||
debug('error sending tweet across the wire'); | ||
} | ||
}); | ||
|
||
ws.on('close', function() { | ||
stream.destroy(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
return wss; | ||
}; |
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
Oops, something went wrong.