Some cleanup.
This commit is contained in:
+70
-19
@@ -12,18 +12,24 @@ class Peer extends EventEmitter
|
||||
|
||||
this._id = id;
|
||||
|
||||
this._authId = null;
|
||||
|
||||
this._socket = socket;
|
||||
|
||||
this._closed = false;
|
||||
|
||||
this._joined = false;
|
||||
|
||||
this._inLobby = false;
|
||||
|
||||
this._authenticated = false;
|
||||
|
||||
this._displayName = false;
|
||||
|
||||
this._picture = null;
|
||||
|
||||
this._email = null;
|
||||
|
||||
this._device = null;
|
||||
|
||||
this._rtpCapabilities = null;
|
||||
@@ -71,20 +77,10 @@ class Peer extends EventEmitter
|
||||
|
||||
this.socket.on('request', (request, cb) =>
|
||||
{
|
||||
logger.debug(
|
||||
'Peer "request" event [method:"%s", peer:"%s"]',
|
||||
request.method, this.id);
|
||||
|
||||
if (this._closed)
|
||||
return;
|
||||
|
||||
this._handleSocketRequest(request, cb)
|
||||
.catch((error) =>
|
||||
{
|
||||
logger.error('request failed [error:"%o"]', error);
|
||||
|
||||
cb(error);
|
||||
});
|
||||
this._handleSocketRequest(request, cb).catch(cb);
|
||||
});
|
||||
|
||||
this.socket.on('disconnect', () =>
|
||||
@@ -100,12 +96,6 @@ class Peer extends EventEmitter
|
||||
|
||||
async _handleSocketRequest(request, cb)
|
||||
{
|
||||
logger.debug(
|
||||
'_handleSocketRequest [peer:"%s"], [request:"%s"]',
|
||||
this.id,
|
||||
request.method
|
||||
);
|
||||
|
||||
if (this._closed)
|
||||
return;
|
||||
|
||||
@@ -121,14 +111,45 @@ class Peer extends EventEmitter
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'changeProfilePicture':
|
||||
{
|
||||
const { picture } = request.data;
|
||||
|
||||
this.picture = picture;
|
||||
|
||||
cb();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_checkAuthentication()
|
||||
{
|
||||
this.authenticated =
|
||||
if (
|
||||
Boolean(this.socket.handshake.session.passport) &&
|
||||
Boolean(this.socket.handshake.session.passport.user);
|
||||
Boolean(this.socket.handshake.session.passport.user)
|
||||
)
|
||||
{
|
||||
const {
|
||||
id,
|
||||
displayName,
|
||||
picture,
|
||||
email
|
||||
} = this.socket.handshake.session.passport.user;
|
||||
|
||||
id && (this.authId = id);
|
||||
displayName && (this.displayName = displayName);
|
||||
picture && (this.picture = picture);
|
||||
email && (this.email = email);
|
||||
|
||||
this.authenticated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.authenticated = false;
|
||||
}
|
||||
}
|
||||
|
||||
get id()
|
||||
@@ -141,6 +162,16 @@ class Peer extends EventEmitter
|
||||
this._id = id;
|
||||
}
|
||||
|
||||
get authId()
|
||||
{
|
||||
return this._authId;
|
||||
}
|
||||
|
||||
set authId(authId)
|
||||
{
|
||||
this._authId = authId;
|
||||
}
|
||||
|
||||
get socket()
|
||||
{
|
||||
return this._socket;
|
||||
@@ -166,6 +197,16 @@ class Peer extends EventEmitter
|
||||
this._joined = joined;
|
||||
}
|
||||
|
||||
get inLobby()
|
||||
{
|
||||
return this._inLobby;
|
||||
}
|
||||
|
||||
set inLobby(inLobby)
|
||||
{
|
||||
this._inLobby = inLobby;
|
||||
}
|
||||
|
||||
get authenticated()
|
||||
{
|
||||
return this._authenticated;
|
||||
@@ -217,6 +258,16 @@ class Peer extends EventEmitter
|
||||
}
|
||||
}
|
||||
|
||||
get email()
|
||||
{
|
||||
return this._email;
|
||||
}
|
||||
|
||||
set email(email)
|
||||
{
|
||||
this._email = email;
|
||||
}
|
||||
|
||||
get device()
|
||||
{
|
||||
return this._device;
|
||||
|
||||
+1
-4
@@ -263,10 +263,7 @@ class Room extends EventEmitter
|
||||
// checks both room and lobby
|
||||
checkEmpty()
|
||||
{
|
||||
if ((this._peers.size == 0) && (this._lobby.checkEmpty()))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return (this._peers.size == 0) && (this._lobby.checkEmpty());
|
||||
}
|
||||
|
||||
_parkPeer(parkPeer)
|
||||
|
||||
Reference in New Issue
Block a user