Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FEC-10760): Youbora - bufferUnderrun event fired when buffering started and no bufferDuration in Ping events #516

Merged
merged 2 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 21 additions & 57 deletions src/state/state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {StateType} from './state-type';
import {CustomEventType, Html5EventType} from '../event/event-type';
import FakeEvent from '../event/fake-event';
import getLogger from '../utils/logger';
import Env from '../utils/env';

/**
* This class responsible to manage all the state machine of the player.
Expand Down Expand Up @@ -68,87 +69,49 @@ export default class StateManager {
*/
_transitions: Transition = {
[StateType.IDLE]: {
[Html5EventType.LOAD_START]: () => {
this._updateState(StateType.LOADING);
this._dispatchEvent();
},
[Html5EventType.PLAY]: () => {
this._updateState(StateType.BUFFERING);
this._dispatchEvent();
},
[Html5EventType.SEEKED]: () => {
this._updateState(StateType.PAUSED);
this._dispatchEvent();
}
[Html5EventType.LOAD_START]: () => this._updateState(StateType.LOADING),
[Html5EventType.PLAY]: () => this._updateState(StateType.BUFFERING),
[Html5EventType.SEEKED]: () => this._updateState(StateType.PAUSED)
},
[StateType.LOADING]: {
[Html5EventType.LOADED_METADATA]: () => {
this._updateState(StateType.PAUSED);
this._dispatchEvent();
},
[Html5EventType.ERROR]: () => {
this._updateState(StateType.IDLE);
this._dispatchEvent();
},
[Html5EventType.LOADED_METADATA]: () => this._updateState(StateType.PAUSED),
[Html5EventType.ERROR]: () => this._updateState(StateType.IDLE),
[Html5EventType.SEEKED]: () => {
if (this._prevState && this._prevState.type === StateType.PLAYING) {
this._updateState(StateType.PLAYING);
this._dispatchEvent();
}
}
},
[StateType.PAUSED]: {
[Html5EventType.PLAY]: () => {
this._updateState(StateType.PLAYING);
this._dispatchEvent();
},
[Html5EventType.PLAYING]: () => {
this._updateState(StateType.PLAYING);
this._dispatchEvent();
},
[Html5EventType.ENDED]: () => {
this._updateState(StateType.IDLE);
this._dispatchEvent();
}
[Html5EventType.PLAY]: () => this._updateState(StateType.PLAYING),
[Html5EventType.PLAYING]: () => this._updateState(StateType.PLAYING),
[Html5EventType.ENDED]: () => this._updateState(StateType.IDLE)
},
[StateType.PLAYING]: {
[Html5EventType.PAUSE]: () => {
this._updateState(StateType.PAUSED);
this._dispatchEvent();
},
[Html5EventType.PAUSE]: () => this._updateState(StateType.PAUSED),
[Html5EventType.WAITING]: () => {
if (this._player.seeking) {
this._updateState(StateType.LOADING);
this._dispatchEvent();
} else {
this._updateState(StateType.BUFFERING);
this._lastWaitingTime = this._player.currentTime;
this._dispatchEvent();
}
},
[Html5EventType.ENDED]: () => {
this._updateState(StateType.IDLE);
this._dispatchEvent();
},
[Html5EventType.ERROR]: () => {
this._updateState(StateType.IDLE);
this._dispatchEvent();
}
[Html5EventType.ENDED]: () => this._updateState(StateType.IDLE),
[Html5EventType.ERROR]: () => this._updateState(StateType.IDLE)
},
[StateType.BUFFERING]: {
[Html5EventType.PLAYING]: () => {
this._updateState(StateType.PLAYING);
this._dispatchEvent();
},
[Html5EventType.PAUSE]: () => {
this._updateState(StateType.PAUSED);
this._dispatchEvent();
},
[Html5EventType.PLAYING]: () => this._updateState(StateType.PLAYING),
[Html5EventType.PAUSE]: () => this._updateState(StateType.PAUSED),
[Html5EventType.TIME_UPDATE]: () => {
if (this._player.currentTime !== this._lastWaitingTime && this._prevState && this._prevState.type === StateType.PLAYING) {
if (
Env.browser.name === 'IE' &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So actually this is the only change in logic, right? the rest seems to be refactoring

Copy link
Contributor Author

@dan-ziv dan-ziv Dec 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes...
Just changing the event dispatching to be from updateState because you always want to do it and there's no need to split it outside in so many places.

this._player.currentTime !== this._lastWaitingTime &&
this._prevState &&
this._prevState.type === StateType.PLAYING
) {
this._lastWaitingTime = null;
this._updateState(StateType.PLAYING);
this._dispatchEvent();
}
}
}
Expand Down Expand Up @@ -215,6 +178,7 @@ export default class StateManager {
this._prevState = this._curState;
this._curState = new State(type);
this._logger.debug(`Switch player state: from ${this._prevState.type} to ${this._curState.type}`);
this._dispatchEvent();
}
}

Expand Down
20 changes: 10 additions & 10 deletions test/src/configs/external-captions.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"He": {
"url": "http://externaltests.dev.kaltura.com/player/library_Player_V3/Captions/Caption_files_VTT/hebrew.vtt",
"label": "Heb",
"language": "he",
"type": "vtt",
"default": false
"url": "http://externaltests.dev.kaltura.com/player/library_Player_V3/Captions/Caption_files_VTT/hebrew.vtt",
"label": "Heb",
"language": "he",
"type": "vtt",
"default": false
},
"Ru": {
"url": "http://externaltests.dev.kaltura.com/player/library_Player_V3/Captions/Caption_files_VTT/hebrew.vtt",
"label": "Rus",
"language": "ru",
"type": "vtt",
"default": false
"url": "http://externaltests.dev.kaltura.com/player/library_Player_V3/Captions/Caption_files_VTT/hebrew.vtt",
"label": "Rus",
"language": "ru",
"type": "vtt",
"default": false
}
}