Skip to content

Commit

Permalink
fix(FEC-8984): add preset event (#439)
Browse files Browse the repository at this point in the history
dispatch preset changed on player Gui
  • Loading branch information
Yuvalke committed Oct 24, 2019
1 parent b00e35e commit 6de3b54
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
| --------------------------------------------------------------- |
| [`UI_CLICKED`](#UI_CLICKED) |
| [`UI_VISIBILITY_CHANGED`](#UI_VISIBILITY_CHANGED) |
| [`UI_PRESET_CHANGE`](#UI_PRESET_CHANGE) |
| [`USER_CLICKED_PLAY`](#USER_CLICKED_PLAY) |
| [`USER_CLICKED_PAUSE`](#USER_CLICKED_PAUSE) |
| [`USER_CLICKED_REWIND`](#USER_CLICKED_REWIND) |
Expand Down Expand Up @@ -39,6 +40,20 @@
#

#

> ### <a name="UI_PRESET_CHANGE"></a>UI_PRESET_CHANGE
>
> Fires when preset change.
> <br><br>_payload parameters:_
>
> | Name | Type | Description |
> | ------ | -------- | ---------------------------------- |
> | `from` | `string` | Preset name before change |
> | `to` | `string` | Preset name after change |
#

> ### <a name="USER_CLICKED_PLAY"></a>USER_CLICKED_PLAY
>
> Fires when the user initiated play by the UI.<br>
Expand Down
4 changes: 4 additions & 0 deletions src/components/event-dispatcher/event-dispatcher-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ function onChangeableComponentsHandler(store: any, action: Object, player: Objec
player.dispatchEvent(new SeekedEvent(action.payload.from, action.payload.to));
break;

case 'PlayerGui':
player.dispatchEvent(new FakeEvent(FakeEvent.Type.UI_PRESET_CHANGE, action.payload));
break;

default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/event/event-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const namespace = 'playkit-ui';
const EventType: {[event: string]: string} = {
UI_CLICKED: `${namespace}-uiclicked`,
UI_VISIBILITY_CHANGED: `${namespace}-uivisibilitychanged`,
UI_PRESET_CHANGE: `${namespace}-uipresetchange`,
USER_CLICKED_PLAY: `${namespace}-userclickedplay`,
USER_CLICKED_PAUSE: `${namespace}-userclickedpause`,
USER_CLICKED_REWIND: `${namespace}-userclickedrewind`,
Expand Down
3 changes: 3 additions & 0 deletions src/middlewares/event-dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ function onChangeableComponentsHandler(store: any, action: Object, player: Objec
player.dispatchEvent(new SeekedEvent(action.payload.from, action.payload.to));
break;

case 'PlayerGui':
player.dispatchEvent(new FakeEvent(FakeEvent.Type.UI_PRESET_CHANGE, action.payload));
break;
default:
break;
}
Expand Down
5 changes: 5 additions & 0 deletions src/player-gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {connect} from 'preact-redux';
import {bindActions} from './utils';
import {actions} from './reducers/shell';
import getLogger from './utils/logger';
import {withEventDispatcher} from 'components/event-dispatcher';

/**
* mapping state to props
Expand All @@ -26,11 +27,14 @@ const mapStateToProps = state => ({
});

const logger = getLogger('PlayerGUI');
const COMPONENT_NAME = 'PlayerGui';

@connect(
mapStateToProps,
bindActions(actions)
)
@withEventDispatcher(COMPONENT_NAME)

/**
* Player GUI component
*
Expand Down Expand Up @@ -74,6 +78,7 @@ class PlayerGUI extends Component {
const presetName = uiComponent ? uiComponent.nodeName.displayName || '' : '';

if (activePresetName !== presetName) {
props.notifyChange({from: activePresetName, to: presetName});
props.updateActivePresetName(presetName);
logger.debug(`set active preset '${presetName}'`);
}
Expand Down

0 comments on commit 6de3b54

Please sign in to comment.