You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
601 B
JavaScript
32 lines
601 B
JavaScript
const whatsappEvents = require('../emitter');
|
|
|
|
module.exports = () => {
|
|
const sessions = new Map();
|
|
|
|
const createSession = (sessionId, ws) => {
|
|
sessions.set(ws, sessionId);
|
|
whatsappEvents.emit('connection:connect', ws);
|
|
return { sessionId };
|
|
};
|
|
|
|
const getSession = sessionId => {
|
|
for (const [ws, storedSessionId] of sessions) {
|
|
if (storedSessionId === sessionId) {
|
|
return ws;
|
|
}
|
|
}
|
|
return null;
|
|
};
|
|
|
|
const removeSession = ws => {
|
|
sessions.delete(ws);
|
|
};
|
|
|
|
return {
|
|
createSession,
|
|
getSession,
|
|
removeSession,
|
|
sessions,
|
|
};
|
|
};
|