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.
34 lines
683 B
JavaScript
34 lines
683 B
JavaScript
9 months ago
|
const whatsappEvents = require('../emitter');
|
||
|
|
||
|
whatsappEvents.on('connection:added', ({ sock, sessionId }) => {});
|
||
|
whatsappEvents.on('connection:removed', ({ sessionId }) => {});
|
||
10 months ago
|
|
||
|
module.exports = () => {
|
||
|
const sessions = new Map();
|
||
|
|
||
10 months ago
|
const createSession = (sessionId, ws) => {
|
||
10 months ago
|
sessions.set(ws, sessionId);
|
||
10 months ago
|
return { sessionId };
|
||
10 months ago
|
};
|
||
|
|
||
|
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,
|
||
|
};
|
||
|
};
|