home-assistant / home-assistant-js-websocket

:aerial_tramway: JavaScript websocket client for Home Assistant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Don't wait to refresh expired token until connection is open

balloob opened this issue · comments

Currently we wait till the websocket connection is open until we check if our access token has expired and renew if it has. We should check if the token has expired the moment we open the connection and have that run in parallel with setting up the websocket connection.

const handleOpen = async (event: MessageEventInit) => {
try {
if (auth.expired) await auth.refreshAccessToken();
socket.send(JSON.stringify(messages.auth(auth.accessToken)));