more flexible leave option for peer v connections
This commit is contained in:
parent
7498c00c95
commit
0d264b4119
@ -7,14 +7,6 @@ var url = require('url');
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
var allowCrossDomain = function(req, res, next) {
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
||||||
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
|
|
||||||
function PeerServer(options) {
|
function PeerServer(options) {
|
||||||
if (!(this instanceof PeerServer)) return new PeerServer(options);
|
if (!(this instanceof PeerServer)) return new PeerServer(options);
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
@ -22,7 +14,7 @@ function PeerServer(options) {
|
|||||||
this._app = express();
|
this._app = express();
|
||||||
this._httpServer = http.createServer(this._app);
|
this._httpServer = http.createServer(this._app);
|
||||||
this._app.use(express.bodyParser());
|
this._app.use(express.bodyParser());
|
||||||
this._app.use(allowCrossDomain);
|
this._app.use(this._allowCrossDomain);
|
||||||
|
|
||||||
options = util.extend({
|
options = util.extend({
|
||||||
port: 80
|
port: 80
|
||||||
@ -52,7 +44,16 @@ function PeerServer(options) {
|
|||||||
|
|
||||||
util.inherits(PeerServer, EventEmitter);
|
util.inherits(PeerServer, EventEmitter);
|
||||||
|
|
||||||
/* Initialize WebSocket server. */
|
/** Handle CORS */
|
||||||
|
PeerServer.prototype._allowCrossDomain = function(req, res, next) {
|
||||||
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||||
|
res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
|
||||||
|
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
||||||
|
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initialize WebSocket server. */
|
||||||
PeerServer.prototype._initializeWSS = function() {
|
PeerServer.prototype._initializeWSS = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
this._wss.on('connection', function(socket) {
|
this._wss.on('connection', function(socket) {
|
||||||
@ -84,6 +85,12 @@ PeerServer.prototype._initializeWSS = function() {
|
|||||||
|
|
||||||
switch (message.type) {
|
switch (message.type) {
|
||||||
case 'LEAVE':
|
case 'LEAVE':
|
||||||
|
// Clean up if a Peer sends a LEAVE.
|
||||||
|
if (!message.dst) {
|
||||||
|
delete self._clients[message.src];
|
||||||
|
delete self._timeouts[message.src];
|
||||||
|
break;
|
||||||
|
}
|
||||||
// ICE candidates
|
// ICE candidates
|
||||||
case 'CANDIDATE':
|
case 'CANDIDATE':
|
||||||
// Offer or answer between peers.
|
// Offer or answer between peers.
|
||||||
@ -92,12 +99,6 @@ PeerServer.prototype._initializeWSS = function() {
|
|||||||
// Firefoxism (connectDataConnection ports)
|
// Firefoxism (connectDataConnection ports)
|
||||||
case 'PORT':
|
case 'PORT':
|
||||||
self._handleTransmission(message.type, message.src, message.dst, data);
|
self._handleTransmission(message.type, message.src, message.dst, data);
|
||||||
|
|
||||||
// Clean up.
|
|
||||||
if (message.type === 'LEAVE') {
|
|
||||||
delete self._clients[message.src];
|
|
||||||
delete self._timeouts[message.src];
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
util.prettyError('message unrecognized');
|
util.prettyError('message unrecognized');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user