08-27-周三_17-09-29
This commit is contained in:
59
node_modules/shoe/index.js
generated
vendored
Normal file
59
node_modules/shoe/index.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
var sockjs = require('sockjs');
|
||||
|
||||
exports = module.exports = function (opts, cb) {
|
||||
if (typeof opts === 'function') {
|
||||
cb = opts;
|
||||
opts = {};
|
||||
}
|
||||
var server = sockjs.createServer();
|
||||
var handler = function (stream) {
|
||||
var _didTimeout = stream._session.didTimeout
|
||||
var _didClose = stream._session.didClose
|
||||
|
||||
stream._session.didTimeout = function () {
|
||||
cleanup()
|
||||
_didTimeout.apply(this, arguments)
|
||||
}
|
||||
stream._session.didClose = function () {
|
||||
cleanup()
|
||||
_didClose.apply(this, arguments)
|
||||
}
|
||||
|
||||
cb(stream)
|
||||
|
||||
function cleanup() {
|
||||
stream.emit("close")
|
||||
if (stream.destroy) {
|
||||
stream.destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof cb === 'function') {
|
||||
server.on('connection', handler);
|
||||
}
|
||||
server.install = function (httpServer, hopts) {
|
||||
if (hopts && hopts.listen && !httpServer.listen) {
|
||||
httpServer = arguments[1];
|
||||
hopts = arguments[0];
|
||||
}
|
||||
if (typeof hopts === 'string') {
|
||||
hopts = { prefix : hopts };
|
||||
}
|
||||
if (!hopts) hopts = {};
|
||||
if (hopts.log === undefined) {
|
||||
// spamming stdout by default is VERY infuriating,
|
||||
// emit an event instead
|
||||
hopts.log = function (severity, line) {
|
||||
server.emit('log', severity, line);
|
||||
};
|
||||
}
|
||||
server.installHandlers(httpServer, hopts);
|
||||
return server;
|
||||
};
|
||||
|
||||
return server;
|
||||
};
|
||||
|
||||
for (var key in sockjs) {
|
||||
exports[key] = sockjs[key];
|
||||
}
|
Reference in New Issue
Block a user