small bugs
This commit is contained in:
parent
d22646805c
commit
afd9ae0bb5
@ -5,6 +5,12 @@ var EventEmitter = require('events').EventEmitter;
|
||||
var WebSocketServer = require('ws').Server;
|
||||
var url = require('url');
|
||||
|
||||
var allowCrossDomain = function(req, res, next) {
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
|
||||
res.header('Access-Control-Allow-Headers', 'Content-Type');
|
||||
next();
|
||||
};
|
||||
|
||||
function PeerServer(options) {
|
||||
if (!(this instanceof PeerServer)) return new PeerServer(options);
|
||||
@ -12,6 +18,11 @@ function PeerServer(options) {
|
||||
|
||||
this._app = express();
|
||||
this._httpServer = http.createServer(this._app);
|
||||
var self = this;
|
||||
this._app.configure(function() {
|
||||
self._app.use(express.bodyParser());
|
||||
self._app.use(allowCrossDomain);
|
||||
});
|
||||
|
||||
options = util.extend({
|
||||
port: 80
|
||||
@ -74,7 +85,7 @@ PeerServer.prototype._initializeWSS = function() {
|
||||
// Clean up.
|
||||
if (message.type === 'LEAVE') {
|
||||
delete self._clients[message.src];
|
||||
delete self._requests[message.src];
|
||||
delete self._timeouts[message.src];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -95,7 +106,7 @@ PeerServer.prototype._initializeHTTP = function() {
|
||||
// Retrieve guaranteed random ID.
|
||||
this._app.get('/id', function(req, res) {
|
||||
var clientId = util.randomId();
|
||||
while (!!self._clients[clientId] || !!self._requests[clientId]) {
|
||||
while (!!self._clients[clientId]) {
|
||||
clientId = util.randomId();
|
||||
}
|
||||
self._startStreaming(res, clientId, function() {
|
||||
@ -158,7 +169,7 @@ PeerServer.prototype._handleTransmission = function(type, src, dst, data) {
|
||||
|
||||
PeerServer.prototype._generateClientId = function() {
|
||||
var clientId = util.randomId();
|
||||
while (!!self._clients[clientId] || !!self._requests[clientId]) {
|
||||
while (!!self._clients[clientId]) {
|
||||
clientId = util.randomId();
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user