Updated serverhistory and fixed some bugs.
parent
f51d07285d
commit
3495245e37
|
|
@ -607,7 +607,9 @@ export default class RoomClient
|
||||||
const {
|
const {
|
||||||
chatHistory,
|
chatHistory,
|
||||||
fileHistory,
|
fileHistory,
|
||||||
lastN
|
lastN,
|
||||||
|
locked,
|
||||||
|
lobbyPeers
|
||||||
} = await this.sendRequest('serverHistory');
|
} = await this.sendRequest('serverHistory');
|
||||||
|
|
||||||
if (chatHistory.length > 0)
|
if (chatHistory.length > 0)
|
||||||
|
|
@ -635,6 +637,23 @@ export default class RoomClient
|
||||||
|
|
||||||
this._spotlights.addSpeakerList(lastN);
|
this._spotlights.addSpeakerList(lastN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
locked ?
|
||||||
|
store.dispatch(stateActions.setRoomLocked()) :
|
||||||
|
store.dispatch(stateActions.setRoomUnLocked());
|
||||||
|
|
||||||
|
if (lobbyPeers.length > 0)
|
||||||
|
{
|
||||||
|
logger.debug('Got lobby peers');
|
||||||
|
|
||||||
|
lobbyPeers.forEach((peer) =>
|
||||||
|
{
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.addLobbyPeer(peer.peerId));
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.setLobbyPeerDisplayName(peer.displayName));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (error)
|
catch (error)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class Lobby extends EventEmitter
|
||||||
// Closed flag.
|
// Closed flag.
|
||||||
this._closed = false;
|
this._closed = false;
|
||||||
|
|
||||||
this._peers = new Map();
|
this._peers = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
close()
|
close()
|
||||||
|
|
@ -25,49 +25,42 @@ class Lobby extends EventEmitter
|
||||||
|
|
||||||
this._closed = true;
|
this._closed = true;
|
||||||
|
|
||||||
// Close the peers
|
Object.values(this._peers).forEach((peer) =>
|
||||||
if (this._peers)
|
|
||||||
{
|
|
||||||
this._peers.forEach((peer) =>
|
|
||||||
{
|
{
|
||||||
if (peer.socket)
|
if (peer.socket)
|
||||||
peer.socket.disconnect();
|
peer.socket.disconnect();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
this._peers.clear();
|
this._peers = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
peerList()
|
peerList()
|
||||||
{
|
{
|
||||||
logger.info('peerList()');
|
logger.info('peerList()');
|
||||||
|
|
||||||
return this._peers;
|
return Object.values(this._peers).map((peer) => ({ peerId: peer.peerId, displayName: peer.displayName }));
|
||||||
}
|
}
|
||||||
|
|
||||||
promoteAllPeers()
|
promoteAllPeers()
|
||||||
{
|
{
|
||||||
logger.info('promoteAllPeers()');
|
logger.info('promoteAllPeers()');
|
||||||
|
|
||||||
if (this._peers)
|
Object.values(this._peers).forEach((peer) =>
|
||||||
{
|
|
||||||
this._peers.forEach((peer) =>
|
|
||||||
{
|
{
|
||||||
if (peer.socket)
|
if (peer.socket)
|
||||||
this.promotePeer(peer.peerId);
|
this.promotePeer(peer.peerId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
promotePeer(peerId)
|
promotePeer(peerId)
|
||||||
{
|
{
|
||||||
logger.info('promotePeer() [peerId: %s]', peerId);
|
logger.info('promotePeer() [peerId: %s]', peerId);
|
||||||
|
|
||||||
const peer = this._peers.get(peerId);
|
const peer = this._peers[peerId];
|
||||||
|
|
||||||
this.emit('promotePeer', peer);
|
this.emit('promotePeer', peer);
|
||||||
|
|
||||||
this._peers.delete(peerId);
|
delete this._peers[peerId];
|
||||||
}
|
}
|
||||||
|
|
||||||
parkPeer({ peerId, consume, socket })
|
parkPeer({ peerId, consume, socket })
|
||||||
|
|
@ -78,7 +71,7 @@ class Lobby extends EventEmitter
|
||||||
|
|
||||||
socket.emit('notification', { method: 'enteredLobby', data: {} });
|
socket.emit('notification', { method: 'enteredLobby', data: {} });
|
||||||
|
|
||||||
this._peers.set(peerId, peer);
|
this._peers[peerId] = peer;
|
||||||
|
|
||||||
socket.on('request', (request, cb) =>
|
socket.on('request', (request, cb) =>
|
||||||
{
|
{
|
||||||
|
|
@ -104,7 +97,7 @@ class Lobby extends EventEmitter
|
||||||
|
|
||||||
this.emit('peerClosed', peer);
|
this.emit('peerClosed', peer);
|
||||||
|
|
||||||
this._peers.delete(peer.peerId);
|
delete this._peers[peer.peerId];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class Room extends EventEmitter
|
||||||
|
|
||||||
this._peerJoining({ ...peer });
|
this._peerJoining({ ...peer });
|
||||||
|
|
||||||
this._peers.forEach((peer) =>
|
Object.values(this._peers).forEach((peer) =>
|
||||||
{
|
{
|
||||||
this._notification(peer.socket, 'promotedPeer', { peerId });
|
this._notification(peer.socket, 'promotedPeer', { peerId });
|
||||||
});
|
});
|
||||||
|
|
@ -75,7 +75,7 @@ class Room extends EventEmitter
|
||||||
{
|
{
|
||||||
const { peerId, displayName } = peer;
|
const { peerId, displayName } = peer;
|
||||||
|
|
||||||
this._peers.forEach((peer) =>
|
Object.values(this._peers).forEach((peer) =>
|
||||||
{
|
{
|
||||||
this._notification(peer.socket, 'lobbyPeerDisplayNameChanged', { peerId, displayName });
|
this._notification(peer.socket, 'lobbyPeerDisplayNameChanged', { peerId, displayName });
|
||||||
});
|
});
|
||||||
|
|
@ -87,7 +87,7 @@ class Room extends EventEmitter
|
||||||
|
|
||||||
const { peerId } = peer;
|
const { peerId } = peer;
|
||||||
|
|
||||||
this._peers.forEach((peer) =>
|
Object.values(this._peers).forEach((peer) =>
|
||||||
{
|
{
|
||||||
this._notification(peer.socket, 'lobbyPeerClosed', { peerId });
|
this._notification(peer.socket, 'lobbyPeerClosed', { peerId });
|
||||||
});
|
});
|
||||||
|
|
@ -99,9 +99,7 @@ class Room extends EventEmitter
|
||||||
|
|
||||||
this._lastN = [];
|
this._lastN = [];
|
||||||
|
|
||||||
// this._io = io;
|
this._peers = {};
|
||||||
|
|
||||||
this._peers = new Map();
|
|
||||||
|
|
||||||
// mediasoup Router instance.
|
// mediasoup Router instance.
|
||||||
// @type {mediasoup.Router}
|
// @type {mediasoup.Router}
|
||||||
|
|
@ -121,7 +119,7 @@ class Room extends EventEmitter
|
||||||
// producer.id, volume);
|
// producer.id, volume);
|
||||||
|
|
||||||
// Notify all Peers.
|
// Notify all Peers.
|
||||||
this._peers.forEach((peer) =>
|
Object.values(this._peers).forEach((peer) =>
|
||||||
{
|
{
|
||||||
this._notification(peer.socket, 'activeSpeaker', {
|
this._notification(peer.socket, 'activeSpeaker', {
|
||||||
peerId : producer.appData.peerId,
|
peerId : producer.appData.peerId,
|
||||||
|
|
@ -135,7 +133,7 @@ class Room extends EventEmitter
|
||||||
// logger.debug('audioLevelObserver "silence" event');
|
// logger.debug('audioLevelObserver "silence" event');
|
||||||
|
|
||||||
// Notify all Peers.
|
// Notify all Peers.
|
||||||
this._peers.forEach((peer) =>
|
Object.values(this._peers).forEach((peer) =>
|
||||||
{
|
{
|
||||||
this._notification(peer.socket, 'activeSpeaker', { peerId : null });
|
this._notification(peer.socket, 'activeSpeaker', { peerId : null });
|
||||||
});
|
});
|
||||||
|
|
@ -162,7 +160,7 @@ class Room extends EventEmitter
|
||||||
// Close the peers
|
// Close the peers
|
||||||
if (this._peers)
|
if (this._peers)
|
||||||
{
|
{
|
||||||
this._peers.forEach((peer) =>
|
Object.values(this._peers).forEach((peer) =>
|
||||||
{
|
{
|
||||||
if (peer.socket)
|
if (peer.socket)
|
||||||
peer.socket.disconnect();
|
peer.socket.disconnect();
|
||||||
|
|
@ -192,23 +190,23 @@ class Room extends EventEmitter
|
||||||
logger.info('handleConnection() [peerId:"%s"]', peerId);
|
logger.info('handleConnection() [peerId:"%s"]', peerId);
|
||||||
|
|
||||||
// This will allow reconnects to join despite lock
|
// This will allow reconnects to join despite lock
|
||||||
if (this._peers.has(peerId))
|
if (this._peers[peerId])
|
||||||
{
|
{
|
||||||
logger.warn(
|
logger.warn(
|
||||||
'handleConnection() | there is already a peer with same peerId, ' +
|
'handleConnection() | there is already a peer with same peerId, ' +
|
||||||
'closing the previous one [peerId:"%s"]',
|
'closing the previous one [peerId:"%s"]',
|
||||||
peerId);
|
peerId);
|
||||||
|
|
||||||
const peer = this._peers.get(peerId);
|
const peer = this._peers[peerId];
|
||||||
|
|
||||||
peer.socket.disconnect();
|
peer.socket.disconnect();
|
||||||
this._peers.delete(peerId);
|
delete this._peers[peerId];
|
||||||
}
|
}
|
||||||
else if (this._locked) // Don't allow connections to a locked room
|
else if (this._locked) // Don't allow connections to a locked room
|
||||||
{
|
{
|
||||||
this._lobby.parkPeer({ peerId, consume, socket });
|
this._lobby.parkPeer({ peerId, consume, socket });
|
||||||
|
|
||||||
this._peers.forEach((peer) =>
|
Object.values(this._peers).forEach((peer) =>
|
||||||
{
|
{
|
||||||
this._notification(peer.socket, 'parkedPeer', { peerId });
|
this._notification(peer.socket, 'parkedPeer', { peerId });
|
||||||
});
|
});
|
||||||
|
|
@ -232,7 +230,7 @@ class Room extends EventEmitter
|
||||||
this._lastN.push(peerId);
|
this._lastN.push(peerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._peers.set(peerId, peer);
|
this._peers[peerId] = peer;
|
||||||
|
|
||||||
this._handlePeer({ peer, consume });
|
this._handlePeer({ peer, consume });
|
||||||
this._notification(socket, 'roomReady');
|
this._notification(socket, 'roomReady');
|
||||||
|
|
@ -253,7 +251,7 @@ class Room extends EventEmitter
|
||||||
picture
|
picture
|
||||||
} = data;
|
} = data;
|
||||||
|
|
||||||
const peer = this._peers.get(peerId);
|
const peer = this._peers[peerId];
|
||||||
|
|
||||||
if (peer)
|
if (peer)
|
||||||
{
|
{
|
||||||
|
|
@ -326,7 +324,7 @@ class Room extends EventEmitter
|
||||||
transport.close();
|
transport.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._peers.delete(peer.id);
|
delete this._peers[peer.id];
|
||||||
|
|
||||||
// If this is the latest Peer in the room, close the room after a while.
|
// If this is the latest Peer in the room, close the room after a while.
|
||||||
if (this._peers.size === 0)
|
if (this._peers.size === 0)
|
||||||
|
|
@ -385,7 +383,7 @@ class Room extends EventEmitter
|
||||||
|
|
||||||
const peerInfos = [];
|
const peerInfos = [];
|
||||||
|
|
||||||
this._peers.forEach((joinedPeer) =>
|
Object.values(this._peers).forEach((joinedPeer) =>
|
||||||
{
|
{
|
||||||
if (joinedPeer.data.joined)
|
if (joinedPeer.data.joined)
|
||||||
{
|
{
|
||||||
|
|
@ -548,7 +546,7 @@ class Room extends EventEmitter
|
||||||
|
|
||||||
cb(null, { id: producer.id });
|
cb(null, { id: producer.id });
|
||||||
|
|
||||||
this._peers.forEach((otherPeer) =>
|
Object.values(this._peers).forEach((otherPeer) =>
|
||||||
{
|
{
|
||||||
if (otherPeer.data.joined && otherPeer !== peer)
|
if (otherPeer.data.joined && otherPeer !== peer)
|
||||||
{
|
{
|
||||||
|
|
@ -817,12 +815,15 @@ class Room extends EventEmitter
|
||||||
case 'serverHistory':
|
case 'serverHistory':
|
||||||
{
|
{
|
||||||
// Return to sender
|
// Return to sender
|
||||||
|
const lobbyPeers = this._lobby.peerList();
|
||||||
cb(
|
cb(
|
||||||
null,
|
null,
|
||||||
{
|
{
|
||||||
chatHistory : this._chatHistory,
|
chatHistory : this._chatHistory,
|
||||||
fileHistory : this._fileHistory,
|
fileHistory : this._fileHistory,
|
||||||
lastN : this._lastN
|
lastN : this._lastN,
|
||||||
|
locked : this._locked,
|
||||||
|
lobbyPeers : lobbyPeers
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue