Skip to content

Commit

Permalink
move sessionHandler and update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ksentak committed Aug 9, 2023
1 parent 0213f5a commit e246727
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions server/src/sessionManagement.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ class SessionHandler {
}
}

let sessionHandler = new SessionHandler();

class FireboltCall {
constructor(methodCall, params) {
this.methodCall = methodCall;
Expand All @@ -101,6 +99,7 @@ class Session {
this.sessionOutput = "log";
this.sessionOutputPath = `./output/sessions/${this.userId}`;
this.mockOutputPath = `./output/mocks/${this.userId}/${this.#sessionStart}`;
this.sessionHandler = new SessionHandler();
}

exportSession() {
Expand Down Expand Up @@ -405,19 +404,19 @@ class Session {
let sessionRecording = {};

function startRecording(userId) {
logger.info('Starting recording');
sessionRecording[userId] = {
recording: true,
recordedSession: new Session(userId)
logger.info(`Starting recording for user: ${userId}`);
sessionRecording[userId] = {
recording: true,
recordedSession: new Session(userId)
};
}

function stopRecording(userId) {
if (isRecording(userId)) {
logger.info('Stopping recording');
logger.info(`Stopping recording for user: ${userId}`);
sessionRecording[userId].recording = false;
const sessionData = sessionRecording[userId].recordedSession.exportSession();
sessionHandler.close();
sessionRecording[userId].recordedSession.sessionHandler.close();
delete sessionRecording[userId];
return sessionData;
} else {
Expand All @@ -437,7 +436,7 @@ function addCall(methodCall, params, userId) {
sessionRecording[userId].recordedSession.calls.push(call);
if (sessionRecording[userId].recordedSession.sessionOutput === "live") {
const data = JSON.stringify(call);
sessionHandler.write(data);
sessionRecording[userId].recordedSession.sessionHandler.write(data);
}
}
}
Expand All @@ -457,11 +456,11 @@ function getOutputFormat() {

function setOutputDir(dir, userId) {
if (sessionRecording[userId].recordedSession.sessionOutput === "live") {
sessionHandler.open(dir);
sessionRecording[userId].recordedSession.sessionHandler.open(dir);
}
sessionRecording[userId].recordedSession.sessionOutputPath = dir;
sessionRecording[userId].recordedSession.mockOutputPath = dir;
logger.info("Setting output path: " + sessionRecording[userId].recordedSession.mockOutputPath);
logger.info(`Setting output path for user ${userId}: ${sessionRecording[userId].recordedSession.mockOutputPath}`);
}

function getSessionOutputDir(){
Expand All @@ -481,7 +480,7 @@ function updateCallWithResponse(method, result, key, userId) {
sessionRecording[userId].recordedSession.calls.concat(...methodCalls);
if (sessionRecording[userId].recordedSession.sessionOutput === "live") {
const data = JSON.stringify(methodCalls[i]);
sessionHandler.write(data);
sessionRecording[userId].recordedSession.sessionHandler.write(data);
}
}
}
Expand Down

0 comments on commit e246727

Please sign in to comment.