diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-10-16 18:32:27 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-10-16 18:32:27 -0500 |
| commit | 1952103f75d1050cfc6fd5382d17e1de8b02cd27 (patch) | |
| tree | 6c421eaff3ef7ef578d22fa097098cf73d8d8935 /src/web | |
| parent | 20a439728957b61a9e77ae00a23dc54873d47e9e (diff) | |
| parent | 3d136ba9eeb01481e0cfb1e9192234444e87a6d2 (diff) | |
| download | slskd-1952103f75d1050cfc6fd5382d17e1de8b02cd27.tar.gz | |
Merge remote-tracking branch 'origin/master' into config-ui
Diffstat (limited to 'src/web')
| -rw-r--r-- | src/web/src/components/App.js | 40 | ||||
| -rw-r--r-- | src/web/src/lib/hubFactory.js | 2 | ||||
| -rw-r--r-- | src/web/src/lib/session.js | 10 |
3 files changed, 28 insertions, 24 deletions
diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index e717b8c0..d298de31 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -36,6 +36,7 @@ const initialState = { applicationState: {}, initialized: false, error: false, + retriesExhausted: false, }; class App extends Component { @@ -48,36 +49,32 @@ class App extends Component { init = async () => { try { const securityEnabled = await session.getSecurityEnabled(); - + if (!securityEnabled) { console.debug('application security is not enabled, per api call') session.enablePassthrough() } - const sessionOk = await session.check(); - - if (!sessionOk) { - return; + if (await session.check()) { + const appHub = createApplicationHubConnection(); + + appHub.on('state', (state) => { + this.setState({ applicationState: state }); + }); + + appHub.onreconnecting(() => this.setState({ error: true, retriesExhausted: false })); + appHub.onclose(() => this.setState({ error: true, retriesExhausted: true })); + appHub.onreconnected(() => this.setState({ error: false, retriesExhausted: false })); + + await appHub.start(); } - const appHub = createApplicationHubConnection(); - - appHub.on('state', (state) => { - this.setState({ applicationState: state }); - }); - - appHub.onreconnecting(() => this.setState({ error: true })); - appHub.onclose(() => this.setState({ error: true })); - appHub.onreconnected(() => this.setState({ error: false })); - - await appHub.start(); - this.setState({ error: false, }); } catch (err) { console.error(err) - this.setState({ error: true }, () => setTimeout(() => this.init(), 1000)) + this.setState({ error: true, retriesExhausted: true }) } finally { this.setState({ initialized: true }); } @@ -105,7 +102,7 @@ class App extends Component { }; render = () => { - const { login, applicationState = {}, error, initialized } = this.state; + const { login, applicationState = {}, error, initialized, retriesExhausted } = this.state; const { version = {}, server } = applicationState; const { isUpdateAvailable, current, latest } = version; @@ -114,7 +111,10 @@ class App extends Component { } if (error) { - return <ErrorSegment suppressPrefix icon='attention' caption='Lost connection to slskd' />; + return <ErrorSegment + suppressPrefix + icon='attention' + caption={<><span>Lost connection to slskd</span><br/><span>{(retriesExhausted ? 'Refresh to reconnect' : 'Retrying...')}</span></>}/>; } if (!session.isLoggedIn() && !session.isPassthroughEnabled()) { diff --git a/src/web/src/lib/hubFactory.js b/src/web/src/lib/hubFactory.js index 3281a80c..b57faa25 100644 --- a/src/web/src/lib/hubFactory.js +++ b/src/web/src/lib/hubFactory.js @@ -12,7 +12,7 @@ export const createHubConnection = ({ url }) => .withUrl(url, { accessTokenFactory: session.getToken }) - .withAutomaticReconnect() + .withAutomaticReconnect([0, 500, 1000, 3000, 5000, 5000, 5000, 5000, 5000]) .withHubProtocol(new JsonHubProtocol()) .configureLogging(LogLevel.Warning) .build(); diff --git a/src/web/src/lib/session.js b/src/web/src/lib/session.js index 2627f6cc..822a28a9 100644 --- a/src/web/src/lib/session.js +++ b/src/web/src/lib/session.js @@ -37,8 +37,12 @@ export const check = async () => { await api.get('/session'); return true; } catch (error) { - console.error('session error; not logged in or session has expired') - logout(); - return false; + if (error.response.status === 401) { + console.error('session error; not logged in or session has expired') + logout(); + return false; + } else { + throw error; + } } };
\ No newline at end of file |
