mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 13:19:44 +02:00
parent
7273b33768
commit
4fe77c305c
15 changed files with 130 additions and 42 deletions
38
server/api/hooks/watcher/index.js
Normal file
38
server/api/hooks/watcher/index.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* watcher hook
|
||||
*
|
||||
* @description :: A hook definition. Extends Sails by adding shadow routes, implicit actions,
|
||||
* and/or initialization logic.
|
||||
* @docs :: https://sailsjs.com/docs/concepts/extending-sails/hooks
|
||||
*/
|
||||
|
||||
module.exports = function defineWatcherHook(sails) {
|
||||
const checkSocketConnectionsToLogout = () => {
|
||||
Object.keys(sails.io.sockets.adapter.rooms).forEach((room) => {
|
||||
if (!room.startsWith('@accessToken:')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const accessToken = room.split(':')[1];
|
||||
|
||||
try {
|
||||
sails.helpers.utils.verifyToken(accessToken);
|
||||
} catch (error) {
|
||||
sails.sockets.broadcast(room, 'logout');
|
||||
sails.sockets.leaveAll(room);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
/**
|
||||
* Runs when this Sails app loads/lifts.
|
||||
*/
|
||||
|
||||
async initialize() {
|
||||
sails.log.info('Initializing custom hook (`watcher`)');
|
||||
|
||||
setInterval(checkSocketConnectionsToLogout, 60 * 1000);
|
||||
},
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue