@playkit-js/playkit-js-providers 2.40.1 → 2.41.0-canary.0-2452bbc
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/dist/index.d.ts +1624 -0
- package/dist/playkit-analytics-service.js +1 -1
- package/dist/playkit-analytics-service.js.map +1 -1
- package/dist/playkit-bookmark-service.js +1 -1
- package/dist/playkit-bookmark-service.js.map +1 -1
- package/dist/playkit-ott-provider.js +1 -1
- package/dist/playkit-ott-provider.js.map +1 -1
- package/dist/playkit-ovp-provider.js +1 -1
- package/dist/playkit-ovp-provider.js.map +1 -1
- package/dist/playkit-stats-service.js +1 -1
- package/dist/playkit-stats-service.js.map +1 -1
- package/dist/tsdoc-metadata.json +11 -0
- package/flow-typed/types/media-config-sources.js +1 -1
- package/flow-typed/types/media-sources.js +1 -1
- package/package.json +48 -45
- package/playkit-analytics-service/package.json +5 -0
- package/playkit-bookmark-service/package.json +5 -0
- package/playkit-ott-provider/package.json +5 -0
- package/playkit-ovp-provider/package.json +5 -0
- package/playkit-stats-service/package.json +5 -0
- package/src/entities/bumper.ts +21 -0
- package/src/entities/drm.ts +47 -0
- package/src/entities/entry-list.ts +13 -0
- package/src/entities/image-source.ts +36 -0
- package/src/entities/media-entry.ts +104 -0
- package/src/entities/media-format.ts +47 -0
- package/src/entities/media-source.ts +70 -0
- package/src/entities/media-sources.ts +79 -0
- package/src/entities/playlist.ts +41 -0
- package/src/k-provider/common/base-provider-parser.ts +0 -0
- package/src/k-provider/common/base-provider.ts +112 -0
- package/src/k-provider/common/base-service-result.ts +56 -0
- package/src/k-provider/common/data-loader-manager.ts +115 -0
- package/src/k-provider/common/multi-request-builder.ts +111 -0
- package/src/k-provider/common/response-types/kaltura-access-control-message.ts +21 -0
- package/src/k-provider/common/response-types/kaltura-drm-playback-plugin-data.ts +38 -0
- package/src/k-provider/ott/config.ts +22 -0
- package/src/k-provider/ott/index.ts +14 -0
- package/src/k-provider/ott/loaders/asset-list-loader.ts +68 -0
- package/src/k-provider/ott/loaders/asset-loader.ts +69 -0
- package/src/k-provider/ott/loaders/data-loader-manager.ts +15 -0
- package/src/k-provider/ott/loaders/session-loader.ts +62 -0
- package/src/k-provider/ott/provider-parser.ts +285 -0
- package/src/k-provider/ott/provider.ts +252 -0
- package/src/k-provider/ott/response-types/kaltura-asset.ts +105 -0
- package/src/k-provider/ott/response-types/kaltura-bumper-playback-plugin-data.ts +27 -0
- package/src/k-provider/ott/response-types/kaltura-playback-context.ts +73 -0
- package/src/k-provider/ott/response-types/kaltura-playback-source.ts +62 -0
- package/src/k-provider/ott/response-types/kaltura-rule-action.ts +25 -0
- package/src/k-provider/ott/services/asset-service.ts +50 -0
- package/src/k-provider/ott/services/bookmark/bookmark-service.ts +48 -0
- package/src/k-provider/ott/services/bookmark/index.ts +11 -0
- package/src/k-provider/ott/services/ott-service.ts +33 -0
- package/src/k-provider/ott/services/user-service.ts +31 -0
- package/src/k-provider/ovp/config.ts +28 -0
- package/src/k-provider/ovp/external-captions-builder.ts +37 -0
- package/src/k-provider/ovp/index.ts +13 -0
- package/src/k-provider/ovp/loaders/data-loader-manager.ts +17 -0
- package/src/k-provider/ovp/loaders/entry-list-loader.ts +69 -0
- package/src/k-provider/ovp/loaders/media-entry-loader.ts +84 -0
- package/src/k-provider/ovp/loaders/playlist-loader.ts +69 -0
- package/src/k-provider/ovp/loaders/session-loader.ts +62 -0
- package/src/k-provider/ovp/loaders/ui-config-loader.ts +71 -0
- package/src/k-provider/ovp/play-source-url-builder.ts +59 -0
- package/src/k-provider/ovp/provider-parser.ts +461 -0
- package/src/k-provider/ovp/provider.ts +358 -0
- package/src/k-provider/ovp/regex-action-handler.ts +149 -0
- package/src/k-provider/ovp/request-params/base-entry-response-profile.ts +28 -0
- package/src/k-provider/ovp/response-types/index.ts +21 -0
- package/src/k-provider/ovp/response-types/kaltura-access-control-modify-request-host-regex-action.ts +35 -0
- package/src/k-provider/ovp/response-types/kaltura-base-entry-list-response.ts +30 -0
- package/src/k-provider/ovp/response-types/kaltura-bumper.ts +25 -0
- package/src/k-provider/ovp/response-types/kaltura-flavor-asset.ts +108 -0
- package/src/k-provider/ovp/response-types/kaltura-media-entries.ts +28 -0
- package/src/k-provider/ovp/response-types/kaltura-media-entry.ts +189 -0
- package/src/k-provider/ovp/response-types/kaltura-metadata-list-response.ts +22 -0
- package/src/k-provider/ovp/response-types/kaltura-metadata.ts +50 -0
- package/src/k-provider/ovp/response-types/kaltura-playback-context.ts +95 -0
- package/src/k-provider/ovp/response-types/kaltura-playback-source.ts +89 -0
- package/src/k-provider/ovp/response-types/kaltura-playlist.ts +33 -0
- package/src/k-provider/ovp/response-types/kaltura-rule-action.ts +27 -0
- package/src/k-provider/ovp/response-types/kaltura-ui-conf-response.ts +89 -0
- package/src/k-provider/ovp/response-types/kaltura-user-entry-list-response.ts +30 -0
- package/src/k-provider/ovp/response-types/kaltura-user-entry.ts +57 -0
- package/src/k-provider/ovp/services/analytics/analytics-service.ts +58 -0
- package/src/k-provider/ovp/services/analytics/index.ts +11 -0
- package/src/k-provider/ovp/services/base-entry-service.ts +75 -0
- package/src/k-provider/ovp/services/meta-data-service.ts +29 -0
- package/src/k-provider/ovp/services/ovp-service.ts +32 -0
- package/src/k-provider/ovp/services/playlist-service.ts +95 -0
- package/src/k-provider/ovp/services/session-service.ts +27 -0
- package/src/k-provider/ovp/services/stats/index.ts +11 -0
- package/src/k-provider/ovp/services/stats/stats-service.ts +32 -0
- package/src/k-provider/ovp/services/ui-conf-service.ts +32 -0
- package/src/types/adapter-data-config.ts +1 -0
- package/src/types/caption-type.ts +1 -0
- package/src/types/drm-data.ts +5 -0
- package/src/types/entry-list.ts +6 -0
- package/src/types/env-config.ts +7 -0
- package/src/types/external-caption-object.ts +7 -0
- package/src/types/filter-options.ts +3 -0
- package/src/types/index.ts +34 -0
- package/src/types/loader.ts +7 -0
- package/src/types/media-config-metadata.ts +13 -0
- package/src/types/media-config-session.ts +6 -0
- package/src/types/media-config-sources.ts +20 -0
- package/src/types/media-config.ts +8 -0
- package/src/types/media-entry.ts +16 -0
- package/src/types/media-format.ts +5 -0
- package/src/types/media-info.ts +21 -0
- package/src/types/media-source.ts +12 -0
- package/src/types/media-sources.ts +11 -0
- package/src/types/network-retry-parameters.ts +5 -0
- package/src/types/playback-context.ts +10 -0
- package/src/types/playlist-info.ts +4 -0
- package/src/types/playlist-item.ts +5 -0
- package/src/types/playlist-metadata.ts +4 -0
- package/src/types/playlist.ts +10 -0
- package/src/types/poster.ts +5 -0
- package/src/types/provider-options.ts +17 -0
- package/src/types/request-loader.ts +6 -0
- package/src/util/clone.ts +23 -0
- package/src/util/error/category.ts +11 -0
- package/src/util/error/code.ts +77 -0
- package/src/util/error/error.ts +47 -0
- package/src/util/error/severity.ts +21 -0
- package/src/util/logger.ts +108 -0
- package/src/util/param.ts +45 -0
- package/src/util/request-builder.ts +187 -0
- package/src/util/xml-parser.ts +39 -0
- package/CHANGELOG.md +0 -959
- package/samples/ott/bookmark.html +0 -23
- package/samples/ott/provider.html +0 -28
- package/samples/ovp/provider.html +0 -30
- package/samples/ovp/stats.html +0 -17
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import OVPSessionService from '../services/session-service';
|
|
2
|
+
import OVPConfiguration from '../config';
|
|
3
|
+
import RequestBuilder from '../../../util/request-builder';
|
|
4
|
+
import {ILoader} from '../../../types';
|
|
5
|
+
|
|
6
|
+
export default class OVPSessionLoader implements ILoader {
|
|
7
|
+
private _widgetId: string;
|
|
8
|
+
private _requests!: Array<RequestBuilder>;
|
|
9
|
+
private _response: any = {};
|
|
10
|
+
|
|
11
|
+
public static get id(): string {
|
|
12
|
+
return 'session';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public set requests(requests: Array<RequestBuilder>) {
|
|
16
|
+
this._requests = requests;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public get requests(): Array<RequestBuilder> {
|
|
20
|
+
return this._requests;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public set response(response: any) {
|
|
24
|
+
this._response.ks = response[0].data.ks;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public get response(): any {
|
|
28
|
+
return this._response.ks;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @constructor
|
|
33
|
+
* @param {Object} params loader params
|
|
34
|
+
*/
|
|
35
|
+
constructor(params: any) {
|
|
36
|
+
this.requests = this.buildRequests(params);
|
|
37
|
+
this._widgetId = params.widgetId;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Builds loader requests
|
|
42
|
+
* @function
|
|
43
|
+
* @param {Object} params Requests parameters
|
|
44
|
+
* @returns {RequestBuilder} The request builder
|
|
45
|
+
* @static
|
|
46
|
+
*/
|
|
47
|
+
public buildRequests(params: any): Array<RequestBuilder> {
|
|
48
|
+
const config = OVPConfiguration.get();
|
|
49
|
+
const requests: Array<RequestBuilder> = [];
|
|
50
|
+
requests.push(OVPSessionService.anonymousSession(config.serviceUrl, params.widgetId));
|
|
51
|
+
return requests;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Loader validation function
|
|
56
|
+
* @function
|
|
57
|
+
* @returns {boolean} Is valid
|
|
58
|
+
*/
|
|
59
|
+
public isValid(): boolean {
|
|
60
|
+
return !!this._widgetId;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import OVPUIConfService from '../services/ui-conf-service';
|
|
2
|
+
import {KalturaUIConfResponse} from '../response-types';
|
|
3
|
+
import OVPConfiguration from '../config';
|
|
4
|
+
import RequestBuilder from '../../../util/request-builder';
|
|
5
|
+
import {ILoader} from '../../../types';
|
|
6
|
+
|
|
7
|
+
export default class OVPUIConfigLoader implements ILoader {
|
|
8
|
+
private _uiConfId: number;
|
|
9
|
+
private _requests!: Array<RequestBuilder>;
|
|
10
|
+
private _response: any = {};
|
|
11
|
+
|
|
12
|
+
public static get id(): string {
|
|
13
|
+
return 'uiConf';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public set requests(requests: Array<RequestBuilder>) {
|
|
17
|
+
this._requests = requests;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public get requests(): Array<RequestBuilder> {
|
|
21
|
+
return this._requests;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public set response(response: any) {
|
|
25
|
+
this._response.uiConf = new KalturaUIConfResponse(response[0].data);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public get response(): any {
|
|
29
|
+
if (this._response && this._response.uiConf && this._response.uiConf.config)
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(this._response.uiConf.config).plugins;
|
|
32
|
+
} catch (err) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @constructor
|
|
42
|
+
* @param {Object} params loader params
|
|
43
|
+
*/
|
|
44
|
+
constructor(params: any) {
|
|
45
|
+
this.requests = this.buildRequests(params);
|
|
46
|
+
this._uiConfId = params.uiConfId;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Builds loader requests
|
|
51
|
+
* @function
|
|
52
|
+
* @param {Object} params Requests parameters
|
|
53
|
+
* @returns {RequestBuilder} The request builder
|
|
54
|
+
* @static
|
|
55
|
+
*/
|
|
56
|
+
public buildRequests(params: any): Array<RequestBuilder> {
|
|
57
|
+
const config = OVPConfiguration.get();
|
|
58
|
+
const requests: Array<RequestBuilder> = [];
|
|
59
|
+
requests.push(OVPUIConfService.get(config.serviceUrl, params.ks, params.uiConfId));
|
|
60
|
+
return requests;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Loader validation function
|
|
65
|
+
* @function
|
|
66
|
+
* @returns {boolean} Is valid
|
|
67
|
+
*/
|
|
68
|
+
public isValid(): boolean {
|
|
69
|
+
return !!this._uiConfId;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import OVPConfiguration from './config';
|
|
2
|
+
|
|
3
|
+
type urlParamsType = {
|
|
4
|
+
partnerId: number,
|
|
5
|
+
entryId: string,
|
|
6
|
+
ks: string,
|
|
7
|
+
uiConfId?: number,
|
|
8
|
+
format: string,
|
|
9
|
+
protocol: string,
|
|
10
|
+
extension: string,
|
|
11
|
+
flavorIds?: string
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default class PlaySourceUrlBuilder {
|
|
15
|
+
/**
|
|
16
|
+
* Returns source url by given url params
|
|
17
|
+
* @function build
|
|
18
|
+
* @param {urlParamsType} urlParams The params
|
|
19
|
+
* @returns {string} The URL
|
|
20
|
+
* @static
|
|
21
|
+
*/
|
|
22
|
+
public static build(urlParams: urlParamsType): string {
|
|
23
|
+
const config = OVPConfiguration.get();
|
|
24
|
+
const serviceUrlOrigin: string = config.serviceUrl.substr(0, config.serviceUrl.lastIndexOf('/'));
|
|
25
|
+
const {partnerId, entryId, ks, uiConfId, format, protocol, extension, flavorIds} = urlParams;
|
|
26
|
+
|
|
27
|
+
//verify mandatory params
|
|
28
|
+
// @ts-expect-error - fff
|
|
29
|
+
if (!serviceUrlOrigin || isNaN(Number.parseInt(partnerId)) || !entryId || !format || !protocol) {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let playUrl = serviceUrlOrigin;
|
|
34
|
+
if (!serviceUrlOrigin.endsWith('/')) {
|
|
35
|
+
playUrl += '/';
|
|
36
|
+
}
|
|
37
|
+
playUrl += 'p/' + partnerId + '/sp/' + partnerId + '00' + '/playManifest/entryId/' + entryId + '/protocol/' + protocol + '/format/' + format;
|
|
38
|
+
|
|
39
|
+
if (flavorIds) {
|
|
40
|
+
playUrl += '/flavorIds/' + flavorIds;
|
|
41
|
+
} else if (uiConfId) {
|
|
42
|
+
playUrl += '/uiConfId/' + uiConfId;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (ks !== '') {
|
|
46
|
+
playUrl += '/ks/' + ks;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (extension !== '') {
|
|
50
|
+
playUrl += '/a.' + extension;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (uiConfId && flavorIds !== '') {
|
|
54
|
+
playUrl += '?uiConfId=' + uiConfId;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return playUrl;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import { KalturaPlaybackContext, KalturaUserEntry } from './response-types';
|
|
2
|
+
import {KalturaMetadataListResponse} from './response-types';
|
|
3
|
+
import {KalturaMediaEntry} from './response-types';
|
|
4
|
+
import {KalturaPlaybackSource} from './response-types';
|
|
5
|
+
import {KalturaBumper} from './response-types';
|
|
6
|
+
import {KalturaDrmPlaybackPluginData} from '../common/response-types/kaltura-drm-playback-plugin-data';
|
|
7
|
+
import PlaySourceUrlBuilder from './play-source-url-builder';
|
|
8
|
+
import XmlParser from '../../util/xml-parser';
|
|
9
|
+
import getLogger from '../../util/logger';
|
|
10
|
+
import OVPConfiguration from './config';
|
|
11
|
+
import MediaEntry from '../../entities/media-entry';
|
|
12
|
+
import Drm from '../../entities/drm';
|
|
13
|
+
import MediaSource from '../../entities/media-source';
|
|
14
|
+
import MediaSources from '../../entities/media-sources';
|
|
15
|
+
import {SupportedStreamFormat, isProgressiveSource} from '../../entities/media-format';
|
|
16
|
+
import Playlist from '../../entities/playlist';
|
|
17
|
+
import EntryList from '../../entities/entry-list';
|
|
18
|
+
import Bumper from '../../entities/bumper';
|
|
19
|
+
import {KalturaRuleAction} from './response-types';
|
|
20
|
+
import {KalturaAccessControlMessage} from '../common/response-types/kaltura-access-control-message';
|
|
21
|
+
import type {OVPMediaEntryLoaderResponse} from './loaders/media-entry-loader';
|
|
22
|
+
import {ExternalCaptionsBuilder} from './external-captions-builder';
|
|
23
|
+
import {ImageSource} from '../../entities/image-source';
|
|
24
|
+
|
|
25
|
+
class OVPProviderParser {
|
|
26
|
+
private static _logger = getLogger('OVPProviderParser');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns parsed media entry by given OVP response objects
|
|
30
|
+
* @function getMediaEntry
|
|
31
|
+
* @param {string} ks - The ks
|
|
32
|
+
* @param {number} partnerId - The partner ID
|
|
33
|
+
* @param {number} uiConfId - The uiConf ID
|
|
34
|
+
* @param {any} mediaEntryResponse - The media entry response
|
|
35
|
+
* @returns {MediaEntry} - The media entry
|
|
36
|
+
* @static
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
public static getMediaEntry(ks: string, partnerId: number, uiConfId: number | undefined, mediaEntryResponse: any): MediaEntry {
|
|
40
|
+
const mediaEntry = new MediaEntry();
|
|
41
|
+
const entry = mediaEntryResponse.entry;
|
|
42
|
+
const playbackContext = mediaEntryResponse.playBackContextResult;
|
|
43
|
+
const metadataList = mediaEntryResponse.metadataListResult;
|
|
44
|
+
const kalturaSources = playbackContext.sources;
|
|
45
|
+
|
|
46
|
+
mediaEntry.sources = OVPProviderParser._getParsedSources(kalturaSources, ks, partnerId, uiConfId, entry, playbackContext);
|
|
47
|
+
OVPProviderParser._fillBaseData(mediaEntry, entry, metadataList);
|
|
48
|
+
if (mediaEntry.type !== MediaEntry.Type.LIVE && OVPConfiguration.get().useApiCaptions && playbackContext.data.playbackCaptions) {
|
|
49
|
+
mediaEntry.sources.captions = ExternalCaptionsBuilder.createConfig(playbackContext.data.playbackCaptions, ks);
|
|
50
|
+
}
|
|
51
|
+
return mediaEntry;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Returns the url with KS
|
|
56
|
+
* @function addKsToUrl
|
|
57
|
+
* @param {String} url - The url to add the KS
|
|
58
|
+
* @param {string} ks - The ks
|
|
59
|
+
* @returns {string} - The url with KS
|
|
60
|
+
* @static
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
public static addKsToUrl(url: string, ks: string): string {
|
|
64
|
+
const hasUrlExtension = (path): boolean => {
|
|
65
|
+
const pathWithoutQuery = path.split('?')[0];
|
|
66
|
+
const pathAfterLastSlash = pathWithoutQuery.replace(/^.*[\\/]/, '');
|
|
67
|
+
return pathAfterLastSlash.indexOf('.') !== -1;
|
|
68
|
+
};
|
|
69
|
+
let ksParam;
|
|
70
|
+
if (ks) {
|
|
71
|
+
if (hasUrlExtension(url)) {
|
|
72
|
+
ksParam = url.indexOf('?') === -1 ? '?ks=' : '&ks=';
|
|
73
|
+
} else {
|
|
74
|
+
ksParam = '/ks/';
|
|
75
|
+
}
|
|
76
|
+
return url + ksParam + ks;
|
|
77
|
+
}
|
|
78
|
+
return url;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Returns parsed playlist by given OVP response objects
|
|
83
|
+
* @function getPlaylist
|
|
84
|
+
* @param {any} playlistResponse - The playlist response
|
|
85
|
+
* @returns {Playlist} - The playlist
|
|
86
|
+
* @static
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
public static getPlaylist(playlistResponse: any): Playlist {
|
|
90
|
+
const playlist = new Playlist();
|
|
91
|
+
const playlistData = playlistResponse.playlistData;
|
|
92
|
+
const playlistItems = playlistResponse.playlistItems.entries;
|
|
93
|
+
const playlistUserEntries = playlistResponse.playlistUserEntries.entries;
|
|
94
|
+
playlist.id = playlistData.id;
|
|
95
|
+
playlist.name = playlistData.name;
|
|
96
|
+
playlist.description = playlistData.description;
|
|
97
|
+
playlist.poster = playlistData.poster;
|
|
98
|
+
playlist.playlistLastEntryId = playlistUserEntries.map((entry: KalturaUserEntry) => {
|
|
99
|
+
return entry.playlistLastEntryId;
|
|
100
|
+
})[0];
|
|
101
|
+
playlistItems.forEach((entry: KalturaMediaEntry) => {
|
|
102
|
+
const mediaEntry = new MediaEntry();
|
|
103
|
+
OVPProviderParser._fillBaseData(mediaEntry, entry);
|
|
104
|
+
playlist.items.push(mediaEntry);
|
|
105
|
+
});
|
|
106
|
+
return playlist;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Returns parsed entry list by given OVP response objects
|
|
111
|
+
* @function getEntryList
|
|
112
|
+
* @param {any} playlistResponse - response
|
|
113
|
+
* @returns {Playlist} - The entry list
|
|
114
|
+
* @static
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
public static getEntryList(playlistResponse: any): EntryList {
|
|
118
|
+
const entryList = new EntryList();
|
|
119
|
+
const playlistItems = playlistResponse.playlistItems.entries;
|
|
120
|
+
playlistItems.forEach(entry => {
|
|
121
|
+
const mediaEntry = new MediaEntry();
|
|
122
|
+
OVPProviderParser._fillBaseData(mediaEntry, entry);
|
|
123
|
+
entryList.items.push(mediaEntry);
|
|
124
|
+
});
|
|
125
|
+
return entryList;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Returns parsed bumper by given OTT response objects.
|
|
130
|
+
* @function getBumper
|
|
131
|
+
* @param {any} assetResponse - The asset response.
|
|
132
|
+
* @param {string} ks - The ks
|
|
133
|
+
* @param {number} partnerId - The partner ID
|
|
134
|
+
* @returns {?Bumper} - The bumper
|
|
135
|
+
* @static
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
public static getBumper(assetResponse: any, ks: string, partnerId: number): Bumper | undefined {
|
|
139
|
+
const playbackContext = assetResponse.playBackContextResult;
|
|
140
|
+
const bumperData: KalturaBumper = playbackContext.bumperData[0];
|
|
141
|
+
if (bumperData) {
|
|
142
|
+
const bumperSources = bumperData && bumperData.sources;
|
|
143
|
+
const progressiveBumper = bumperSources.find(bumper => isProgressiveSource(bumper.format));
|
|
144
|
+
if (progressiveBumper) {
|
|
145
|
+
const parsedSources = OVPProviderParser._parseProgressiveSources(progressiveBumper, playbackContext, ks, partnerId, 0, bumperData.entryId);
|
|
146
|
+
if (parsedSources[0]) {
|
|
147
|
+
return new Bumper({url: parsedSources[0].url, clickThroughUrl: bumperData.clickThroughUrl});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private static _fillBaseData(mediaEntry: MediaEntry, entry: KalturaMediaEntry, metadataList?: KalturaMetadataListResponse): MediaEntry {
|
|
154
|
+
mediaEntry.poster = entry.poster;
|
|
155
|
+
mediaEntry.id = entry.id;
|
|
156
|
+
mediaEntry.duration = entry.duration;
|
|
157
|
+
mediaEntry.downloadUrl = entry.downloadUrl || '';
|
|
158
|
+
mediaEntry.metadata = OVPProviderParser._parseMetadata(metadataList);
|
|
159
|
+
mediaEntry.metadata.description = entry.description || '';
|
|
160
|
+
mediaEntry.metadata.entryId = entry.id || '';
|
|
161
|
+
mediaEntry.metadata.name = entry.name || '';
|
|
162
|
+
if (entry.createdAt) mediaEntry.metadata.createdAt = entry.createdAt;
|
|
163
|
+
if (entry.updatedAt) mediaEntry.metadata.updatedAt = entry.updatedAt;
|
|
164
|
+
if (entry.creatorId) mediaEntry.metadata.creatorId = entry.creatorId;
|
|
165
|
+
if (entry.endDate) mediaEntry.metadata.endDate = entry.endDate;
|
|
166
|
+
if (entry.views) mediaEntry.metadata.views = entry.views;
|
|
167
|
+
if (entry.plays) mediaEntry.metadata.plays = entry.plays;
|
|
168
|
+
mediaEntry.metadata.tags = entry.tags || '';
|
|
169
|
+
mediaEntry.status = entry.status;
|
|
170
|
+
|
|
171
|
+
mediaEntry.type = OVPProviderParser._getEntryType(entry.entryType, entry.type);
|
|
172
|
+
if (mediaEntry.type === MediaEntry.Type.LIVE) {
|
|
173
|
+
mediaEntry.dvrStatus = entry.dvrStatus;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return mediaEntry;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private static _getEntryType(entryTypeEnum: number, typeEnum: number | string): string {
|
|
180
|
+
let type = MediaEntry.Type.UNKNOWN;
|
|
181
|
+
switch (entryTypeEnum) {
|
|
182
|
+
case KalturaMediaEntry.MediaType.IMAGE.value:
|
|
183
|
+
type = MediaEntry.Type.IMAGE;
|
|
184
|
+
break;
|
|
185
|
+
case KalturaMediaEntry.MediaType.AUDIO.value:
|
|
186
|
+
type = MediaEntry.Type.AUDIO;
|
|
187
|
+
break;
|
|
188
|
+
default:
|
|
189
|
+
switch (typeEnum) {
|
|
190
|
+
case KalturaMediaEntry.EntryType.MEDIA_CLIP.value:
|
|
191
|
+
type = MediaEntry.Type.VOD;
|
|
192
|
+
break;
|
|
193
|
+
case KalturaMediaEntry.EntryType.LIVE_STREAM.value:
|
|
194
|
+
case KalturaMediaEntry.EntryType.LIVE_CHANNEL.value:
|
|
195
|
+
type = MediaEntry.Type.LIVE;
|
|
196
|
+
break;
|
|
197
|
+
default:
|
|
198
|
+
type = MediaEntry.Type.UNKNOWN;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return type;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Returns the parsed sources
|
|
206
|
+
* @function _getParsedSources
|
|
207
|
+
* @param {Array<KalturaPlaybackSource>} kalturaSources - The kaltura sources
|
|
208
|
+
* @param {string} ks - The ks
|
|
209
|
+
* @param {number} partnerId - The partner ID
|
|
210
|
+
* @param {number} uiConfId - The uiConf ID
|
|
211
|
+
* @param {Object} entry - The entry
|
|
212
|
+
* @param {KalturaPlaybackContext} playbackContext - The playback context
|
|
213
|
+
* @return {MediaSources} - A media sources
|
|
214
|
+
* @static
|
|
215
|
+
* @private
|
|
216
|
+
*/
|
|
217
|
+
private static _getParsedSources(
|
|
218
|
+
kalturaSources: Array<KalturaPlaybackSource>,
|
|
219
|
+
ks: string,
|
|
220
|
+
partnerId: number,
|
|
221
|
+
uiConfId: number | undefined,
|
|
222
|
+
entry: any,
|
|
223
|
+
playbackContext: KalturaPlaybackContext
|
|
224
|
+
): MediaSources {
|
|
225
|
+
const sources = new MediaSources();
|
|
226
|
+
const addAdaptiveSource = (source: KalturaPlaybackSource): void => {
|
|
227
|
+
const parsedSource = OVPProviderParser._parseAdaptiveSource(source, playbackContext, ks, partnerId, uiConfId, entry.id);
|
|
228
|
+
if (parsedSource) {
|
|
229
|
+
const sourceFormat = SupportedStreamFormat.get(source.format);
|
|
230
|
+
sources.map(parsedSource, sourceFormat);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
const parseAdaptiveSources = (): void => {
|
|
234
|
+
kalturaSources.filter(source => !isProgressiveSource(source.format)).forEach(addAdaptiveSource);
|
|
235
|
+
};
|
|
236
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
237
|
+
const parseProgressiveSources = () => {
|
|
238
|
+
const progressiveSource = kalturaSources.find(source => {
|
|
239
|
+
//match progressive source with supported protocol(http/s)
|
|
240
|
+
return isProgressiveSource(source.format) && source.getProtocol(OVPProviderParser._getBaseProtocol()) !== '';
|
|
241
|
+
});
|
|
242
|
+
sources.progressive = OVPProviderParser._parseProgressiveSources(progressiveSource, playbackContext, ks, partnerId, uiConfId, entry.id);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const parseImageSources = (): void => {
|
|
246
|
+
sources.image.push(new ImageSource(entry));
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const parseExternalMedia = (): void => {
|
|
250
|
+
const mediaSource = new MediaSource();
|
|
251
|
+
mediaSource.mimetype = 'video/youtube';
|
|
252
|
+
mediaSource.url = entry.referenceId;
|
|
253
|
+
mediaSource.id = entry.id + '_youtube';
|
|
254
|
+
sources.progressive.push(mediaSource);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
if (entry.type === KalturaMediaEntry.EntryType.EXTERNAL_MEDIA.value) {
|
|
258
|
+
parseExternalMedia();
|
|
259
|
+
} else if (entry.entryType === KalturaMediaEntry.MediaType.IMAGE.value) {
|
|
260
|
+
parseImageSources();
|
|
261
|
+
} else if (kalturaSources && kalturaSources.length > 0) {
|
|
262
|
+
parseAdaptiveSources();
|
|
263
|
+
parseProgressiveSources();
|
|
264
|
+
}
|
|
265
|
+
return sources;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Returns a parsed adaptive source
|
|
270
|
+
* @function _parseAdaptiveSource
|
|
271
|
+
* @param {KalturaPlaybackSource} kalturaSource - A kaltura source
|
|
272
|
+
* @param {KalturaPlaybackContext} playbackContext - The playback context
|
|
273
|
+
* @param {string} ks - The ks
|
|
274
|
+
* @param {number} partnerId - The partner ID
|
|
275
|
+
* @param {number} uiConfId - The uiConf ID
|
|
276
|
+
* @param {string} entryId - The entry id
|
|
277
|
+
* @returns {?MediaSource} - The parsed adaptive kalturaSource
|
|
278
|
+
* @static
|
|
279
|
+
* @private
|
|
280
|
+
*/
|
|
281
|
+
private static _parseAdaptiveSource(
|
|
282
|
+
kalturaSource: KalturaPlaybackSource,
|
|
283
|
+
playbackContext: KalturaPlaybackContext,
|
|
284
|
+
ks: string,
|
|
285
|
+
partnerId: number,
|
|
286
|
+
uiConfId: number | undefined,
|
|
287
|
+
entryId: string
|
|
288
|
+
): MediaSource | null {
|
|
289
|
+
const mediaSource: MediaSource = new MediaSource();
|
|
290
|
+
if (kalturaSource) {
|
|
291
|
+
let playUrl: string = '';
|
|
292
|
+
const mediaFormat = SupportedStreamFormat.get(kalturaSource.format);
|
|
293
|
+
const protocol = kalturaSource.getProtocol(OVPProviderParser._getBaseProtocol());
|
|
294
|
+
const deliveryProfileId = kalturaSource.deliveryProfileId;
|
|
295
|
+
const format = kalturaSource.format;
|
|
296
|
+
let extension: string = '';
|
|
297
|
+
if (mediaFormat) {
|
|
298
|
+
extension = mediaFormat.pathExt;
|
|
299
|
+
mediaSource.mimetype = mediaFormat.mimeType;
|
|
300
|
+
}
|
|
301
|
+
// in case playbackSource doesn't have flavors we don't need to build the url and we'll use the provided one.
|
|
302
|
+
if (kalturaSource.hasFlavorIds()) {
|
|
303
|
+
if (!extension && playbackContext.flavorAssets && playbackContext.flavorAssets.length > 0) {
|
|
304
|
+
extension = playbackContext.flavorAssets[0].fileExt;
|
|
305
|
+
}
|
|
306
|
+
playUrl = PlaySourceUrlBuilder.build({
|
|
307
|
+
entryId,
|
|
308
|
+
flavorIds: kalturaSource.flavorIds,
|
|
309
|
+
format,
|
|
310
|
+
ks,
|
|
311
|
+
partnerId,
|
|
312
|
+
uiConfId,
|
|
313
|
+
extension,
|
|
314
|
+
protocol
|
|
315
|
+
});
|
|
316
|
+
} else {
|
|
317
|
+
playUrl = OVPProviderParser.addKsToUrl(kalturaSource.url, ks);
|
|
318
|
+
}
|
|
319
|
+
if (!playUrl) {
|
|
320
|
+
const message = `failed to create play url from source, discarding source: (${entryId}_${deliveryProfileId}), ${format}`;
|
|
321
|
+
OVPProviderParser._logger.warn(message);
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
mediaSource.url = playUrl;
|
|
325
|
+
mediaSource.id = entryId + '_' + deliveryProfileId + ',' + format;
|
|
326
|
+
if (kalturaSource.hasDrmData()) {
|
|
327
|
+
const drmParams: Array<Drm> = [];
|
|
328
|
+
kalturaSource.drm.forEach(drm => {
|
|
329
|
+
drmParams.push(new Drm(drm.licenseURL, KalturaDrmPlaybackPluginData.Scheme[drm.scheme], drm.certificate));
|
|
330
|
+
});
|
|
331
|
+
mediaSource.drmData = drmParams;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return mediaSource;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Returns parsed progressive sources
|
|
339
|
+
* @function _parseProgressiveSources
|
|
340
|
+
* @param {KalturaPlaybackSource} kalturaSource - A kaltura source
|
|
341
|
+
* @param {KalturaPlaybackContext} playbackContext - The playback context
|
|
342
|
+
* @param {string} ks - The ks
|
|
343
|
+
* @param {number} partnerId - The partner ID
|
|
344
|
+
* @param {number} uiConfId - The uiConf ID
|
|
345
|
+
* @param {string} entryId - The entry id
|
|
346
|
+
* @returns {Array<MediaSource>} - The parsed progressive kalturaSources
|
|
347
|
+
* @static
|
|
348
|
+
* @private
|
|
349
|
+
*/
|
|
350
|
+
private static _parseProgressiveSources(
|
|
351
|
+
kalturaSource: KalturaPlaybackSource | undefined,
|
|
352
|
+
playbackContext: KalturaPlaybackContext,
|
|
353
|
+
ks: string,
|
|
354
|
+
partnerId: number,
|
|
355
|
+
uiConfId: number | undefined,
|
|
356
|
+
entryId: string
|
|
357
|
+
): Array<MediaSource> {
|
|
358
|
+
const videoSources: Array<MediaSource> = [];
|
|
359
|
+
const audioSources: Array<MediaSource> = [];
|
|
360
|
+
if (kalturaSource) {
|
|
361
|
+
const protocol = kalturaSource.getProtocol(OVPProviderParser._getBaseProtocol());
|
|
362
|
+
const format = kalturaSource.format;
|
|
363
|
+
const deliveryProfileId = kalturaSource.deliveryProfileId;
|
|
364
|
+
const sourceId = deliveryProfileId + ',' + format;
|
|
365
|
+
playbackContext.flavorAssets.map(flavor => {
|
|
366
|
+
const mediaSource: MediaSource = new MediaSource();
|
|
367
|
+
mediaSource.id = flavor.id + sourceId;
|
|
368
|
+
mediaSource.mimetype = flavor.fileExt === 'mp3' ? 'audio/mp3' : 'video/mp4';
|
|
369
|
+
mediaSource.height = flavor.height;
|
|
370
|
+
mediaSource.width = flavor.width;
|
|
371
|
+
mediaSource.bandwidth = flavor.bitrate * 1024;
|
|
372
|
+
mediaSource.label = flavor.label || flavor.language;
|
|
373
|
+
const playUrl = PlaySourceUrlBuilder.build({
|
|
374
|
+
entryId,
|
|
375
|
+
flavorIds: flavor.id,
|
|
376
|
+
format,
|
|
377
|
+
ks,
|
|
378
|
+
partnerId: partnerId,
|
|
379
|
+
uiConfId: uiConfId,
|
|
380
|
+
extension: flavor.fileExt,
|
|
381
|
+
protocol
|
|
382
|
+
});
|
|
383
|
+
if (playUrl === '') {
|
|
384
|
+
OVPProviderParser._logger.warn(`failed to create play url from source, discarding source: (${entryId}_${deliveryProfileId}), ${format}.`);
|
|
385
|
+
return null;
|
|
386
|
+
} else {
|
|
387
|
+
mediaSource.url = playUrl;
|
|
388
|
+
if (flavor.height && flavor.width) {
|
|
389
|
+
videoSources.push(mediaSource);
|
|
390
|
+
} else {
|
|
391
|
+
audioSources.push(mediaSource);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
//If we have only audio flavors return them, otherwise return video flavors
|
|
397
|
+
return audioSources.length && !videoSources.length ? audioSources : videoSources;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Ovp metadata parser
|
|
402
|
+
* @function _parseMetaData
|
|
403
|
+
* @param {KalturaMetadataListResponse} metadataList The metadata list
|
|
404
|
+
* @returns {Object} Parsed metadata
|
|
405
|
+
* @static
|
|
406
|
+
* @private
|
|
407
|
+
*/
|
|
408
|
+
private static _parseMetadata(metadataList: KalturaMetadataListResponse | undefined): any {
|
|
409
|
+
const metadata: any = {};
|
|
410
|
+
if (metadataList && metadataList.metas && metadataList.metas.length > 0) {
|
|
411
|
+
metadataList.metas.forEach(meta => {
|
|
412
|
+
if (meta.xml) {
|
|
413
|
+
const domParser: DOMParser = new DOMParser();
|
|
414
|
+
meta.xml = meta.xml.replace(/\r?\n|\r/g, '');
|
|
415
|
+
meta.xml = meta.xml.replace(/>\s*/g, '>');
|
|
416
|
+
meta.xml = meta.xml.replace(/>\s*/g, '>');
|
|
417
|
+
const metaXml: any = domParser.parseFromString(meta.xml, 'text/xml');
|
|
418
|
+
const metasObj: any = XmlParser.xmlToJson(metaXml);
|
|
419
|
+
const metaKeys = Object.keys(metasObj.metadata);
|
|
420
|
+
metaKeys.forEach(key => {
|
|
421
|
+
metadata[key] = metasObj.metadata[key]['#text'];
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
return metadata;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Returns the base protocol
|
|
431
|
+
* @function _getBaseProtocol
|
|
432
|
+
* @returns {string} - The base protocol
|
|
433
|
+
* @static
|
|
434
|
+
* @private
|
|
435
|
+
*/
|
|
436
|
+
private static _getBaseProtocol(): string {
|
|
437
|
+
const config = OVPConfiguration.get();
|
|
438
|
+
const protocolRegex = /^https?:/;
|
|
439
|
+
const result = protocolRegex.exec(config.cdnUrl);
|
|
440
|
+
const protocol = result ? result[0] : document.location.protocol;
|
|
441
|
+
if (typeof protocol === 'string') {
|
|
442
|
+
return protocol.slice(0, -1); // remove ':' from the end
|
|
443
|
+
}
|
|
444
|
+
return 'https';
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
public static hasBlockAction(response: OVPMediaEntryLoaderResponse): boolean {
|
|
448
|
+
return response.playBackContextResult.hasBlockAction();
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
public static getBlockAction(response: OVPMediaEntryLoaderResponse): KalturaRuleAction | undefined {
|
|
452
|
+
return response.playBackContextResult.getBlockAction();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
public static getErrorMessages(response: OVPMediaEntryLoaderResponse): Array<KalturaAccessControlMessage> {
|
|
456
|
+
return response.playBackContextResult.getErrorMessages();
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export const addKsToUrl = OVPProviderParser.addKsToUrl;
|
|
461
|
+
export default OVPProviderParser;
|