@playkit-js/unisphere-service 0.0.17-canary.0-e5f111c

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.
Files changed (46) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +99 -0
  3. package/dist/index.d.ts +40 -0
  4. package/dist/playkit-unisphere-service.js +3 -0
  5. package/dist/playkit-unisphere-service.js.LICENSE.txt +1 -0
  6. package/dist/playkit-unisphere-service.js.map +1 -0
  7. package/dist/tsdoc-metadata.json +11 -0
  8. package/package.json +100 -0
  9. package/src/components/close-button/close-button.tsx +25 -0
  10. package/src/components/close-button/index.ts +1 -0
  11. package/src/components/container-element/container-element.tsx +13 -0
  12. package/src/components/container-element/index.ts +1 -0
  13. package/src/components/index.ts +4 -0
  14. package/src/components/sidepanel-buttons-container/index.ts +1 -0
  15. package/src/components/sidepanel-buttons-container/sidepanel-buttons-container.tsx +40 -0
  16. package/src/components/upper-bar-icon/index.ts +1 -0
  17. package/src/components/upper-bar-icon/upper-bar-icon.tsx +23 -0
  18. package/src/index.ts +6 -0
  19. package/src/services/container/container-manager.ts +25 -0
  20. package/src/services/container/index.ts +1 -0
  21. package/src/services/container/producers/base-container-producer.ts +37 -0
  22. package/src/services/container/producers/container-producer.ts +8 -0
  23. package/src/services/container/producers/index.ts +3 -0
  24. package/src/services/container/producers/sidepanel-container-producer.scss +59 -0
  25. package/src/services/container/producers/sidepanel-container-producer.tsx +67 -0
  26. package/src/services/container/producers/simple-container-producer.tsx +27 -0
  27. package/src/services/index.ts +3 -0
  28. package/src/services/unisphere/index.ts +4 -0
  29. package/src/services/unisphere/unisphere-base-service.ts +35 -0
  30. package/src/services/unisphere/unisphere-element-service.ts +25 -0
  31. package/src/services/unisphere/unisphere-event-service.ts +36 -0
  32. package/src/services/unisphere/unisphere-runtime-service.ts +17 -0
  33. package/src/services/unisphere/unisphere-storage-service.ts +42 -0
  34. package/src/services/unisphere/unisphere-workspace-service.ts +25 -0
  35. package/src/services/utils/index.ts +1 -0
  36. package/src/services/utils/utils.ts +9 -0
  37. package/src/types/container-types.ts +6 -0
  38. package/src/types/global.d.ts +1 -0
  39. package/src/types/index.ts +5 -0
  40. package/src/types/integrations.ts +38 -0
  41. package/src/types/service-keys.ts +6 -0
  42. package/src/types/unisphere-event.ts +3 -0
  43. package/src/types/unisphere-plugin-config.ts +38 -0
  44. package/src/types/unisphere-storage-keys.ts +9 -0
  45. package/src/unisphere-plugin-manager.tsx +254 -0
  46. package/src/unisphere-plugin.ts +45 -0
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.54.0"
9
+ }
10
+ ]
11
+ }
package/package.json ADDED
@@ -0,0 +1,100 @@
1
+ {
2
+ "name": "@playkit-js/unisphere-service",
3
+ "version": "0.0.17-canary.0-e5f111c",
4
+ "description": "Playkit JS Unisphere Service plugin",
5
+ "main": "dist/playkit-unisphere-service.js",
6
+ "typings": "dist/index.d.ts",
7
+ "files": [
8
+ "dist/**/*",
9
+ "src/**/*"
10
+ ],
11
+ "license": "AGPL-3.0",
12
+ "homepage": "https://github.com/kaltura/playkit-js-unisphere-service",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/kaltura/playkit-js-unisphere-service"
16
+ },
17
+ "keywords": [
18
+ "@playkit-js/unisphere-service",
19
+ "kaltura",
20
+ "player"
21
+ ],
22
+ "scripts": {
23
+ "dev": "webpack serve --open --mode development",
24
+ "watch": "webpack --mode development --watch",
25
+ "build:prod": "webpack --mode production",
26
+ "build": "yarn run build:prod && yarn run build:types",
27
+ "build:types": "tsc --build tsconfig-lib.json && mkdir -p lib && api-extractor run --local",
28
+ "type-check": "tsc --noEmit",
29
+ "type-check:watch": "yarn run type-check --watch",
30
+ "lint": "eslint src/ --ext .js --ext .ts",
31
+ "lint:fix": "yarn run lint --fix",
32
+ "prettier": "prettier --write .",
33
+ "test": "echo 'TODO'",
34
+ "clean": "rimraf ./dist",
35
+ "prebuild": "npm run clean",
36
+ "precommit": "npm run build:prod && npm run type-check && npm run lint",
37
+ "pushTaggedRelease": "git push --follow-tags --no-verify origin master",
38
+ "release": "standard-version"
39
+ },
40
+ "dependencies": {
41
+ "@unisphere/core": "^1.83.0",
42
+ "@unisphere/genie-core": "1.2.0-entry-level.1",
43
+ "@unisphere/runtime": "^1.83.0",
44
+ "@unisphere/runtime-js": "^1.82.0"
45
+ },
46
+ "devDependencies": {
47
+ "@babel/core": "^7.23.7",
48
+ "@babel/plugin-proposal-decorators": "^7.10.5",
49
+ "@babel/plugin-transform-react-jsx": "^7.23.4",
50
+ "@babel/plugin-transform-runtime": "^7.23.7",
51
+ "@babel/preset-env": "^7.23.8",
52
+ "@babel/preset-typescript": "^7.23.3",
53
+ "@babel/runtime": "^7.23.8",
54
+ "@microsoft/api-extractor": "^7.48.1",
55
+ "@playkit-js/browserslist-config": "1.0.8",
56
+ "@playkit-js/common": "1.5.19",
57
+ "@playkit-js/kaltura-player-js": "3.17.33-canary.0-d4f707b",
58
+ "@playkit-js/ui-managers": "1.6.4",
59
+ "@typescript-eslint/eslint-plugin": "^5.58.0",
60
+ "@typescript-eslint/parser": "^5.58.0",
61
+ "babel-loader": "^9.1.3",
62
+ "conventional-github-releaser": "3.1.3",
63
+ "css-loader": "^6.9.0",
64
+ "cypress": "13.13.1",
65
+ "eslint": "^8.42.0",
66
+ "eslint-config-preact": "^1.3.0",
67
+ "eslint-config-prettier": "^8.8.0",
68
+ "eslint-plugin-cypress": "^2.13.3",
69
+ "eslint-plugin-prettier": "^4.2.1",
70
+ "prettier": "^2.8.4",
71
+ "sass": "^1.69.7",
72
+ "sass-loader": "^13.3.3",
73
+ "standard-version": "^9.5.0",
74
+ "style-loader": "^3.3.4",
75
+ "ts-loader": "^9.4.2",
76
+ "typescript": "^5.3.3",
77
+ "typescript-plugin-css-modules": "^5.0.2",
78
+ "webpack": "^5.89.0",
79
+ "webpack-cli": "^5.1.4",
80
+ "webpack-dev-server": "^4.15.1"
81
+ },
82
+ "peerDependencies": {
83
+ "@playkit-js/kaltura-player-js": "3.17.33-canary.0-d4f707b",
84
+ "preact": "10.4.6",
85
+ "preact-i18n": "2.0.0-preactx.2"
86
+ },
87
+ "publishConfig": {
88
+ "access": "public"
89
+ },
90
+ "browserslist": [
91
+ "extends @playkit-js/browserslist-config"
92
+ ],
93
+ "kaltura": {
94
+ "name": "unisphere",
95
+ "dependencies": {
96
+ "playkit-ui-managers": "1.8.2",
97
+ "playkit-timeline": "3.1.4"
98
+ }
99
+ }
100
+ }
@@ -0,0 +1,25 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ import { h } from 'preact';
3
+ import { ui } from '@playkit-js/kaltura-player-js';
4
+
5
+ const { Tooltip } = ui.components;
6
+
7
+ const CLEAR_ICON =
8
+ 'M15.6592 14.245L10.7048 9.29061C10.317 8.9028 9.68581 8.90476 9.29528 9.29528C8.90204 9.68853 8.90267 10.3169 9.29061 10.7048L14.245 15.6592L9.29061 20.6137C8.9028 21.0015 8.90476 21.6327 9.29528 22.0232C9.68853 22.4165 10.3169 22.4158 10.7048 22.0279L15.6592 17.0735L20.6137 22.0279C21.0015 22.4157 21.6327 22.4137 22.0232 22.0232C22.4165 21.63 22.4158 21.0016 22.0279 20.6137L17.0735 15.6592L22.0279 10.7048C22.4157 10.317 22.4137 9.68581 22.0232 9.29528C21.63 8.90204 21.0016 8.90267 20.6137 9.29061L15.6592 14.245Z';
9
+
10
+ interface CloseButtonProps {
11
+ onClick: () => void;
12
+ className?: string;
13
+ }
14
+
15
+ const CloseButton = ({ onClick, className }: CloseButtonProps): preact.JSX.Element => (
16
+ <button data-testid={'player_unisphere_closeButton'} className={className} onClick={onClick}>
17
+ <Tooltip label="Close" type="bottom">
18
+ <svg width="32px" height="32px" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
19
+ <path d={CLEAR_ICON} fill="white" />
20
+ </svg>
21
+ </Tooltip>
22
+ </button>
23
+ );
24
+
25
+ export { CloseButton };
@@ -0,0 +1 @@
1
+ export { CloseButton } from './close-button';
@@ -0,0 +1,13 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ import { h } from 'preact';
3
+
4
+ interface ContainerProps {
5
+ id: string;
6
+ style?: { [property: string]: string };
7
+ }
8
+
9
+ const ContainerElement = (props: ContainerProps): preact.JSX.Element => {
10
+ return <div data-testid={'player_unisphere_containerElement'} style={props.style ?? {}} id={props.id}></div>;
11
+ };
12
+
13
+ export { ContainerElement };
@@ -0,0 +1 @@
1
+ export { ContainerElement } from './container-element';
@@ -0,0 +1,4 @@
1
+ export * from './close-button';
2
+ export * from './container-element';
3
+ export * from './sidepanel-buttons-container';
4
+ export * from './upper-bar-icon';
@@ -0,0 +1 @@
1
+ export { SidepanelButtonsContainer } from './sidepanel-buttons-container';
@@ -0,0 +1,40 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ import { h } from 'preact';
3
+ import { ui } from '@playkit-js/kaltura-player-js';
4
+ import { UnisphereIntegrationButton } from '../../types/integrations';
5
+
6
+ const { Tooltip } = ui.components;
7
+
8
+ interface SidepanelButtonsContainerProps {
9
+ buttons: UnisphereIntegrationButton[];
10
+ buttonClassName: string;
11
+ containerClassName: string;
12
+ }
13
+
14
+ const SidepanelButtonsContainer = ({ buttons, buttonClassName, containerClassName }: SidepanelButtonsContainerProps): preact.JSX.Element => (
15
+ <div data-testid={'player_unisphere_sidepanelButtons'} className={containerClassName}>
16
+ {buttons
17
+ .filter((button) => button.visible !== false)
18
+ .map((button) => (
19
+ <button
20
+ data-testid={'player_unisphere_sidepanelButton'}
21
+ key={button.id}
22
+ className={buttonClassName}
23
+ title={button.tooltip}
24
+ onClick={() => {
25
+ if (button.onClick) {
26
+ button.onClick();
27
+ }
28
+ }}
29
+ >
30
+ <Tooltip label={button.tooltip} type="bottom">
31
+ <svg id={`unisphere-icon-${button.id}`} width="24px" height="32px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
32
+ <path d={button.icon} fill="white" />
33
+ </svg>
34
+ </Tooltip>
35
+ </button>
36
+ ))}
37
+ </div>
38
+ );
39
+
40
+ export { SidepanelButtonsContainer };
@@ -0,0 +1 @@
1
+ export { UpperBarIcon } from './upper-bar-icon';
@@ -0,0 +1,23 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ import { h } from 'preact';
3
+
4
+ import { ui } from '@playkit-js/kaltura-player-js';
5
+ const { Tooltip, Icon } = ui.components;
6
+
7
+ interface UpperBarIconProps {
8
+ id: string;
9
+ iconPath: string;
10
+ label: string;
11
+ }
12
+
13
+ const UpperBarIcon = ({ id, label, iconPath }: UpperBarIconProps): preact.JSX.Element => {
14
+ return (
15
+ <Tooltip label={label} type="bottom">
16
+ <button type="button" data-testid={'player_unisphere_upperBarIcon'} aria-label={label} className={ui.style.upperBarIcon}>
17
+ <Icon id={`unisphere-icon-${id}`} height={32} width={32} viewBox={'0 0 32 32'} path={iconPath} />
18
+ </button>
19
+ </Tooltip>
20
+ );
21
+ };
22
+
23
+ export { UpperBarIcon };
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { registerPlugin } from '@playkit-js/kaltura-player-js';
2
+ import { PLUGIN_NAME, UnispherePlugin } from './unisphere-plugin';
3
+
4
+ registerPlugin(PLUGIN_NAME, UnispherePlugin);
5
+
6
+ export type { UnisphereIntegrations } from './types/integrations';
@@ -0,0 +1,25 @@
1
+ import { KalturaPlayer } from '@playkit-js/kaltura-player-js';
2
+ import { ContainerConfig, ContainerTypes } from '../../types';
3
+ import { SidePanelContainerProducer, SimpleContainerProducer, ContainerProducer } from './producers';
4
+
5
+ class ContainerManager {
6
+ private containerProducers: Map<string, ContainerProducer<any>> = new Map();
7
+
8
+ constructor(private player: KalturaPlayer) {
9
+ this.containerProducers.set(ContainerTypes.SIDEPANEL, new SidePanelContainerProducer());
10
+ this.containerProducers.set(ContainerTypes.SIMPLE, new SimpleContainerProducer());
11
+ }
12
+
13
+ public createContainer(containerConfig: ContainerConfig): string | null {
14
+ const containerProducer = this.containerProducers.get(containerConfig.containerType);
15
+ return containerProducer ? containerProducer.createContainer(this.player, containerConfig) : null;
16
+ }
17
+
18
+ public destroy(): void {
19
+ for (const [containerType] of this.containerProducers) {
20
+ this.containerProducers.get(containerType)?.destroy();
21
+ }
22
+ }
23
+ }
24
+
25
+ export { ContainerManager };
@@ -0,0 +1 @@
1
+ export { ContainerManager } from './container-manager';
@@ -0,0 +1,37 @@
1
+ import { KalturaPlayer } from '@playkit-js/kaltura-player-js';
2
+ import { SidePanelsManager } from '@playkit-js/ui-managers';
3
+
4
+ import { ContainerConfig, ServiceKeys } from '../../../types';
5
+ import { getUniqueId } from '../../utils';
6
+
7
+ abstract class BaseContainerProducer {
8
+ protected _disposers: Map<string, () => void> = new Map<string, () => void>();
9
+
10
+ protected generateId(containerConfig: ContainerConfig): string {
11
+ return getUniqueId(`${containerConfig.containerType}_container_`);
12
+ }
13
+
14
+ protected getSidePanelsManager(player: KalturaPlayer): SidePanelsManager | undefined {
15
+ return player.getService(ServiceKeys.SIDE_PANELS_MANAGER) as SidePanelsManager;
16
+ }
17
+
18
+ protected addDisposer(containerId: string, disposer: () => void): void {
19
+ this._disposers.set(containerId, disposer);
20
+ }
21
+
22
+ public dispose(containerId: string): void {
23
+ const disposer = this._disposers.get(containerId);
24
+ if (disposer) {
25
+ disposer();
26
+ this._disposers.delete(containerId);
27
+ }
28
+ }
29
+
30
+ public destroy(): void {
31
+ for (const [containerId] of this._disposers) {
32
+ this.dispose(containerId);
33
+ }
34
+ }
35
+ }
36
+
37
+ 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,3 @@
1
+ export { SidePanelContainerProducer } from './sidepanel-container-producer';
2
+ export { SimpleContainerProducer } from './simple-container-producer';
3
+ export * from './container-producer';
@@ -0,0 +1,59 @@
1
+ .sidepanel-container {
2
+ background: rgba(0, 0, 0, 0.6);
3
+ height: 100%;
4
+ display: flex;
5
+ flex-direction: column;
6
+ }
7
+
8
+ .sidepanel-header {
9
+ display: flex;
10
+ align-items: center;
11
+ width: 100%;
12
+ padding: 16px 16px 0 16px;
13
+ gap: 8px;
14
+ }
15
+
16
+ .sidepanel-title {
17
+ color: #FFFFFF;
18
+ flex: 1;
19
+ min-width: 0;
20
+ font-size: 16px;
21
+ font-weight: 700;
22
+ line-height: 100%;
23
+ letter-spacing: 0.01em;
24
+ margin: 0;
25
+ justify-content: center;
26
+ }
27
+
28
+ .sidepanel-buttons-container {
29
+ display: flex;
30
+ align-items: center;
31
+ justify-content: center;
32
+ line-height: 100%;
33
+ }
34
+
35
+ .sidepanel-button {
36
+ background: none !important;
37
+ border: none !important;
38
+ cursor: pointer;
39
+ display: flex;
40
+ align-items: center;
41
+ justify-content: center;
42
+ padding: 0;
43
+ border-radius: 4px;
44
+ flex-shrink: 0;
45
+ transition: background-color 0.2s ease;
46
+ width: 32px;
47
+ height: 32px;
48
+
49
+ &:focus-visible {
50
+ outline: 2px solid rgba(255, 255, 255, 0.6);
51
+ outline-offset: 2px;
52
+ }
53
+ }
54
+
55
+ .sidepanel-content {
56
+ flex: 1;
57
+ overflow: auto;
58
+ height: 100%;
59
+ }
@@ -0,0 +1,67 @@
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 { CloseButton, ContainerElement, SidepanelButtonsContainer } from '../../../components';
6
+ import { ContainerConfig } from '../../../types';
7
+ import { UnisphereStorageService } from '../../unisphere';
8
+
9
+ import { ContainerProducer } from './container-producer';
10
+ import { BaseContainerProducer } from './base-container-producer';
11
+ import * as style from './sidepanel-container-producer.scss';
12
+
13
+ interface HeaderSidepanelContainerConfig extends ContainerConfig {
14
+ layout: any;
15
+ runtime: any;
16
+ }
17
+
18
+ class SidePanelContainerProducer extends BaseContainerProducer implements ContainerProducer<HeaderSidepanelContainerConfig> {
19
+ public createContainer(player: KalturaPlayer, containerConfig: HeaderSidepanelContainerConfig): string | null {
20
+ const containerId = this.generateId(containerConfig);
21
+ const { unisphereArea, position, expandMode, presets, layout } = containerConfig;
22
+
23
+ console.log('Creating side panel with containerId:', containerId);
24
+ const panelId = this.getSidePanelsManager(player)?.add({
25
+ label: containerId,
26
+ panelComponent: () => this.createSidepanelComponent(layout, containerId, panelId, player),
27
+ presets,
28
+ position,
29
+ expandMode
30
+ }) as number;
31
+
32
+ if (typeof panelId === 'number') {
33
+ this.addDisposer(containerId, () => {
34
+ this.getSidePanelsManager(player)?.remove(panelId);
35
+ });
36
+
37
+ UnisphereStorageService.update(unisphereArea, { upperBarIcon: { panelId } });
38
+ return containerId;
39
+ }
40
+ return null;
41
+ }
42
+
43
+ private createSidepanelComponent(layout: any, containerId: string, panelId: number, player: KalturaPlayer): preact.JSX.Element {
44
+ return (
45
+ <div data-testid={'player_unisphere_sidepanelComponent'} className={style.sidepanelContainer}>
46
+ <div data-testid={'player_unisphere_sidepanelHeader'} className={style.sidepanelHeader}>
47
+ <h3 data-testid={'player_unisphere_sidepanelTitle'} className={style.sidepanelTitle}>
48
+ {layout.sidepanel.header.type === 'buttons' ? layout.sidepanel.header.title : ''}
49
+ </h3>
50
+ {layout.sidepanel.header.buttons && (
51
+ <SidepanelButtonsContainer
52
+ buttons={layout.sidepanel.header.buttons}
53
+ buttonClassName={style.sidepanelButton}
54
+ containerClassName={style.sidepanelButtonsContainer}
55
+ />
56
+ )}
57
+ {layout.sidepanel.header.showCloseButton && (
58
+ <CloseButton className={style.sidepanelButton} onClick={() => this.getSidePanelsManager(player)?.deactivateItem(panelId)} />
59
+ )}
60
+ </div>
61
+ <ContainerElement style={{ flex: '1', overflow: 'auto', height: '100%' }} id={containerId} />
62
+ </div>
63
+ ) as preact.JSX.Element;
64
+ }
65
+ }
66
+
67
+ 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 style={{ width: 'inherit' }} id={containerId} />
21
+ });
22
+
23
+ this.addDisposer(containerId, disposer);
24
+ return containerId;
25
+ }
26
+ }
27
+ export { SimpleContainerProducer };
@@ -0,0 +1,3 @@
1
+ export * from './unisphere';
2
+ export * from './container';
3
+ export * from './utils';
@@ -0,0 +1,4 @@
1
+ export { UnisphereWorkspaceService } from './unisphere-workspace-service';
2
+ export { UnisphereElementService } from './unisphere-element-service';
3
+ export { UnisphereEventService } from './unisphere-event-service';
4
+ export { UnisphereStorageService } from './unisphere-storage-service';
@@ -0,0 +1,35 @@
1
+ import { UnisphereWorkspaceType } from '@unisphere/runtime';
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 addToUnsubscribeMap(unsubscribe: () => void): number {
14
+ UnisphereBaseService.unsubscribeMap.set(UnisphereBaseService.sequence, unsubscribe);
15
+ ++UnisphereBaseService.sequence;
16
+ return UnisphereBaseService.sequence;
17
+ }
18
+
19
+ protected static unsubscribeAll(): void {
20
+ for (const [key, disposer] of UnisphereBaseService.unsubscribeMap) {
21
+ disposer();
22
+ UnisphereBaseService.unsubscribeMap.delete(key);
23
+ }
24
+ }
25
+
26
+ public static unsubscribe(id: number): void {
27
+ const unsubscribe = UnisphereBaseService.unsubscribeMap.get(id);
28
+ if (!unsubscribe) return;
29
+
30
+ unsubscribe();
31
+ UnisphereBaseService.unsubscribeMap.delete(id);
32
+ }
33
+ }
34
+
35
+ export { UnisphereBaseService };
@@ -0,0 +1,25 @@
1
+ import { UnisphereBaseService } from './unisphere-base-service';
2
+ import { UnisphereElementBaseType } from '@unisphere/runtime';
3
+ import { UnisphereWorkspaceService } from './unisphere-workspace-service';
4
+
5
+ class UnisphereElementService extends UnisphereBaseService {
6
+ public static get = async ({
7
+ widgetId,
8
+ context,
9
+ settings
10
+ }: {
11
+ widgetId: string;
12
+ context: string; // todo rename
13
+ settings: unknown;
14
+ }): Promise<UnisphereElementBaseType<any> | null> => {
15
+ const workspace = UnisphereWorkspaceService.get();
16
+ try {
17
+ const result = await workspace?.loadRuntime(widgetId, context, settings || {});
18
+ return result ? result?.runtime : null;
19
+ } catch (e) {
20
+ return Promise.reject(e);
21
+ }
22
+ };
23
+ }
24
+
25
+ export { UnisphereElementService };
@@ -0,0 +1,36 @@
1
+ import { PubSubServiceType } from '@unisphere/runtime';
2
+ import { UnisphereBaseService } from './unisphere-base-service';
3
+ import { UnisphereWorkspaceService } from './unisphere-workspace-service';
4
+
5
+ const PUB_SUB_SERVICE_KEY = 'unisphere.service.pub-sub';
6
+
7
+ class UnisphereEventService extends UnisphereBaseService {
8
+ public static subscribe = (event: string, callback: (data: { payload: { [key: string]: unknown } }) => void): number => {
9
+ const workspace = UnisphereWorkspaceService.get();
10
+ const pubSubService = workspace?.getService<PubSubServiceType>(PUB_SUB_SERVICE_KEY);
11
+
12
+ if (pubSubService) {
13
+ const unsubscribe = pubSubService!.subscribe(event, callback);
14
+ return UnisphereEventService.addToUnsubscribeMap(unsubscribe);
15
+ }
16
+
17
+ return -1;
18
+ };
19
+
20
+ public static emit = (event: string, payload: Record<string, unknown>): void => {
21
+ const workspace = UnisphereWorkspaceService.get();
22
+
23
+ const pubSubService = workspace?.getService<PubSubServiceType>(PUB_SUB_SERVICE_KEY);
24
+ pubSubService?.emit({
25
+ id: event,
26
+ version: '1.0.0',
27
+ payload
28
+ });
29
+ };
30
+
31
+ public static destroy(): void {
32
+ UnisphereEventService.unsubscribeAll();
33
+ }
34
+ }
35
+
36
+ export { UnisphereEventService };
@@ -0,0 +1,17 @@
1
+ import { UnisphereBaseService } from './unisphere-base-service';
2
+ import { UnisphereWorkspaceService } from './unisphere-workspace-service';
3
+
4
+ class UnisphereRuntimeService extends UnisphereBaseService {
5
+ public static get = async ({ widgetName, runtimeName, settings }: { widgetName: string; runtimeName: string; settings: unknown }) => {
6
+ const workspace = UnisphereWorkspaceService.get();
7
+ try {
8
+ const result = await workspace?.loadRuntime(widgetName, runtimeName, settings || {});
9
+
10
+ return result ? result?.runtime : null;
11
+ } catch (e) {
12
+ return Promise.reject(e);
13
+ }
14
+ };
15
+ }
16
+
17
+ export { UnisphereRuntimeService };
@@ -0,0 +1,42 @@
1
+ import { StorageServiceListener, StorageServiceType } from '@unisphere/runtime';
2
+ import { UnisphereBaseService } from './unisphere-base-service';
3
+ import { UnisphereWorkspaceService } from './unisphere-workspace-service';
4
+
5
+ const STORAGE_NAMESPACE = 'player';
6
+ const STORAGE_SERVICE_KEY = 'unisphere.service.storage';
7
+
8
+ class UnisphereStorageService extends UnisphereBaseService {
9
+ public static update = (key: string, value: unknown): void => {
10
+ const workspace = UnisphereWorkspaceService.get();
11
+
12
+ const storageService = <StorageServiceType>workspace?.getService(STORAGE_SERVICE_KEY);
13
+ storageService?.update(STORAGE_NAMESPACE, key, value);
14
+ };
15
+
16
+ public static get = (key: string): unknown => {
17
+ const workspace = UnisphereWorkspaceService.get();
18
+ const storageService = <StorageServiceType>workspace?.getService(STORAGE_SERVICE_KEY);
19
+ return storageService ? storageService.get(STORAGE_NAMESPACE, key) : null;
20
+ };
21
+
22
+ public static subscribe = (key: string, callback: StorageServiceListener): void => {
23
+ const workspace = UnisphereWorkspaceService.get();
24
+ const storageService = <StorageServiceType>workspace?.getService(STORAGE_SERVICE_KEY);
25
+
26
+ if (storageService) {
27
+ const unsubscribe = storageService.subscribe(callback, {
28
+ namespace: STORAGE_NAMESPACE,
29
+ property: key,
30
+ emitLastValue: true
31
+ });
32
+
33
+ UnisphereStorageService.addToUnsubscribeMap(unsubscribe);
34
+ }
35
+ };
36
+
37
+ public static destroy(): void {
38
+ UnisphereStorageService.unsubscribeAll();
39
+ }
40
+ }
41
+
42
+ export { UnisphereStorageService };