@@ -4,11 +4,13 @@ import {ManagedSettings} from '../settings/managed-settings'
44import { RestreamioStreamingPlatform , RestreamioToken } from './types'
55import { SettingsManager } from 'streamdeck-typescript'
66import createAuthRefreshInterceptor from 'axios-auth-refresh'
7+ import * as rax from 'retry-axios'
78
89export class RestreamioClient {
910 private managedGlobalSettings : ManagedGlobalSettings
1011 private managedSettings ?: ManagedSettings
1112 private authenticatedAxios : AxiosInstance
13+ private unAuthenticatedAxios : AxiosInstance
1214
1315 static fromSettingsManager (
1416 settingsManager : SettingsManager ,
@@ -27,6 +29,19 @@ export class RestreamioClient {
2729 this . managedGlobalSettings = managedGlobalSettings
2830 this . managedSettings = managedSettings
2931 this . authenticatedAxios = this . createAuthenticatedAxios ( )
32+ this . unAuthenticatedAxios = RestreamioClient . createUnauthenticatedAxios ( )
33+ }
34+
35+ private static createUnauthenticatedAxios ( ) : AxiosInstance {
36+ const unauthenticatedAxios = axios . create ( )
37+
38+ unauthenticatedAxios . defaults . raxConfig = {
39+ instance : unauthenticatedAxios ,
40+ }
41+
42+ rax . attach ( unauthenticatedAxios )
43+
44+ return unauthenticatedAxios
3045 }
3146
3247 private createAuthenticatedAxios ( ) : AxiosInstance {
@@ -36,11 +51,9 @@ export class RestreamioClient {
3651 const token = this . getToken ( )
3752
3853 if ( ! token ) {
39- console . log ( 'we have no token' )
4054 return request
4155 }
4256
43- console . log ( 'token is' , token )
4457 request . headers [ 'Authorization' ] = `Bearer ${ token . accessToken } `
4558
4659 return request
@@ -58,9 +71,6 @@ export class RestreamioClient {
5871 return axios
5972 . post ( refreshUrl , formData )
6073 . then ( async tokenRefreshResponse => {
61- console . log ( 'ok, we refreshed!' )
62- console . log ( 'previous token' , this . getToken ( ) )
63- console . log ( 'new token' , tokenRefreshResponse )
6474 this . managedGlobalSettings . registerRestreamioAccount (
6575 tokenRefreshResponse . data ,
6676 )
@@ -72,6 +82,12 @@ export class RestreamioClient {
7282 } )
7383 } )
7484
85+ authenticatedAxios . defaults . raxConfig = {
86+ instance : authenticatedAxios ,
87+ }
88+
89+ rax . attach ( authenticatedAxios )
90+
7591 return authenticatedAxios
7692 }
7793
0 commit comments