From c1d033bab786e3ac31990540b93e979e4f77ba26 Mon Sep 17 00:00:00 2001 From: JonathanTGold Date: Sun, 3 Mar 2024 13:56:02 +0100 Subject: [PATCH 1/4] [DualScreen Plugin]: Add Events (used by kava analytics) --- src/dualscreen.tsx | 15 +++++++++++++-- src/events/events.ts | 11 +++++++++++ src/events/index.ts | 2 ++ src/index.ts | 2 ++ 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/events/events.ts create mode 100644 src/events/index.ts diff --git a/src/dualscreen.tsx b/src/dualscreen.tsx index 5e84aa4..518c8b9 100755 --- a/src/dualscreen.tsx +++ b/src/dualscreen.tsx @@ -27,11 +27,12 @@ import {ImagePlayer, SlideItem, SlideThumbnail} from './image-player'; import {core, ui, BasePlugin, IEngineDecoratorProvider, KalturaPlayer} from '@playkit-js/kaltura-player-js'; import {OnClickEvent} from '@playkit-js/common/dist/hoc/a11y-wrapper'; import './styles/global.scss'; +import { DualscreenEvents } from "./events"; const { reducers: {shell} } = ui; -const {EventType} = core; +const {EventType, FakeEvent} = core; const HAS_DUAL_SCREEN_PLUGIN_OVERLAY = 'has-dual-screen-plugin-overlay'; const PRESETS = ['Playback', 'Live', 'Ads']; @@ -39,7 +40,7 @@ const IMAGE_PLAYER_ID = 'imagePlayer'; const MAIN_PLAYER_ID = 'mainPlayer'; export class DualScreen extends BasePlugin implements IEngineDecoratorProvider { - private _layout: Layout; + private layout!: Layout; private _externalLayout: ExternalLayout | null = null; private _pipPosition: Position = Position.BottomRight; private _removeActivesArr: Function[] = []; @@ -85,6 +86,16 @@ export class DualScreen extends BasePlugin implements IEngineD return new DualScreenEngineDecorator(engine, this, dispatcher); } + set _layout(layout: Layout) { + this.layout = layout; + // @ts-expect-error - TS2339: Property 'dispatchEvent' does not exist on type 'KalturaPlayer' + this.player.dispatchEvent(new FakeEvent(DualscreenEvents.CHANGE_LAYOUT, {layout: this._layout})); + } + + get _layout(): Layout { + return this.layout; + } + get ready() { return this._readyPromise; } diff --git a/src/events/events.ts b/src/events/events.ts new file mode 100644 index 0000000..afc0eff --- /dev/null +++ b/src/events/events.ts @@ -0,0 +1,11 @@ +const namespace = 'dualscreen'; + +/** + * dualscreen plugin event types. + */ +export const DualscreenEvents = { + /** + * Fired when dual-screen mode chances. + */ + CHANGE_LAYOUT: `${namespace}-change_layout`, +}; diff --git a/src/events/index.ts b/src/events/index.ts new file mode 100644 index 0000000..542b7a8 --- /dev/null +++ b/src/events/index.ts @@ -0,0 +1,2 @@ +import {DualscreenEvents} from './events'; +export {DualscreenEvents}; diff --git a/src/index.ts b/src/index.ts index 51b23d9..a285cae 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ /// import {DualScreen} from './dualscreen'; +import {DualscreenEvents} from './events'; declare var __VERSION__: string; declare var __NAME__: string; @@ -10,6 +11,7 @@ const NAME = __NAME__; export {DualScreen as Plugin}; export {VERSION, NAME}; +export {DualscreenEvents}; const pluginName: string = 'dualscreen'; KalturaPlayer.core.registerPlugin(pluginName, DualScreen); From bc0eaacd4f73de797d320bc906f7effcea1a5139 Mon Sep 17 00:00:00 2001 From: JonathanTGold Date: Sun, 3 Mar 2024 14:17:52 +0100 Subject: [PATCH 2/4] fix --- src/events/events.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/events/events.ts b/src/events/events.ts index afc0eff..c836a21 100644 --- a/src/events/events.ts +++ b/src/events/events.ts @@ -1,4 +1,4 @@ -const namespace = 'dualscreen'; +const namespace = 'Dual__screen'; /** * dualscreen plugin event types. @@ -7,5 +7,5 @@ export const DualscreenEvents = { /** * Fired when dual-screen mode chances. */ - CHANGE_LAYOUT: `${namespace}-change_layout`, + CHANGE_LAYOUT: `${namespace}_change_layout`, }; From 1203422272628f916749fdaf4a44b4e23880c122 Mon Sep 17 00:00:00 2001 From: JonathanTGold Date: Mon, 4 Mar 2024 13:37:47 +0100 Subject: [PATCH 3/4] preventing the change layout event from be fired when layout was not changed --- src/dualscreen.tsx | 8 +++++--- src/events/events.ts | 4 +--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dualscreen.tsx b/src/dualscreen.tsx index 518c8b9..24f0c26 100755 --- a/src/dualscreen.tsx +++ b/src/dualscreen.tsx @@ -87,9 +87,11 @@ export class DualScreen extends BasePlugin implements IEngineD } set _layout(layout: Layout) { - this.layout = layout; - // @ts-expect-error - TS2339: Property 'dispatchEvent' does not exist on type 'KalturaPlayer' - this.player.dispatchEvent(new FakeEvent(DualscreenEvents.CHANGE_LAYOUT, {layout: this._layout})); + if(layout !== this.layout) { + this.layout = layout; + // @ts-expect-error - TS2339: Property 'dispatchEvent' does not exist on type 'KalturaPlayer' + this.player.dispatchEvent(new FakeEvent(DualscreenEvents.CHANGE_LAYOUT, {layout: this._layout})); + } } get _layout(): Layout { diff --git a/src/events/events.ts b/src/events/events.ts index c836a21..0cf760e 100644 --- a/src/events/events.ts +++ b/src/events/events.ts @@ -1,5 +1,3 @@ -const namespace = 'Dual__screen'; - /** * dualscreen plugin event types. */ @@ -7,5 +5,5 @@ export const DualscreenEvents = { /** * Fired when dual-screen mode chances. */ - CHANGE_LAYOUT: `${namespace}_change_layout`, + CHANGE_LAYOUT: 'dualscreen_change_layout', }; From 948b88a70a0258dc709e93609c8a60b3e177b305 Mon Sep 17 00:00:00 2001 From: JonathanTGold Date: Mon, 11 Mar 2024 16:22:26 +0100 Subject: [PATCH 4/4] fix --- src/dualscreen.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dualscreen.tsx b/src/dualscreen.tsx index 24f0c26..5f937e3 100755 --- a/src/dualscreen.tsx +++ b/src/dualscreen.tsx @@ -27,7 +27,7 @@ import {ImagePlayer, SlideItem, SlideThumbnail} from './image-player'; import {core, ui, BasePlugin, IEngineDecoratorProvider, KalturaPlayer} from '@playkit-js/kaltura-player-js'; import {OnClickEvent} from '@playkit-js/common/dist/hoc/a11y-wrapper'; import './styles/global.scss'; -import { DualscreenEvents } from "./events"; +import {DualscreenEvents} from './events'; const { reducers: {shell} @@ -87,10 +87,10 @@ export class DualScreen extends BasePlugin implements IEngineD } set _layout(layout: Layout) { - if(layout !== this.layout) { + if (layout !== this.layout) { this.layout = layout; // @ts-expect-error - TS2339: Property 'dispatchEvent' does not exist on type 'KalturaPlayer' - this.player.dispatchEvent(new FakeEvent(DualscreenEvents.CHANGE_LAYOUT, {layout: this._layout})); + this.player.dispatchEvent(new FakeEvent(DualscreenEvents.CHANGE_LAYOUT, {layout})); } }