From 87682abb0b131db7fc6efd946567b9e53641e3fd Mon Sep 17 00:00:00 2001 From: Kirill Karpov <85180621+karpov-kir@users.noreply.github.com> Date: Wed, 15 May 2024 10:49:36 +0400 Subject: [PATCH] Migrate to latest Conviva types (#105) --- @types/conviva/Conviva.d.ts | 456 +++++++++++++++++++++ @types/conviva/ConvivaExtension.d.ts | 83 ++++ @types/conviva/index.d.ts | 2 + CHANGELOG.md | 6 + example/conviva-core-sdk.d.ts | 8 +- package-lock.json | 333 +++++++++++++-- package.json | 8 +- spec/helper/MockHelper.ts | 17 +- spec/tests/ContentMetadata.spec.ts | 5 +- spec/tests/ExternalSessionManaging.spec.ts | 4 +- spec/tests/PlayerEvents.spec.ts | 6 +- src/ts/ContentMetadataBuilder.ts | 49 ++- src/ts/Conviva.d.ts | 328 --------------- src/ts/ConvivaAnalytics.ts | 12 +- src/ts/Html5Logging.ts | 2 +- src/ts/helper/AdBreakHelper.ts | 5 +- tsconfig.build.json | 9 + tsconfig.json | 11 +- webpack.common.js | 9 +- 19 files changed, 933 insertions(+), 420 deletions(-) create mode 100644 @types/conviva/Conviva.d.ts create mode 100644 @types/conviva/ConvivaExtension.d.ts create mode 100644 @types/conviva/index.d.ts delete mode 100644 src/ts/Conviva.d.ts create mode 100644 tsconfig.build.json diff --git a/@types/conviva/Conviva.d.ts b/@types/conviva/Conviva.d.ts new file mode 100644 index 0000000..0d4bc16 --- /dev/null +++ b/@types/conviva/Conviva.d.ts @@ -0,0 +1,456 @@ +/** + * Definitions are copied from `conviva-core-sdk` package. + */ + +declare module Conviva { + type valueof = T[keyof T]; + + enum ConvivaKeys { + APPLICATION_VERSION = 'c3.app.version', + ASSET_NAME = 'Conviva.assetName', + CUSTOMER_KEY = 'customerKey', + DEFAULT_RESOURCE = 'Conviva.defaultResource', + DURATION = 'Conviva.duration', + ENCODED_FRAMERATE = 'Conviva.encodedFrameRate', + FRAMEWORK_NAME = 'Conviva.frameworkName', + FRAMEWORK_VERSION = 'Conviva.frameworkVersion', + IS_LIVE = 'Conviva.streamType', + MANUFACTURER = 'DeviceManufacturer', + PLAYER_NAME = 'Conviva.applicationName', + POD_DURATION = 'podDuration', + POD_INDEX = 'podIndex', + POD_POSITION = 'podPosition', + STREAM_URL = 'Conviva.streamUrl', + VIEWER_ID = 'Conviva.viewerId', + + // DeviceMetadata + BRAND = 'DeviceBrand', + CATEGORY = 'DeviceCategory', + MODEL = 'DeviceModel', + OS_NAME = 'OperatingSystemName', + OS_VERSION = 'OperatingSystemVersion', + SCREEN_RESOLUTION_HEIGHT = 'ScreenHeight', + SCREEN_RESOLUTION_SCALE_FACTOR = 'ScaleFactor', + SCREEN_RESOLUTION_WIDTH = 'ScreenWidth', + TYPE = 'DeviceType', + VERSION = 'DeviceVersion', + + // CallbackFunctions + CONSOLE_LOG = 'consoleLog', + CREATE_TIMER = 'createTimer', + GET_EPOCH_TIME_IN_MS = 'getEpochTimeInMs', + LOAD_DATA = 'loadData', + MAKE_REQUEST = 'makeRequest', + SAVE_DATA = 'saveData', + + // Init options + LOG_LEVEL = 'logLevel', + GATEWAY_URL = 'gatewayUrl', + + // Playback + BITRATE = 'BITRATE', + AVG_BITRATE = 'AVG_BITRATE', + BUFFER_LENGTH = 'BUFFER_LENGTH', + CDN_IP = 'CDN_IP', + PLAYER_STATE = 'PLAYER_STATE', + PLAY_HEAD_TIME = 'PLAY_HEAD_TIME', + RENDERED_FRAMERATE = 'RENDERED_FRAMERATE', + RESOLUTION = 'RESOLUTION', + SEEK_ENDED = 'SEEK_ENDED', + SEEK_STARTED = 'SEEK_STARTED', + AUDIO_LANGUAGE = 'AUDIO_LANGUAGE', + SUBTITLES_LANGUAGE = 'SUBTITLES_LANGUAGE', + CLOSED_CAPTIONS_LANGUAGE = 'CLOSED_CAPTIONS_LANGUAGE', + + + // PlayerState + BUFFERING = 'BUFFERING', + NOT_MONITORED = 'NOT_MONITORED', + PAUSED = 'PAUSED', + PLAYING = 'PLAYING', + STOPPED = 'STOPPED', + UNKNOWN = 'UNKNOWN', + + // StreamType + VOD = 'VOD', + LIVE = 'LIVE', + + // Device Categories + CAT_ANDROID_DEVICE = 'AND', + CAT_APPLE_DEVICE = 'APL', + CAT_CHROMECAST = 'CHR', + CAT_DESKTOP_APP = 'DSKAPP', + CAT_DEVICE_SIMULATOR = 'SIMULATOR', + CAT_KAIOS_DEVICE = 'KAIOS', + CAT_LG_TV = 'LGTV', + CAT_NINTENDO = 'NINTENDO', + CAT_PLAYSTATION = 'PS', + CAT_ROKU = 'RK', + CAT_SAMSUNG_TV = 'SAMSUNGTV', + CAT_SET_TOP_BOX = 'STB', + CAT_SMART_TV = 'TV', + CAT_TIVO = 'TIVO', + CAT_WEB = 'WEB', + CAT_WINDOWS_DEVICE = 'WIN', + CAT_XBOX = 'XB', + + // Device Metadata Keys + META_BRAND = 'DeviceBrand', + META_CATEGORY = 'DeviceCategory', + META_MANUFACTURER = 'DeviceManufacturer', + META_MODEL = 'DeviceModel', + META_OS_NAME = 'OperatingSystemName', + META_OS_VERSION = 'OperatingSystemVersion', + META_TYPE = 'DeviceType', + META_VERSION = 'DeviceVersion', + + // DeviceType + TYPE_CONSOLE = 'Console', + TYPE_DESKTOP = 'DESKTOP', + TYPE_MOBILE = 'Mobile', + TYPE_SETTOP = 'Settop', + TYPE_SMARTTV = 'SmartTV', + TYPE_TABLET = 'Tablet', + + // setAdListener info + AD_PRELOAD_FEATURE = 'adPreloading', + AD_TAG_URL = 'adTagUrl', + IMASDK_CONTENT_PLAYER = 'imaMainContentPlayer', + + // setPlayer extraListeners + CONVIVA_AD_MODULE = 'convivaAdModule', + CONVIVA_MODULE = 'convivaModule', + MEDIA_ELEMENT = 'mediaElement', +} + +interface ConvivaUtils { + [ConvivaKeys.CONSOLE_LOG]?(message: string, logLevel: valueof): void; + [ConvivaKeys.MAKE_REQUEST]?( + method: 'GET' | 'POST', + url: string, + data: any, + contentType: string, + timeout: number, + callback: (succes: boolean, response: string) => void, + ): void; + [ConvivaKeys.SAVE_DATA]?( + path: string, + key: string, + data: string, + callback: (success: boolean, data: string) => void, + ): void; + [ConvivaKeys.LOAD_DATA]?(path: string, key: string, callback: (success: boolean, data: string) => void): void; + [ConvivaKeys.GET_EPOCH_TIME_IN_MS]?(): number; + [ConvivaKeys.CREATE_TIMER]?(action: () => void, time: number, actionName?: string): () => void; +} + +interface ConvivaOptions { + [ConvivaKeys.LOG_LEVEL]?: number; + [ConvivaKeys.GATEWAY_URL]?: string; +} + +interface ConvivaDeviceMetadata { + [ConvivaKeys.BRAND]?: string; + [ConvivaKeys.MANUFACTURER]?: string; + [ConvivaKeys.MODEL]?: string; + [ConvivaKeys.TYPE]?: valueof; + [ConvivaKeys.VERSION]?: string; + [ConvivaKeys.OS_NAME]?: string; + [ConvivaKeys.OS_VERSION]?: string; + [ConvivaKeys.CATEGORY]?: valueof; + [ConvivaKeys.SCREEN_RESOLUTION_WIDTH]?: number; + [ConvivaKeys.SCREEN_RESOLUTION_HEIGHT]?: number; + [ConvivaKeys.SCREEN_RESOLUTION_SCALE_FACTOR]?: number; +} + +interface ConvivaPlayerInfo { + [ConvivaKeys.FRAMEWORK_NAME]?: string; + [ConvivaKeys.FRAMEWORK_VERSION]?: string; +} + +interface ConvivaPlayerExtraListeners { + [Constants.MEDIA_ELEMENT]?: object; + [Constants.CONVIVA_MODULE]?: object; + [Constants.CONVIVA_AD_MODULE]?: object; +} + +interface ConvivaAdBreakInfo { + [ConvivaKeys.POD_POSITION]?: string; + [ConvivaKeys.POD_DURATION]?: number; + [ConvivaKeys.POD_INDEX]?: number; +} + +interface ConvivaAdListenerInfo { + [ConvivaKeys.AD_TAG_URL]?: string; + [ConvivaKeys.AD_PRELOAD_FEATURE]?: boolean; + [ConvivaKeys.IMASDK_CONTENT_PLAYER]: object; +} + +type ConvivaMetadata = { + [ConvivaKeys.IS_LIVE]?: + | ConvivaConstants['StreamType']['LIVE'] + | ConvivaConstants['StreamType']['UNKNOWN'] + | ConvivaConstants['StreamType']['VOD']; + [ConvivaKeys.ASSET_NAME]?: string | null; + [ConvivaKeys.DURATION]?: number | null; + [ConvivaKeys.PLAYER_NAME]?: string; + [ConvivaKeys.STREAM_URL]?: string | null; + [ConvivaKeys.ENCODED_FRAMERATE]?: number | null; + [ConvivaKeys.VIEWER_ID]?: string | null; + [ConvivaKeys.DEFAULT_RESOURCE]?: string | null; +} & { [key: string]: string }; // Custom tags + +interface VideoAnalytics { + configureExistingSession(sessionKey: string): void; + release(): void; + reportAdBreakEnded(): void; + reportAdBreakStarted( + type: valueof, + value: valueof, + adBreakInfo?: object, + ): void; + reportPlaybackEnded(): void; + reportPlaybackError(errorMessage: string, errorSeverity?: valueof): void; + reportPlaybackEvent(eventType: string, eventDetail?: object): void; + reportPlaybackFailed(errorMessage: string, contentInfo?: ConvivaMetadata): void; + reportPlaybackMetric( + metricKey: valueof, + metricValue?: valueof | number | string, + metricValue2?: valueof | number | string, + ): void; + reportPlaybackRequested(contentInfo?: ConvivaMetadata): void; + setCallback(callback: () => void | null): void; + setContentInfo(contentInfo: ConvivaMetadata): void; + setPlayer(playerInstance: object, extraListeners?: ConvivaPlayerExtraListeners): void; + setPlayerInfo(playerInfo: ConvivaPlayerInfo): void; +} + +interface AdAnalytics { + release(): void; + reportAdEnded(): void; + reportAdError(errorMessage: string, errorSeverity: valueof): void; + reportAdFailed(errorMessage: string, adInfo?: ConvivaMetadata): void; + reportAdLoaded(adInfo?: ConvivaMetadata): void; + reportAdMetric( + metricKey: valueof, + metricValue?: valueof | number | string, + metricValue2?: valueof | number | string, + ): void; + reportAdPlayerEvent(eventType: valueof, detail?: object): void; + reportAdSkipped(): void; + reportAdStarted(adInfo?: ConvivaMetadata): void; + setAdInfo(adInfo: ConvivaMetadata): void; + setAdListener(adsLoader: object, info: ConvivaAdListenerInfo): void; + setAdPlayerInfo(adPlayerInfo: ConvivaPlayerInfo): void; + setCallback(callback: () => void | null): void; +} + +namespace Analytics { + function buildAdAnalytics(videoAnalytics?: VideoAnalytics): AdAnalytics; + function buildVideoAnalytics(): VideoAnalytics; + function configureExistingClient(convivaLegacyClient: object): void; + function init(customerKey: string, callbackFunctions: ConvivaUtils | null, options: ConvivaOptions): void; + function release(): void; + function reportAppBackgrounded(): void; + function reportAppEvent(eventType: string, eventDetail?: { [key: string]: string }): void; + function reportAppForegrounded(): void; + function reportDeviceMetric(metricKey: string, metricValue: number | string): void; + function setDeviceMetadata(deviceMetadata: ConvivaDeviceMetadata): void; + function setUniqueIdentifier(indentifiers: object, callback?: () => void): void; // TODO: Define identifiers type + function setUserPreferenceForDataCollection(identifiers: object, forAllApps: boolean): void; // TODO: Define identifiers type + function setUserPreferenceForDataDeletion(identifiers: object): void; // TODO: Define identifiers type +} + +interface ConvivaConstants { + AD_PRELOAD_FEATURE: ConvivaKeys.AD_PRELOAD_FEATURE; + AD_TAG_URL: ConvivaKeys.AD_TAG_URL; + AdPlayer: { + CONTENT: 'CONTENT'; + SEPARATE: 'SEPARATE'; + }; + AdPosition: { + MIDROLL: 'Mid-roll'; + POSTROLL: 'Post-roll'; + PREROLL: 'Pre-roll'; + }; + AdServingType: { + INLINE: 'Inline'; + WRAPPER: 'Wrapper'; + }; + AdSlates: { + BLACKOUT_SLATE: 'Blackout slate'; + COMMERCIAL_SLATE: 'Commercial Break slate'; + OTHER_SLATE: 'Other slate'; + REGULAR: 'Regular Ad'; + TECHNICAL_DIFFICULTIES_SLATE: 'Technical Difficulties slate'; + VPAID: 'VPAID'; + }; + AdType: { + CLIENT_SIDE: 'Client Side'; + SERVER_SIDE: 'Server Side'; + }; + APPLICATION_VERSION: ConvivaKeys.APPLICATION_VERSION; + ASSET_NAME: ConvivaKeys.ASSET_NAME; + CONVIVA_AD_MODULE: ConvivaKeys.CONVIVA_AD_MODULE; + CONVIVA_MODULE: ConvivaKeys.CONVIVA_MODULE; + CUSTOMER_KEY: ConvivaKeys.CUSTOMER_KEY; + CallbackFunctions: { + CONSOLE_LOG: ConvivaKeys.CONSOLE_LOG; + MAKE_REQUEST: ConvivaKeys.MAKE_REQUEST; + SAVE_DATA: ConvivaKeys.SAVE_DATA; + LOAD_DATA: ConvivaKeys.LOAD_DATA; + GET_EPOCH_TIME_IN_MS: ConvivaKeys.GET_EPOCH_TIME_IN_MS; + CREATE_TIMER: ConvivaKeys.CREATE_TIMER; + }; + DEFAULT_RESOURCE: ConvivaKeys.DEFAULT_RESOURCE; + DURATION: ConvivaKeys.DURATION; + DeviceCategory: { + ANDROID_DEVICE: ConvivaKeys.CAT_ANDROID_DEVICE; + APPLE_DEVICE: ConvivaKeys.CAT_APPLE_DEVICE; + CHROMECAST: ConvivaKeys.CAT_CHROMECAST; + DESKTOP_APP: ConvivaKeys.CAT_DESKTOP_APP; + DEVICE_SIMULATOR: ConvivaKeys.CAT_DEVICE_SIMULATOR; + KAIOS_DEVICE: ConvivaKeys.CAT_KAIOS_DEVICE; + LG_TV: ConvivaKeys.CAT_LG_TV; + NINTENDO: ConvivaKeys.CAT_NINTENDO; + PLAYSTATION: ConvivaKeys.CAT_PLAYSTATION; + ROKU: ConvivaKeys.CAT_ROKU; + SAMSUNG_TV: ConvivaKeys.CAT_SAMSUNG_TV; + SET_TOP_BOX: ConvivaKeys.CAT_SET_TOP_BOX; + SMART_TV: ConvivaKeys.CAT_SMART_TV; + TIVO: ConvivaKeys.CAT_TIVO; + WEB: ConvivaKeys.CAT_WEB; + WINDOWS_DEVICE: ConvivaKeys.CAT_WINDOWS_DEVICE; + XBOX: ConvivaKeys.CAT_XBOX; + }; + DeviceMetadata: { + BRAND: ConvivaKeys.META_BRAND; + CATEGORY: ConvivaKeys.META_CATEGORY; + MANUFACTURER: ConvivaKeys.META_MANUFACTURER; + MODEL: ConvivaKeys.META_MODEL; + OS_NAME: ConvivaKeys.META_OS_NAME; + OS_VERSION: ConvivaKeys.META_OS_VERSION; + TYPE: ConvivaKeys.META_TYPE; + VERSION: ConvivaKeys.META_VERSION; + SCREEN_RESOLUTION_WIDTH: ConvivaKeys.SCREEN_RESOLUTION_WIDTH; + SCREEN_RESOLUTION_HEIGHT: ConvivaKeys.SCREEN_RESOLUTION_HEIGHT; + SCREEN_RESOLUTION_SCALE_FACTOR: ConvivaKeys.SCREEN_RESOLUTION_SCALE_FACTOR; + }; + DeviceType: { + CONSOLE: ConvivaKeys.TYPE_CONSOLE; + DESKTOP: ConvivaKeys.TYPE_DESKTOP; + MOBILE: ConvivaKeys.TYPE_MOBILE; + SETTOP: ConvivaKeys.TYPE_SETTOP; + SMARTTV: ConvivaKeys.TYPE_SMARTTV; + TABLET: ConvivaKeys.TYPE_TABLET; + }; + ENCODED_FRAMERATE: ConvivaKeys.ENCODED_FRAMERATE; + ErrorSeverity: { + FATAL: 1; + WARNING: 0; + }; + ErrorType: { + ERROR_3P_COMPONENT: 'ERROR_3P_COMPONENT'; + ERROR_DEVICE_LIMIT: 'ERROR_DEVICE_LIMIT'; + ERROR_INVALID_SLOT: 'ERROR_INVALID_SLOT'; + ERROR_INVALID_VALUE: 'ERROR_INVALID_VALUE'; + ERROR_IO: 'ERROR_IO'; + ERROR_MISSING_PARAMETER: 'ERROR_MISSING_PARAMETER'; + ERROR_NO_AD_AVAILABLE: 'ERROR_NO_AD_AVAILABLE'; + ERROR_NULL_ASSET: 'ERROR_NULL_ASSET'; + ERROR_PARSE: 'ERROR_PARSE'; + ERROR_TIMEOUT: 'ERROR_TIMEOUT'; + ERROR_UNKNOWN: 'ERROR_UNKNOWN'; + ERROR_UNMATCHED_SLOT_SIZE: 'ERROR_UNMATCHED_SLOT_SIZE'; + ERROR_UNSUPPORTED_3P_FEATURE: 'ERROR_UNSUPPORTED_3P_FEATURE'; + }; + Events: { + AD_ATTEMPTED: 'Conviva.AdAttempted'; + AD_CLOSE: 'Conviva.AdClose'; + AD_COMPLETE: 'Conviva.AdComplete'; + AD_END: 'Conviva.AdEnd'; + AD_ERROR: 'Conviva.AdError'; + AD_FIRST_QUARTILE: 'Conviva.AdFirstQuartile'; + AD_IMPRESSION_END: 'Conviva.AdImpressionEnd'; + AD_IMPRESSION_START: 'Conviva.AdImpression'; + AD_MID_QUARTILE: 'Conviva.AdMidQuartile'; + AD_PROGRESS: 'Conviva.AdProgress'; + AD_REQUESTED: 'Conviva.AdRequested'; + AD_RESPONSE: 'Conviva.AdResponse'; + AD_SKIPPED: 'Conviva.AdSkipped'; + AD_SLOT_ENDED: 'Conviva.SlotEnded'; + AD_SLOT_STARTED: 'Conviva.SlotStarted'; + AD_START: 'Conviva.AdStart'; + AD_THIRD_QUARTILE: 'Conviva.AdThirdQuartile'; + BUMPER_VIDEO_ENDED: 'Conviva.BumperVideoEnded'; + BUMPER_VIDEO_STARTED: 'Conviva.BumperVideoStarted'; + CONTENT_PAUSED: 'Conviva.PauseContent'; + CONTENT_RESUMED: 'Conviva.ResumeContent'; + POD_END: 'Conviva.PodEnd'; + POD_START: 'Conviva.PodStart'; + USER_WAIT_ENDED: 'Conviva.UserWaitEnded'; + USER_WAIT_STARTED: 'Conviva.UserWaitStarted'; + }; + FRAMEWORK_NAME: ConvivaKeys.FRAMEWORK_NAME; + FRAMEWORK_VERSION: ConvivaKeys.FRAMEWORK_VERSION; + GATEWAY_URL: ConvivaKeys.GATEWAY_URL; + IMASDK_CONTENT_PLAYER: ConvivaKeys.IMASDK_CONTENT_PLAYER; + IS_LIVE: ConvivaKeys.IS_LIVE; + LOG_LEVEL: ConvivaKeys.LOG_LEVEL; + LogLevel: { + DEBUG: 0; + INFO: 1; + WARNING: 2; + ERROR: 3; + NONE: 4; + }; + MEDIA_ELEMENT: ConvivaKeys.MEDIA_ELEMENT; + MODULE_NAME: string; + MODULE_VERSION: string; + Network: { + CONNECTION_TYPE: 'CONNECTION_TYPE'; + LINK_ENCRYPTION: 'LINK_ENCRYPTION'; + SIGNAL_STRENGTH: 'SIGNAL_STRENGTH'; + }; + NO_SESSION_KEY: number; + PLAYER_NAME: ConvivaKeys.PLAYER_NAME; + POD_DURATION: ConvivaKeys.POD_DURATION; + POD_INDEX: ConvivaKeys.POD_INDEX; + POD_POSITION: ConvivaKeys.POD_POSITION; + Playback: { + BITRATE: 'BITRATE'; + AVG_BITRATE: 'AVG_BITRATE'; + PLAY_HEAD_TIME: 'PLAY_HEAD_TIME'; + RESOLUTION: 'RESOLUTION'; + BUFFER_LENGTH: 'BUFFER_LENGTH'; + PLAYER_STATE: 'PLAYER_STATE'; + RENDERED_FRAMERATE: 'RENDERED_FRAMERATE'; + SEEK_STARTED: 'SEEK_STARTED'; + SEEK_ENDED: 'SEEK_ENDED'; + CDN_IP: 'CDN_IP'; + DROPPED_FRAMES_TOTAL: 'DROPPED_FRAMES_TOTAL'; + DROPPED_FRAMES_COUNT: 'DROPPED_FRAMES_COUNT'; + AUDIO_LANGUAGE: 'AUDIO_LANGUAGE'; + SUBTITLES_LANGUAGE: 'SUBTITLES_LANGUAGE'; + CLOSED_CAPTIONS_LANGUAGE: 'CLOSED_CAPTIONS_LANGUAGE'; + }; + PlayerState: { + BUFFERING: ConvivaKeys.BUFFERING; + NOT_MONITORED: ConvivaKeys.NOT_MONITORED; + PAUSED: ConvivaKeys.PAUSED; + PLAYING: ConvivaKeys.PLAYING; + STOPPED: ConvivaKeys.STOPPED; + UNKNOWN: ConvivaKeys.UNKNOWN; + }; + STREAM_URL: ConvivaKeys.STREAM_URL; + StreamType: { + UNKNOWN: 'UNKNOWN'; + VOD: 'VOD'; + LIVE: 'LIVE'; + }; + VIEWER_ID: ConvivaKeys.VIEWER_ID; + version: string; + } + + const Constants: ConvivaConstants; +} diff --git a/@types/conviva/ConvivaExtension.d.ts b/@types/conviva/ConvivaExtension.d.ts new file mode 100644 index 0000000..5334756 --- /dev/null +++ b/@types/conviva/ConvivaExtension.d.ts @@ -0,0 +1,83 @@ +/** + * The following properties exist in the `window.Conviva` object but they are missing + * in types of `conviva-core-sdk` package for some reason, so let's add them manually. + */ + +declare module Conviva { + class ContentMetadata { + public static readonly StreamType: Conviva.ConvivaConstants['StreamType'] + public applicationName: string; + public assetName: string; + public custom: {}; + public defaultResource: string; + public duration: number; + public encodedFrameRate: number; + public streamType: Conviva.valueof; + public streamUrl: string; + public viewerId: string; + } + + interface LoggingInterface { + consoleLog(message: string, logLevel: Conviva.valueof): void; + + release(): void; + } + + class SystemSettings { + public static readonly LogLevel: Conviva.ConvivaConstants['LogLevel']; + public allowUncaughtExceptions: boolean; + public httpTimeout: number; + public logLevel: Conviva.valueof; + public storageTimeout: number; + } + + interface TimeInterface { + getEpochTimeMs(): number; + + release(): void; + } + + type TimerAction = () => void; + + type TimerCancelFunction = () => void; + + interface TimerInterface { + createTimer(timerAction: TimerAction, intervalMs: number, actionName?: string | null): TimerCancelFunction; + + release(): void; + } + + type HttpRequestCancelFunction = () => void; + + type HttpRequestCallback = (succeeded: boolean, data: string) => void; + + interface HttpInterface { + makeRequest( + httpMethod: 'GET' | 'POST', + url: string, + data: string | null, + contentType: string | null, + timeoutMs: number, + callback: HttpRequestCallback | null, + ): HttpRequestCancelFunction; + + release(): void; + } + + type StorageLoadDataCallback = (succeeded: boolean, data: string | null) => void; + + type StorageSaveDataCallback = (succeeded: boolean, data: string | null) => void; + + interface StorageInterface { + loadData(storageSpace: string, storageKey: string, callback: StorageLoadDataCallback): void; + + saveData(storageSpace: string, storageKey: string, data: string, callback: StorageSaveDataCallback): void; + + release(): void; + } + + interface VideoAnalytics { + reportAppEvent(eventType: string, eventDetail: { [key: string]: string }): void; + getSessionId(): number; + } +} diff --git a/@types/conviva/index.d.ts b/@types/conviva/index.d.ts new file mode 100644 index 0000000..d451674 --- /dev/null +++ b/@types/conviva/index.d.ts @@ -0,0 +1,2 @@ +import './Conviva' +import './ConvivaExtension' diff --git a/CHANGELOG.md b/CHANGELOG.md index 879d3b6..6b1bd84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Changed +- Updated Conviva types to the latest version and fixed some type issues + +### Deprecated +- Removed `framework` and `frameworkVersion` custom metadata fields (custom tags) + ## 4.2.0 - 2023-08-24 ### Added - Support for Conviva-SDK version 4.7.0 diff --git a/example/conviva-core-sdk.d.ts b/example/conviva-core-sdk.d.ts index 5cefb06..df0c6b4 100644 --- a/example/conviva-core-sdk.d.ts +++ b/example/conviva-core-sdk.d.ts @@ -1,3 +1,7 @@ +/** + * Definitions are copied from `conviva-core-sdk` package. + */ + export type valueof = T[keyof T]; declare enum ConvivaKeys { @@ -164,7 +168,9 @@ export interface ConvivaPlayerInfo { } export interface ConvivaPlayerExtraListeners { - [ConvivaKeys.MEDIA_ELEMENT]: object; + [Constants.MEDIA_ELEMENT]?: object; + [Constants.CONVIVA_MODULE]?: object; + [Constants.CONVIVA_AD_MODULE]?: object; } export interface ConvivaAdBreakInfo { diff --git a/package-lock.json b/package-lock.json index 29e79c4..324782c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,9 +20,9 @@ "prettier": "^2.8.8", "string-replace-loader": "^2.1.1", "ts-jest": "^23.10.5", - "ts-loader": "^5.3.1", + "ts-loader": "^8.4.0", "tslint": "^5.11.0", - "typescript": "^3.2.2", + "typescript": "^4.9.5", "webpack": "^4.27.1", "webpack-cli": "^3.1.2", "webpack-dev-server": "^3.10.3", @@ -10074,19 +10074,189 @@ } }, "node_modules/ts-loader": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/ts-loader/-/ts-loader-5.3.1.tgz", - "integrity": "sha512-fDDgpBH3SR8xlt2MasLdz3Yy611PQ/UY/KGyo7TgXhTRU/6sS8uGG0nJYnU1OdFBNKcoYbId1UTNaAOUn+i41g==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/ts-loader/-/ts-loader-8.4.0.tgz", + "integrity": "sha512-6nFY3IZ2//mrPc+ImY3hNWx1vCHyEhl6V+wLmL4CZcm6g1CqX7UKrkc6y0i4FwcfOhxyMPCfaEvh20f4r9GNpw==", "dev": true, "dependencies": { - "chalk": "^2.3.0", + "chalk": "^4.1.0", "enhanced-resolve": "^4.0.0", - "loader-utils": "^1.0.2", - "micromatch": "^3.1.4", - "semver": "^5.0.1" + "loader-utils": "^2.0.0", + "micromatch": "^4.0.0", + "semver": "^7.3.4" }, "engines": { - "node": ">=6.11.5" + "node": ">=10.0.0" + }, + "peerDependencies": { + "typescript": "*", + "webpack": "*" + } + }, + "node_modules/ts-loader/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/ts-loader/node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/ts-loader/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/ts-loader/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/ts-loader/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/ts-loader/node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/ts-loader/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/ts-loader/node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/ts-loader/node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/ts-loader/node_modules/loader-utils": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz", + "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==", + "dev": true, + "dependencies": { + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^2.1.2" + }, + "engines": { + "node": ">=8.9.0" + } + }, + "node_modules/ts-loader/node_modules/micromatch": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "dev": true, + "dependencies": { + "braces": "^3.0.2", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=8.6" + } + }, + "node_modules/ts-loader/node_modules/semver": { + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", + "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/ts-loader/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/ts-loader/node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" } }, "node_modules/tslib": { @@ -10198,9 +10368,9 @@ "dev": true }, "node_modules/typescript": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.2.2.tgz", - "integrity": "sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -19250,16 +19420,133 @@ } }, "ts-loader": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/ts-loader/-/ts-loader-5.3.1.tgz", - "integrity": "sha512-fDDgpBH3SR8xlt2MasLdz3Yy611PQ/UY/KGyo7TgXhTRU/6sS8uGG0nJYnU1OdFBNKcoYbId1UTNaAOUn+i41g==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/ts-loader/-/ts-loader-8.4.0.tgz", + "integrity": "sha512-6nFY3IZ2//mrPc+ImY3hNWx1vCHyEhl6V+wLmL4CZcm6g1CqX7UKrkc6y0i4FwcfOhxyMPCfaEvh20f4r9GNpw==", "dev": true, "requires": { - "chalk": "^2.3.0", + "chalk": "^4.1.0", "enhanced-resolve": "^4.0.0", - "loader-utils": "^1.0.2", - "micromatch": "^3.1.4", - "semver": "^5.0.1" + "loader-utils": "^2.0.0", + "micromatch": "^4.0.0", + "semver": "^7.3.4" + }, + "dependencies": { + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "requires": { + "fill-range": "^7.0.1" + } + }, + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, + "json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true + }, + "loader-utils": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz", + "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==", + "dev": true, + "requires": { + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^2.1.2" + } + }, + "micromatch": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "dev": true, + "requires": { + "braces": "^3.0.2", + "picomatch": "^2.3.1" + } + }, + "semver": { + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", + "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", + "dev": true + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + } } }, "tslib": { @@ -19350,9 +19637,9 @@ "dev": true }, "typescript": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.2.2.tgz", - "integrity": "sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "dev": true }, "uglify-js": { diff --git a/package.json b/package.json index b6d68a5..4fabcf0 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,8 @@ "clean": "rm -rf ./dist", "build": "npm run build:describe && npm run lint && npm run clean && npm run build:lib && npm run build:bundle", "build:describe": "echo \"Building Player Integration...\"", - "build:lib": "./node_modules/.bin/tsc --module commonjs --outDir ./dist/lib --declaration", - "build:esm": "./node_modules/.bin/tsc --module es6 --outDir ./dist/lib-esm --declaration", + "build:lib": "./node_modules/.bin/tsc -p ./tsconfig.build.json --module commonjs --outDir ./dist/lib --declaration", + "build:esm": "./node_modules/.bin/tsc -p ./tsconfig.build.json --module es6 --outDir ./dist/lib-esm --declaration", "build:bundle": "./node_modules/.bin/webpack --config webpack.prod.js", "test": "./node_modules/.bin/jest", "prepublishOnly": "npm run build" @@ -40,9 +40,9 @@ "prettier": "^2.8.8", "string-replace-loader": "^2.1.1", "ts-jest": "^23.10.5", - "ts-loader": "^5.3.1", + "ts-loader": "^8.4.0", "tslint": "^5.11.0", - "typescript": "^3.2.2", + "typescript": "^4.9.5", "webpack": "^4.27.1", "webpack-cli": "^3.1.2", "webpack-dev-server": "^3.10.3", diff --git a/spec/helper/MockHelper.ts b/spec/helper/MockHelper.ts index d6da90f..b7aa5d5 100644 --- a/spec/helper/MockHelper.ts +++ b/spec/helper/MockHelper.ts @@ -1,4 +1,3 @@ -/// import { PlayerEvent } from './PlayerEvent'; import { AdBreakEvent, @@ -359,8 +358,8 @@ class PlayerEventHelper implements EventEmitter { type: PlayerEvent.AdSkipped, ad: { isLinear: true, - width: null, - height: null, + width: 0, + height: 0, }, }); } @@ -371,8 +370,8 @@ class PlayerEventHelper implements EventEmitter { type: PlayerEvent.AdStarted, ad: { isLinear: true, - width: null, - height: null, + width: 0, + height: 0, }, }); } @@ -461,14 +460,14 @@ class PlayerEventHelper implements EventEmitter { sourceQuality: { id: '1', bitrate: 250_000, - width: null, - height: null, + width: 0, + height: 0, }, targetQuality: { id: '2', bitrate: bitrate, - width: null, - height: null, + width: 0, + height: 0, }, }); } diff --git a/spec/tests/ContentMetadata.spec.ts b/spec/tests/ContentMetadata.spec.ts index 36e756b..2d13f45 100644 --- a/spec/tests/ContentMetadata.spec.ts +++ b/spec/tests/ContentMetadata.spec.ts @@ -1,4 +1,3 @@ -/// import { PlayerType, StreamType, VRContentType } from 'bitmovin-player'; import { ConvivaAnalytics } from '../../src/ts'; import { MockHelper, TestingPlayerAPI } from '../helper/MockHelper'; @@ -8,7 +7,7 @@ jest.mock('../../src/ts/Html5Logging'); describe('content metadata spec', () => { let convivaAnalytics: ConvivaAnalytics; let playerMock: TestingPlayerAPI; - let convivaVideoAnalytics: Conviva.ConvivaVideoAnalytics; + let convivaVideoAnalytics: Conviva.VideoAnalytics; beforeEach(() => { MockHelper.mockConviva(); @@ -134,7 +133,7 @@ describe('content metadata spec', () => { describe('externally content metadata updates', () => { describe('before playback started (with init session event)', () => { beforeEach(() => { - jest.spyOn(playerMock, 'getSource').mockReturnValue(undefined); + jest.spyOn(playerMock, 'getSource').mockReturnValue(null); }); describe('it does create session with', () => { diff --git a/spec/tests/ExternalSessionManaging.spec.ts b/spec/tests/ExternalSessionManaging.spec.ts index cf7ac9d..ae2e3b6 100644 --- a/spec/tests/ExternalSessionManaging.spec.ts +++ b/spec/tests/ExternalSessionManaging.spec.ts @@ -6,7 +6,7 @@ jest.mock('../../src/ts/Html5Logging'); describe('externally session managing', () => { let convivaAnalytics: ConvivaAnalytics; let playerMock: TestingPlayerAPI; - let convivaVideoAnalyticsMock: Conviva.ConvivaVideoAnalytics; + let convivaVideoAnalyticsMock: Conviva.VideoAnalytics; beforeEach(() => { MockHelper.mockConviva(); @@ -25,7 +25,7 @@ describe('externally session managing', () => { describe('before loading source', () => { beforeEach(() => { - jest.spyOn(playerMock, 'getSource').mockReturnValue(undefined); + jest.spyOn(playerMock, 'getSource').mockReturnValue(null); }); it('throw without asset name initialize session', () => { diff --git a/spec/tests/PlayerEvents.spec.ts b/spec/tests/PlayerEvents.spec.ts index cba66a9..20e72fe 100644 --- a/spec/tests/PlayerEvents.spec.ts +++ b/spec/tests/PlayerEvents.spec.ts @@ -1,12 +1,10 @@ -/// - import { MockHelper, TestingPlayerAPI } from '../helper/MockHelper'; import { ConvivaAnalytics } from '../../src/ts'; describe('player event tests', () => { let convivaAnalytics: ConvivaAnalytics; let playerMock: TestingPlayerAPI; - let convivaVideoAnalytics: Conviva.ConvivaVideoAnalytics; + let convivaVideoAnalytics: Conviva.VideoAnalytics; beforeEach(() => { MockHelper.mockConviva(); @@ -242,7 +240,6 @@ describe('player event tests', () => { expect(convivaVideoAnalytics.reportAdBreakStarted).toHaveBeenCalledWith( Conviva.Constants.AdType.CLIENT_SIDE, Conviva.Constants.AdPlayer.SEPARATE, - Conviva.Constants.AdPosition.PREROLL, ); }); @@ -253,7 +250,6 @@ describe('player event tests', () => { expect(convivaVideoAnalytics.reportAdBreakStarted).toHaveBeenCalledWith( Conviva.Constants.AdType.CLIENT_SIDE, Conviva.Constants.AdPlayer.SEPARATE, - Conviva.Constants.AdPosition.MIDROLL, ); }); diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index 2eb5b05..938b958 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -1,10 +1,16 @@ +type NoStringIndex = { [K in keyof T as string extends K ? never : K]: T[K] }; + +type ReservedContentMetadata = NoStringIndex; + +export type CustomContentMetadata = { [key: string]: string }; + export interface Metadata { // Can only be set once assetName?: string; // Can only be set before playback started viewerId?: string; - streamType?: Conviva.ContentMetadata.StreamType; + streamType?: Conviva.valueof; applicationName?: string; custom?: CustomContentMetadata; duration?: number; @@ -17,14 +23,6 @@ export interface Metadata { frameworkVersion?: string; } -export interface ConvivaMetadata { - [key: string]: string | number; -} - -export interface CustomContentMetadata { - [key: string]: string; -} - export class ContentMetadataBuilder { private readonly logger: Conviva.LoggingInterface; private contentMetadata: Conviva.ContentMetadata; @@ -62,7 +60,7 @@ export class ContentMetadataBuilder { this.playbackStarted = value; } - build(): ConvivaMetadata { + build(): Conviva.ConvivaMetadata { if (!this.playbackStarted) { // Asset name is only allowed to be set once if (!this.contentMetadata.assetName) { @@ -73,8 +71,6 @@ export class ContentMetadataBuilder { this.contentMetadata.streamType = this.metadataOverrides.streamType || this.metadata.streamType; this.contentMetadata.applicationName = this.metadataOverrides.applicationName || this.metadata.applicationName; this.contentMetadata.duration = this.metadataOverrides.duration || this.metadata.duration; - this.contentMetadata.framework = this.metadataOverrides.framework || this.metadata.framework; - this.contentMetadata.frameworkVersion = this.metadataOverrides.frameworkVersion || this.metadata.frameworkVersion; this.contentMetadata.custom = this.custom; } @@ -83,20 +79,21 @@ export class ContentMetadataBuilder { this.contentMetadata.defaultResource = this.metadataOverrides.defaultResource || this.metadata.defaultResource; this.contentMetadata.streamUrl = this.metadataOverrides.streamUrl || this.metadata.streamUrl; - const convivaContentInfo = {} as ConvivaMetadata; - convivaContentInfo[Conviva.Constants.ASSET_NAME] = this.contentMetadata.assetName; - convivaContentInfo[Conviva.Constants.ENCODED_FRAMERATE] = this.contentMetadata.encodedFrameRate; - convivaContentInfo[Conviva.Constants.DURATION] = this.contentMetadata.duration; - convivaContentInfo[Conviva.Constants.DEFAULT_RESOURCE] = this.contentMetadata.defaultResource; - convivaContentInfo[Conviva.Constants.STREAM_URL] = this.contentMetadata.streamUrl; - convivaContentInfo[Conviva.Constants.IS_LIVE] = this.contentMetadata.streamType; - convivaContentInfo[Conviva.Constants.VIEWER_ID] = this.contentMetadata.viewerId || 'GET_VIEWER_ID_FROM_PLAYER'; - convivaContentInfo[Conviva.Constants.PLAYER_NAME] = - this.contentMetadata.applicationName || 'GET_PLAYER_NAME_OR_TYPE'; - convivaContentInfo[Conviva.Constants.FRAMEWORK_NAME] = this.contentMetadata.framework; - convivaContentInfo[Conviva.Constants.FRAMEWORK_VERSION] = this.contentMetadata.frameworkVersion; + const convivaContentInfo: ReservedContentMetadata = { + [Conviva.Constants.ASSET_NAME]: this.contentMetadata.assetName, + [Conviva.Constants.ENCODED_FRAMERATE]: this.contentMetadata.encodedFrameRate, + [Conviva.Constants.DURATION]: this.contentMetadata.duration, + [Conviva.Constants.DEFAULT_RESOURCE]: this.contentMetadata.defaultResource, + [Conviva.Constants.STREAM_URL]: this.contentMetadata.streamUrl, + [Conviva.Constants.IS_LIVE]: this.contentMetadata.streamType, + [Conviva.Constants.VIEWER_ID]: this.contentMetadata.viewerId || 'GET_VIEWER_ID_FROM_PLAYER', + [Conviva.Constants.PLAYER_NAME]: this.contentMetadata.applicationName || 'GET_PLAYER_NAME_OR_TYPE', + }; - return { ...convivaContentInfo, ...this.contentMetadata.custom }; + return { + ...convivaContentInfo, + ...this.contentMetadata.custom, + } as Conviva.ConvivaMetadata; } // These methods should be treated as package private @@ -116,7 +113,7 @@ export class ContentMetadataBuilder { return this.metadataOverrides.viewerId || this.metadata.viewerId; } - set streamType(newValue: Conviva.ContentMetadata.StreamType) { + set streamType(newValue: Conviva.valueof) { this.metadata.streamType = newValue; } diff --git a/src/ts/Conviva.d.ts b/src/ts/Conviva.d.ts deleted file mode 100644 index 6a5a83e..0000000 --- a/src/ts/Conviva.d.ts +++ /dev/null @@ -1,328 +0,0 @@ -declare namespace Conviva { - namespace Constants { - enum AdPlayer { - CONTENT, - SEPARATE, - } - - enum AdPosition { - PREROLL, - MIDROLL, - POSTROLL, - } - - enum AdStream { - CONTENT, - SEPARATE, - } - - enum DeviceType { - DESKTOP, - CONSOLE, - SETTOP, - MOBILE, - TABLET, - SMARTTV, - UNKNOWN, - } - - enum DeviceCategory { - ANDROID_DEVICE, - APPLE_DEVICE, - CHROMECAST, - DESKTOP_APP, - DEVICE_SIMULATOR, - LG_TV, - NINTENDO, - PLAYSTATION, - ROKU, - SAMSUNG_TV, - SET_TOP_BOX, - SMART_TV, - TIVO, - WEB, - WINDOWS_DEVICE, - XBOX, - } - - enum ErrorSeverity { - FATAL, - WARNING, - } - - enum CallbackFunctions { - CONSOLE_LOG, - MAKE_REQUEST, - SAVE_DATA, - LOAD_DATA, - CREATE_TIMER, - GET_EPOCH_TIME_IN_MS, - } - - enum Playback { - AUDIO_LANGUAGE, - BITRATE, - BUFFER_LENGTH, - CDN_IP, - CLOSED_CAPTIONS_LANGUAGE, - PLAYER_STATE, - PLAY_HEAD_TIME, - RENDERED_FRAMERATE, - RESOLUTION, - SEEK_ENDED, - SEEK_STARTED, - SUBTITLES_LANGUAGE, - } - - enum Network { - CONNECTION_TYPE, - LINK_ENCRYPTION, - SIGNAL_STRENGTH, - } - - enum PlayerState { - STOPPED, - PLAYING, - BUFFERING, - PAUSED, - UNKNOWN, - NOT_MONITORED, - } - - const NO_SESSION_KEY: number; - - const version: string; - - const GATEWAY_URL: string; - - const LOG_LEVEL: string; - - const ASSET_NAME: string; - - const PLAYER_NAME: string; - - const ENCODED_FRAMERATE: string; - - const DURATION: string; - - const DEFAULT_RESOURCE: string; - - const STREAM_URL: string; - - const IS_LIVE: string; - - const VIEWER_ID: string; - - const FRAMEWORK_NAME: string; - - const FRAMEWORK_VERSION: string; - - enum LogLevel { - DEBUG, - INFO, - WARNING, - ERROR, - NONE, - } - - enum StreamType { - UNKNOWN, - LIVE, - VOD, - } - - enum AdType { - CLIENT_SIDE, - SERVER_SIDE, - } - - enum DeviceMetadata { - BRAND, - CATEGORY, - MANUFACTURER, - MODEL, - OS_NAME, - OS_VERSION, - TYPE, - VERSION, - } - } - - type DeviceMetadata = { - [key: string]: Conviva.Constants.DeviceCategory | Conviva.Constants.DeviceType | string; - }; - - class Analytics { - public static init( - customerKey: string, - callbackFunctions: any, - settings?: { [key: string]: string | number }, - ): void; - public static buildVideoAnalytics(): Conviva.ConvivaVideoAnalytics; - public static setDeviceMetadata(metadata: DeviceMetadata): Conviva.Constants.DeviceCategory; - public static release(): void; - } - - interface ConvivaVideoAnalytics { - reportPlaybackRequested(contentInfo?: { [key: string]: number | string }): void; - - reportPlaybackFailed(errorMessage: string, contentInfo?: { [key: string]: number | string }): void; - - reportPlaybackEnded(): void; - - setContentInfo(contentInfo: { [key: string]: number | string }): void; - - setPlayerInfo(playerInfo: { [key: string]: number | string }): void; - - reportPlaybackMetric( - event: Conviva.Constants.Playback | Conviva.Constants.PlayerState, - value?: string | number, - ): void; - - reportDeviceMetric(metric: Conviva.Constants.Network, value?: string | number): void; - - reportAdBreakStarted( - adType: Conviva.Constants.AdType, - adPlayer: Conviva.Constants.AdPlayer, - position?: Conviva.Constants.AdPosition, - ): void; - - reportAdBreakEnded(): void; - - reportPlaybackEvent(eventType: string, eventDetail: { [key: string]: string }): void; - - reportAppEvent(eventType: string, eventDetail: { [key: string]: string }): void; - - setCallback(callback: Function): void; - - getSessionId(): number; - - release(): void; - } - - class ClientSettings { - public customerKey: string; - public gatewayUrl: string; - public heartbeatInterval: number; - - constructor(customerKey: string); - } - - namespace ContentMetadata { - enum StreamType { - UNKNOWN, - LIVE, - VOD, - } - } - - class ContentMetadata { - public applicationName: string; - public assetName: string; - public custom: {}; - public defaultResource: string; - public duration: number; - public encodedFrameRate: number; - public streamType: ContentMetadata.StreamType; - public streamUrl: string; - public viewerId: string; - public frameworkVersion: string; - public framework: string; - } - - type HttpRequestCancelFunction = () => void; - - type HttpRequestCallback = (succeeded: boolean, data: string) => void; - - interface HttpInterface { - makeRequest( - httpMethod: 'GET' | 'POST', - url: string, - data: string | null, - contentType: string | null, - timeoutMs: number, - callback: HttpRequestCallback | null, - ): HttpRequestCancelFunction; - - release(): void; - } - - interface LoggingInterface { - consoleLog(message: string, logLevel: SystemSettings.LogLevel): void; - - release(): void; - } - - interface MetadataInterface { - getBrowserName(): string | null; - - getBrowserVersion(): string | null; - - getDeviceBrand(): string | null; - - getDeviceManufacturer(): string | null; - - getDeviceModel(): string | null; - - getDeviceType(): Constants.DeviceType; - - getDeviceVersion(): string | null; - - getFrameworkName(): string | null; - - getFrameworkVersion(): string | null; - - getOperatingSystemName(): string | null; - - getOperatingSystemVersion(): string | null; - - getDeviceCategory(): Constants.DeviceCategory | null; - - release(): void; - } - - type StorageLoadDataCallback = (succeeded: boolean, data: string | null) => void; - - type StorageSaveDataCallback = (succeeded: boolean, data: string | null) => void; - - interface StorageInterface { - loadData(storageSpace: string, storageKey: string, callback: StorageLoadDataCallback): void; - - saveData(storageSpace: string, storageKey: string, data: string, callback: StorageSaveDataCallback): void; - - release(): void; - } - - namespace SystemSettings { - enum LogLevel { - DEBUG, - INFO, - WARNING, - ERROR, - NONE, - } - } - - class SystemSettings { - public allowUncaughtExceptions: boolean; - public httpTimeout: number; - public logLevel: SystemSettings.LogLevel; - public storageTimeout: number; - } - - interface TimeInterface { - getEpochTimeMs(): number; - - release(): void; - } - - type TimerAction = () => void; - - type TimerCancelFunction = () => void; - - interface TimerInterface { - createTimer(timerAction: TimerAction, intervalMs: number, actionName?: string | null): TimerCancelFunction; - - release(): void; - } -} diff --git a/src/ts/ConvivaAnalytics.ts b/src/ts/ConvivaAnalytics.ts index d994d33..5fad371 100644 --- a/src/ts/ConvivaAnalytics.ts +++ b/src/ts/ConvivaAnalytics.ts @@ -47,7 +47,7 @@ export interface ConvivaAnalyticsConfiguration { * user agent string parsing by the Conviva SDK. (default: WEB) * @deprecated Use `deviceMetadata.category` field */ - deviceCategory?: Conviva.Constants.DeviceCategory; + deviceCategory?: Conviva.valueof; /** * Option to override the Conviva Device Metadata. @@ -59,7 +59,7 @@ export interface ConvivaAnalyticsConfiguration { * user agent string parsing by the Conviva SDK. * (default: The same specified in config.deviceCategory) */ - category?: Conviva.Constants.DeviceCategory; + category?: Conviva.valueof; /** * Option to override the Conviva Device Brand. @@ -83,7 +83,7 @@ export interface ConvivaAnalyticsConfiguration { * Option to override the Conviva Device Type * (Default: Auto extract from User Agent string) */ - type?: Conviva.Constants.DeviceType; + type?: Conviva.valueof; /** * Option to override the Conviva Device Version. @@ -121,7 +121,7 @@ export class ConvivaAnalytics { private readonly logger: Conviva.LoggingInterface; private sessionKey: number; - private convivaVideoAnalytics: Conviva.ConvivaVideoAnalytics; + private convivaVideoAnalytics: Conviva.VideoAnalytics; /** * Tracks the ad playback status and is true between ON_AD_STARTED and ON_AD_FINISHED/SKIPPED/ERROR. @@ -332,7 +332,7 @@ export class ConvivaAnalytics { */ public reportPlaybackDeficiency( message: string, - severity: Conviva.Constants.ErrorSeverity, + severity: Conviva.valueof, endSession: boolean = true, ) { if (!this.isSessionActive()) { @@ -354,7 +354,6 @@ export class ConvivaAnalytics { this.convivaVideoAnalytics.reportAdBreakStarted( Conviva.Constants.AdType.CLIENT_SIDE, Conviva.Constants.AdPlayer.SEPARATE, - Conviva.Constants.AdPosition.PREROLL, ); this.debugLog('Tracking paused.'); } @@ -696,7 +695,6 @@ export class ConvivaAnalytics { this.convivaVideoAnalytics.reportAdBreakStarted( Conviva.Constants.AdType.CLIENT_SIDE, Conviva.Constants.AdPlayer.SEPARATE, - adPosition, ); }; diff --git a/src/ts/Html5Logging.ts b/src/ts/Html5Logging.ts index 212e8c4..63d7ef4 100644 --- a/src/ts/Html5Logging.ts +++ b/src/ts/Html5Logging.ts @@ -1,7 +1,7 @@ import SystemSettings = Conviva.SystemSettings; export class Html5Logging implements Conviva.LoggingInterface { - public consoleLog(message: string, logLevel: SystemSettings.LogLevel): void { + public consoleLog(message: string, logLevel: Conviva.valueof): void { if (typeof console === 'undefined') { return; } diff --git a/src/ts/helper/AdBreakHelper.ts b/src/ts/helper/AdBreakHelper.ts index e57d24d..68f449c 100644 --- a/src/ts/helper/AdBreakHelper.ts +++ b/src/ts/helper/AdBreakHelper.ts @@ -1,7 +1,10 @@ import { AdBreak, PlayerAPI } from 'bitmovin-player'; export class AdBreakHelper { - public static mapAdPosition(adBreak: AdBreak, player: PlayerAPI): Conviva.Constants.AdPosition { + public static mapAdPosition( + adBreak: AdBreak, + player: PlayerAPI, + ): Conviva.valueof { if (adBreak.scheduleTime <= 0) { return Conviva.Constants.AdPosition.PREROLL; } diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..deeb670 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "files": [ + "./src/ts/index.ts" + ], + "include": [ + "./src" + ] +} diff --git a/tsconfig.json b/tsconfig.json index 34306d9..cf75d14 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,4 @@ { - "files": [ - "src/ts/index.ts" - ], "compilerOptions": { "outDir": "./dist", "target": "es5", @@ -10,9 +7,7 @@ "lib": ["es2015", "dom"], "sourceMap": true, "noImplicitAny": true, - "removeComments": false - }, - "include": [ - "./src" - ] + "removeComments": false, + "types": ["./@types/conviva", "jest"], + } } diff --git a/webpack.common.js b/webpack.common.js index eb91d99..5ad17ba 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -8,8 +8,13 @@ module.exports = { rules: [ { test: /\.tsx?$/, - use: 'ts-loader', - exclude: /node_modules/ + use: { + loader: 'ts-loader', + options: { + configFile: 'tsconfig.build.json' + } + }, + exclude: /node_modules/, }, { test: /\.tsx?$/,