🏗 Wired up the events correctly

This commit is contained in:
2023-11-13 16:41:58 -05:00
parent 1229feb69c
commit 11fbaf10db

View File

@@ -26,90 +26,92 @@ export default class SocketService extends Service {
"/": { "/": {
events: { events: {
call: { call: {
// whitelist: ["math.*", "say.*", "accounts.*", "rooms.*", "io.*"], whitelist: ["socket.resumeSession"],
}, },
action: async (data) => {
switch (data.type) {
case "RESUME_SESSION":
console.log("Attempting to resume session...");
try {
const sessionRecord = await Session.find({
sessionId: data.session.sessionId,
});
// 1. Check for sessionId's existence, and a match
if (
sessionRecord.length !== 0 &&
sessionRecord[0].sessionId ===
data.session.sessionId
) {
// 2. Find if the queue has active jobs
const jobs: JobType = await this.broker.call(
"jobqueue.getJobCountsByType",
{}
);
const { active } = jobs;
if (active > 0) { // async (data) => {
// 3. Get job counts // console.log("uldas", data);
const completedJobCount = // switch (data.type) {
await pubClient.get( // case "RESUME_SESSION":
"completedJobCount" // console.log("Attempting to resume session...");
); // try {
const failedJobCount = await pubClient.get( // const sessionRecord = await Session.find({
"failedJobCount" // sessionId: data.session.sessionId,
); // });
// // 1. Check for sessionId's existence, and a match
// 4. Send the counts to the active socket.io session // if (
await this.broker.call("socket.broadcast", { // sessionRecord.length !== 0 &&
namespace: "/", // sessionRecord[0].sessionId ===
event: "action", // data.session.sessionId
args: [ // ) {
{ // // 2. Find if the queue has active jobs
type: "RESTORE_JOB_COUNTS_AFTER_SESSION_RESTORATION", // const jobs: JobType = await this.broker.call(
completedJobCount, // "jobqueue.getJobCountsByType",
failedJobCount, // {}
queueStatus: "running", // );
}, // const { active } = jobs;
], //
}); // if (active > 0) {
} // // 3. Get job counts
} // const completedJobCount =
} catch (err) { // await pubClient.get(
throw new MoleculerError( // "completedJobCount"
err, // );
500, // const failedJobCount = await pubClient.get(
"SESSION_ID_NOT_FOUND", // "failedJobCount"
{ // );
data: data.session.sessionId, //
} // // 4. Send the counts to the active socket.io session
); // await this.broker.call("socket.broadcast", {
} // namespace: "/",
// event: "action",
break; // args: [
// {
case "LS_SET_QUEUE_STATUS": // type: "RESTORE_JOB_COUNTS_AFTER_SESSION_RESTORATION",
console.log(data); // completedJobCount,
await this.broker.call( // failedJobCount,
"jobqueue.toggle", // queueStatus: "running",
{ action: data.data.queueAction }, // },
{} // ],
); // });
break; // }
case "LS_SINGLE_IMPORT": // }
console.info("AirDC++ finished a download -> "); // } catch (err) {
console.log(data); // throw new MoleculerError(
await this.broker.call( // err,
"library.importDownloadedComic", // 500,
{ bundle: data }, // "SESSION_ID_NOT_FOUND",
{} // {
); // data: data.session.sessionId,
break; // }
// uncompress archive events // );
case "COMICBOOK_EXTRACTION_SUCCESS": // }
console.log(data); //
return data; // break;
} //
}, // case "LS_SET_QUEUE_STATUS":
// console.log(data);
// await this.broker.call(
// "jobqueue.toggle",
// { action: data.data.queueAction },
// {}
// );
// break;
// case "LS_SINGLE_IMPORT":
// console.info("AirDC++ finished a download -> ");
// console.log(data);
// await this.broker.call(
// "library.importDownloadedComic",
// { bundle: data },
// {}
// );
// break;
// // uncompress archive events
// case "COMICBOOK_EXTRACTION_SUCCESS":
// console.log(data);
// return data;
// }
// },
}, },
}, },
}, },
@@ -119,7 +121,11 @@ export default class SocketService extends Service {
}, },
}, },
hooks: {}, hooks: {},
actions: {}, actions: {
resumeSession: (ctx: Context<{}>) => {
console.log("aya re", ctx.params);
},
},
methods: {}, methods: {},
async started() { async started() {
this.io.on("connection", async (socket) => { this.io.on("connection", async (socket) => {