Do more refactoring

This commit is contained in:
David Majdandžić
2023-03-29 17:37:23 +02:00
parent 4d790b83b8
commit b8347d6fa6
3 changed files with 45 additions and 50 deletions

View File

@@ -1,4 +1,5 @@
import EventEmitter from "events";
import {Center} from "../Center/Center";
import Logger from "../Logger";
import {SessionManager} from "../SessionManager";
import {SmppSession} from "../SmppSession";
@@ -7,6 +8,8 @@ import {Client} from "./Client";
const CLIENT_SESSIONS_FILE: string = process.env.CLIENT_SESSIONS_FILE || "client_sessions.json";
export default class ClientSessionManager extends SessionManager {
comparatorFn: (arg: any, session: SmppSession) => boolean = (arg: any, session: SmppSession) => (session as Client).getUrl() === arg;
StorageFile: string = CLIENT_SESSIONS_FILE;
ManagedSessionClass: any = Client;
sessionId: number = 0;
sessions: Client[] = [];
@@ -20,29 +23,6 @@ export default class ClientSessionManager extends SessionManager {
// super.eventEmitter.on(super.SESSION_ADDED_EVENT, (session: SmppSession) => this.eventEmitter.emit(this.SESSION_ADDED_EVENT, session));
}
// TODO: Move this to superclass too
getExisting(arg: any): Promise<SmppSession> {
return new Promise<SmppSession>((resolve, reject) => {
this.logger.log1(`Looking for session with url ${arg}...`);
let session: SmppSession | undefined = this.sessions.find((s: Client) => s.getUrl() === arg);
if (session) {
this.logger.log1(`Found session with url ${arg}`);
resolve(session);
} else {
this.logger.log1(`Session with url ${arg} not found`);
reject(`Session with url ${arg} not found`);
}
});
}
cleanup(): void {
throw new Error("Method not implemented.");
}
setup(): void {
throw new Error("Method not implemented.");
}
// setup(): void {
// try {
// this.logger.log1(`Loading clients from ${CLIENT_SESSIONS_FILE}`)