Add underlying code to handle authenticating websocket credentials

This commit is contained in:
Dane Everitt 2019-09-08 17:48:37 -07:00
parent 1ae374069c
commit 086018751d
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
12 changed files with 240 additions and 35 deletions

View file

@ -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 ]);

View file

@ -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;