-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace compile constants with ini files
* BREAKING_CHANGE: add ini files for app config sources definitions instead of using compile time env variables * feat: improved app and root components, updated to functional components * fix: use react hooks for navigation and better UI * fix: improve error and demo dialog UI/UX * fix: better error for bad settings, remove netlify refs * fix: limit demo UI to only work with config IDs
- Loading branch information
Showing
55 changed files
with
823 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
APP_UNSAFE_ALLOW_DYNAMIC_CONFIG=0 | ||
APP_API_BASE_URL=https://cdn.jwplayer.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
APP_CONFIG_DEFAULT_SOURCE= | ||
APP_UNSAFE_ALLOW_DYNAMIC_CONFIG=1 | ||
APP_DEMO_DEFAULT_CONFIG_ID=225tvq1i | ||
APP_DEMO_FALLBACK_CONFIG_ID=225tvq1i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
APP_CONFIG_DEFAULT_SOURCE=uzcyv8xh | ||
APP_UNSAFE_ALLOW_DYNAMIC_CONFIG=1 | ||
APP_API_BASE_URL=https://content-portal.jwplatform.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Initialization (ini) File | ||
|
||
The JW OTT Web App loads a small initialization (.ini) file at startup. This file provides a mechanism to set key parameters without modifying the source code. | ||
Template ini files are included in the repo and with the pre-compiled production release builds ([.webapp.prod.ini](/ini/templates/.webapp.prod.ini)). | ||
Make sure you include a copy of the ini file edited to include your account data at `/public/.webapp.ini` for the application to load correctly. | ||
|
||
For all manual builds (`yarn start` or `yarn build`), the ini file is copied from `/ini/.webapp.<mode>.ini` to `build/public/.webapp.ini`, which the application fetches and parses at startup. | ||
If a file doesn't exist in /ini/.webapp.<mode>.ini, then the template file will first be copied from [`/ini/templates`](/ini/templates). | ||
All of the .ini files inside of /ini are ignored in git, so you can create your own files locally to run the application with your account parameters without creating conflicts with committed code or leaking your details into source control. | ||
|
||
## Ini Parameters | ||
|
||
### defaultConfigSource | ||
|
||
The 8 character ID of the app config from your JWP account (or the url path) that the web app will use to load its content. Be careful to ensure that this config is always available or your app will fail to load. | ||
|
||
> Note: you probably always want to include a default config source for any production deployment. If there are no valid config sources the application will throw an error at startup. | ||
### additionalAllowedConfigSources[] | ||
|
||
An array of of 8-character IDs (entered 1 per line) for app configs in your JWP account (or url paths) that can be used with the [`app-config=<config source>` query param](configuration.md#switching-between-app-configs). | ||
This may be useful for example if you have a staging or experimental config that you want to be able to test on your site using the [`app-config` query parameter](configuration.md#switching-between-app-configs) without changing the default config that the application loads with for all of your users. | ||
See [.webapp.test.ini](/ini/templates/.webapp.test.ini) for an example. | ||
|
||
### UNSAFE_allowAnyConfigSource | ||
|
||
Boolean flag which if true, enables **ANY** 8-character app config ID (or path) to be specified with the [`app-config=<config source>` query param](configuration.md#switching-between-app-configs). | ||
|
||
>***Warning:** Generally the `UNSAFE_allowAnyConfigSource` option should only be used for dev, test, or demo deployments, because it will allow anyone to create URL's that specify any config to be displayed on your domain.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
"public": "build/public", | ||
"ignore": [ | ||
"firebase.json", | ||
"**/.*", | ||
"**/node_modules/**" | ||
], | ||
"rewrites": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
; The demo app should load with the config prompt screen | ||
defaultConfigSource = | ||
; Allow any config in demo mode (this should only really be run on JWP's demo site at https://app-preview.jwplayer.com/) | ||
UNSAFE_allowAnyConfigSource = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
; This is a basic Blender demo | ||
defaultConfigSource = gnnuzabk | ||
; When developing, switching between configs is useful for test and debug | ||
UNSAFE_allowAnyConfigSource = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
; jwdev mode runs in the JWP internal dev environment, so this is an app config hosted there | ||
defaultConfigSource = uzcyv8xh | ||
; When developing, switching between configs is useful for test and debug | ||
UNSAFE_allowAnyConfigSource = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
; This is the app config that your application will load at startup | ||
defaultConfigSource = ; Enter your 8 digit config ID (i.e. gnnuzabk) here (case sensitive) | ||
|
||
;******************************************************************************************** | ||
; If you want to support app configs other than the default with the app-config= query param | ||
; add them individually one per line here. | ||
; See .webapp.test.ini for an example. | ||
;******************************************************************************************** | ||
;additionalAllowedConfigSources[] = | ||
;additionalAllowedConfigSources[] = | ||
;additionalAllowedConfigSources[] = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defaultConfigSource = gnnuzabk | ||
additionalAllowedConfigSources[] = kujzeu1b | ||
additionalAllowedConfigSources[] = ata6ucb8 | ||
additionalAllowedConfigSources[] = nvqkufhy | ||
additionalAllowedConfigSources[] = 7weyqrua | ||
additionalAllowedConfigSources[] = ozylzc5m |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,50 @@ | ||
import React, { Component } from 'react'; | ||
import { getI18n, I18nextProvider } from 'react-i18next'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { BrowserRouter, HashRouter } from 'react-router-dom'; | ||
|
||
import type { Config } from '#types/Config'; | ||
import Router from '#src/containers/Router/Router'; | ||
import LoadingOverlay from '#components/LoadingOverlay/LoadingOverlay'; | ||
import QueryProvider from '#src/providers/QueryProvider'; | ||
import { restoreWatchHistory } from '#src/stores/WatchHistoryController'; | ||
import { initializeAccount } from '#src/stores/AccountController'; | ||
import { initializeFavorites } from '#src/stores/FavoritesController'; | ||
import { logDev } from '#src/utils/common'; | ||
import { loadAndValidateConfig } from '#src/utils/configLoad'; | ||
import { clearStoredConfig } from '#src/utils/configOverride'; | ||
import { PersonalShelf } from '#src/enum/PersonalShelf'; | ||
import initI18n from '#src/i18n/config'; | ||
|
||
import '#src/screenMapping'; | ||
import '#src/styles/main.scss'; | ||
import initI18n from '#src/i18n/config'; | ||
import Root from '#components/Root/Root'; | ||
import { ErrorPageWithoutTranslation } from '#components/ErrorPage/ErrorPage'; | ||
import LoadingOverlay from '#components/LoadingOverlay/LoadingOverlay'; | ||
|
||
interface State { | ||
error: Error | null; | ||
isLoading: boolean; | ||
error?: Error; | ||
} | ||
|
||
class App extends Component { | ||
public state: State = { | ||
error: null, | ||
isLoading: true, | ||
}; | ||
export default function App() { | ||
const [i18nState, seti18nState] = useState<State>({ isLoading: true }); | ||
|
||
componentDidCatch(error: Error) { | ||
this.setState({ error }); | ||
} | ||
|
||
async initializeServices(config: Config) { | ||
if (config?.integrations?.cleeng?.id) { | ||
await initializeAccount(); | ||
} | ||
|
||
// We only request favorites and continue_watching data if there is a corresponding item in the content section | ||
// and a playlist in the features section. | ||
// We first initialize the account otherwise if we have favorites saved as externalData and in a local storage the sections may blink | ||
if (config.features?.continueWatchingList && config.content.some((el) => el.type === PersonalShelf.ContinueWatching)) { | ||
await restoreWatchHistory(); | ||
} | ||
useEffect(() => { | ||
initI18n() | ||
.then(() => seti18nState({ isLoading: false })) | ||
.catch((e) => seti18nState({ isLoading: false, error: e as Error })); | ||
}, []); | ||
|
||
if (config.features?.favoritesList && config.content.some((el) => el.type === PersonalShelf.Favorites)) { | ||
await initializeFavorites(); | ||
} | ||
if (i18nState.isLoading) { | ||
return <LoadingOverlay />; | ||
} | ||
|
||
configLoadingHandler = (isLoading: boolean) => { | ||
this.setState({ isLoading }); | ||
logDev(`Loading config: ${isLoading}`); | ||
}; | ||
|
||
configErrorHandler = (error: Error) => { | ||
clearStoredConfig(); | ||
|
||
this.setState({ error }); | ||
this.setState({ isLoading: false }); | ||
logDev('Error while loading the config:', error); | ||
}; | ||
|
||
configValidationCompletedHandler = async (config: Config) => { | ||
await this.initializeServices(config); | ||
this.setState({ isLoading: false }); | ||
}; | ||
|
||
async componentDidMount() { | ||
await initI18n(); | ||
await loadAndValidateConfig(this.configLoadingHandler, this.configErrorHandler, this.configValidationCompletedHandler); | ||
} | ||
|
||
render() { | ||
const { isLoading, error } = this.state; | ||
|
||
if (isLoading) { | ||
return <LoadingOverlay />; | ||
} | ||
|
||
if (i18nState.error) { | ||
// Don't be tempted to translate these strings. If i18n fails to load, translations won't work anyhow | ||
return ( | ||
<I18nextProvider i18n={getI18n()}> | ||
<QueryProvider> | ||
<Router error={error} /> | ||
</QueryProvider> | ||
</I18nextProvider> | ||
<ErrorPageWithoutTranslation | ||
title={'Unable to load translations'} | ||
message={'Check your language settings and try again later. If the problem persists contact technical support.'} | ||
error={i18nState.error} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default App; | ||
const Router = import.meta.env.APP_PUBLIC_GITHUB_PAGES ? HashRouter : BrowserRouter; | ||
|
||
return ( | ||
<QueryProvider> | ||
<Router> | ||
<Root /> | ||
</Router> | ||
</QueryProvider> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.