Answer the question
In order to leave comments, you need to log in
Do I need validation or can I rely on websocket events?
On the site, people go and edit their projects. Sometimes one of the following situations happens:
1. Two people came in to edit the project at the same time.
2. The person opened the edit form, started doing something, and left without closing or saving the changes. Then he came home and did something there. On the next morning returned to work and continued to edit the open form.
In general, problems happen, customers write to us, we figure it out for a long time, etc.
As a result, we decided to do this: as soon as the project is opened for editing, it is blocked for all other people who have access to it and it is reported that the project is currently being edited by someone.
I wrote a small nodejs program for this.
const WebSocket = require('ws');
let locked = [];
WSS.on('connection', ws => {
ws.on('close', () => {
delete locked[i];
broadcastMessage(id, {type: 'updateLocks', data: locked);
});
ws.on('message', json => {
if (message.type === 'lock') {
locked.push({project_id: message.data.id});
}
broadcastMessage(id, {type: 'updateLocks', data: locked);
});
broadcastMessage(id, {type: 'updateLocks', data: locked);
});
Answer the question
In order to leave comments, you need to log in
It's a bad idea to check every 10 seconds - you can put the server down.
Is it possible to bypass the array of connected people forcibly by pressing a button from the web interface?
Let's say the user opens the editor, he displays a message about the lock and the "Update information" button, clicked on the button - the server did all the checks, if there is a lock - display information about who is editing the project at the moment, if there are no locks - give access.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question