@playkit-js/unisphere 0.0.2-canary.0-0e931f0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +135 -0
- package/dist/index.d.ts +1 -0
- package/dist/playkit-unisphere.js +3 -0
- package/dist/playkit-unisphere.js.LICENSE.txt +1 -0
- package/dist/playkit-unisphere.js.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +96 -0
- package/src/components/container-element/container-element.tsx +13 -0
- package/src/components/container-element/index.ts +1 -0
- package/src/components/index.ts +2 -0
- package/src/components/upper-bar-icon/index.ts +1 -0
- package/src/components/upper-bar-icon/upper-bar-icon.tsx +23 -0
- package/src/index.ts +4 -0
- package/src/services/container/container-manager.ts +25 -0
- package/src/services/container/index.ts +1 -0
- package/src/services/container/producers/base-container-producer.ts +42 -0
- package/src/services/container/producers/container-producer.ts +8 -0
- package/src/services/container/producers/index.ts +3 -0
- package/src/services/container/producers/sidepanel-container-producer.tsx +37 -0
- package/src/services/container/producers/simple-container-producer.tsx +27 -0
- package/src/services/index.ts +1 -0
- package/src/services/unisphere/index.ts +3 -0
- package/src/services/unisphere/unisphere-base-service.ts +46 -0
- package/src/services/unisphere/unisphere-element-service.ts +11 -0
- package/src/services/unisphere/unisphere-event-service.ts +30 -0
- package/src/services/unisphere/unisphere-storage-service.ts +37 -0
- package/src/types/global.d.ts +1 -0
- package/src/types/index.ts +3 -0
- package/src/types/unisphere-event.ts +8 -0
- package/src/types/unisphere-plugin-config.ts +25 -0
- package/src/types/unisphere-storage-keys.ts +8 -0
- package/src/unisphere-plugin-manager.tsx +176 -0
- package/src/unisphere-plugin.tsx +41 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { KalturaPlayer } from '@playkit-js/kaltura-player-js';
|
|
2
|
+
import { Utils } from '@playkit-js/playkit-js';
|
|
3
|
+
import { SidePanelsManager } from '@playkit-js/ui-managers';
|
|
4
|
+
|
|
5
|
+
import { ContainerConfig } from '../../../types';
|
|
6
|
+
|
|
7
|
+
abstract class BaseContainerProducer {
|
|
8
|
+
protected _disposers: Map<string, () => void> = new Map<string, () => void>();
|
|
9
|
+
|
|
10
|
+
protected generateId(containerConfig: ContainerConfig): string {
|
|
11
|
+
const iterations = 4;
|
|
12
|
+
let result = `${containerConfig.containerType}_container_`;
|
|
13
|
+
for (let i = 0; i < iterations; ++i) {
|
|
14
|
+
result += Utils.Generator.uniqueId();
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
protected getSidePanelsManager(player: KalturaPlayer): SidePanelsManager | undefined {
|
|
20
|
+
return player.getService('sidePanelsManager') as SidePanelsManager;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
protected addDisposer(containerId: string, disposer: () => void): void {
|
|
24
|
+
this._disposers.set(containerId, disposer);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public dispose(containerId: string): void {
|
|
28
|
+
const disposer = this._disposers.get(containerId);
|
|
29
|
+
if (disposer) {
|
|
30
|
+
disposer();
|
|
31
|
+
this._disposers.delete(containerId);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public destroy(): void {
|
|
36
|
+
for (const [containerId] of this._disposers) {
|
|
37
|
+
this.dispose(containerId);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { BaseContainerProducer };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { KalturaPlayer } from '@playkit-js/kaltura-player-js';
|
|
2
|
+
import { ContainerConfig } from '../../../types';
|
|
3
|
+
|
|
4
|
+
export interface ContainerProducer<T extends ContainerConfig> {
|
|
5
|
+
createContainer(player: KalturaPlayer, containerConfig: T): string | null;
|
|
6
|
+
dispose(containerId: string): void;
|
|
7
|
+
destroy(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
+
import { h } from 'preact';
|
|
3
|
+
|
|
4
|
+
import { KalturaPlayer } from '@playkit-js/kaltura-player-js';
|
|
5
|
+
import { ContainerElement } from '../../../components';
|
|
6
|
+
import { SidePanelContainerConfig } from '../../../types';
|
|
7
|
+
import { UnisphereStorageService } from '../../unisphere';
|
|
8
|
+
|
|
9
|
+
import { ContainerProducer } from './container-producer';
|
|
10
|
+
import { BaseContainerProducer } from './base-container-producer';
|
|
11
|
+
|
|
12
|
+
class SidePanelContainerProducer extends BaseContainerProducer implements ContainerProducer<SidePanelContainerConfig> {
|
|
13
|
+
public createContainer(player: KalturaPlayer, containerConfig: SidePanelContainerConfig): string | null {
|
|
14
|
+
const containerId = this.generateId(containerConfig);
|
|
15
|
+
const { unisphereArea, position, expandMode, presets } = containerConfig;
|
|
16
|
+
|
|
17
|
+
const panelId = this.getSidePanelsManager(player)?.add({
|
|
18
|
+
label: containerId,
|
|
19
|
+
panelComponent: () => (<ContainerElement style={{ height: '100%' }} id={containerId} />) as preact.JSX.Element,
|
|
20
|
+
presets,
|
|
21
|
+
position,
|
|
22
|
+
expandMode
|
|
23
|
+
}) as number;
|
|
24
|
+
|
|
25
|
+
if (typeof panelId === 'number') {
|
|
26
|
+
this.addDisposer(containerId, () => {
|
|
27
|
+
this.getSidePanelsManager(player)?.remove(panelId);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
UnisphereStorageService.update(unisphereArea, { upperBarIcon: { panelId } });
|
|
31
|
+
return containerId;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { SidePanelContainerProducer };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
+
import { h } from 'preact';
|
|
3
|
+
|
|
4
|
+
import { KalturaPlayer } from '@playkit-js/kaltura-player-js';
|
|
5
|
+
|
|
6
|
+
import { SimpleContainerConfig } from '../../../types';
|
|
7
|
+
import { ContainerElement } from '../../../components';
|
|
8
|
+
import { BaseContainerProducer } from './base-container-producer';
|
|
9
|
+
import { ContainerProducer } from './container-producer';
|
|
10
|
+
|
|
11
|
+
class SimpleContainerProducer extends BaseContainerProducer implements ContainerProducer<SimpleContainerConfig> {
|
|
12
|
+
public createContainer(player: KalturaPlayer, containerConfig: SimpleContainerConfig): string | null {
|
|
13
|
+
const containerId = this.generateId(containerConfig);
|
|
14
|
+
const { playerArea, presets } = containerConfig;
|
|
15
|
+
|
|
16
|
+
const disposer = player.ui.addComponent({
|
|
17
|
+
label: containerId,
|
|
18
|
+
presets,
|
|
19
|
+
area: playerArea,
|
|
20
|
+
get: () => <ContainerElement id={containerId} />
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
this.addDisposer(containerId, disposer);
|
|
24
|
+
return containerId;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export { SimpleContainerProducer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './unisphere';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { UnisphereWorkspaceType } from '@unisphere/core-js';
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
unisphereWorkspace: UnisphereWorkspaceType;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
abstract class UnisphereBaseService {
|
|
10
|
+
private static unsubscribeMap: Map<number, () => void> = new Map();
|
|
11
|
+
private static sequence = -1;
|
|
12
|
+
|
|
13
|
+
protected static getWorkspace = (): Promise<UnisphereWorkspaceType> => {
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
const interval = setInterval(() => {
|
|
16
|
+
if (window.unisphereWorkspace) {
|
|
17
|
+
resolve(window.unisphereWorkspace);
|
|
18
|
+
clearTimeout(interval);
|
|
19
|
+
}
|
|
20
|
+
}, 1000);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
protected static addToUnsubscribeMap(unsubscribe: () => void): number {
|
|
25
|
+
UnisphereBaseService.unsubscribeMap.set(UnisphereBaseService.sequence, unsubscribe);
|
|
26
|
+
++UnisphereBaseService.sequence;
|
|
27
|
+
return UnisphereBaseService.sequence;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected static unsubscribeAll(): void {
|
|
31
|
+
for (const [key, disposer] of UnisphereBaseService.unsubscribeMap) {
|
|
32
|
+
disposer();
|
|
33
|
+
UnisphereBaseService.unsubscribeMap.delete(key);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public static unsubscribe(id: number): void {
|
|
38
|
+
const unsubscribe = UnisphereBaseService.unsubscribeMap.get(id);
|
|
39
|
+
if (!unsubscribe) return;
|
|
40
|
+
|
|
41
|
+
unsubscribe();
|
|
42
|
+
UnisphereBaseService.unsubscribeMap.delete(id);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { UnisphereBaseService };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UnisphereElementBase } from '@unisphere/core-js';
|
|
2
|
+
import { UnisphereBaseService } from './unisphere-base-service';
|
|
3
|
+
|
|
4
|
+
class UnisphereElementService extends UnisphereBaseService {
|
|
5
|
+
public static get = async ({ widgetId, context }: { widgetId: string; context: string }): Promise<UnisphereElementBase<HTMLDivElement> | null> => {
|
|
6
|
+
const workspace = await UnisphereElementService.getWorkspace();
|
|
7
|
+
return Promise.resolve(workspace.getElement(widgetId, context));
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { UnisphereElementService };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PubSubServiceType } from '@unisphere/core-js';
|
|
2
|
+
import { UnisphereBaseService } from './unisphere-base-service';
|
|
3
|
+
|
|
4
|
+
const PUB_SUB_SERVICE_KEY = 'unisphere.service.pub-sub';
|
|
5
|
+
|
|
6
|
+
class UnisphereEventService extends UnisphereBaseService {
|
|
7
|
+
public static subscribe = async (event: string, callback: (data: { payload: { [key: string]: unknown } }) => void): Promise<unknown> => {
|
|
8
|
+
const workspace = await UnisphereEventService.getWorkspace();
|
|
9
|
+
const pubSubService = workspace.getService<PubSubServiceType>(PUB_SUB_SERVICE_KEY);
|
|
10
|
+
const unsubscribe = pubSubService!.subscribe(event, callback);
|
|
11
|
+
return Promise.resolve(UnisphereEventService.addToUnsubscribeMap(unsubscribe));
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
public static emit = (event: string, payload: Record<string, unknown>): void => {
|
|
15
|
+
UnisphereEventService.getWorkspace().then((workspace) => {
|
|
16
|
+
const pubSubService = workspace.getService<PubSubServiceType>(PUB_SUB_SERVICE_KEY);
|
|
17
|
+
pubSubService?.emit({
|
|
18
|
+
id: event,
|
|
19
|
+
version: '1.0.0',
|
|
20
|
+
payload
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
public reset(): void {
|
|
26
|
+
UnisphereEventService.unsubscribeAll();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { UnisphereEventService };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { StorageServiceListener, StorageServiceType } from '@unisphere/core-js';
|
|
2
|
+
import { UnisphereBaseService } from './unisphere-base-service';
|
|
3
|
+
|
|
4
|
+
const STORAGE_NAMESPACE = 'player';
|
|
5
|
+
const STORAGE_SERVICE_KEY = 'unisphere.service.storage';
|
|
6
|
+
|
|
7
|
+
class UnisphereStorageService extends UnisphereBaseService {
|
|
8
|
+
public static update = (key: string, value: unknown): void => {
|
|
9
|
+
UnisphereStorageService.getWorkspace().then((workspace) => {
|
|
10
|
+
const storageService = <StorageServiceType>workspace.getService(STORAGE_SERVICE_KEY);
|
|
11
|
+
storageService.update(STORAGE_NAMESPACE, key, value);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
public static get = async (key: string): Promise<unknown> => {
|
|
16
|
+
const workspace = await UnisphereStorageService.getWorkspace();
|
|
17
|
+
const storageService = <StorageServiceType>workspace.getService(STORAGE_SERVICE_KEY);
|
|
18
|
+
return Promise.resolve(storageService.get(STORAGE_NAMESPACE, key));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
public static subscribe = async (key: string, callback: StorageServiceListener): Promise<number> => {
|
|
22
|
+
const workspace = await UnisphereStorageService.getWorkspace();
|
|
23
|
+
const storageService = <StorageServiceType>workspace.getService(STORAGE_SERVICE_KEY);
|
|
24
|
+
const unsubscribe = storageService.subscribe(callback, {
|
|
25
|
+
namespace: STORAGE_NAMESPACE,
|
|
26
|
+
property: key,
|
|
27
|
+
emitLastValue: true
|
|
28
|
+
});
|
|
29
|
+
return Promise.resolve(UnisphereStorageService.addToUnsubscribeMap(unsubscribe));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
public reset(): void {
|
|
33
|
+
UnisphereStorageService.unsubscribeAll();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { UnisphereStorageService };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '*.scss';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export enum UnisphereEvent {
|
|
2
|
+
UPPER_BAR_ICON_SHOW = 'unisphere.event.player.upper-bar-icon.show',
|
|
3
|
+
SIDE_PANEL_OPEN = 'unisphere.event.player.side-panel.open',
|
|
4
|
+
SIDE_PANEL_CLOSE = 'unisphere.event.player.side-panel.close',
|
|
5
|
+
SET_VALUE_CURRENT_TIME = 'unisphere.event.player.set-value.current-time',
|
|
6
|
+
CHAPTERS_ADD = 'unisphere.event.player.chapters.add',
|
|
7
|
+
PLAYER_RESIZE = 'unisphere.event.player.resize'
|
|
8
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ReservedPresetAreas, ReservedPresetNames } from 'services/preset-manager/models/preset-item-data';
|
|
2
|
+
|
|
3
|
+
export interface ContainerConfig {
|
|
4
|
+
containerType: string;
|
|
5
|
+
presets: ReservedPresetNames[];
|
|
6
|
+
unisphereArea: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SidePanelContainerConfig extends ContainerConfig {
|
|
10
|
+
position?: string;
|
|
11
|
+
expandMode?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SimpleContainerConfig extends ContainerConfig {
|
|
15
|
+
playerArea: ReservedPresetAreas;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface WidgetConfig {
|
|
19
|
+
widgetId: string;
|
|
20
|
+
context: string;
|
|
21
|
+
containers: ContainerConfig[];
|
|
22
|
+
}
|
|
23
|
+
export interface UnispherePluginConfig {
|
|
24
|
+
widgets: WidgetConfig[];
|
|
25
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
+
import { h } from 'preact';
|
|
3
|
+
|
|
4
|
+
import { core, ui, KalturaPlayer } from '@playkit-js/kaltura-player-js';
|
|
5
|
+
import { SidePanelsManager, UpperBarManager } from '@playkit-js/ui-managers';
|
|
6
|
+
|
|
7
|
+
import { UnisphereEvent, UnisphereStorageKeys, WidgetConfig } from './types';
|
|
8
|
+
import { UpperBarIcon } from './components';
|
|
9
|
+
import { UnisphereElementService, UnisphereEventService, UnisphereStorageService } from './services';
|
|
10
|
+
import { ContainerManager } from './services/container';
|
|
11
|
+
|
|
12
|
+
class UnispherePluginManager {
|
|
13
|
+
private iconIds = new Map<string, number>();
|
|
14
|
+
private persistentIconIds = new Map<string, number>();
|
|
15
|
+
private panelIds = new Map<string, number>();
|
|
16
|
+
private eventDisposerIds: number[] = [];
|
|
17
|
+
private storageDisposerIds: number[] = [];
|
|
18
|
+
private containerManager: ContainerManager;
|
|
19
|
+
|
|
20
|
+
constructor(private player: KalturaPlayer, private eventManager: core.EventManager) {
|
|
21
|
+
this.addEventHandlers();
|
|
22
|
+
this.containerManager = new ContainerManager(player);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private get upperBarManager(): UpperBarManager | undefined {
|
|
26
|
+
return this.player.getService('upperBarManager') as UpperBarManager;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private get sidePanelsManager(): SidePanelsManager | undefined {
|
|
30
|
+
return this.player.getService('sidePanelsManager') as SidePanelsManager;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private get timelineManager():
|
|
34
|
+
| {
|
|
35
|
+
addKalturaCuePoint: (
|
|
36
|
+
startTime: number,
|
|
37
|
+
type: string,
|
|
38
|
+
index: number,
|
|
39
|
+
title: string,
|
|
40
|
+
options: { onClick: ({ cuePoint }: { cuePoint: { id: string } }) => void }
|
|
41
|
+
) => void;
|
|
42
|
+
}
|
|
43
|
+
| undefined {
|
|
44
|
+
return this.player.getService('timeline');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private async addEventHandlers(): Promise<void> {
|
|
48
|
+
const eventDisposerIds = (await Promise.all([
|
|
49
|
+
UnisphereEventService.subscribe(UnisphereEvent.UPPER_BAR_ICON_SHOW, ({ payload }) => {
|
|
50
|
+
const { id, label, order, iconPath, panelId, isPersistent } = payload;
|
|
51
|
+
this.addUpperBarIcon(id as string, label as string, order as number, iconPath as string, panelId as number, isPersistent as boolean);
|
|
52
|
+
}),
|
|
53
|
+
UnisphereEventService.subscribe(UnisphereEvent.SIDE_PANEL_OPEN, ({ payload }) => {
|
|
54
|
+
const { panelId } = payload;
|
|
55
|
+
this.sidePanelsManager?.activateItem(panelId as number);
|
|
56
|
+
}),
|
|
57
|
+
UnisphereEventService.subscribe(UnisphereEvent.SIDE_PANEL_CLOSE, ({ payload }) => {
|
|
58
|
+
const { panelId } = payload;
|
|
59
|
+
this.sidePanelsManager?.deactivateItem(panelId as number);
|
|
60
|
+
}),
|
|
61
|
+
UnisphereEventService.subscribe(UnisphereEvent.SET_VALUE_CURRENT_TIME, ({ payload }) => {
|
|
62
|
+
const currentTime = payload.currentTime as number;
|
|
63
|
+
if ((currentTime as number) >= 0) {
|
|
64
|
+
this.player.currentTime = currentTime as number;
|
|
65
|
+
}
|
|
66
|
+
}),
|
|
67
|
+
UnisphereEventService.subscribe(UnisphereEvent.CHAPTERS_ADD, ({ payload }) => {
|
|
68
|
+
const chapters = payload.chapters as { title: string; time: string }[];
|
|
69
|
+
if (chapters && chapters.length) {
|
|
70
|
+
for (let i = 0; i < chapters.length; ++i) {
|
|
71
|
+
const { title, time } = chapters[i];
|
|
72
|
+
const startTime = +time;
|
|
73
|
+
this.timelineManager?.addKalturaCuePoint(startTime, 'Chapter', i, title, {
|
|
74
|
+
onClick: ({ cuePoint }: { cuePoint: { id: string } }) => {
|
|
75
|
+
UnisphereStorageService.update(UnisphereStorageKeys.SELECTED_CHAPTER, cuePoint.id);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
])) as number[];
|
|
82
|
+
this.eventDisposerIds.push(...eventDisposerIds);
|
|
83
|
+
|
|
84
|
+
this.eventManager.listen(this.player, core.EventType.TIME_UPDATE, () => {
|
|
85
|
+
UnisphereStorageService.update(UnisphereStorageKeys.CURRENT_TIME, `${this.player.currentTime}`);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
this.eventManager.listen(this.player, ui.EventType.GUI_RESIZE, () => {
|
|
89
|
+
UnisphereEventService.emit(UnisphereEvent.PLAYER_RESIZE, {});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
this.eventManager.listen(this.player, core.EventType.PAUSE, () => {
|
|
93
|
+
UnisphereStorageService.update(UnisphereStorageKeys.IS_PAUSED, true);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
this.eventManager.listen(this.player, core.EventType.PLAY, () => {
|
|
97
|
+
UnisphereStorageService.update(UnisphereStorageKeys.IS_PAUSED, false);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private addUpperBarIcon(id: string, label: string, order: number, iconPath: string, panelId: number, isPersistent: boolean): void {
|
|
102
|
+
if (this.iconIds.has(id) || this.persistentIconIds.has(id)) return;
|
|
103
|
+
|
|
104
|
+
const iconId = this.upperBarManager?.add({
|
|
105
|
+
displayName: label,
|
|
106
|
+
ariaLabel: label,
|
|
107
|
+
order,
|
|
108
|
+
component: () => (<UpperBarIcon id={id} label={label} iconPath={iconPath} />) as preact.JSX.Element,
|
|
109
|
+
svgIcon: { path: iconPath },
|
|
110
|
+
onClick: () => {
|
|
111
|
+
if (this.sidePanelsManager?.isItemActive(panelId)) {
|
|
112
|
+
this.sidePanelsManager?.deactivateItem(panelId);
|
|
113
|
+
} else {
|
|
114
|
+
this.sidePanelsManager?.activateItem(panelId);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}) as number;
|
|
118
|
+
|
|
119
|
+
if (isPersistent) {
|
|
120
|
+
this.iconIds.set(id, iconId);
|
|
121
|
+
} else {
|
|
122
|
+
this.persistentIconIds.set(id, iconId);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public loadWidgets(widgets: WidgetConfig[]): void {
|
|
127
|
+
for (const widget of widgets) {
|
|
128
|
+
const { widgetId, context } = widget;
|
|
129
|
+
if (!widgetId || !context) continue;
|
|
130
|
+
|
|
131
|
+
for (const containerConfig of widget.containers) {
|
|
132
|
+
if (!containerConfig.unisphereArea) continue;
|
|
133
|
+
|
|
134
|
+
const containerId = this.containerManager.createContainer(containerConfig);
|
|
135
|
+
if (containerId) {
|
|
136
|
+
UnisphereElementService.get({ widgetId, context }).then((element) => {
|
|
137
|
+
element?.assignAreaByName(containerConfig.unisphereArea, containerId);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public updateSessionData(): void {
|
|
145
|
+
UnisphereStorageService.update(UnisphereStorageKeys.PLAYER_SESSION, {
|
|
146
|
+
entryId: this.player.sources.id,
|
|
147
|
+
ks: this.player.config.session?.ks
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
public reset(): void {
|
|
152
|
+
for (const v of this.iconIds.values()) {
|
|
153
|
+
this.upperBarManager?.remove(v);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public destroy(): void {
|
|
158
|
+
this.reset();
|
|
159
|
+
|
|
160
|
+
this.containerManager.destroy();
|
|
161
|
+
|
|
162
|
+
for (const v of this.persistentIconIds.values()) {
|
|
163
|
+
this.upperBarManager?.remove(v);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
for (const id of this.eventDisposerIds) {
|
|
167
|
+
UnisphereEventService.unsubscribe(id);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for (const id of this.storageDisposerIds) {
|
|
171
|
+
UnisphereStorageService.unsubscribe(id);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export { UnispherePluginManager };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BasePlugin, KalturaPlayer } from '@playkit-js/kaltura-player-js';
|
|
2
|
+
import { UnispherePluginConfig } from './types';
|
|
3
|
+
import { UnispherePluginManager } from './unisphere-plugin-manager';
|
|
4
|
+
|
|
5
|
+
export const pluginName = 'unisphere';
|
|
6
|
+
|
|
7
|
+
export class UnispherePlugin extends BasePlugin {
|
|
8
|
+
public static defaultConfig: UnispherePluginConfig = {
|
|
9
|
+
widgets: []
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
private isReady = false;
|
|
13
|
+
private unispherePluginManager: UnispherePluginManager;
|
|
14
|
+
|
|
15
|
+
constructor(name: string, player: KalturaPlayer, config: UnispherePluginConfig) {
|
|
16
|
+
super(name, player, config);
|
|
17
|
+
this.unispherePluginManager = new UnispherePluginManager(player, this.eventManager);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public static isValid(): boolean {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public loadMedia(): void {
|
|
25
|
+
this.unispherePluginManager.updateSessionData();
|
|
26
|
+
|
|
27
|
+
if (!this.isReady) {
|
|
28
|
+
this.unispherePluginManager.loadWidgets(this.config.widgets);
|
|
29
|
+
this.isReady = true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public reset(): void {
|
|
34
|
+
this.unispherePluginManager.reset();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public destroy(): void {
|
|
38
|
+
this.eventManager.destroy();
|
|
39
|
+
this.unispherePluginManager.destroy();
|
|
40
|
+
}
|
|
41
|
+
}
|