merge
This commit is contained in:
parent
7547f5f1ae
commit
9760350959
@ -74,9 +74,11 @@ PeerServer.prototype._initializeWSS = function() {
|
|||||||
if (!self._clients[key] || !self._clients[key][id]) {
|
if (!self._clients[key] || !self._clients[key][id]) {
|
||||||
self._checkKey(key, ip, function(err) {
|
self._checkKey(key, ip, function(err) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
self._clients[key][id] = { token: token, ip: ip };
|
if (!self._clients[key][id]) {
|
||||||
self._ips[ip]++;
|
self._clients[key][id] = { token: token, ip: ip };
|
||||||
socket.send(JSON.stringify({ type: 'OPEN' }));
|
self._ips[ip]++;
|
||||||
|
socket.send(JSON.stringify({ type: 'OPEN' }));
|
||||||
|
}
|
||||||
self._configureWS(socket, key, id, token);
|
self._configureWS(socket, key, id, token);
|
||||||
} else {
|
} else {
|
||||||
socket.send(JSON.stringify({ type: 'ERROR', payload: { msg: err } }));
|
socket.send(JSON.stringify({ type: 'ERROR', payload: { msg: err } }));
|
||||||
@ -122,7 +124,6 @@ PeerServer.prototype._configureWS = function(socket, key, id, token) {
|
|||||||
socket.on('message', function(data) {
|
socket.on('message', function(data) {
|
||||||
try {
|
try {
|
||||||
var message = JSON.parse(data);
|
var message = JSON.parse(data);
|
||||||
util.log(message);
|
|
||||||
|
|
||||||
switch (message.type) {
|
switch (message.type) {
|
||||||
case 'LEAVE':
|
case 'LEAVE':
|
||||||
@ -162,11 +163,11 @@ PeerServer.prototype._checkKey = function(key, ip, cb) {
|
|||||||
if (!this._clients[key]) {
|
if (!this._clients[key]) {
|
||||||
this._clients[key] = {};
|
this._clients[key] = {};
|
||||||
}
|
}
|
||||||
if (!this._outstanding[key]) {
|
if (!self._outstanding[key]) {
|
||||||
this._outstanding[key] = {};
|
self._outstanding[key] = {};
|
||||||
}
|
}
|
||||||
if (!this._ips[ip]) {
|
if (!self._ips[ip]) {
|
||||||
this._ips[ip] = 0;
|
self._ips[ip] = 0;
|
||||||
}
|
}
|
||||||
// Check concurrent limit
|
// Check concurrent limit
|
||||||
if (Object.keys(this._clients[key]).length >= this._options.concurrent_limit) {
|
if (Object.keys(this._clients[key]).length >= this._options.concurrent_limit) {
|
||||||
@ -210,7 +211,7 @@ PeerServer.prototype._initializeHTTP = function() {
|
|||||||
|
|
||||||
if (!self._clients[key] || !self._clients[key][id]) {
|
if (!self._clients[key] || !self._clients[key][id]) {
|
||||||
self._checkKey(key, ip, function(err) {
|
self._checkKey(key, ip, function(err) {
|
||||||
if (!err) {
|
if (!err && !self._clients[key][id]) {
|
||||||
self._clients[key][id] = { token: token, ip: ip };
|
self._clients[key][id] = { token: token, ip: ip };
|
||||||
self._ips[ip]++;
|
self._ips[ip]++;
|
||||||
self._startStreaming(res, key, id, token, true);
|
self._startStreaming(res, key, id, token, true);
|
||||||
@ -347,6 +348,7 @@ PeerServer.prototype._handleTransmission = function(key, message) {
|
|||||||
// User is connected!
|
// User is connected!
|
||||||
if (destination) {
|
if (destination) {
|
||||||
try {
|
try {
|
||||||
|
util.log(type, 'from', src, 'to', dst);
|
||||||
if (destination.socket) {
|
if (destination.socket) {
|
||||||
destination.socket.send(data);
|
destination.socket.send(data);
|
||||||
} else if (destination.res) {
|
} else if (destination.res) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user