Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit 97c74c3a79b2b050ba12f87727b453e3359b2531 @AndrewSwerlick committed Sep 6, 2011
Showing with 9,752 additions and 0 deletions.
  1. +6 −0 README
  2. +41 −0 keyMap.js
  3. +1 −0 node_modules/node-x11
  4. +9 −0 node_modules/socket.io/.gitignore
  5. +3 −0 node_modules/socket.io/.npmignore
  6. +140 −0 node_modules/socket.io/History.md
  7. +22 −0 node_modules/socket.io/Makefile
  8. +343 −0 node_modules/socket.io/Readme.md
  9. +87 −0 node_modules/socket.io/examples/chat/app.js
  10. +83 −0 node_modules/socket.io/examples/chat/index.jade
  11. +11 −0 node_modules/socket.io/examples/chat/package.json
  12. +96 −0 node_modules/socket.io/examples/chat/public/stylesheets/mixins.styl
  13. +188 −0 node_modules/socket.io/examples/chat/public/stylesheets/style.css
  14. +118 −0 node_modules/socket.io/examples/chat/public/stylesheets/style.styl
  15. +81 −0 node_modules/socket.io/examples/irc-output/app.js
  16. +28 −0 node_modules/socket.io/examples/irc-output/index.jade
  17. +164 −0 node_modules/socket.io/examples/irc-output/irc.js
  18. +10 −0 node_modules/socket.io/examples/irc-output/package.json
  19. +69 −0 node_modules/socket.io/examples/irc-output/public/stylesheets/style.styl
  20. +8 −0 node_modules/socket.io/index.js
  21. +96 −0 node_modules/socket.io/lib/logger.js
  22. +1,026 −0 node_modules/socket.io/lib/manager.js
  23. +350 −0 node_modules/socket.io/lib/namespace.js
  24. +243 −0 node_modules/socket.io/lib/parser.js
  25. +128 −0 node_modules/socket.io/lib/socket.io.js
  26. +352 −0 node_modules/socket.io/lib/socket.js
  27. +98 −0 node_modules/socket.io/lib/store.js
  28. +143 −0 node_modules/socket.io/lib/stores/memory.js
  29. +250 −0 node_modules/socket.io/lib/stores/redis.js
  30. +534 −0 node_modules/socket.io/lib/transport.js
  31. +102 −0 node_modules/socket.io/lib/transports/flashsocket.js
  32. +82 −0 node_modules/socket.io/lib/transports/htmlfile.js
  33. +135 −0 node_modules/socket.io/lib/transports/http-polling.js
  34. +111 −0 node_modules/socket.io/lib/transports/http.js
  35. +12 −0 node_modules/socket.io/lib/transports/index.js
  36. +78 −0 node_modules/socket.io/lib/transports/jsonp-polling.js
  37. +33 −0 node_modules/socket.io/lib/transports/websocket.js
  38. +350 −0 node_modules/socket.io/lib/transports/websocket/default.js
  39. +465 −0 node_modules/socket.io/lib/transports/websocket/hybi-07-12.js
  40. +10 −0 node_modules/socket.io/lib/transports/websocket/index.js
  41. +72 −0 node_modules/socket.io/lib/transports/xhr-polling.js
  42. +50 −0 node_modules/socket.io/lib/util.js
  43. +30 −0 node_modules/socket.io/package.json
  44. +27 −0 node_modules/socket.io/support/node-websocket-client/LICENSE
  45. +22 −0 node_modules/socket.io/support/node-websocket-client/Makefile
  46. +41 −0 node_modules/socket.io/support/node-websocket-client/README.md
  47. +12 −0 node_modules/socket.io/support/node-websocket-client/examples/client-unix.js
  48. +10 −0 node_modules/socket.io/support/node-websocket-client/examples/client.js
  49. +13 −0 node_modules/socket.io/support/node-websocket-client/examples/server-unix.js
  50. +599 −0 node_modules/socket.io/support/node-websocket-client/lib/websocket.js
  51. +22 −0 node_modules/socket.io/support/node-websocket-client/package.json
  52. +68 −0 node_modules/socket.io/support/node-websocket-client/test/test-basic.js
  53. +43 −0 node_modules/socket.io/support/node-websocket-client/test/test-client-close.js
  54. +43 −0 node_modules/socket.io/support/node-websocket-client/test/test-readonly-attrs.js
  55. +26 −0 node_modules/socket.io/support/node-websocket-client/test/test-ready-state.js
  56. +41 −0 node_modules/socket.io/support/node-websocket-client/test/test-server-close.js
  57. +63 −0 node_modules/socket.io/support/node-websocket-client/test/test-unix-send-fd.js
  58. +46 −0 node_modules/socket.io/support/node-websocket-client/test/test-unix-sockets.js
  59. +244 −0 node_modules/socket.io/test/common.js
  60. +21 −0 node_modules/socket.io/test/fixtures/cert.crt
  61. +27 −0 node_modules/socket.io/test/fixtures/key.key
  62. +125 −0 node_modules/socket.io/test/io.test.js
  63. +54 −0 node_modules/socket.io/test/leaks/socket.leaktest.js
  64. +731 −0 node_modules/socket.io/test/manager.test.js
  65. +247 −0 node_modules/socket.io/test/namespace.test.js
  66. +356 −0 node_modules/socket.io/test/parser.test.js
  67. +15 −0 node_modules/socket.io/test/socket.js
  68. +190 −0 node_modules/socket.io/test/stores.memory.test.js
  69. +240 −0 node_modules/socket.io/test/stores.redis.test.js
  70. +168 −0 node_modules/socket.io/test/transports.flashsocket.test.js
Sorry, we could not display the entire diff because it was too big.
6 README
@@ -0,0 +1,6 @@
+node-remote is a simple web server/webpage pair that allows you to remotely control the disply on the server by browsing to a webpage on any client machine. The page picks up mouse movements and keyboard presses and transmits them to the server via socket.io. Read more at
+
+RUNNING THE SERVER
+Start the server with the command node remote-server.js. Note you have to run this command from within the display that you want to be controlling, not a remote session.
+
+Then just have your client browse to port 8000 on the server. Note the client needs to support websockets, so either chrome or firefox is your best bet.
41 keyMap.js
@@ -0,0 +1,41 @@
+ var staticMap = {
+ '18': 'LT',
+ '8' : 'BackSpace',
+ '20' : 'CAPS_LOCK',
+ '188' : ',',
+ // COMMAND: 91,
+ // COMMAND_LEFT: 91, // COMMAND
+ // COMMAND_RIGHT: 93,
+ '17' : 'Ctrl',
+ '46' : 'Delete',
+ '40' : 'Down',
+ '35' : 'End',
+ '13' : 'Return',
+ '27' : 'Escape',
+ '36' : 'Home',
+ '45' : 'Insert',
+ '37' : 'Left',
+ //MENU: 93, // COMMAND_RIGHT
+ // NUMPAD_ADD: 107,
+ // NUMPAD_DECIMAL: 110,
+ // NUMPAD_DIVIDE: 111,
+ // NUMPAD_ENTER: 108,
+ // NUMPAD_MULTIPLY: 106,
+ // NUMPAD_SUBTRACT: 109,
+ '34' : 'Page_Down',
+ '33' : 'Page_up',
+ '190' : 'period' ,
+ '39' : 'Right',
+ '16' :'Shift',
+ '32' : 'space',
+ '9' : 'tab',
+ '38' : 'up'
+ // WINDOWS: 91
+}
+
+module.exports.mapKey = function(keyCode){
+ key = staticMap[keyCode];
+ if (key== undefined)
+ key = String.fromCharCode(keyCode);
+ return key;
+}
1 node_modules/node-x11
@@ -0,0 +1 @@
+Subproject commit 0a09793726663fc21d9485813f1b307c54919cd3
9 node_modules/socket.io/.gitignore
@@ -0,0 +1,9 @@
+.DS_Store
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+node_modules
3 node_modules/socket.io/.npmignore
@@ -0,0 +1,3 @@
+support
+test
+examples
140 node_modules/socket.io/History.md
@@ -0,0 +1,140 @@
+
+0.8.3 / 2011-09-03
+==================
+
+ * Fixed `\n` parsing for non-JSON packets (fixes #479).
+ * Fixed parsing of certain unicode characters (fixes #451).
+ * Fixed transport message packet logging.
+ * Fixed emission of `error` event resulting in an uncaught exception if unhandled (fixes #476).
+ * Fixed; allow for falsy values as the configuration value of `log level` (fixes #491).
+ * Fixed repository URI in `package.json`. Fixes #504.
+ * Added text/plain content-type to handshake responses [einaros]
+ * Improved single byte writes [einaros]
+ * Updated socket.io-flashsocket default port from 843 to 10843 [3rd-Eden]
+ * Updated client.
+
+0.8.2 / 2011-08-29
+==================
+
+ * Updated client.
+
+0.8.1 / 2011-08-29
+==================
+
+ * Fixed utf8 bug in send framing in websocket [einaros]
+ * Fixed typo in docs [Znarkus]
+ * Fixed bug in send framing for over 64kB of data in websocket [einaros]
+ * Corrected ping handling in websocket transport [einaros]
+
+0.8.0 / 2011-08-28
+==================
+
+ * Updated to work with two-level websocket versioning. [einaros]
+ * Added hybi07 support. [einaros]
+ * Added hybi10 support. [einaros]
+ * Added http referrer verification to manager.js verifyOrigin. [einaors]
+
+0.7.11 / 2011-08-27
+===================
+
+ * Updated socket.io-client.
+
+0.7.10 / 2011-08-27
+===================
+
+ * Updated socket.io-client.
+
+0.7.9 / 2011-08-12
+==================
+
+ * Updated socket.io-client.
+ * Make sure we only do garbage collection when the server we receive is actually run.
+
+0.7.8 / 2011-08-08
+==================
+
+ * Changed; make sure sio#listen passes options to both HTTP server and socket.io manager.
+ * Added docs for sio#listen.
+ * Added options parameter support for Manager constructor.
+ * Added memory leaks tests and test-leaks Makefile task.
+ * Removed auto npm-linking from make test.
+ * Make sure that you can disable heartbeats. [3rd-Eden]
+ * Fixed rooms memory leak [3rd-Eden]
+ * Send response once we got all POST data, not immediately [Pita]
+ * Fixed onLeave behavior with missing clientsk [3rd-Eden]
+ * Prevent duplicate references in rooms.
+ * Added alias for `to` to `in` and `in` to `to`.
+ * Fixed roomClients definition.
+ * Removed dependency on redis for installation without npm [3rd-Eden]
+ * Expose path and querystring in handshakeData [3rd-Eden]
+
+0.7.7 / 2011-07-12
+==================
+
+ * Fixed double dispatch handling with emit to closed clients.
+ * Added test for emitting to closed clients to prevent regression.
+ * Fixed race condition in redis test.
+ * Changed Transport#end instrumentation.
+ * Leveraged $emit instead of emit internally.
+ * Made tests faster.
+ * Fixed double disconnect events.
+ * Fixed disconnect logic
+ * Simplified remote events handling in Socket.
+ * Increased testcase timeout.
+ * Fixed unknown room emitting (GH-291). [3rd-Eden]
+ * Fixed `address` in handshakeData. [3rd-Eden]
+ * Removed transports definition in chat example.
+ * Fixed room cleanup
+ * Fixed; make sure the client is cleaned up after booting.
+ * Make sure to mark the client as non-open if the connection is closed.
+ * Removed unneeded `buffer` declarations.
+ * Fixed; make sure to clear socket handlers and subscriptions upon transport close.
+
+0.7.6 / 2011-06-30
+==================
+
+ * Fixed general dispatching when a client has closed.
+
+0.7.5 / 2011-06-30
+==================
+
+ * Fixed dispatching to clients that are disconnected.
+
+0.7.4 / 2011-06-30
+==================
+
+ * Fixed; only clear handlers if they were set. [level09]
+
+0.7.3 / 2011-06-30
+==================
+
+ * Exposed handshake data to clients.
+ * Refactored dispatcher interface.
+ * Changed; Moved id generation method into the manager.
+ * Added sub-namespace authorization. [3rd-Eden]
+ * Changed; normalized SocketNamespace local eventing [dvv]
+ * Changed; Use packet.reason or default to 'packet' [3rd-Eden]
+ * Changed console.error to console.log.
+ * Fixed; bind both servers at the same time do that the test never times out.
+ * Added 304 support.
+ * Removed `Transport#name` for abstract interface.
+ * Changed; lazily require http and https module only when needed. [3rd-Eden]
+
+0.7.2 / 2011-06-22
+==================
+
+ * Make sure to write a packet (of type `noop`) when closing a poll.
+ This solves a problem with cross-domain requests being flagged as aborted and
+ reconnection being triggered.
+ * Added `noop` message type.
+
+0.7.1 / 2011-06-21
+==================
+
+ * Fixed cross-domain XHR.
+ * Added CORS test to xhr-polling suite.
+
+0.7.0 / 2010-06-21
+==================
+
+ * http://socket.io/announcement.html
22 node_modules/socket.io/Makefile
@@ -0,0 +1,22 @@
+
+ALL_TESTS = $(shell find test/ -name '*.test.js')
+
+run-tests:
+ @./node_modules/.bin/expresso \
+ -t 3000 \
+ -I support \
+ -I lib \
+ --serial \
+ $(TESTFLAGS) \
+ $(TESTS)
+
+test:
+ @$(MAKE) TESTS="$(ALL_TESTS)" run-tests
+
+test-cov:
+ @TESTFLAGS=--cov $(MAKE) test
+
+test-leaks:
+ @ls test/leaks/* | xargs node --expose_debug_as=debug --expose_gc
+
+.PHONY: test
343 node_modules/socket.io/Readme.md
@@ -0,0 +1,343 @@
+# Socket.IO
+
+Socket.IO is a Node.JS project that makes WebSockets and realtime possible in
+all browsers. It also enhances WebSockets by providing built-in multiplexing,
+horizontal scalability, automatic JSON encoding/decoding, and more.
+
+## How to Install
+
+ npm install socket.io
+
+## How to use
+
+First, require `socket.io`:
+
+```js
+var io = require('socket.io');
+```
+
+Next, attach it to a HTTP/HTTPS server. If you're using the fantastic `express`
+web framework:
+
+```js
+var app = express.createServer()
+ , io = io.listen(app);
+
+app.listen(80);
+
+io.sockets.on('connection', function (socket) {
+ socket.emit('news', { hello: 'world' });
+ socket.on('my other event', function (data) {
+ console.log(data);
+ });
+});
+```
+
+Finally, load it from the client side code:
+
+```html
+<script src="/socket.io/socket.io.js"></script>
+<script>
+ var socket = io.connect('http://localhost');
+ socket.on('news', function (data) {
+ console.log(data);
+ socket.emit('my other event', { my: 'data' });
+ });
+</script>
+```
+
+For more thorough examples, look at the `examples/` directory.
+
+## Short recipes
+
+### Sending and receiving events.
+
+Socket.IO allows you to emit and receive custom events.
+Besides `connect`, `message` and `disconnect`, you can emit custom events:
+
+```js
+// note, io.listen(<port>) will create a http server for you
+var io = require('socket.io').listen(80);
+
+io.sockets.on('connection', function (socket) {
+ io.sockets.emit('this', { will: 'be received by everyone' });
+
+ socket.on('private message', function (from, msg) {
+ console.log('I received a private message by ', from, ' saying ', msg);
+ });
+
+ socket.on('disconnect', function () {
+ sockets.emit('user disconnected');
+ });
+});
+```
+
+### Storing data associated to a client
+
+Sometimes it's necessary to store data associated with a client that's
+necessary for the duration of the session.
+
+#### Server side
+
+```js
+var io = require('socket.io').listen(80);
+
+io.sockets.on('connection', function (socket) {
+ socket.on('set nickname', function (name) {
+ socket.set('nickname', name, function () { socket.emit('ready'); });
+ });
+
+ socket.on('msg', function () {
+ socket.get('nickname', function (err, name) {
+ console.log('Chat message by ', name);
+ });
+ });
+});
+```
+
+#### Client side
+
+```html
+<script>
+ var socket = io.connect('http://localhost');
+
+ socket.on('connect', function () {
+ socket.emit('set nickname', confirm('What is your nickname?'));
+ socket.on('ready', function () {
+ console.log('Connected !');
+ socket.emit('msg', confirm('What is your message?'));
+ });
+ });
+</script>
+```
+
+### Restricting yourself to a namespace
+
+If you have control over all the messages and events emitted for a particular
+application, using the default `/` namespace works.
+
+If you want to leverage 3rd-party code, or produce code to share with others,
+socket.io provides a way of namespacing a `socket`.
+
+This has the benefit of `multiplexing` a single connection. Instead of
+socket.io using two `WebSocket` connections, it'll use one.
+
+The following example defines a socket that listens on '/chat' and one for
+'/news':
+
+#### Server side
+
+```js
+var io = require('socket.io').listen(80);
+
+var chat = io
+ .of('/chat');
+ .on('connection', function (socket) {
+ socket.emit('a message', { that: 'only', '/chat': 'will get' });
+ chat.emit('a message', { everyone: 'in', '/chat': 'will get' });
+ });
+
+var news = io
+ .of('/news');
+ .on('connection', function (socket) {
+ socket.emit('item', { news: 'item' });
+ });
+```
+
+#### Client side:
+
+```html
+<script>
+ var chat = io.connect('http://localhost/chat')
+ , news = io.connect('http://localhost/news');
+
+ chat.on('connect', function () {
+ chat.emit('hi!');
+ });
+
+ news.on('news', function () {
+ news.emit('woot');
+ });
+</script>
+```
+
+### Sending volatile messages.
+
+Sometimes certain messages can be dropped. Let's say you have an app that
+shows realtime tweets for the keyword `bieber`.
+
+If a certain client is not ready to receive messages (because of network slowness
+or other issues, or because he's connected through long polling and is in the
+middle of a request-response cycle), if he doesn't receive ALL the tweets related
+to bieber your application won't suffer.
+
+In that case, you might want to send those messages as volatile messages.
+
+#### Server side
+
+```js
+var io = require('socket.io').listen(80);
+
+io.sockets.on('connection', function (socket) {
+ var tweets = setInterval(function () {
+ getBieberTweet(function (tweet) {
+ socket.volatile.emit('bieber tweet', tweet);
+ });
+ }, 100);
+
+ socket.on('disconnect', function () {
+ clearInterval(tweets);
+ });
+});
+```
+
+#### Client side
+
+In the client side, messages are received the same way whether they're volatile
+or not.
+
+### Getting acknowledgements
+
+Sometimes, you might want to get a callback when the client confirmed the message
+reception.
+
+To do this, simply pass a function as the last parameter of `.send` or `.emit`.
+What's more, when you use `.emit`, the acknowledgement is done by you, which
+means you can also pass data along:
+
+#### Server side
+
+```js
+var io = require('socket.io').listen(80);
+
+io.sockets.on('connection', function (socket) {
+ socket.on('ferret', function (name, fn) {
+ fn('woot');
+ });
+});
+```
+
+#### Client side
+
+```html
+<script>
+ var socket = io.connect(); // TIP: .connect with no args does auto-discovery
+ socket.on('connection', function () {
+ socket.emit('ferret', 'tobi', function (data) {
+ console.log(data); // data will be 'woot'
+ });
+ });
+</script>
+```
+
+### Broadcasting messages
+
+To broadcast, simply add a `broadcast` flag to `emit` and `send` method calls.
+Broadcasting means sending a message to everyone else except for the socket
+that starts it.
+
+#### Server side
+
+```js
+var io = require('socket.io').listen(80);
+
+io.sockets.on('connection', function (socket) {
+ socket.broadcast.emit('user connected');
+ socket.broadcast.json.send({ a: 'message' });
+});
+```
+
+### Rooms
+
+Sometimes you want to put certain sockets in the same room, so that it's easy
+to broadcast to all of them together.
+
+Think of this as built-in channels for sockets. Sockets `join` and `leave`
+rooms in each socket.
+
+#### Server side
+
+```js
+var io = require('socket.io').listen(80);
+
+io.sockets.on('connection', function (socket) {
+ socket.join('justin bieber fans');
+ socket.broadcast.to('justin bieber fans').emit('new fan');
+ io.sockets.in('rammstein fans').emit('new non-fan');
+});
+```
+
+### Using it just as a cross-browser WebSocket
+
+If you just want the WebSocket semantics, you can do that too.
+Simply leverage `send` and listen on the `message` event:
+
+#### Server side
+
+```js
+var io = require('socket.io').listen(80);
+
+io.sockets.on('connection', function (socket) {
+ socket.on('message', function () { });
+ socket.on('disconnect', function () { });
+});
+```
+
+#### Client side
+
+```html
+<script>
+ var socket = io.connect('http://localhost/');
+ socket.on('connect', function () {
+ socket.send('hi');
+
+ socket.on('message', function (msg) {
+ // my msg
+ });
+ });
+</script>
+```
+
+### Changing configuration
+
+Configuration in socket.io is TJ-style:
+
+#### Server side
+
+```js
+var io = require('socket.io').listen(80);
+
+io.configure(function () {
+ io.set('transports', ['websocket', 'flashsocket', 'xhr-polling']);
+});
+
+io.configure('development', function () {
+ io.set('transports', ['websocket', 'xhr-polling']);
+ io.enable('log');
+});
+```
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2011 Guillermo Rauch &lt;guillermo@learnboost.com&gt;
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
87 node_modules/socket.io/examples/chat/app.js
@@ -0,0 +1,87 @@
+
+/**
+ * Bootstrap app.
+ */
+
+require.paths.unshift(__dirname + '/../../lib/');
+
+/**
+ * Module dependencies.
+ */
+
+var express = require('express')
+ , stylus = require('stylus')
+ , nib = require('nib')
+ , sio = require('socket.io');
+
+/**
+ * App.
+ */
+
+var app = express.createServer();
+
+/**
+ * App configuration.
+ */
+
+app.configure(function () {
+ app.use(stylus.middleware({ src: __dirname + '/public', compile: compile }))
+ app.use(express.static(__dirname + '/public'));
+ app.set('views', __dirname);
+ app.set('view engine', 'jade');
+
+ function compile (str, path) {
+ return stylus(str)
+ .set('filename', path)
+ .use(nib());
+ };
+});
+
+/**
+ * App routes.
+ */
+
+app.get('/', function (req, res) {
+ res.render('index', { layout: false });
+});
+
+/**
+ * App listen.
+ */
+
+app.listen(3000, function () {
+ var addr = app.address();
+ console.log(' app listening on http://' + addr.address + ':' + addr.port);
+});
+
+/**
+ * Socket.IO server (single process only)
+ */
+
+var io = sio.listen(app)
+ , nicknames = {};
+
+io.sockets.on('connection', function (socket) {
+ socket.on('user message', function (msg) {
+ socket.broadcast.emit('user message', socket.nickname, msg);
+ });
+
+ socket.on('nickname', function (nick, fn) {
+ if (nicknames[nick]) {
+ fn(true);
+ } else {
+ fn(false);
+ nicknames[nick] = socket.nickname = nick;
+ socket.broadcast.emit('announcement', nick + ' connected');
+ io.sockets.emit('nicknames', nicknames);
+ }
+ });
+
+ socket.on('disconnect', function () {
+ if (!socket.nickname) return;
+
+ delete nicknames[socket.nickname];
+ socket.broadcast.emit('announcement', socket.nickname + ' disconnected');
+ socket.broadcast.emit('nicknames', nicknames);
+ });
+});
83 node_modules/socket.io/examples/chat/index.jade
@@ -0,0 +1,83 @@
+doctype 5
+html
+ head
+ link(href='/stylesheets/style.css', rel='stylesheet')
+ script(src='http://code.jquery.com/jquery-1.6.1.min.js')
+ script(src='/socket.io/socket.io.js')
+ script
+ // socket.io specific code
+ var socket = io.connect();
+
+ socket.on('connect', function () {
+ $('#chat').addClass('connected');
+ });
+
+ socket.on('announcement', function (msg) {
+ $('#lines').append($('<p>').append($('<em>').text(msg)));
+ });
+
+ socket.on('nicknames', function (nicknames) {
+ $('#nicknames').empty().append($('<span>Online: </span>'));
+ for (var i in nicknames) {
+ $('#nicknames').append($('<b>').text(nicknames[i]));
+ }
+ });
+
+ socket.on('user message', message);
+ socket.on('reconnect', function () {
+ $('#lines').remove();
+ message('System', 'Reconnected to the server');
+ });
+
+ socket.on('reconnecting', function () {
+ message('System', 'Attempting to re-connect to the server');
+ });
+
+ socket.on('error', function (e) {
+ message('System', e ? e : 'A unknown error occurred');
+ });
+
+ function message (from, msg) {
+ $('#lines').append($('<p>').append($('<b>').text(from), msg));
+ }
+
+ // dom manipulation
+ $(function () {
+ $('#set-nickname').submit(function (ev) {
+ socket.emit('nickname', $('#nick').val(), function (set) {
+ if (!set) {
+ clear();
+ return $('#chat').addClass('nickname-set');
+ }
+ $('#nickname-err').css('visibility', 'visible');
+ });
+ return false;
+ });
+
+ $('#send-message').submit(function () {
+ message('me', $('#message').val());
+ socket.emit('user message', $('#message').val());
+ clear();
+ $('#lines').get(0).scrollTop = 10000000;
+ return false;
+ });
+
+ function clear () {
+ $('#message').val('').focus();
+ };
+ });
+ body
+ #chat
+ #nickname
+ form.wrap#set-nickname
+ p Please type in your nickname and press enter.
+ input#nick
+ p#nickname-err Nickname already in use
+ #connecting
+ .wrap Connecting to socket.io server
+ #messages
+ #nicknames
+ #lines
+ form#send-message
+ input#message
+ button Send
11 node_modules/socket.io/examples/chat/package.json
@@ -0,0 +1,11 @@
+{
+ "name": "chat.io"
+ , "description": "example chat application with socket.io"
+ , "version": "0.0.1"
+ , "dependencies": {
+ "express": "2.3.11"
+ , "jade": "0.12.1"
+ , "stylus": "0.13.3"
+ , "nib": "0.0.8"
+ }
+}
96 node_modules/socket.io/examples/chat/public/stylesheets/mixins.styl
@@ -0,0 +1,96 @@
+border-radius(n)
+ -webkit-border-radius n
+ -moz-border-radius n
+ border-radius n
+
+// replace str with val
+
+replace(expr, str, val)
+ expr = clone(expr)
+ for e, i in expr
+ if str == e
+ expr[i] = val
+ expr
+
+// normalize gradient point (webkit)
+
+grad-point(pos)
+ if length(pos) == 1
+ return left pos if pos in (top bottom)
+ return pos top if pos in (left right)
+ else if pos[0] in (top bottom)
+ pos[1] pos[0]
+ else
+ pos
+
+// implicit color stop position
+
+pos-in-stops(i, stops)
+ len = length(stops)
+ if len - 1 == i
+ 100%
+ else if i
+ unit(i / len * 100, '%')
+ else
+ 0%
+
+// normalize color stops
+// - (color pos) -> (pos color)
+// - (color) -> (implied-pos color)
+
+normalize-stops(stops)
+ stops = clone(stops)
+ for stop, i in stops
+ if length(stop) == 1
+ color = stop[0]
+ stop[0] = pos-in-stops(i, stops)
+ stop[1] = color
+ else if typeof(stop[1]) == 'unit'
+ pos = stop[1]
+ stop[1] = stop[0]
+ stop[0] = pos
+ stops
+
+// join color stops with the given translation function
+
+join-stops(stops, translate)
+ str = ''
+ len = length(stops)
+ for stop, i in stops
+ str += ', ' if i
+ pos = stop[0]
+ color = stop[1]
+ str += translate(color, pos)
+ unquote(str)
+
+// webkit translation function
+
+webkit-stop(color, pos)
+ s('color-stop(%d, %s)', pos / 100, color)
+
+// mozilla translation function
+
+moz-stop(color, pos)
+ s('%s %s', color, pos)
+
+// create a linear gradient with the given start
+// position, followed by color stops
+
+linear-gradient(start, stops...)
+ error('color stops required') unless length(stops)
+ prop = current-property[0]
+ val = current-property[1]
+ stops = normalize-stops(stops)
+
+ // webkit
+ end = grad-point(opposite-position(start))
+ webkit = s('-webkit-gradient(linear, %s, %s, %s)', grad-point(start), end, join-stops(stops, webkit-stop))
+ add-property(prop, replace(val, '__CALL__', webkit))
+
+ // moz
+ stops = join-stops(stops, moz-stop)
+ moz = s('-moz-linear-gradient(%s, %s)', start, stops)
+ add-property(prop, replace(val, '__CALL__', moz))
+
+ // literal
+ s('linear-gradient(%s, %s)', start, stops)
188 node_modules/socket.io/examples/chat/public/stylesheets/style.css
@@ -0,0 +1,188 @@
+#chat,
+#nickname,
+#messages {
+ width: 600px;
+}
+#chat {
+ position: relative;
+ border: 1px solid #ccc;
+}
+#nickname,
+#connecting {
+ position: absolute;
+ height: 410px;
+ z-index: 100;
+ left: 0;
+ top: 0;
+ background: #fff;
+ text-align: center;
+ width: 600px;
+ font: 15px Georgia;
+ color: #666;
+ display: block;
+}
+#nickname .wrap,
+#connecting .wrap {
+ padding-top: 150px;
+}
+#nickname input {
+ border: 1px solid #ccc;
+ padding: 10px;
+}
+#nickname input:focus {
+ border-color: #999;
+ outline: 0;
+}
+#nickname #nickname-err {
+ color: #8b0000;
+ font-size: 12px;
+ visibility: hidden;
+}
+.connected #connecting {
+ display: none;
+}
+.nickname-set #nickname {
+ display: none;
+}
+#messages {
+ height: 380px;
+ background: #eee;
+}
+#messages em {
+ text-shadow: 0 1px 0 #fff;
+ color: #999;
+}
+#messages p {
+ padding: 0;
+ margin: 0;
+ font: 12px Helvetica, Arial;
+ padding: 5px 10px;
+}
+#messages p b {
+ display: inline-block;
+ padding-right: 10px;
+}
+#messages p:nth-child(even) {
+ background: #fafafa;
+}
+#messages #nicknames {
+ background: #ccc;
+ padding: 2px 4px 4px;
+ font: 11px Helvetica;
+}
+#messages #nicknames span {
+ color: #000;
+}
+#messages #nicknames b {
+ display: inline-block;
+ color: #fff;
+ background: #999;
+ padding: 3px 6px;
+ margin-right: 5px;
+ -webkit-border-radius: 10px;
+ -moz-border-radius: 10px;
+ border-radius: 10px;
+ text-shadow: 0 1px 0 #666;
+}
+#messages #lines {
+ height: 355px;
+ overflow: auto;
+ overflow-x: hidden;
+ overflow-y: auto;
+}
+#messages #lines::-webkit-scrollbar {
+ width: 6px;
+ height: 6px;
+}
+#messages #lines::-webkit-scrollbar-button:start:decrement,
+#messages #lines ::-webkit-scrollbar-button:end:increment {
+ display: block;
+ height: 10px;
+}
+#messages #lines::-webkit-scrollbar-button:vertical:increment {
+ background-color: #fff;
+}
+#messages #lines::-webkit-scrollbar-track-piece {
+ background-color: #fff;
+ -webkit-border-radius: 3px;
+}
+#messages #lines::-webkit-scrollbar-thumb:vertical {
+ height: 50px;
+ background-color: #ccc;
+ -webkit-border-radius: 3px;
+}
+#messages #lines::-webkit-scrollbar-thumb:horizontal {
+ width: 50px;
+ background-color: #fff;
+ -webkit-border-radius: 3px;
+}
+#send-message {
+ background: #fff;
+ position: relative;
+}
+#send-message input {
+ border: none;
+ height: 30px;
+ padding: 0 10px;
+ line-height: 30px;
+ vertical-align: middle;
+ width: 580px;
+}
+#send-message input:focus {
+ outline: 0;
+}
+#send-message button {
+ position: absolute;
+ top: 5px;
+ right: 5px;
+}
+button {
+ margin: 0;
+ -webkit-user-select: none;
+ -moz-user-select: none;
+ user-select: none;
+ display: inline-block;
+ text-decoration: none;
+ background: #43a1f7;
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #43a1f7), color-stop(1, #377ad0));
+ background: -webkit-linear-gradient(top, #43a1f7 0%, #377ad0 100%);
+ background: -moz-linear-gradient(top, #43a1f7 0%, #377ad0 100%);
+ background: linear-gradient(top, #43a1f7 0%, #377ad0 100%);
+ border: 1px solid #2e70c4;
+ -webkit-border-radius: 16px;
+ -moz-border-radius: 16px;
+ border-radius: 16px;
+ color: #fff;
+ font-family: "lucida grande", sans-serif;
+ font-size: 11px;
+ font-weight: normal;
+ line-height: 1;
+ padding: 3px 10px 5px 10px;
+ text-align: center;
+ text-shadow: 0 -1px 1px #2d6dc0;
+}
+button:hover,
+button.hover {
+ background: darker;
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #43a1f7), color-stop(1, #2e70c4));
+ background: -webkit-linear-gradient(top, #43a1f7 0%, #2e70c4 100%);
+ background: -moz-linear-gradient(top, #43a1f7 0%, #2e70c4 100%);
+ background: linear-gradient(top, #43a1f7 0%, #2e70c4 100%);
+ border: 1px solid #2e70c4;
+ cursor: pointer;
+ text-shadow: 0 -1px 1px #2c6bbb;
+}
+button:active,
+button.active {
+ background: #2e70c4;
+ border: 1px solid #2e70c4;
+ border-bottom: 1px solid #2861aa;
+ text-shadow: 0 -1px 1px #2b67b5;
+}
+button:focus,
+button.focus {
+ outline: none;
+ -webkit-box-shadow: 0 1px 0 0 rgba(255,255,255,0.4), 0 0 4px 0 #377ad0;
+ -moz-box-shadow: 0 1px 0 0 rgba(255,255,255,0.4), 0 0 4px 0 #377ad0;
+ box-shadow: 0 1px 0 0 rgba(255,255,255,0.4), 0 0 4px 0 #377ad0;
+}
118 node_modules/socket.io/examples/chat/public/stylesheets/style.styl
@@ -0,0 +1,118 @@
+@import 'nib'
+
+#chat, #nickname, #messages
+ width 600px
+
+#chat
+ position relative
+ border 1px solid #ccc
+
+#nickname, #connecting
+ position absolute
+ height 410px
+ z-index 100
+ left 0
+ top 0
+ background #fff
+ text-align center
+ width 600px
+ font 15px Georgia
+ color #666
+ display block
+ .wrap
+ padding-top 150px
+
+#nickname
+ input
+ border 1px solid #ccc
+ padding 10px
+ &:focus
+ border-color #999
+ outline 0
+ #nickname-err
+ color darkred
+ font-size 12px
+ visibility hidden
+
+.connected
+ #connecting
+ display none
+
+.nickname-set
+ #nickname
+ display none
+
+#messages
+ height 380px
+ background #eee
+ em
+ text-shadow 0 1px 0 #fff
+ color #999
+ p
+ padding 0
+ margin 0
+ font 12px Helvetica, Arial
+ padding 5px 10px
+ b
+ display inline-block
+ padding-right 10px
+ p:nth-child(even)
+ background #fafafa
+ #nicknames
+ background #ccc
+ padding 2px 4px 4px
+ font 11px Helvetica
+ span
+ color black
+ b
+ display inline-block
+ color #fff
+ background #999
+ padding 3px 6px
+ margin-right 5px
+ border-radius 10px
+ text-shadow 0 1px 0 #666
+ #lines
+ height 355px
+ overflow auto
+ overflow-x hidden
+ overflow-y auto
+ &::-webkit-scrollbar
+ width 6px
+ height 6px
+ &::-webkit-scrollbar-button:start:decrement, ::-webkit-scrollbar-button:end:increment
+ display block
+ height 10px
+ &::-webkit-scrollbar-button:vertical:increment
+ background-color #fff
+ &::-webkit-scrollbar-track-piece
+ background-color #fff
+ -webkit-border-radius 3px
+ &::-webkit-scrollbar-thumb:vertical
+ height 50px
+ background-color #ccc
+ -webkit-border-radius 3px
+ &::-webkit-scrollbar-thumb:horizontal
+ width 50px
+ background-color #fff
+ -webkit-border-radius 3px
+
+#send-message
+ background #fff
+ position relative
+ input
+ border none
+ height 30px
+ padding 0 10px
+ line-height 30px
+ vertical-align middle
+ width 580px
+ &:focus
+ outline 0
+ button
+ position absolute
+ top 5px
+ right 5px
+
+button
+ download-button()
81 node_modules/socket.io/examples/irc-output/app.js
@@ -0,0 +1,81 @@
+
+/**
+ * Bootstrap app.
+ */
+
+require.paths.unshift(__dirname + '/../../lib/');
+
+/**
+ * Module dependencies.
+ */
+
+var express = require('express')
+ , stylus = require('stylus')
+ , nib = require('nib')
+ , sio = require('socket.io')
+ , irc = require('./irc');
+
+/**
+ * App.
+ */
+
+var app = express.createServer();
+
+/**
+ * App configuration.
+ */
+
+app.configure(function () {
+ app.use(stylus.middleware({ src: __dirname + '/public', compile: compile }))
+ app.use(express.static(__dirname + '/public'));
+ app.set('views', __dirname);
+ app.set('view engine', 'jade');
+
+ function compile (str, path) {
+ return stylus(str)
+ .set('filename', path)
+ .use(nib());
+ };
+});
+
+/**
+ * App routes.
+ */
+
+app.get('/', function (req, res) {
+ res.render('index', { layout: false });
+});
+
+/**
+ * App listen.
+ */
+
+app.listen(3000, function () {
+ var addr = app.address();
+ console.log(' app listening on http://' + addr.address + ':' + addr.port);
+});
+
+/**
+ * Socket.IO server
+ */
+
+var io = sio.listen(app)
+
+/**
+ * Connect to IRC.
+ */
+
+var client = new irc.Client('irc.freenode.net', 6667);
+client.connect('socketio\\test\\' + String(Math.random()).substr(-3));
+client.on('001', function () {
+ this.send('JOIN', '#node.js');
+});
+client.on('PART', function (prefix) {
+ io.sockets.emit('announcement', irc.user(prefix) + ' left the channel');
+});
+client.on('JOIN', function (prefix) {
+ io.sockets.emit('announcement', irc.user(prefix) + ' joined the channel');
+});
+client.on('PRIVMSG', function (prefix, channel, text) {
+ io.sockets.emit('irc message', irc.user(prefix), text);
+});
28 node_modules/socket.io/examples/irc-output/index.jade
@@ -0,0 +1,28 @@
+doctype 5
+html
+ head
+ link(href='/stylesheets/style.css', rel='stylesheet')
+ script(src='http://code.jquery.com/jquery-1.6.1.min.js')
+ script(src='/socket.io/socket.io.js')
+ script
+ var socket = io.connect();
+
+ socket.on('connect', function () {
+ $('#irc').addClass('connected');
+ });
+
+ socket.on('announcement', function (msg) {
+ $('#messages').append($('<p>').append($('<em>').text(msg)));
+ $('#messages').get(0).scrollTop = 10000000;
+ });
+
+ socket.on('irc message', function (user, msg) {
+ $('#messages').append($('<p>').append($('<b>').text(user), msg));
+ $('#messages').get(0).scrollTop = 10000000;
+ });
+ body
+ h2 Node.JS IRC
+ #irc
+ #connecting
+ .wrap Connecting to socket.io server
+ #messages
164 node_modules/socket.io/examples/irc-output/irc.js
@@ -0,0 +1,164 @@
+/**
+ * From https://github.com/felixge/nodelog/
+ */
+
+var sys = require('sys');
+var tcp = require('net');
+var irc = exports;
+
+function bind(fn, scope) {
+ var bindArgs = Array.prototype.slice.call(arguments);
+ bindArgs.shift();
+ bindArgs.shift();
+
+ return function() {
+ var args = Array.prototype.slice.call(arguments);
+ fn.apply(scope, bindArgs.concat(args));
+ };
+}
+
+function each(set, iterator) {
+ for (var i = 0; i < set.length; i++) {
+ var r = iterator(set[i], i);
+ if (r === false) {
+ return;
+ }
+ }
+}
+
+var Client = irc.Client = function(host, port) {
+ this.host = host || 'localhost';
+ this.port = port || 6667;
+
+ this.connection = null;
+ this.buffer = '';
+ this.encoding = 'utf8';
+ this.timeout = 10 * 60 * 60 * 1000;
+
+ this.nick = null;
+ this.user = null;
+ this.real = null;
+}
+sys.inherits(Client, process.EventEmitter);
+
+Client.prototype.connect = function(nick, user, real) {
+ var connection = tcp.createConnection(this.port, this.host);
+ connection.setEncoding(this.encoding);
+ connection.setTimeout(this.timeout);
+ connection.addListener('connect', bind(this.onConnect, this));
+ connection.addListener('data', bind(this.onReceive, this));
+ connection.addListener('end', bind(this.onEof, this));
+ connection.addListener('timeout', bind(this.onTimeout, this));
+ connection.addListener('close', bind(this.onClose, this));
+
+ this.nick = nick;
+ this.user = user || 'guest';
+ this.real = real || 'Guest';
+
+ this.connection = connection;
+};
+
+Client.prototype.disconnect = function(why) {
+ if (this.connection.readyState !== 'closed') {
+ this.connection.close();
+ sys.puts('disconnected (reason: '+why+')');
+ this.emit('DISCONNECT', why);
+ }
+};
+
+Client.prototype.send = function(arg1) {
+ if (this.connection.readyState !== 'open') {
+ return this.disconnect('cannot send with readyState: '+this.connection.readyState);
+ }
+
+ var message = [];
+ for (var i = 0; i< arguments.length; i++) {
+ if (arguments[i]) {
+ message.push(arguments[i]);
+ }
+ }
+ message = message.join(' ');
+
+ sys.puts('> '+message);
+ message = message + "\r\n";
+ this.connection.write(message, this.encoding);
+};
+
+Client.prototype.parse = function(message) {
+ var match = message.match(/(?:(:[^\s]+) )?([^\s]+) (.+)/);
+ var parsed = {
+ prefix: match[1],
+ command: match[2]
+ };
+
+ var params = match[3].match(/(.*?) ?:(.*)/);
+ if (params) {
+ // Params before :
+ params[1] = (params[1])
+ ? params[1].split(' ')
+ : [];
+ // Rest after :
+ params[2] = params[2]
+ ? [params[2]]
+ : [];
+
+ params = params[1].concat(params[2]);
+ } else {
+ params = match[3].split(' ');
+ }
+
+ parsed.params = params;
+ return parsed;
+};
+
+Client.prototype.onConnect = function() {
+ this.send('NICK', this.nick);
+ this.send('USER', this.user, '0', '*', ':'+this.real);
+};
+
+Client.prototype.onReceive = function(chunk) {
+ this.buffer = this.buffer + chunk;
+
+ while (this.buffer) {
+ var offset = this.buffer.indexOf("\r\n");
+ if (offset < 0) {
+ return;
+ }
+
+ var message = this.buffer.substr(0, offset);
+ this.buffer = this.buffer.substr(offset + 2);
+ sys.puts('< '+message);
+
+ message = this.parse(message);
+
+ this.emit.apply(this, [message.command, message.prefix].concat(message.params));
+
+ if (message !== false) {
+ this.onMessage(message);
+ }
+ }
+};
+
+Client.prototype.onMessage = function(message) {
+ switch (message.command) {
+ case 'PING':
+ this.send('PONG', ':'+message.params[0]);
+ break;
+ }
+};
+
+Client.prototype.onEof = function() {
+ this.disconnect('eof');
+};
+
+Client.prototype.onTimeout = function() {
+ this.disconnect('timeout');
+};
+
+Client.prototype.onClose = function() {
+ this.disconnect('close');
+};
+
+exports.user = function(prefix) {
+ return prefix.match(/:([^!]+)!/)[1]
+};
10 node_modules/socket.io/examples/irc-output/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "socket.io-irc"
+ , "version": "0.0.1"
+ , "dependencies": {
+ "express": "2.3.11"
+ , "jade": "0.12.1"
+ , "stylus": "0.13.3"
+ , "nib": "0.0.8"
+ }
+}
69 node_modules/socket.io/examples/irc-output/public/stylesheets/style.styl
@@ -0,0 +1,69 @@
+@import 'nib'
+
+h2
+ font bold 18px Helvetica Neue, Arial
+
+#irc, #messages
+ width 600px
+
+#irc
+ position relative
+ border 1px solid #ccc
+
+#connecting
+ position absolute
+ height 410px
+ z-index 100
+ left 0
+ top 0
+ background #fff
+ text-align center
+ width 600px
+ font 15px Georgia
+ color #666
+ display block
+ .wrap
+ padding-top 150px
+
+.connected
+ #connecting
+ display none
+
+#messages
+ height 380px
+ background #eee
+ overflow auto
+ overflow-x hidden
+ overflow-y auto
+ &::-webkit-scrollbar
+ width 6px
+ height 6px
+ &::-webkit-scrollbar-button:start:decrement, ::-webkit-scrollbar-button:end:increment
+ display block
+ height 10px
+ &::-webkit-scrollbar-button:vertical:increment
+ background-color #fff
+ &::-webkit-scrollbar-track-piece
+ background-color #fff
+ -webkit-border-radius 3px
+ &::-webkit-scrollbar-thumb:vertical
+ height 50px
+ background-color #ccc
+ -webkit-border-radius 3px
+ &::-webkit-scrollbar-thumb:horizontal
+ width 50px
+ background-color #fff
+ -webkit-border-radius 3px
+ em
+ text-shadow 0 1px 0 #fff
+ color #999
+ p
+ padding 0
+ margin 0
+ font 12px Helvetica, Arial
+ padding 5px 10px
+ b
+ display inline-block
+ padding-right 10px
+ p:nth-child(even)
+ background #fafafa
8 node_modules/socket.io/index.js
@@ -0,0 +1,8 @@
+
+/*!
+ * socket.io-node
+ * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+module.exports = require('./lib/socket.io');
96 node_modules/socket.io/lib/logger.js
@@ -0,0 +1,96 @@
+
+/*!
+ * socket.io-node
+ * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var util = require('./util')
+ , toArray = util.toArray;
+
+/**
+ * Log levels.
+ */
+
+var levels = [
+ 'error'
+ , 'warn'
+ , 'info'
+ , 'debug'
+];
+
+/**
+ * Colors for log levels.
+ */
+
+var colors = [
+ 31
+ , 33
+ , 36
+ , 90
+];
+
+/**
+ * Pads the nice output to the longest log level.
+ */
+
+function pad (str) {
+ var max = 0;
+
+ for (var i = 0, l = levels.length; i < l; i++)
+ max = Math.max(max, levels[i].length);
+
+ if (str.length < max)
+ return str + new Array(max - str.length + 1).join(' ');
+
+ return str;
+};
+
+/**
+ * Logger (console).
+ *
+ * @api public
+ */
+
+var Logger = module.exports = function (opts) {
+ opts = opts || {}
+ this.colors = false !== opts.colors;
+ this.level = 3;
+};
+
+/**
+ * Log method.
+ *
+ * @api public
+ */
+
+Logger.prototype.log = function (type) {
+ var index = levels.indexOf(type);
+
+ if (index > this.level)
+ return this;
+
+ console.log.apply(
+ console
+ , [this.colors
+ ? ' \033[' + colors[index] + 'm' + pad(type) + ' -\033[39m'
+ : type + ':'
+ ].concat(toArray(arguments).slice(1))
+ );
+
+ return this;
+};
+
+/**
+ * Generate methods.
+ */
+
+levels.forEach(function (name) {
+ Logger.prototype[name] = function () {
+ this.log.apply(this, [name].concat(toArray(arguments)));
+ };
+});
1,026 node_modules/socket.io/lib/manager.js
@@ -0,0 +1,1026 @@
+/*!
+ * socket.io-node
+ * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var fs = require('fs')
+ , url = require('url')
+ , util = require('./util')
+ , store = require('./store')
+ , client = require('socket.io-client')
+ , transports = require('./transports')
+ , Logger = require('./logger')
+ , Socket = require('./socket')
+ , MemoryStore = require('./stores/memory')
+ , SocketNamespace = require('./namespace')
+ , EventEmitter = process.EventEmitter;
+
+/**
+ * Export the constructor.
+ */
+
+exports = module.exports = Manager;
+
+/**
+ * Default transports.
+ */
+
+var defaultTransports = exports.defaultTransports = [
+ 'websocket'
+ , 'htmlfile'
+ , 'xhr-polling'
+ , 'jsonp-polling'
+];
+
+/**
+ * Inherited defaults.
+ */
+
+var parent = module.parent.exports
+ , protocol = parent.protocol;
+
+/**
+ * Manager constructor.
+ *
+ * @param {HTTPServer} server
+ * @param {Object} options, optional
+ * @api public
+ */
+
+function Manager (server, options) {
+ this.server = server;
+ this.namespaces = {};
+ this.sockets = this.of('');
+ this.settings = {
+ origins: '*:*'
+ , log: true
+ , store: new MemoryStore
+ , logger: new Logger
+ , heartbeats: true
+ , resource: '/socket.io'
+ , transports: defaultTransports
+ , authorization: false
+ , 'log level': 3
+ , 'close timeout': 25
+ , 'heartbeat timeout': 15
+ , 'heartbeat interval': 20
+ , 'polling duration': 20
+ , 'flash policy server': true
+ , 'flash policy port': 10843
+ , 'destroy upgrade': true
+ , 'browser client': true
+ , 'browser client minification': false
+ , 'browser client etag': false
+ , 'browser client handler': false
+ , 'client store expiration': 15
+ };
+
+ for (var i in options) {
+ this.settings[i] = options[i];
+ }
+
+ this.initStore();
+
+ // reset listeners
+ this.oldListeners = server.listeners('request');
+ server.removeAllListeners('request');
+
+ var self = this;
+
+ server.on('request', function (req, res) {
+ self.handleRequest(req, res);
+ });
+
+ server.on('upgrade', function (req, socket, head) {
+ self.handleUpgrade(req, socket, head);
+ });
+
+ server.on('close', function () {
+ clearInterval(self.gc);
+ });
+
+ server.once('listening', function () {
+ self.gc = setInterval(self.garbageCollection.bind(self), 10000);
+ });
+
+ for (var i in transports) {
+ if (transports[i].init) {
+ transports[i].init(this);
+ }
+ }
+
+ this.log.info('socket.io started');
+};
+
+Manager.prototype.__proto__ = EventEmitter.prototype
+
+/**
+ * Store accessor shortcut.
+ *
+ * @api public
+ */
+
+Manager.prototype.__defineGetter__('store', function () {
+ var store = this.get('store');
+ store.manager = this;
+ return store;
+});
+
+/**
+ * Logger accessor.
+ *
+ * @api public
+ */
+
+Manager.prototype.__defineGetter__('log', function () {
+ if (this.disabled('log')) return;
+
+ var logger = this.get('logger');
+ logger.level = this.get('log level') || -1;
+
+ return logger;
+});
+
+/**
+ * Get settings.
+ *
+ * @api public
+ */
+
+Manager.prototype.get = function (key) {
+ return this.settings[key];
+};
+
+/**
+ * Set settings
+ *
+ * @api public
+ */
+
+Manager.prototype.set = function (key, value) {
+ if (arguments.length == 1) return this.get(key);
+ this.settings[key] = value;
+ this.emit('set:' + key, this.settings[key], key);
+ return this;
+};
+
+/**
+ * Enable a setting
+ *
+ * @api public
+ */
+
+Manager.prototype.enable = function (key) {
+ this.settings[key] = true;
+ this.emit('set:' + key, this.settings[key], key);
+ return this;
+};
+
+/**
+ * Disable a setting
+ *
+ * @api public
+ */
+
+Manager.prototype.disable = function (key) {
+ this.settings[key] = false;
+ this.emit('set:' + key, this.settings[key], key);
+ return this;
+};
+
+/**
+ * Checks if a setting is enabled
+ *
+ * @api public
+ */
+
+Manager.prototype.enabled = function (key) {
+ return !!this.settings[key];
+};
+
+/**
+ * Checks if a setting is disabled
+ *
+ * @api public
+ */
+
+Manager.prototype.disabled = function (key) {
+ return !this.settings[key];
+};
+
+/**
+ * Configure callbacks.
+ *
+ * @api public
+ */
+
+Manager.prototype.configure = function (env, fn) {
+ if ('function' == typeof env) {
+ env.call(this);
+ } else if (env == process.env.NODE_ENV) {
+ fn.call(this);
+ }
+
+ return this;
+};
+
+/**
+ * Initializes everything related to the message dispatcher.
+ *
+ * @api private
+ */
+
+Manager.prototype.initStore = function () {
+ this.handshaken = {};
+ this.connected = {};
+ this.open = {};
+ this.closed = {};
+ this.closedA = [];
+ this.rooms = {};
+ this.roomClients = {};
+
+ var self = this;
+
+ this.store.subscribe('handshake', function (id, data) {
+ self.onHandshake(id, data);
+ });
+
+ this.store.subscribe('connect', function (id) {
+ self.onConnect(id);
+ });
+
+ this.store.subscribe('open', function (id) {
+ self.onOpen(id);
+ });
+
+ this.store.subscribe('join', function (id, room) {
+ self.onJoin(id, room);
+ });
+
+ this.store.subscribe('leave', function (id, room) {
+ self.onLeave(id, room);
+ });
+
+ this.store.subscribe('close', function (id) {
+ self.onClose(id);
+ });
+
+ this.store.subscribe('dispatch', function (room, packet, volatile, exceptions) {
+ self.onDispatch(room, packet, volatile, exceptions);
+ });
+
+ this.store.subscribe('disconnect', function (id) {
+ self.onDisconnect(id);
+ });
+};
+
+/**
+ * Called when a client handshakes.
+ *
+ * @param text
+ */
+
+Manager.prototype.onHandshake = function (id, data) {
+ this.handshaken[id] = data;
+};
+
+/**
+ * Called when a client connects (ie: transport first opens)
+ *
+ * @api private
+ */
+
+Manager.prototype.onConnect = function (id) {
+ this.connected[id] = true;
+};
+
+/**
+ * Called when a client opens a request in a different node.
+ *
+ * @api private
+ */
+
+Manager.prototype.onOpen = function (id) {
+ this.open[id] = true;
+
+ // if we were buffering messages for the client, clear them
+ if (this.closed[id]) {
+ var self = this;
+
+ this.closedA.splice(this.closedA.indexOf(id), 1);
+
+ this.store.unsubscribe('dispatch:' + id, function () {
+ delete self.closed[id];
+ });
+ }
+
+ // clear the current transport
+ if (this.transports[id]) {
+ this.transports[id].discard();
+ this.transports[id] = null;
+ }
+};
+
+/**
+ * Called when a message is sent to a namespace and/or room.
+ *
+ * @api private
+ */
+
+Manager.prototype.onDispatch = function (room, packet, volatile, exceptions) {
+ if (this.rooms[room]) {
+ for (var i = 0, l = this.rooms[room].length; i < l; i++) {
+ var id = this.rooms[room][i];
+
+ if (!~exceptions.indexOf(id)) {
+ if (this.transports[id] && this.transports[id].open) {
+ this.transports[id].onDispatch(packet, volatile);
+ } else if (!volatile) {
+ this.onClientDispatch(id, packet);
+ }
+ }
+ }
+ }
+};
+
+/**
+ * Called when a client joins a nsp / room.
+ *
+ * @api private
+ */
+
+Manager.prototype.onJoin = function (id, name) {
+ if (!this.roomClients[id]) {
+ this.roomClients[id] = {};
+ }
+
+ if (!this.rooms[name]) {
+ this.rooms[name] = [];
+ }
+
+ if (!~this.rooms[name].indexOf(id)) {
+ this.rooms[name].push(id);
+ this.roomClients[id][name] = true;
+ }
+};
+
+/**
+ * Called when a client leaves a nsp / room.
+ *
+ * @param private
+ */
+
+Manager.prototype.onLeave = function (id, room) {
+ if (this.rooms[room]) {
+ var index = this.rooms[room].indexOf(id);
+
+ if (index >= 0) {
+ this.rooms[room].splice(index, 1);
+ }
+
+ if (!this.rooms[room].length) {
+ delete this.rooms[room];
+ }
+ delete this.roomClients[id][room];
+ }
+};
+
+/**
+ * Called when a client closes a request in different node.
+ *
+ * @api private
+ */
+
+Manager.prototype.onClose = function (id) {
+ if (this.open[id]) {
+ delete this.open[id];
+ }
+
+ this.closed[id] = [];
+ this.closedA.push(id);
+
+ var self = this;
+
+ this.store.subscribe('dispatch:' + id, function (packet, volatile) {
+ if (!volatile) {
+ self.onClientDispatch(id, packet);
+ }
+ });
+};
+
+/**
+ * Dispatches a message for a closed client.
+ *
+ * @api private
+ */
+
+Manager.prototype.onClientDispatch = function (id, packet) {
+ if (this.closed[id]) {
+ this.closed[id].push(packet);
+ }
+};
+
+/**
+ * Receives a message for a client.
+ *
+ * @api private
+ */
+
+Manager.prototype.onClientMessage = function (id, packet) {
+ if (this.namespaces[packet.endpoint]) {
+ this.namespaces[packet.endpoint].handlePacket(id, packet);
+ }
+};
+
+/**
+ * Fired when a client disconnects (not triggered).
+ *
+ * @api private
+ */
+
+Manager.prototype.onClientDisconnect = function (id, reason) {
+ for (var name in this.namespaces) {
+ if (this.roomClients[id][name]) {
+ this.namespaces[name].handleDisconnect(id, reason);
+ }
+ }
+
+ this.onDisconnect(id);
+};
+
+/**
+ * Called when a client disconnects.
+ *
+ * @param text
+ */
+
+Manager.prototype.onDisconnect = function (id, local) {
+ delete this.handshaken[id];
+
+ if (this.open[id]) {
+ delete this.open[id];
+ }
+
+ if (this.connected[id]) {
+ delete this.connected[id];
+ }
+
+ if (this.transports[id]) {
+ this.transports[id].discard();
+ delete this.transports[id];
+ }
+
+ if (this.closed[id]) {
+ delete this.closed[id];
+ this.closedA.splice(this.closedA.indexOf(id), 1);
+ }
+
+ if (this.roomClients[id]) {
+ for (var room in this.roomClients[id]) {
+ this.onLeave(id, room);
+ }
+ delete this.roomClients[id]
+ }
+
+ this.store.destroyClient(id, this.get('client store expiration'));
+
+ this.store.unsubscribe('dispatch:' + id);
+
+ if (local) {
+ this.store.unsubscribe('message:' + id);
+ this.store.unsubscribe('disconnect:' + id);
+ }
+};
+
+/**
+ * Handles an HTTP request.
+ *
+ * @api private
+ */
+
+Manager.prototype.handleRequest = function (req, res) {
+ var data = this.checkRequest(req);
+
+ if (!data) {
+ for (var i = 0, l = this.oldListeners.length; i < l; i++) {
+ this.oldListeners[i].call(this.server, req, res);
+ }
+
+ return;
+ }
+
+ if (data.static || !data.transport && !data.protocol) {
+ if (data.static && this.enabled('browser client')) {
+ this.handleClientRequest(req, res, data);
+ } else {
+ res.writeHead(200);
+ res.end('Welcome to socket.io.');
+
+ this.log.info('unhandled socket.io url');
+ }
+
+ return;
+ }
+
+ if (data.protocol != protocol) {
+ res.writeHead(500);
+ res.end('Protocol version not supported.');
+
+ this.log.info('client protocol version unsupported');
+ } else {
+ if (data.id) {
+ this.handleHTTPRequest(data, req, res);
+ } else {
+ this.handleHandshake(data, req, res);
+ }
+ }
+};
+
+/**
+ * Handles an HTTP Upgrade.
+ *
+ * @api private
+ */
+
+Manager.prototype.handleUpgrade = function (req, socket, head) {
+ var data = this.checkRequest(req)
+ , self = this;
+
+ if (!data) {
+ if (this.enabled('destroy upgrade')) {
+ socket.end();
+ this.log.debug('destroying non-socket.io upgrade');
+ }
+
+ return;
+ }
+
+ req.head = head;
+ this.handleClient(data, req);
+};
+
+/**
+ * Handles a normal handshaken HTTP request (eg: long-polling)
+ *
+ * @api private
+ */
+
+Manager.prototype.handleHTTPRequest = function (data, req, res) {
+ req.res = res;
+ this.handleClient(data, req);
+};
+
+/**
+ * Intantiantes a new client.
+ *
+ * @api private
+ */
+
+Manager.prototype.handleClient = function (data, req) {
+ var socket = req.socket
+ , store