forked from meteor/meteor
-
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.
Factor socket.io into stream package on the server as well. Much clea…
…ner now.
- Loading branch information
Nick Martin
committed
Dec 13, 2011
1 parent
46effaa
commit 918d15a
Showing
3 changed files
with
80 additions
and
46 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
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 +1,51 @@ | ||
if (typeof Sky === "undefined") Sky = {}; | ||
|
||
(function () { | ||
|
||
////////// Internals ////////// | ||
|
||
var registration_callbacks = []; | ||
|
||
|
||
// basic socketio setup | ||
var socketio = __skybreak_bootstrap__.require('socket.io'); | ||
|
||
var io = socketio.listen(__skybreak_bootstrap__.app); | ||
io.configure(function() { | ||
// Don't serve static files from socket.io. We serve them separately | ||
// to get gzip and other fun things. | ||
io.set('browser client', false); | ||
|
||
io.set('log level', 1); | ||
// XXX disable websockets! they break chrome both debugging | ||
// and node-http-proxy (used in outer app) | ||
io.set('transports', _.without(io.transports(), 'websocket')); | ||
}); | ||
|
||
// call all our callbacks when we get a new socket. they will do the | ||
// work of setting up handlers and such for specific messages. | ||
io.sockets.on('connection', function (socket) { | ||
_.each(registration_callbacks, function (callback) { | ||
callback(socket); | ||
}); | ||
}); | ||
|
||
////////// API for other packages ////////// | ||
|
||
Sky._stream = { | ||
// call my callback when a new socket connects. | ||
// also call it for all current connections. | ||
register: function (callback) { | ||
registration_callbacks.push(callback); | ||
_.each(io.sockets.sockets, function (socket) { | ||
callback(socket); | ||
}); | ||
}, | ||
|
||
// get a list of all sockets | ||
all_sockets: function () { | ||
return io.sockets.sockets; | ||
} | ||
}; | ||
|
||
})(); |