2024-01-03 20:39:53 +01:00
|
|
|
import { io } from 'socket.io-client';
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
|
|
|
export async function load() {
|
|
|
|
const credFile = './credentials.json';
|
|
|
|
const socket = io('https://status.neshweb.net/');
|
|
|
|
|
2024-01-03 21:09:58 +01:00
|
|
|
let credentials = {
|
|
|
|
username: '',
|
|
|
|
password: ''
|
|
|
|
};
|
2024-01-03 20:39:53 +01:00
|
|
|
if (fs.existsSync(credFile)) {
|
2024-01-03 21:09:58 +01:00
|
|
|
const buf = fs.readFileSync(credFile);
|
2024-01-03 20:39:53 +01:00
|
|
|
credentials = JSON.parse(buf.toString());
|
|
|
|
} else {
|
|
|
|
console.error('Credentials File does not exist, Socket.io connection will not work.');
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(credentials);
|
|
|
|
|
|
|
|
let token = '';
|
|
|
|
|
|
|
|
socket.on('connect', () => {
|
|
|
|
socket.emit(
|
|
|
|
'login',
|
|
|
|
{ username: credentials.username, password: credentials.password, token: '' },
|
|
|
|
(res) => {
|
|
|
|
token = res.token;
|
|
|
|
console.log('Token is:', token);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
while (token == '') {
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
token
|
|
|
|
};
|
|
|
|
}
|