New version of lastN

This commit is contained in:
Håvar Aambø Fosstveit
2018-10-24 09:54:51 +02:00
parent 64224fa830
commit 345f8d9c3d
2 changed files with 147 additions and 23 deletions
+27 -1
View File
@@ -38,6 +38,9 @@ class Room extends EventEmitter
this._fileHistory = [];
this._lastN = [];
this._io = io;
this._signalingPeers = new Map();
@@ -123,6 +126,13 @@ class Room extends EventEmitter
const signalingPeer = { peerName : peerName, socket : socket };
const index = this._lastN.indexOf(peerName);
if (index === -1) // We don't have this peer, add to end
{
this._lastN.push(peerName);
}
this._handleSignalingPeer(signalingPeer);
}
@@ -140,6 +150,14 @@ class Room extends EventEmitter
this._currentActiveSpeaker = activePeer;
const index = this._lastN.indexOf(activePeer.name);
if (index > -1) // We have this speaker in the list, move to front
{
this._lastN.splice(index, 1);
this._lastN = [activePeer.name].concat(this._lastN);
}
const activeVideoProducer = activePeer.producers
.find((producer) => producer.kind === 'video');
@@ -269,7 +287,8 @@ class Room extends EventEmitter
null,
{
chatHistory : this._chatHistory,
fileHistory : this._fileHistory
fileHistory : this._fileHistory,
lastN : this._lastN
}
);
});
@@ -325,6 +344,13 @@ class Room extends EventEmitter
if (mediaPeer && !mediaPeer.closed)
mediaPeer.close();
const index = this._lastN.indexOf(signalingPeer.peerName);
if (index > -1) // We have this peer in the list, remove
{
this._lastN.splice(index, 1);
}
// If this is the latest peer in the room, close the room.
// However wait a bit (for reconnections).
setTimeout(() =>