-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UI wrapper): disabling UI (#107)
Created a UI wrapper using the proxy pattern, which all the UI actions will pass through it. UI can be disable using the following configuration: ui: { disable: true }
- Loading branch information
Dan Ziv
authored
Apr 16, 2018
1 parent
185ffce
commit 5784a75
Showing
5 changed files
with
80 additions
and
54 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// @flow | ||
import {UIManager} from 'playkit-js-ui' | ||
import {getPreviewThumbnailConfig} from 'poster-and-thumbs' | ||
|
||
class UIWrapper { | ||
_uiManager: UIManager; | ||
_disabled: boolean = false; | ||
|
||
constructor(player: Player, config: UIOptionsObject) { | ||
if (config.disable) { | ||
this._disabled = true; | ||
appendPlayerViewToTargetContainer(config.targetId, player.getView()); | ||
} else { | ||
this._uiManager = new UIManager(player, config); | ||
if (config.customPreset) { | ||
this._uiManager.buildCustomUI(config.customPreset) | ||
} else { | ||
this._uiManager.buildDefaultUI(); | ||
} | ||
} | ||
} | ||
|
||
setConfig(config: Object, componentAlias?: string): void { | ||
if (this._disabled) return; | ||
this._uiManager.setConfig(config, componentAlias); | ||
} | ||
|
||
setErrorPresetConfig(mediaInfo: ProviderMediaInfoObject): void { | ||
if (this._disabled) return; | ||
this._uiManager.setConfig({mediaInfo: mediaInfo}, 'error'); | ||
} | ||
|
||
setSeekbarConfig(mediaConfig: Object): void { | ||
if (this._disabled) return; | ||
const seekbarConfig = getPreviewThumbnailConfig(this._uiManager, mediaConfig); | ||
if (seekbarConfig) { | ||
this._uiManager.setConfig(seekbarConfig, 'seekbar'); | ||
} | ||
} | ||
|
||
setLoadingSpinnerState(show: boolean): void { | ||
if (this._disabled) return; | ||
this._uiManager.setConfig({show: show}, 'loading'); | ||
} | ||
} | ||
|
||
/** | ||
* Appends the player view to the target element in the dom. | ||
* @param {string} targetId - The target id. | ||
* @param {HTMLDivElement} view - The player div element. | ||
* @returns {void} | ||
*/ | ||
function appendPlayerViewToTargetContainer(targetId: string, view: HTMLDivElement): void { | ||
const targetContainer = document.getElementById(targetId); | ||
if (targetContainer) { | ||
targetContainer.appendChild(view); | ||
} | ||
} | ||
|
||
export {UIWrapper}; |
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