Add underlying code to handle authenticating websocket credentials
This commit is contained in:
parent
1ae374069c
commit
086018751d
12 changed files with 240 additions and 35 deletions
|
@ -59,7 +59,7 @@ export default () => {
|
|||
terminal.clear();
|
||||
|
||||
instance
|
||||
.addListener('stats', data => console.log(JSON.parse(data)))
|
||||
// .addListener('stats', data => console.log(JSON.parse(data)))
|
||||
.addListener('console output', handleConsoleOutput);
|
||||
|
||||
instance.send('send logs');
|
||||
|
@ -67,7 +67,7 @@ export default () => {
|
|||
|
||||
return () => {
|
||||
instance && instance
|
||||
.removeListener('console output', handleConsoleOutput)
|
||||
.removeAllListeners('console output')
|
||||
.removeAllListeners('stats');
|
||||
};
|
||||
}, [ connected, instance ]);
|
||||
|
|
|
@ -15,19 +15,21 @@ export default () => {
|
|||
return;
|
||||
}
|
||||
|
||||
console.log('Connecting!');
|
||||
|
||||
const socket = new Websocket(
|
||||
`wss://wings.pterodactyl.test:8080/api/servers/${server.uuid}/ws`,
|
||||
'CC8kHCuMkXPosgzGO6d37wvhNcksWxG6kTrA',
|
||||
);
|
||||
const socket = new Websocket(server.uuid);
|
||||
|
||||
socket.on('SOCKET_OPEN', () => setConnectionState(true));
|
||||
socket.on('SOCKET_CLOSE', () => setConnectionState(false));
|
||||
socket.on('SOCKET_ERROR', () => setConnectionState(false));
|
||||
socket.on('status', (status) => setServerStatus(status));
|
||||
|
||||
setInstance(socket);
|
||||
socket.connect()
|
||||
.then(() => setInstance(socket))
|
||||
.catch(error => console.error(error));
|
||||
|
||||
return () => {
|
||||
socket && socket.close();
|
||||
instance && instance!.removeAllListeners();
|
||||
};
|
||||
}, [ server ]);
|
||||
|
||||
return null;
|
||||
|
|
Reference in a new issue