Added session & session manager
This commit is contained in:
parent
1b91e330c1
commit
478bd76aeb
44
models/session.js
Normal file
44
models/session.js
Normal file
@ -0,0 +1,44 @@
|
||||
class Session {
|
||||
constructor(id) {
|
||||
this._id = id;
|
||||
this._started = Date.now();
|
||||
this._current = null;
|
||||
this._previous = null;
|
||||
this._lastScrobble = null;
|
||||
this._pauseDuration = 0;
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get playing() {
|
||||
return this._current;
|
||||
}
|
||||
|
||||
set playing(value) {
|
||||
this._current = value;
|
||||
}
|
||||
|
||||
get started() {
|
||||
return this._started;
|
||||
}
|
||||
|
||||
get lastScrobbleTimestamp() {
|
||||
return this._lastScrobble;
|
||||
}
|
||||
|
||||
set lastScrobbleTimestamp(value) {
|
||||
this._lastScrobble = value;
|
||||
}
|
||||
|
||||
get pauseDuration() {
|
||||
return this._pauseDuration;
|
||||
}
|
||||
|
||||
set pauseDuration(value) {
|
||||
this._pauseDuration = value;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Session;
|
33
services/session-manager.js
Normal file
33
services/session-manager.js
Normal file
@ -0,0 +1,33 @@
|
||||
class SessionManager {
|
||||
constructor() {
|
||||
this._sessions = {};
|
||||
}
|
||||
|
||||
add(session) {
|
||||
if (!session || !session.id)
|
||||
return;
|
||||
|
||||
this._sessions[session.id] = session;
|
||||
}
|
||||
|
||||
contains(sessionId) {
|
||||
return this._sessions[sessionId] != null;
|
||||
}
|
||||
|
||||
get(sessionId) {
|
||||
return this._sessions[sessionId];
|
||||
}
|
||||
|
||||
getSessionIds() {
|
||||
return Object.keys(this._sessions);
|
||||
}
|
||||
|
||||
remove(sessionId) {
|
||||
if (!sessionId)
|
||||
return;
|
||||
|
||||
delete this._sessions[sessionId];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new SessionManager();
|
Loading…
Reference in New Issue
Block a user