Handle websocket authentication slightly differently to make errors easier to work with

This commit is contained in:
Dane Everitt 2019-12-21 17:31:04 -08:00
parent 02c0d934c3
commit 11c17245c2
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 26 additions and 9 deletions

View file

@ -11,7 +11,7 @@ export default () => {
const updateToken = (uuid: string, socket: Websocket) => {
getWebsocketToken(uuid)
.then(data => socket.setToken(data.token))
.then(data => socket.setToken(data.token, true))
.catch(error => console.error(error));
};
@ -24,7 +24,7 @@ export default () => {
const socket = new Websocket();
socket.on('SOCKET_OPEN', () => setConnectionState(true));
socket.on('auth success', () => setConnectionState(true));
socket.on('SOCKET_CLOSE', () => setConnectionState(false));
socket.on('SOCKET_ERROR', () => setConnectionState(false));
socket.on('status', (status) => setServerStatus(status));
@ -38,7 +38,10 @@ export default () => {
getWebsocketToken(server.uuid)
.then(data => {
// Connect and then set the authentication token.
socket.setToken(data.token).connect(data.socket);
// Once that is done, set the instance.
setInstance(socket);
})
.catch(error => console.error(error));