To add new task client should:
-
Connect to the server with
web-sockets
such as socket.io, pass client by query and listen to task channel -
call POST request with query params:
- <
Integer
> client - <
Integer
> date in seconds! - <
String
> task
To work correctly both client
at POST-request and client
at socket-connection`s query should be the equal!
const ServerURI = 'https://stro-schedule-service.herokuapp.com'
const ClientId = 149521;
const TaskName = 'Aleshka';
const TaskDate = Date.now() / 1000 + 100;//Run task in 100 seconds after call;
const Tasks = {
[TaskName]: () => console.log('Aleshka works');
};
const socket = io(`${ServerURI}`, { query: { client:ClientId }});
socket.on('connect', () => {
socket.on('task', (taskId) => {
Tasks[taskId]();
});
});
axios.post(`${ServerURI}?client=${ClientId}&date=${TaskDate}&task=${TaskName}`);