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-14289): Player v7 | Player doesn't recover well after network disconnection #914

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions src/common/utils/setup-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ function validateProviderConfig(options: KalturaPlayerConfig): void {
/**
* Creates the player container dom element.
* @private
* @param {string} targetId - The div id which the player will append to.
* @returns {string} - The player container id.
* @param options
*/
function createKalturaPlayerContainer(targetId: string): string {
function createKalturaPlayerContainer(options: PartialKPOptionsObject): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you explain why this was needed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

before destroying the old player we save his config.
when we are doing player.setup again after destroying the old player, we need access to the "options.ui.targetId" from the config.
we are creating a new player with the same config as the old one, so we need is element id to be the same.
if we won't use the old element id "options.ui.targetId", it will create the new player with unmatched element id which will cause errors later in the process of the player.setup.

const el = document.createElement('div');
el.id = Utils.Generator.uniqueId(5);
el.id = options?.ui?.targetId || Utils.Generator.uniqueId(5);
el.className = CONTAINER_CLASS_NAME;
el.setAttribute('tabindex', '-1');
const parentNode = document.getElementById(targetId);
const parentNode = document.getElementById(options.targetId);
if (parentNode && el) {
parentNode.appendChild(el);
}
Expand Down Expand Up @@ -337,7 +337,7 @@ function getServerUIConf(): any {
* @returns {KalturaPlayerConfig} - default kaltura player options.
*/
function getDefaultOptions(options: PartialKPOptionsObject): KalturaPlayerConfig {
const targetId = createKalturaPlayerContainer(options.targetId);
const targetId = createKalturaPlayerContainer(options);
// TODO - fix all KalturaPlayerConfig and Partial relationships
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down
10 changes: 6 additions & 4 deletions tests/e2e/common/utils/setup-helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import * as SetupHelpers from '../../../../src/common/utils/setup-helpers';
import { Env } from '@playkit-js/playkit-js';
import { Images } from '../../mock-data/images';

const targetId = 'player-placeholder_setup-helpers.spec';
const options = {
targetId: 'player-placeholder_setup-helpers.spec'
};

describe('error handling', () => {
it('should throw error because no config provided', (done) => {
Expand Down Expand Up @@ -100,15 +102,15 @@ describe('error handling', () => {

describe('createKalturaPlayerContainer', () => {
beforeEach(() => {
TestUtils.createElement('DIV', targetId);
TestUtils.createElement('DIV', options.targetId);
});

afterEach(() => {
TestUtils.removeElement(targetId);
TestUtils.removeElement(options.targetId);
});

it('should create kaltura player container', () => {
const containerId = SetupHelpers.createKalturaPlayerContainer(targetId);
const containerId = SetupHelpers.createKalturaPlayerContainer(options);
const el = document.getElementById(containerId);
el.should.exist;
el.className.should.equal('kaltura-player-container');
Expand Down