Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add policyfile server #19

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/engine.io.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ exports.attach = function (server, options) {
server.on('connection', function (socket) {
engine.handleSocket(socket);
});
if (options.policyPort) {
var policyServer = require('policyfile').createServer();
server.on('close', policyServer.close.bind(policyServer));
policyServer.listen(options.policyPort);
}
}

return engine;
Expand Down
63 changes: 0 additions & 63 deletions lib/transports/flashsocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,66 +35,3 @@ FlashSocket.prototype.__proto__ = WebSocket.prototype;
*/

FlashSocket.prototype.name = 'flashsocket';

/**
* Listens for new configuration changes of the Manager
* this way we can enable and disable the flash server.
*
* @param {Manager} Manager instance.
* @api private
*/

FlashSocket.init = function (manager) {
var server;
function create () {
server = require('policyfile').createServer({
log: function(msg){
manager.log.info(msg.toLowerCase());
}
}, manager.get('origins'));

server.on('close', function (e) {
server = null;
});

server.listen(manager.get('flash policy port'), manager.server);

manager.flashPolicyServer = server;
}

// listen for origin changes, so we can update the server
manager.on('set:origins', function (value, key) {
if (!server) return;

// update the origins and compile a new response buffer
server.origins = Array.isArray(value) ? value : [value];
server.compile();
});

// destory the server and create a new server
manager.on('set:flash policy port', function (value, key) {
var transports = manager.get('transports');
if (~transports.indexOf('flashsocket')) {
if (server) {
if (server.port === value) return;
// destroy the server and rebuild it on a new port
try {
server.close();
}
catch (e) { /* ignore exception. could e.g. be that the server isn't started yet */ }
}
create();
}
});

// only start the server
manager.on('set:transports', function (value, key){
if (!server && ~manager.get('transports').indexOf('flashsocket')) {
create();
}
});
// check if we need to initialize at start
if (~manager.get('transports').indexOf('flashsocket')){
create();
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"debug": "0.6.0"
, "engine.io-client": "git://github.com/LearnBoost/engine.io-client.git#78f2471e29"
, "websocket.io": "0.1.6"
, "policyfile": "0.0.5"
}
, "devDependencies": {
"mocha": "*"
Expand Down