mirror of https://github.com/jitsi/jitsi-meet
parent
29dc63fbcb
commit
8758c222c6
@ -0,0 +1,9 @@ |
||||
/** |
||||
* Action used to set custom user properties. |
||||
*/ |
||||
export const SET_DYNAMIC_BRANDING_DATA = 'SET_DYNAMIC_BRANDING_DATA'; |
||||
|
||||
/** |
||||
* Action used to signal the branding elements are ready to be displayed |
||||
*/ |
||||
export const SET_DYNAMIC_BRANDING_READY = 'SET_DYNAMIC_BRANDING_READY'; |
@ -0,0 +1,66 @@ |
||||
// @flow
|
||||
|
||||
import { getLogger } from 'jitsi-meet-logger'; |
||||
|
||||
import { doGetJSON } from '../base/util'; |
||||
|
||||
import { SET_DYNAMIC_BRANDING_DATA, SET_DYNAMIC_BRANDING_READY } from './actionTypes'; |
||||
import { extractFqnFromPath } from './functions'; |
||||
|
||||
const logger = getLogger(__filename); |
||||
|
||||
/** |
||||
* Fetches custom branding data. |
||||
* If there is no data or the request fails, sets the `customizationReady` flag |
||||
* so the defaults can be displayed. |
||||
* |
||||
* @returns {Function} |
||||
*/ |
||||
export function fetchCustomBrandingData() { |
||||
return async function(dispatch: Function, getState: Function) { |
||||
const state = getState(); |
||||
const baseUrl = state['features/base/config'].brandingDataUrl; |
||||
const { customizationReady } = state['features/dynamic-branding']; |
||||
|
||||
if (!customizationReady) { |
||||
const fqn = extractFqnFromPath(state['features/base/connection'].locationURL.pathname); |
||||
|
||||
if (baseUrl && fqn) { |
||||
try { |
||||
const res = await doGetJSON(`${baseUrl}?conferenceFqn=${encodeURIComponent(fqn)}`); |
||||
|
||||
return dispatch(setDynamicBrandingData(res)); |
||||
} catch (err) { |
||||
logger.error('Error fetching branding data', err); |
||||
} |
||||
} |
||||
|
||||
dispatch(setDynamicBrandingReady()); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* Action used to set the user customizations. |
||||
* |
||||
* @param {Object} value - The custom data to be set. |
||||
* @returns {Object} |
||||
*/ |
||||
function setDynamicBrandingData(value) { |
||||
return { |
||||
type: SET_DYNAMIC_BRANDING_DATA, |
||||
value |
||||
}; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Action used to signal the branding elements are ready to be displayed. |
||||
* |
||||
* @returns {Object} |
||||
*/ |
||||
function setDynamicBrandingReady() { |
||||
return { |
||||
type: SET_DYNAMIC_BRANDING_READY |
||||
}; |
||||
} |
@ -0,0 +1,15 @@ |
||||
// @flow
|
||||
|
||||
/** |
||||
* Extracts the fqn part from a path, where fqn represents |
||||
* tenant/roomName. |
||||
* |
||||
* @param {string} path - The URL path. |
||||
* @returns {string} |
||||
*/ |
||||
export function extractFqnFromPath(path: string) { |
||||
const parts = path.split('/'); |
||||
const len = parts.length; |
||||
|
||||
return parts.length > 2 ? `${parts[len - 2]}/${parts[len - 1]}` : ''; |
||||
} |
@ -0,0 +1,4 @@ |
||||
export * from './actions'; |
||||
export * from './functions'; |
||||
|
||||
import './reducer'; |
@ -0,0 +1,46 @@ |
||||
// @flow
|
||||
|
||||
import { ReducerRegistry } from '../base/redux'; |
||||
|
||||
import { SET_DYNAMIC_BRANDING_DATA, SET_DYNAMIC_BRANDING_READY } from './actionTypes'; |
||||
|
||||
/** |
||||
* The name of the redux store/state property which is the root of the redux |
||||
* state of the feature {@code dynamic-branding}. |
||||
*/ |
||||
const STORE_NAME = 'features/dynamic-branding'; |
||||
|
||||
const DEFAULT_STATE = { |
||||
backgroundColor: '', |
||||
backgroundImageUrl: '', |
||||
customizationReady: false, |
||||
logoClickUrl: '', |
||||
logoImageUrl: '' |
||||
}; |
||||
|
||||
/** |
||||
* Reduces redux actions for the purposes of the feature {@code dynamic-branding}. |
||||
*/ |
||||
ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => { |
||||
switch (action.type) { |
||||
case SET_DYNAMIC_BRANDING_DATA: { |
||||
const { backgroundColor, backgroundImageUrl, logoClickUrl, logoImageUrl } = action.value; |
||||
|
||||
return { |
||||
backgroundColor, |
||||
backgroundImageUrl, |
||||
logoClickUrl, |
||||
logoImageUrl, |
||||
customizationReady: true |
||||
}; |
||||
} |
||||
case SET_DYNAMIC_BRANDING_READY: |
||||
return { |
||||
...state, |
||||
customizationReady: true |
||||
}; |
||||
|
||||
} |
||||
|
||||
return state; |
||||
}); |
Loading…
Reference in new issue