From c088ab6456feb33659fa206898da3092624d86db Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Thu, 16 May 2024 16:02:16 +0400 Subject: [PATCH 01/25] Expose extended types --- @types/conviva/Conviva.d.ts | 456 ------------------ @types/conviva/index.d.ts | 2 - example/conviva-core-sdk.d.ts | 454 ----------------- package-lock.json | 13 + package.json | 1 + src/ts/ContentMetadataBuilder.ts | 83 ++-- src/ts/ConvivaAnalytics.ts | 15 +- src/ts/Html5Http.ts | 11 +- src/ts/Html5Logging.ts | 2 +- src/ts/Html5Storage.ts | 7 +- src/ts/Html5Time.ts | 2 + src/ts/Html5Timer.ts | 5 +- .../ts/conviva/ConvivaExtension.ts | 36 +- src/ts/helper/AdBreakHelper.ts | 1 + src/ts/index.ts | 6 +- tsconfig.json | 2 +- webpack.common.js | 1 + 17 files changed, 97 insertions(+), 1000 deletions(-) delete mode 100644 @types/conviva/Conviva.d.ts delete mode 100644 @types/conviva/index.d.ts delete mode 100644 example/conviva-core-sdk.d.ts rename @types/conviva/ConvivaExtension.d.ts => src/ts/conviva/ConvivaExtension.ts (66%) diff --git a/@types/conviva/Conviva.d.ts b/@types/conviva/Conviva.d.ts deleted file mode 100644 index 0d4bc16..0000000 --- a/@types/conviva/Conviva.d.ts +++ /dev/null @@ -1,456 +0,0 @@ -/** - * 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/index.d.ts b/@types/conviva/index.d.ts deleted file mode 100644 index d451674..0000000 --- a/@types/conviva/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import './Conviva' -import './ConvivaExtension' diff --git a/example/conviva-core-sdk.d.ts b/example/conviva-core-sdk.d.ts deleted file mode 100644 index df0c6b4..0000000 --- a/example/conviva-core-sdk.d.ts +++ /dev/null @@ -1,454 +0,0 @@ -/** - * Definitions are copied from `conviva-core-sdk` package. - */ - -export type valueof = T[keyof T]; - -declare 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', -} - -export 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; -} - -export interface ConvivaOptions { - [ConvivaKeys.LOG_LEVEL]?: number; - [ConvivaKeys.GATEWAY_URL]?: string; -} - -export 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; -} - -export interface ConvivaPlayerInfo { - [ConvivaKeys.FRAMEWORK_NAME]?: string; - [ConvivaKeys.FRAMEWORK_VERSION]?: string; -} - -export interface ConvivaPlayerExtraListeners { - [Constants.MEDIA_ELEMENT]?: object; - [Constants.CONVIVA_MODULE]?: object; - [Constants.CONVIVA_AD_MODULE]?: object; -} - -export interface ConvivaAdBreakInfo { - [ConvivaKeys.POD_POSITION]?: string; - [ConvivaKeys.POD_DURATION]?: number; - [ConvivaKeys.POD_INDEX]?: number; -} - -export interface ConvivaAdListenerInfo { - [ConvivaKeys.AD_TAG_URL]?: string; - [ConvivaKeys.AD_PRELOAD_FEATURE]?: boolean; - [ConvivaKeys.IMASDK_CONTENT_PLAYER]: object; -} - -export 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 - -export 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; -} - -export 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; -} - -export 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 -} - -export 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; -} - -export const Constants: ConvivaConstants; diff --git a/package-lock.json b/package-lock.json index 324782c..10840cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,7 @@ "webpack-merge": "^4.1.5" }, "peerDependencies": { + "@convivainc/conviva-js-coresdk": "^4.7.6", "bitmovin-player": "^8.31.0" } }, @@ -260,6 +261,12 @@ "to-fast-properties": "^2.0.0" } }, + "node_modules/@convivainc/conviva-js-coresdk": { + "version": "4.7.6", + "resolved": "https://registry.npmjs.org/@convivainc/conviva-js-coresdk/-/conviva-js-coresdk-4.7.6.tgz", + "integrity": "sha512-xsOLxGWQkfBTKN4Ios5LIVfuf+2QjKTWc1guUM4cNPNR6H+rFrx1jhOiDHJoXMDVniN6xbbxwdhpIcc/v0s4BQ==", + "peer": true + }, "node_modules/@types/events": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", @@ -11545,6 +11552,12 @@ "to-fast-properties": "^2.0.0" } }, + "@convivainc/conviva-js-coresdk": { + "version": "4.7.6", + "resolved": "https://registry.npmjs.org/@convivainc/conviva-js-coresdk/-/conviva-js-coresdk-4.7.6.tgz", + "integrity": "sha512-xsOLxGWQkfBTKN4Ios5LIVfuf+2QjKTWc1guUM4cNPNR6H+rFrx1jhOiDHJoXMDVniN6xbbxwdhpIcc/v0s4BQ==", + "peer": true + }, "@types/events": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", diff --git a/package.json b/package.json index 4fabcf0..2211981 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "webpack-merge": "^4.1.5" }, "peerDependencies": { + "@convivainc/conviva-js-coresdk": "^4.7.6", "bitmovin-player": "^8.31.0" } } diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index 938b958..72c782e 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -1,47 +1,28 @@ +import * as Conviva from '@convivainc/conviva-js-coresdk'; + 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.valueof; - applicationName?: string; - custom?: CustomContentMetadata; - duration?: number; - - // Dynamic - encodedFrameRate?: number; - defaultResource?: string; - streamUrl?: string; - framework?: string; - frameworkVersion?: string; -} +export type CustomMetadata = Conviva.ContentMetadata['custom']; export class ContentMetadataBuilder { private readonly logger: Conviva.LoggingInterface; - private contentMetadata: Conviva.ContentMetadata; - // internal metadata fields to enable merging / overriding - private metadataOverrides: Metadata = {}; - private metadata: Metadata = {}; + private metadataOverrides: Partial = {}; + private metadata: Partial = {}; + private latestBuiltMetadata?: Partial; private playbackStarted: boolean = false; constructor(logger: Conviva.LoggingInterface) { this.logger = logger; - this.contentMetadata = new Conviva.ContentMetadata(); } /** * This method is used for custom content metadata updates during / before a session. * @param newValue */ - setOverrides(newValue: Metadata) { + setOverrides(newValue: Partial) { if (this.playbackStarted) { this.logger.consoleLog( '[ Conviva Analytics ] Playback has started. Only some metadata attributes will be updated', @@ -52,7 +33,7 @@ export class ContentMetadataBuilder { this.metadataOverrides = { ...this.metadataOverrides, ...newValue }; } - getOverrides(): Metadata { + getOverrides(): Partial { return this.metadataOverrides; } @@ -61,38 +42,42 @@ export class ContentMetadataBuilder { } build(): Conviva.ConvivaMetadata { + const latestBuiltMetadata: Partial = this.latestBuiltMetadata || {}; + if (!this.playbackStarted) { // Asset name is only allowed to be set once - if (!this.contentMetadata.assetName) { - this.contentMetadata.assetName = this.assetName; + if (!latestBuiltMetadata.assetName) { + latestBuiltMetadata.assetName = this.assetName; } - this.contentMetadata.viewerId = this.viewerId; - 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; + latestBuiltMetadata.viewerId = this.viewerId; + latestBuiltMetadata.streamType = this.metadataOverrides.streamType || this.metadata.streamType; + latestBuiltMetadata.applicationName = this.metadataOverrides.applicationName || this.metadata.applicationName; + latestBuiltMetadata.duration = this.metadataOverrides.duration || this.metadata.duration; - this.contentMetadata.custom = this.custom; + latestBuiltMetadata.custom = this.custom; } - this.contentMetadata.encodedFrameRate = this.metadataOverrides.encodedFrameRate || this.metadata.encodedFrameRate; - this.contentMetadata.defaultResource = this.metadataOverrides.defaultResource || this.metadata.defaultResource; - this.contentMetadata.streamUrl = this.metadataOverrides.streamUrl || this.metadata.streamUrl; + latestBuiltMetadata.encodedFrameRate = this.metadataOverrides.encodedFrameRate || this.metadata.encodedFrameRate; + latestBuiltMetadata.defaultResource = this.metadataOverrides.defaultResource || this.metadata.defaultResource; + latestBuiltMetadata.streamUrl = this.metadataOverrides.streamUrl || this.metadata.streamUrl; + + this.latestBuiltMetadata = latestBuiltMetadata; 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', + [Conviva.Constants.ASSET_NAME]: latestBuiltMetadata.assetName, + [Conviva.Constants.ENCODED_FRAMERATE]: latestBuiltMetadata.encodedFrameRate, + [Conviva.Constants.DURATION]: latestBuiltMetadata.duration, + [Conviva.Constants.DEFAULT_RESOURCE]: latestBuiltMetadata.defaultResource, + [Conviva.Constants.STREAM_URL]: latestBuiltMetadata.streamUrl, + [Conviva.Constants.IS_LIVE]: latestBuiltMetadata.streamType, + [Conviva.Constants.VIEWER_ID]: latestBuiltMetadata.viewerId || 'GET_VIEWER_ID_FROM_PLAYER', + [Conviva.Constants.PLAYER_NAME]: latestBuiltMetadata.applicationName || 'GET_PLAYER_NAME_OR_TYPE', }; return { ...convivaContentInfo, - ...this.contentMetadata.custom, + ...latestBuiltMetadata.custom, } as Conviva.ConvivaMetadata; } @@ -121,11 +106,11 @@ export class ContentMetadataBuilder { this.metadata.applicationName = newValue; } - set custom(newValue: CustomContentMetadata) { + set custom(newValue: Conviva.ContentMetadata['custom']) { this.metadata.custom = newValue; } - get custom(): CustomContentMetadata { + get custom(): Conviva.ContentMetadata['custom'] { return { ...this.metadataOverrides.custom, ...this.metadata.custom, // Keep our custom tags in case someone tries to override them @@ -152,6 +137,6 @@ export class ContentMetadataBuilder { this.metadataOverrides = {}; this.metadata = {}; this.playbackStarted = false; - this.contentMetadata = new Conviva.ContentMetadata(); + this.latestBuiltMetadata = undefined; } } diff --git a/src/ts/ConvivaAnalytics.ts b/src/ts/ConvivaAnalytics.ts index 5fad371..67c7ce1 100644 --- a/src/ts/ConvivaAnalytics.ts +++ b/src/ts/ConvivaAnalytics.ts @@ -1,4 +1,5 @@ -import { +import * as Conviva from '@convivainc/conviva-js-coresdk'; +import type { AdBreak, AdBreakEvent, AdEvent, @@ -23,7 +24,7 @@ import { Html5Storage } from './Html5Storage'; import { Html5Time } from './Html5Time'; import { Html5Timer } from './Html5Timer'; import { Timeout } from 'bitmovin-player-ui/dist/js/framework/timeout'; -import { ContentMetadataBuilder, Metadata } from './ContentMetadataBuilder'; +import { ContentMetadataBuilder } from './ContentMetadataBuilder'; import { ObjectUtils } from './helper/ObjectUtils'; import { BrowserUtils } from './helper/BrowserUtils'; import { ArrayUtils } from 'bitmovin-player-ui/dist/js/framework/arrayutils'; @@ -185,7 +186,7 @@ export class ConvivaAnalytics { this.isAd = false; const deviceMetadataFromConfig = this.config.deviceMetadata || {}; - const deviceMetadata = { + const deviceMetadata: Conviva.ConvivaDeviceMetadata = { [Conviva.Constants.DeviceMetadata.CATEGORY]: deviceMetadataFromConfig.category || this.config.deviceCategory || Conviva.Constants.DeviceCategory.WEB, [Conviva.Constants.DeviceMetadata.BRAND]: deviceMetadataFromConfig.brand, @@ -198,7 +199,7 @@ export class ConvivaAnalytics { }; Conviva.Analytics.setDeviceMetadata(deviceMetadata); - let callbackFunctions = {} as { [key: string]: Function }; + let callbackFunctions: Record = {}; callbackFunctions[Conviva.Constants.CallbackFunctions.CONSOLE_LOG] = this.logger.consoleLog; callbackFunctions[Conviva.Constants.CallbackFunctions.MAKE_REQUEST] = new Html5Http().makeRequest; const html5Storage = new Html5Storage(); @@ -207,7 +208,7 @@ export class ConvivaAnalytics { callbackFunctions[Conviva.Constants.CallbackFunctions.CREATE_TIMER] = new Html5Timer().createTimer; callbackFunctions[Conviva.Constants.CallbackFunctions.GET_EPOCH_TIME_IN_MS] = new Html5Time().getEpochTimeMs; - const settings = {} as { [key: string]: string | number }; + const settings: Record = {}; settings[Conviva.Constants.GATEWAY_URL] = config.gatewayUrl; settings[Conviva.Constants.LOG_LEVEL] = this.config.debugLoggingEnabled ? Conviva.Constants.LogLevel.DEBUG @@ -318,7 +319,7 @@ export class ConvivaAnalytics { * @param metadataOverrides Metadata attributes which will be used to track to conviva. * @see ContentMetadataBuilder for more information about permitted attributes */ - public updateContentMetadata(metadataOverrides: Metadata) { + public updateContentMetadata(metadataOverrides: Partial) { this.internalUpdateContentMetadata(metadataOverrides); } @@ -401,7 +402,7 @@ export class ConvivaAnalytics { } } - private internalUpdateContentMetadata(metadataOverrides: Metadata) { + private internalUpdateContentMetadata(metadataOverrides: Partial) { this.contentMetadataBuilder.setOverrides(metadataOverrides); if (!this.isSessionActive()) { diff --git a/src/ts/Html5Http.ts b/src/ts/Html5Http.ts index 673c698..a2fcf50 100644 --- a/src/ts/Html5Http.ts +++ b/src/ts/Html5Http.ts @@ -1,5 +1,4 @@ -import HttpRequestCancelFunction = Conviva.HttpRequestCancelFunction; -import HttpRequestCallback = Conviva.HttpRequestCallback; +import * as Conviva from '@convivainc/conviva-js-coresdk'; export class Html5Http implements Conviva.HttpInterface { public makeRequest( @@ -8,8 +7,8 @@ export class Html5Http implements Conviva.HttpInterface { data: string | null, contentType: string | null, timeoutMs: number, - callback: HttpRequestCallback | null, - ): HttpRequestCancelFunction { + callback: Conviva.HttpRequestCallback | null, + ): Conviva.HttpRequestCancelFunction { return this.makeRequestStandard.apply(this, arguments); } @@ -23,8 +22,8 @@ export class Html5Http implements Conviva.HttpInterface { data: string | null, contentType: string | null, timeoutMs: number, - callback: HttpRequestCallback | null, - ): HttpRequestCancelFunction { + callback: Conviva.HttpRequestCallback | null, + ): Conviva.HttpRequestCancelFunction { const xmlHttpReq = new XMLHttpRequest(); xmlHttpReq.open(httpMethod, url, true); diff --git a/src/ts/Html5Logging.ts b/src/ts/Html5Logging.ts index 63d7ef4..3c3a60b 100644 --- a/src/ts/Html5Logging.ts +++ b/src/ts/Html5Logging.ts @@ -1,4 +1,4 @@ -import SystemSettings = Conviva.SystemSettings; +import * as Conviva from '@convivainc/conviva-js-coresdk'; export class Html5Logging implements Conviva.LoggingInterface { public consoleLog(message: string, logLevel: Conviva.valueof): void { diff --git a/src/ts/Html5Storage.ts b/src/ts/Html5Storage.ts index 9524fca..65d4bf6 100644 --- a/src/ts/Html5Storage.ts +++ b/src/ts/Html5Storage.ts @@ -1,8 +1,7 @@ -import StorageLoadDataCallback = Conviva.StorageLoadDataCallback; -import StorageSaveDataCallback = Conviva.StorageSaveDataCallback; +import * as Conviva from '@convivainc/conviva-js-coresdk'; export class Html5Storage implements Conviva.StorageInterface { - public saveData(storageSpace: string, storageKey: string, data: string, callback: StorageSaveDataCallback): void { + public saveData(storageSpace: string, storageKey: string, data: string, callback: Conviva.StorageSaveDataCallback): void { const localStorageKey = storageSpace + '.' + storageKey; try { localStorage.setItem(localStorageKey, data); @@ -12,7 +11,7 @@ export class Html5Storage implements Conviva.StorageInterface { } } - public loadData(storageSpace: string, storageKey: string, callback: StorageLoadDataCallback): void { + public loadData(storageSpace: string, storageKey: string, callback: Conviva.StorageLoadDataCallback): void { const localStorageKey = storageSpace + '.' + storageKey; try { const data = localStorage.getItem(localStorageKey); diff --git a/src/ts/Html5Time.ts b/src/ts/Html5Time.ts index 8513f58..75af3af 100644 --- a/src/ts/Html5Time.ts +++ b/src/ts/Html5Time.ts @@ -1,3 +1,5 @@ +import * as Conviva from '@convivainc/conviva-js-coresdk'; + export class Html5Time implements Conviva.TimeInterface { public getEpochTimeMs(): number { const d = new Date(); diff --git a/src/ts/Html5Timer.ts b/src/ts/Html5Timer.ts index 43a5368..6b74170 100644 --- a/src/ts/Html5Timer.ts +++ b/src/ts/Html5Timer.ts @@ -1,8 +1,7 @@ -import TimerCancelFunction = Conviva.TimerCancelFunction; -import TimerAction = Conviva.TimerAction; +import * as Conviva from '@convivainc/conviva-js-coresdk'; export class Html5Timer implements Conviva.TimerInterface { - public createTimer(timerAction: TimerAction, intervalMs: number, actionName?: string | null): TimerCancelFunction { + public createTimer(timerAction: Conviva.TimerAction, intervalMs: number, actionName?: string | null): Conviva.TimerCancelFunction { let timerId = window.setInterval(timerAction, intervalMs); return function () { if (timerId !== -1) { diff --git a/@types/conviva/ConvivaExtension.d.ts b/src/ts/conviva/ConvivaExtension.ts similarity index 66% rename from @types/conviva/ConvivaExtension.d.ts rename to src/ts/conviva/ConvivaExtension.ts index 5334756..1e7ef06 100644 --- a/@types/conviva/ConvivaExtension.d.ts +++ b/src/ts/conviva/ConvivaExtension.ts @@ -1,11 +1,15 @@ /** * 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. + * + * Keep this is the source code, so the types are available in the compiled code. */ -declare module Conviva { - class ContentMetadata { - public static readonly StreamType: Conviva.ConvivaConstants['StreamType'] +import * as Conviva from '@convivainc/conviva-js-coresdk'; + +declare module '@convivainc/conviva-js-coresdk' { + export class ContentMetadata { + public static readonly StreamType: Conviva.ConvivaConstants['StreamType']; public applicationName: string; public assetName: string; public custom: {}; @@ -17,13 +21,13 @@ declare module Conviva { public viewerId: string; } - interface LoggingInterface { + export interface LoggingInterface { consoleLog(message: string, logLevel: Conviva.valueof): void; release(): void; } - class SystemSettings { + export class SystemSettings { public static readonly LogLevel: Conviva.ConvivaConstants['LogLevel']; public allowUncaughtExceptions: boolean; public httpTimeout: number; @@ -31,27 +35,27 @@ declare module Conviva { public storageTimeout: number; } - interface TimeInterface { + export interface TimeInterface { getEpochTimeMs(): number; release(): void; } - type TimerAction = () => void; + export type TimerAction = () => void; - type TimerCancelFunction = () => void; + export type TimerCancelFunction = () => void; - interface TimerInterface { + export interface TimerInterface { createTimer(timerAction: TimerAction, intervalMs: number, actionName?: string | null): TimerCancelFunction; release(): void; } - type HttpRequestCancelFunction = () => void; + export type HttpRequestCancelFunction = () => void; - type HttpRequestCallback = (succeeded: boolean, data: string) => void; + export type HttpRequestCallback = (succeeded: boolean, data: string) => void; - interface HttpInterface { + export interface HttpInterface { makeRequest( httpMethod: 'GET' | 'POST', url: string, @@ -64,11 +68,11 @@ declare module Conviva { release(): void; } - type StorageLoadDataCallback = (succeeded: boolean, data: string | null) => void; + export type StorageLoadDataCallback = (succeeded: boolean, data: string | null) => void; - type StorageSaveDataCallback = (succeeded: boolean, data: string | null) => void; + export type StorageSaveDataCallback = (succeeded: boolean, data: string | null) => void; - interface StorageInterface { + export interface StorageInterface { loadData(storageSpace: string, storageKey: string, callback: StorageLoadDataCallback): void; saveData(storageSpace: string, storageKey: string, data: string, callback: StorageSaveDataCallback): void; @@ -76,7 +80,7 @@ declare module Conviva { release(): void; } - interface VideoAnalytics { + export interface VideoAnalytics { reportAppEvent(eventType: string, eventDetail: { [key: string]: string }): void; getSessionId(): number; } diff --git a/src/ts/helper/AdBreakHelper.ts b/src/ts/helper/AdBreakHelper.ts index 68f449c..c45abd6 100644 --- a/src/ts/helper/AdBreakHelper.ts +++ b/src/ts/helper/AdBreakHelper.ts @@ -1,4 +1,5 @@ import { AdBreak, PlayerAPI } from 'bitmovin-player'; +import * as Conviva from '@convivainc/conviva-js-coresdk'; export class AdBreakHelper { public static mapAdPosition( diff --git a/src/ts/index.ts b/src/ts/index.ts index 1b3be63..6fd0bdd 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -1,2 +1,6 @@ +import './conviva/ConvivaExtension'; + export { ConvivaAnalytics, ConvivaAnalyticsConfiguration, EventAttributes } from './ConvivaAnalytics'; -export { Metadata, CustomContentMetadata } from './ContentMetadataBuilder'; +export { ConvivaMetadata } from '@convivainc/conviva-js-coresdk'; +export { CustomMetadata } from './ContentMetadataBuilder'; + diff --git a/tsconfig.json b/tsconfig.json index cf75d14..b579a5f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,6 @@ "sourceMap": true, "noImplicitAny": true, "removeComments": false, - "types": ["./@types/conviva", "jest"], + "types": ["jest"], } } diff --git a/webpack.common.js b/webpack.common.js index 5ad17ba..8a3b0a1 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -52,4 +52,5 @@ module.exports = { content: 'export * from \'./lib/index\';' }), ], + externals: ['@convivainc/conviva-js-coresdk'] }; From 92be405f5755907dd48f1320605cb394a12f5e46 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Thu, 16 May 2024 16:05:18 +0400 Subject: [PATCH 02/25] Fix tests --- spec/helper/MockHelper.ts | 30 ++++++++++++---------- spec/tests/ContentMetadata.spec.ts | 7 +++-- spec/tests/ExternalSessionManaging.spec.ts | 7 +++-- spec/tests/PlayerEvents.spec.ts | 8 ++++-- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/spec/helper/MockHelper.ts b/spec/helper/MockHelper.ts index b7aa5d5..3ffcdfb 100644 --- a/spec/helper/MockHelper.ts +++ b/spec/helper/MockHelper.ts @@ -15,26 +15,28 @@ import { SubtitleEvent, } from 'bitmovin-player'; import { ArrayUtils } from 'bitmovin-player-ui/dist/js/framework/arrayutils'; +import * as Conviva from '@convivainc/conviva-js-coresdk'; declare const global: any; export namespace MockHelper { - export function mockConviva(): void { - global.Conviva = {}; - global.Conviva.SystemInterface = jest.fn().mockImplementation(); - global.Conviva.SystemSettings = jest.fn().mockImplementation(); - global.Conviva.SystemSettings.LogLevel = { + export function createConvivaMock(): typeof Conviva { + const ConvivaMock: Record = {}; + + ConvivaMock.SystemInterface = jest.fn().mockImplementation(); + ConvivaMock.SystemSettings = jest.fn().mockImplementation(); + ConvivaMock.SystemSettings.LogLevel = { WARNING: 'warning', }; - global.Conviva.SystemFactory = jest.fn().mockImplementation(); - global.Conviva.ClientSettings = jest.fn().mockImplementation(); - global.Conviva.ContentMetadata = jest.fn().mockImplementation(); + ConvivaMock.SystemFactory = jest.fn().mockImplementation(); + ConvivaMock.ClientSettings = jest.fn().mockImplementation(); + ConvivaMock.ContentMetadata = jest.fn().mockImplementation(); - global.Conviva.ContentMetadata.StreamType = { + ConvivaMock.ContentMetadata.StreamType = { LIVE: 'live', VOD: 'vod', UNKNOWN: 'unknown', }; - global.Conviva.Constants = { + ConvivaMock.Constants = { DeviceCategory: { WEB: 'WEB', }, @@ -130,15 +132,15 @@ export namespace MockHelper { const reportAppEvent = jest.fn(); const release = jest.fn(); - global.Conviva.Analytics = jest.fn().mockImplementation(); - global.Conviva.Analytics = { + ConvivaMock.Analytics = jest.fn().mockImplementation(); + ConvivaMock.Analytics = { init: jest.fn().mockImplementation(), release: jest.fn().mockImplementation(), setDeviceMetadata: jest.fn().mockImplementation(), updateContentMetadata: jest.fn().mockImplementation(), }; - global.Conviva.Analytics.buildVideoAnalytics = jest.fn().mockImplementation(() => { + ConvivaMock.Analytics.buildVideoAnalytics = jest.fn().mockImplementation(() => { return { reportPlaybackRequested, reportPlaybackFailed, @@ -156,6 +158,8 @@ export namespace MockHelper { release, }; }); + + return ConvivaMock as typeof Conviva; } // Custom cast SDK implementation diff --git a/spec/tests/ContentMetadata.spec.ts b/spec/tests/ContentMetadata.spec.ts index 2d13f45..0c6a8b2 100644 --- a/spec/tests/ContentMetadata.spec.ts +++ b/spec/tests/ContentMetadata.spec.ts @@ -1,7 +1,12 @@ import { PlayerType, StreamType, VRContentType } from 'bitmovin-player'; import { ConvivaAnalytics } from '../../src/ts'; import { MockHelper, TestingPlayerAPI } from '../helper/MockHelper'; +import * as Conviva from '@convivainc/conviva-js-coresdk'; +jest.mock('@convivainc/conviva-js-coresdk', () => { + const { MockHelper } = jest.requireActual('../helper/MockHelper'); + return MockHelper.createConvivaMock(); +}); jest.mock('../../src/ts/Html5Logging'); describe('content metadata spec', () => { @@ -10,8 +15,6 @@ describe('content metadata spec', () => { let convivaVideoAnalytics: Conviva.VideoAnalytics; beforeEach(() => { - MockHelper.mockConviva(); - playerMock = MockHelper.getPlayerMock(); convivaVideoAnalytics = Conviva.Analytics.buildVideoAnalytics(); diff --git a/spec/tests/ExternalSessionManaging.spec.ts b/spec/tests/ExternalSessionManaging.spec.ts index ae2e3b6..f20b1dd 100644 --- a/spec/tests/ExternalSessionManaging.spec.ts +++ b/spec/tests/ExternalSessionManaging.spec.ts @@ -1,6 +1,11 @@ import { ConvivaAnalytics } from '../../src/ts'; import { MockHelper, TestingPlayerAPI } from '../helper/MockHelper'; +import * as Conviva from '@convivainc/conviva-js-coresdk'; +jest.mock('@convivainc/conviva-js-coresdk', () => { + const { MockHelper } = jest.requireActual('../helper/MockHelper'); + return MockHelper.createConvivaMock(); +}); jest.mock('../../src/ts/Html5Logging'); describe('externally session managing', () => { @@ -9,8 +14,6 @@ describe('externally session managing', () => { let convivaVideoAnalyticsMock: Conviva.VideoAnalytics; beforeEach(() => { - MockHelper.mockConviva(); - playerMock = MockHelper.getPlayerMock(); convivaVideoAnalyticsMock = Conviva.Analytics.buildVideoAnalytics(); diff --git a/spec/tests/PlayerEvents.spec.ts b/spec/tests/PlayerEvents.spec.ts index 20e72fe..ace1ebe 100644 --- a/spec/tests/PlayerEvents.spec.ts +++ b/spec/tests/PlayerEvents.spec.ts @@ -1,5 +1,11 @@ import { MockHelper, TestingPlayerAPI } from '../helper/MockHelper'; import { ConvivaAnalytics } from '../../src/ts'; +import * as Conviva from '@convivainc/conviva-js-coresdk'; + +jest.mock('@convivainc/conviva-js-coresdk', () => { + const { MockHelper } = jest.requireActual('../helper/MockHelper'); + return MockHelper.createConvivaMock(); +}); describe('player event tests', () => { let convivaAnalytics: ConvivaAnalytics; @@ -7,8 +13,6 @@ describe('player event tests', () => { let convivaVideoAnalytics: Conviva.VideoAnalytics; beforeEach(() => { - MockHelper.mockConviva(); - playerMock = MockHelper.getPlayerMock(); convivaVideoAnalytics = Conviva.Analytics.buildVideoAnalytics(); From c260da0aa738cbba308b4c5e6c11b3648be33f29 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Thu, 16 May 2024 17:28:45 +0400 Subject: [PATCH 03/25] Clean up --- example/index.html | 2 -- spec/helper/MockHelper.ts | 5 ++--- src/ts/conviva/ConvivaExtension.ts | 2 +- src/ts/index.ts | 2 -- webpack.common.js | 9 ++++++++- webpack.prod.js | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/example/index.html b/example/index.html index 3c8d546..d18faba 100644 --- a/example/index.html +++ b/example/index.html @@ -74,8 +74,6 @@ conviva.updateContentMetadata({ applicationName: 'Bitmovin Player Conviva Analytics Integration Test Page', viewerId: 'uniqueViewerId', - framework: 'Bitmovin Player', - frameworkVersion: player.version, custom: { appVersion: '1.0', contentId: 'someContentId', diff --git a/spec/helper/MockHelper.ts b/spec/helper/MockHelper.ts index 3ffcdfb..94b6a94 100644 --- a/spec/helper/MockHelper.ts +++ b/spec/helper/MockHelper.ts @@ -15,11 +15,10 @@ import { SubtitleEvent, } from 'bitmovin-player'; import { ArrayUtils } from 'bitmovin-player-ui/dist/js/framework/arrayutils'; -import * as Conviva from '@convivainc/conviva-js-coresdk'; declare const global: any; export namespace MockHelper { - export function createConvivaMock(): typeof Conviva { + export function createConvivaMock() { const ConvivaMock: Record = {}; ConvivaMock.SystemInterface = jest.fn().mockImplementation(); @@ -159,7 +158,7 @@ export namespace MockHelper { }; }); - return ConvivaMock as typeof Conviva; + return ConvivaMock; } // Custom cast SDK implementation diff --git a/src/ts/conviva/ConvivaExtension.ts b/src/ts/conviva/ConvivaExtension.ts index 1e7ef06..558c0f8 100644 --- a/src/ts/conviva/ConvivaExtension.ts +++ b/src/ts/conviva/ConvivaExtension.ts @@ -2,7 +2,7 @@ * 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. * - * Keep this is the source code, so the types are available in the compiled code. + * Keep this in the source code, so the types are available in the compiled code therefore in the consuming projects as. */ import * as Conviva from '@convivainc/conviva-js-coresdk'; diff --git a/src/ts/index.ts b/src/ts/index.ts index 6fd0bdd..0169bc4 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -1,5 +1,3 @@ -import './conviva/ConvivaExtension'; - export { ConvivaAnalytics, ConvivaAnalyticsConfiguration, EventAttributes } from './ConvivaAnalytics'; export { ConvivaMetadata } from '@convivainc/conviva-js-coresdk'; export { CustomMetadata } from './ContentMetadataBuilder'; diff --git a/webpack.common.js b/webpack.common.js index 8a3b0a1..2048fcf 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -52,5 +52,12 @@ module.exports = { content: 'export * from \'./lib/index\';' }), ], - externals: ['@convivainc/conviva-js-coresdk'] + externals: { + '@convivainc/conviva-js-coresdk': { + commonjs: '@convivainc/conviva-js-coresdk', + commonjs2: '@convivainc/conviva-js-coresdk', + amd: '@convivainc/conviva-js-coresdk', + root: ['Conviva'] + }, + } }; diff --git a/webpack.prod.js b/webpack.prod.js index ccbdab8..f7741b0 100644 --- a/webpack.prod.js +++ b/webpack.prod.js @@ -2,5 +2,5 @@ const merge = require('webpack-merge'); const common = require('./webpack.common.js'); module.exports = merge(common, { - mode: 'production', + mode: 'development', }); From ecbbf27b253e4c85fc0d4c395db3f63997229358 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Thu, 16 May 2024 18:45:08 +0400 Subject: [PATCH 04/25] Simplify metadata builder --- src/ts/ContentMetadataBuilder.ts | 75 +++++++++++++++++++----------- src/ts/conviva/ConvivaExtension.ts | 4 +- 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index 72c782e..cf44ee6 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -41,43 +41,64 @@ export class ContentMetadataBuilder { this.playbackStarted = value; } - build(): Conviva.ConvivaMetadata { - const latestBuiltMetadata: Partial = this.latestBuiltMetadata || {}; + private getStaticMetadata() { + const metadata: Partial = {}; + // This metadata can only be changed before the playback is started if (!this.playbackStarted) { // Asset name is only allowed to be set once - if (!latestBuiltMetadata.assetName) { - latestBuiltMetadata.assetName = this.assetName; - } + metadata.assetName = this.latestBuiltMetadata.assetName || this.assetName; - latestBuiltMetadata.viewerId = this.viewerId; - latestBuiltMetadata.streamType = this.metadataOverrides.streamType || this.metadata.streamType; - latestBuiltMetadata.applicationName = this.metadataOverrides.applicationName || this.metadata.applicationName; - latestBuiltMetadata.duration = this.metadataOverrides.duration || this.metadata.duration; + metadata.viewerId = this.viewerId; + metadata.streamType = this.metadataOverrides.streamType || this.metadata.streamType; + metadata.applicationName = this.metadataOverrides.applicationName || this.metadata.applicationName; + metadata.duration = this.metadataOverrides.duration || this.metadata.duration; - latestBuiltMetadata.custom = this.custom; + metadata.custom = this.custom; + } + // If the playback has been started, the values cannot be changed and the latest values before the playback started has to be used + else { + metadata.assetName = this.latestBuiltMetadata.assetName; + metadata.viewerId = this.latestBuiltMetadata.viewerId; + metadata.streamType = this.latestBuiltMetadata.streamType; + metadata.applicationName = this.latestBuiltMetadata.applicationName; + metadata.duration = this.latestBuiltMetadata.duration; + metadata.custom = this.latestBuiltMetadata.custom; } - latestBuiltMetadata.encodedFrameRate = this.metadataOverrides.encodedFrameRate || this.metadata.encodedFrameRate; - latestBuiltMetadata.defaultResource = this.metadataOverrides.defaultResource || this.metadata.defaultResource; - latestBuiltMetadata.streamUrl = this.metadataOverrides.streamUrl || this.metadata.streamUrl; - - this.latestBuiltMetadata = latestBuiltMetadata; - - const convivaContentInfo: ReservedContentMetadata = { - [Conviva.Constants.ASSET_NAME]: latestBuiltMetadata.assetName, - [Conviva.Constants.ENCODED_FRAMERATE]: latestBuiltMetadata.encodedFrameRate, - [Conviva.Constants.DURATION]: latestBuiltMetadata.duration, - [Conviva.Constants.DEFAULT_RESOURCE]: latestBuiltMetadata.defaultResource, - [Conviva.Constants.STREAM_URL]: latestBuiltMetadata.streamUrl, - [Conviva.Constants.IS_LIVE]: latestBuiltMetadata.streamType, - [Conviva.Constants.VIEWER_ID]: latestBuiltMetadata.viewerId || 'GET_VIEWER_ID_FROM_PLAYER', - [Conviva.Constants.PLAYER_NAME]: latestBuiltMetadata.applicationName || 'GET_PLAYER_NAME_OR_TYPE', + return metadata; + } + + private getDynamicMetadata(): Partial { + return { + encodedFrameRate: this.metadataOverrides.encodedFrameRate || this.metadata.encodedFrameRate, + defaultResource: this.metadataOverrides.defaultResource || this.metadata.defaultResource, + streamUrl: this.metadataOverrides.streamUrl || this.metadata.streamUrl, + } + } + + build(): Conviva.ConvivaMetadata { + const newMetadata: Partial = { + ...this.getStaticMetadata(), + ...this.getDynamicMetadata(), + }; + + this.latestBuiltMetadata = newMetadata; + + const reservedMetadata: ReservedContentMetadata = { + [Conviva.Constants.ASSET_NAME]: newMetadata.assetName, + [Conviva.Constants.ENCODED_FRAMERATE]: newMetadata.encodedFrameRate, + [Conviva.Constants.DURATION]: newMetadata.duration, + [Conviva.Constants.DEFAULT_RESOURCE]: newMetadata.defaultResource, + [Conviva.Constants.STREAM_URL]: newMetadata.streamUrl, + [Conviva.Constants.IS_LIVE]: newMetadata.streamType, + [Conviva.Constants.VIEWER_ID]: newMetadata.viewerId || 'GET_VIEWER_ID_FROM_PLAYER', + [Conviva.Constants.PLAYER_NAME]: newMetadata.applicationName || 'GET_PLAYER_NAME_OR_TYPE', }; return { - ...convivaContentInfo, - ...latestBuiltMetadata.custom, + ...reservedMetadata, + ...newMetadata.custom, } as Conviva.ConvivaMetadata; } diff --git a/src/ts/conviva/ConvivaExtension.ts b/src/ts/conviva/ConvivaExtension.ts index 558c0f8..e528389 100644 --- a/src/ts/conviva/ConvivaExtension.ts +++ b/src/ts/conviva/ConvivaExtension.ts @@ -2,7 +2,7 @@ * 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. * - * Keep this in the source code, so the types are available in the compiled code therefore in the consuming projects as. + * Keep this in the source code, so the types are available in the compiled code therefore in the consuming projects as well. */ import * as Conviva from '@convivainc/conviva-js-coresdk'; @@ -12,7 +12,7 @@ declare module '@convivainc/conviva-js-coresdk' { public static readonly StreamType: Conviva.ConvivaConstants['StreamType']; public applicationName: string; public assetName: string; - public custom: {}; + public custom: Record; public defaultResource: string; public duration: number; public encodedFrameRate: number; From 1fda763047cc199dee24a076c198900141d396fc Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Thu, 16 May 2024 18:49:19 +0400 Subject: [PATCH 05/25] Update comments --- src/ts/conviva/ConvivaExtension.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ts/conviva/ConvivaExtension.ts b/src/ts/conviva/ConvivaExtension.ts index e528389..a7941e1 100644 --- a/src/ts/conviva/ConvivaExtension.ts +++ b/src/ts/conviva/ConvivaExtension.ts @@ -10,15 +10,21 @@ import * as Conviva from '@convivainc/conviva-js-coresdk'; declare module '@convivainc/conviva-js-coresdk' { export class ContentMetadata { public static readonly StreamType: Conviva.ConvivaConstants['StreamType']; - public applicationName: string; + + // Can only be set once public assetName: string; + + // Can only be set before playback started + public viewerId: string; + public streamType: Conviva.valueof; + public applicationName: string; public custom: Record; - public defaultResource: string; public duration: number; + + // Dynamic + public defaultResource: string; public encodedFrameRate: number; - public streamType: Conviva.valueof; public streamUrl: string; - public viewerId: string; } export interface LoggingInterface { From 582944cb23d76861e755969d17c3e887af6da459 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Thu, 16 May 2024 18:58:41 +0400 Subject: [PATCH 06/25] Fix types --- src/ts/ContentMetadataBuilder.ts | 2 +- src/ts/conviva/ConvivaExtension.ts | 3 +++ src/ts/index.ts | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index cf44ee6..3b8a82f 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -74,7 +74,7 @@ export class ContentMetadataBuilder { encodedFrameRate: this.metadataOverrides.encodedFrameRate || this.metadata.encodedFrameRate, defaultResource: this.metadataOverrides.defaultResource || this.metadata.defaultResource, streamUrl: this.metadataOverrides.streamUrl || this.metadata.streamUrl, - } + }; } build(): Conviva.ConvivaMetadata { diff --git a/src/ts/conviva/ConvivaExtension.ts b/src/ts/conviva/ConvivaExtension.ts index a7941e1..bc5de91 100644 --- a/src/ts/conviva/ConvivaExtension.ts +++ b/src/ts/conviva/ConvivaExtension.ts @@ -91,3 +91,6 @@ declare module '@convivainc/conviva-js-coresdk' { getSessionId(): number; } } + +// This is required, otherwise this file cannot be imported. +export {}; diff --git a/src/ts/index.ts b/src/ts/index.ts index 0169bc4..cbd54ca 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -1,4 +1,6 @@ +// Import to extend Conviva types. +import './conviva/ConvivaExtension'; + export { ConvivaAnalytics, ConvivaAnalyticsConfiguration, EventAttributes } from './ConvivaAnalytics'; export { ConvivaMetadata } from '@convivainc/conviva-js-coresdk'; export { CustomMetadata } from './ContentMetadataBuilder'; - From 922edd7ff668f5dd9d979eb6200ef2168e5dd15b Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Thu, 16 May 2024 18:59:49 +0400 Subject: [PATCH 07/25] Clean up --- webpack.prod.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webpack.prod.js b/webpack.prod.js index f7741b0..ccbdab8 100644 --- a/webpack.prod.js +++ b/webpack.prod.js @@ -2,5 +2,5 @@ const merge = require('webpack-merge'); const common = require('./webpack.common.js'); module.exports = merge(common, { - mode: 'development', + mode: 'production', }); From c41c3dc1600be509dee7a0b0e66354a192666be3 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Thu, 16 May 2024 19:00:41 +0400 Subject: [PATCH 08/25] Extend comment --- src/ts/conviva/ConvivaExtension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ts/conviva/ConvivaExtension.ts b/src/ts/conviva/ConvivaExtension.ts index bc5de91..38854d5 100644 --- a/src/ts/conviva/ConvivaExtension.ts +++ b/src/ts/conviva/ConvivaExtension.ts @@ -92,5 +92,5 @@ declare module '@convivainc/conviva-js-coresdk' { } } -// This is required, otherwise this file cannot be imported. +// This is required, otherwise this file cannot be imported (would fail in runtime without it). export {}; From b0c5b865d0a9904c297fda52316ac98cf25776c0 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Thu, 16 May 2024 19:01:54 +0400 Subject: [PATCH 09/25] Rename a variable --- src/ts/ContentMetadataBuilder.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index 3b8a82f..634c06d 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -85,7 +85,7 @@ export class ContentMetadataBuilder { this.latestBuiltMetadata = newMetadata; - const reservedMetadata: ReservedContentMetadata = { + const newReservedMetadata: ReservedContentMetadata = { [Conviva.Constants.ASSET_NAME]: newMetadata.assetName, [Conviva.Constants.ENCODED_FRAMERATE]: newMetadata.encodedFrameRate, [Conviva.Constants.DURATION]: newMetadata.duration, @@ -97,7 +97,7 @@ export class ContentMetadataBuilder { }; return { - ...reservedMetadata, + ...newReservedMetadata, ...newMetadata.custom, } as Conviva.ConvivaMetadata; } From 8b9e1cbaf5878585010fcd6a391dda71d7183223 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Thu, 16 May 2024 19:04:52 +0400 Subject: [PATCH 10/25] Fix tests --- src/ts/ContentMetadataBuilder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index 634c06d..58a5dab 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -11,7 +11,7 @@ export class ContentMetadataBuilder { private metadataOverrides: Partial = {}; private metadata: Partial = {}; - private latestBuiltMetadata?: Partial; + private latestBuiltMetadata: Partial = {}; private playbackStarted: boolean = false; constructor(logger: Conviva.LoggingInterface) { From 117670e3e83cf699d9516454b7c011f999f36d84 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Thu, 16 May 2024 19:08:22 +0400 Subject: [PATCH 11/25] Fix cleanup --- src/ts/ContentMetadataBuilder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index 58a5dab..db43d46 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -158,6 +158,6 @@ export class ContentMetadataBuilder { this.metadataOverrides = {}; this.metadata = {}; this.playbackStarted = false; - this.latestBuiltMetadata = undefined; + this.latestBuiltMetadata = {}; } } From f262b50e105908f4b7add2c4f4abc3a43f2f9e96 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Fri, 17 May 2024 10:07:16 +0400 Subject: [PATCH 12/25] Update exports --- src/ts/ContentMetadataBuilder.ts | 24 +++++++++++++----------- src/ts/index.ts | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index db43d46..e9a70f9 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -4,14 +4,16 @@ type NoStringIndex = { [K in keyof T as string extends K ? never : K]: T[K] } type ReservedContentMetadata = NoStringIndex; -export type CustomMetadata = Conviva.ContentMetadata['custom']; +export type CustomMetadata = ContentMetadata['custom']; + +export type ContentMetadata = Conviva.ContentMetadata; export class ContentMetadataBuilder { private readonly logger: Conviva.LoggingInterface; - private metadataOverrides: Partial = {}; - private metadata: Partial = {}; - private latestBuiltMetadata: Partial = {}; + private metadataOverrides: Partial = {}; + private metadata: Partial = {}; + private latestBuiltMetadata: Partial = {}; private playbackStarted: boolean = false; constructor(logger: Conviva.LoggingInterface) { @@ -22,7 +24,7 @@ export class ContentMetadataBuilder { * This method is used for custom content metadata updates during / before a session. * @param newValue */ - setOverrides(newValue: Partial) { + setOverrides(newValue: Partial) { if (this.playbackStarted) { this.logger.consoleLog( '[ Conviva Analytics ] Playback has started. Only some metadata attributes will be updated', @@ -33,7 +35,7 @@ export class ContentMetadataBuilder { this.metadataOverrides = { ...this.metadataOverrides, ...newValue }; } - getOverrides(): Partial { + getOverrides(): Partial { return this.metadataOverrides; } @@ -42,7 +44,7 @@ export class ContentMetadataBuilder { } private getStaticMetadata() { - const metadata: Partial = {}; + const metadata: Partial = {}; // This metadata can only be changed before the playback is started if (!this.playbackStarted) { @@ -69,7 +71,7 @@ export class ContentMetadataBuilder { return metadata; } - private getDynamicMetadata(): Partial { + private getDynamicMetadata(): Partial { return { encodedFrameRate: this.metadataOverrides.encodedFrameRate || this.metadata.encodedFrameRate, defaultResource: this.metadataOverrides.defaultResource || this.metadata.defaultResource, @@ -78,7 +80,7 @@ export class ContentMetadataBuilder { } build(): Conviva.ConvivaMetadata { - const newMetadata: Partial = { + const newMetadata: Partial = { ...this.getStaticMetadata(), ...this.getDynamicMetadata(), }; @@ -127,11 +129,11 @@ export class ContentMetadataBuilder { this.metadata.applicationName = newValue; } - set custom(newValue: Conviva.ContentMetadata['custom']) { + set custom(newValue: CustomMetadata) { this.metadata.custom = newValue; } - get custom(): Conviva.ContentMetadata['custom'] { + get custom(): CustomMetadata { return { ...this.metadataOverrides.custom, ...this.metadata.custom, // Keep our custom tags in case someone tries to override them diff --git a/src/ts/index.ts b/src/ts/index.ts index cbd54ca..8fc2fa6 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -3,4 +3,4 @@ import './conviva/ConvivaExtension'; export { ConvivaAnalytics, ConvivaAnalyticsConfiguration, EventAttributes } from './ConvivaAnalytics'; export { ConvivaMetadata } from '@convivainc/conviva-js-coresdk'; -export { CustomMetadata } from './ContentMetadataBuilder'; +export { ContentMetadata, CustomMetadata } from './ContentMetadataBuilder'; From 40ba99a5bd46b213cb29a4f0b8a0129c55253a7c Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Fri, 17 May 2024 10:14:57 +0400 Subject: [PATCH 13/25] Update types --- src/ts/ContentMetadataBuilder.ts | 24 ++++++++++-------------- src/ts/index.ts | 2 -- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index e9a70f9..23de452 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -4,16 +4,12 @@ type NoStringIndex = { [K in keyof T as string extends K ? never : K]: T[K] } type ReservedContentMetadata = NoStringIndex; -export type CustomMetadata = ContentMetadata['custom']; - -export type ContentMetadata = Conviva.ContentMetadata; - export class ContentMetadataBuilder { private readonly logger: Conviva.LoggingInterface; - private metadataOverrides: Partial = {}; - private metadata: Partial = {}; - private latestBuiltMetadata: Partial = {}; + private metadataOverrides: Partial = {}; + private metadata: Partial = {}; + private latestBuiltMetadata: Partial = {}; private playbackStarted: boolean = false; constructor(logger: Conviva.LoggingInterface) { @@ -24,7 +20,7 @@ export class ContentMetadataBuilder { * This method is used for custom content metadata updates during / before a session. * @param newValue */ - setOverrides(newValue: Partial) { + setOverrides(newValue: Partial) { if (this.playbackStarted) { this.logger.consoleLog( '[ Conviva Analytics ] Playback has started. Only some metadata attributes will be updated', @@ -35,7 +31,7 @@ export class ContentMetadataBuilder { this.metadataOverrides = { ...this.metadataOverrides, ...newValue }; } - getOverrides(): Partial { + getOverrides(): Partial { return this.metadataOverrides; } @@ -44,7 +40,7 @@ export class ContentMetadataBuilder { } private getStaticMetadata() { - const metadata: Partial = {}; + const metadata: Partial = {}; // This metadata can only be changed before the playback is started if (!this.playbackStarted) { @@ -71,7 +67,7 @@ export class ContentMetadataBuilder { return metadata; } - private getDynamicMetadata(): Partial { + private getDynamicMetadata(): Partial { return { encodedFrameRate: this.metadataOverrides.encodedFrameRate || this.metadata.encodedFrameRate, defaultResource: this.metadataOverrides.defaultResource || this.metadata.defaultResource, @@ -80,7 +76,7 @@ export class ContentMetadataBuilder { } build(): Conviva.ConvivaMetadata { - const newMetadata: Partial = { + const newMetadata: Partial = { ...this.getStaticMetadata(), ...this.getDynamicMetadata(), }; @@ -129,11 +125,11 @@ export class ContentMetadataBuilder { this.metadata.applicationName = newValue; } - set custom(newValue: CustomMetadata) { + set custom(newValue: Conviva.ContentMetadata['custom']) { this.metadata.custom = newValue; } - get custom(): CustomMetadata { + get custom(): Conviva.ContentMetadata['custom'] { return { ...this.metadataOverrides.custom, ...this.metadata.custom, // Keep our custom tags in case someone tries to override them diff --git a/src/ts/index.ts b/src/ts/index.ts index 8fc2fa6..476916a 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -2,5 +2,3 @@ import './conviva/ConvivaExtension'; export { ConvivaAnalytics, ConvivaAnalyticsConfiguration, EventAttributes } from './ConvivaAnalytics'; -export { ConvivaMetadata } from '@convivainc/conviva-js-coresdk'; -export { ContentMetadata, CustomMetadata } from './ContentMetadataBuilder'; From 5936b5a78caa82f70fbfd1e4e435caccf861e8e0 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Fri, 17 May 2024 10:20:01 +0400 Subject: [PATCH 14/25] Update types --- src/ts/ContentMetadataBuilder.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index 23de452..72cd944 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -4,12 +4,16 @@ type NoStringIndex = { [K in keyof T as string extends K ? never : K]: T[K] } type ReservedContentMetadata = NoStringIndex; +export type Metadata = Conviva.ContentMetadata & { + // TODO extend it with additional standard tags +} + export class ContentMetadataBuilder { private readonly logger: Conviva.LoggingInterface; - private metadataOverrides: Partial = {}; - private metadata: Partial = {}; - private latestBuiltMetadata: Partial = {}; + private metadataOverrides: Partial = {}; + private metadata: Partial = {}; + private latestBuiltMetadata: Partial = {}; private playbackStarted: boolean = false; constructor(logger: Conviva.LoggingInterface) { @@ -20,7 +24,7 @@ export class ContentMetadataBuilder { * This method is used for custom content metadata updates during / before a session. * @param newValue */ - setOverrides(newValue: Partial) { + setOverrides(newValue: Partial) { if (this.playbackStarted) { this.logger.consoleLog( '[ Conviva Analytics ] Playback has started. Only some metadata attributes will be updated', @@ -31,7 +35,7 @@ export class ContentMetadataBuilder { this.metadataOverrides = { ...this.metadataOverrides, ...newValue }; } - getOverrides(): Partial { + getOverrides(): Partial { return this.metadataOverrides; } @@ -40,7 +44,7 @@ export class ContentMetadataBuilder { } private getStaticMetadata() { - const metadata: Partial = {}; + const metadata: Partial = {}; // This metadata can only be changed before the playback is started if (!this.playbackStarted) { @@ -67,7 +71,7 @@ export class ContentMetadataBuilder { return metadata; } - private getDynamicMetadata(): Partial { + private getDynamicMetadata(): Partial { return { encodedFrameRate: this.metadataOverrides.encodedFrameRate || this.metadata.encodedFrameRate, defaultResource: this.metadataOverrides.defaultResource || this.metadata.defaultResource, @@ -76,7 +80,7 @@ export class ContentMetadataBuilder { } build(): Conviva.ConvivaMetadata { - const newMetadata: Partial = { + const newMetadata: Partial = { ...this.getStaticMetadata(), ...this.getDynamicMetadata(), }; @@ -125,11 +129,11 @@ export class ContentMetadataBuilder { this.metadata.applicationName = newValue; } - set custom(newValue: Conviva.ContentMetadata['custom']) { + set custom(newValue: Metadata['custom']) { this.metadata.custom = newValue; } - get custom(): Conviva.ContentMetadata['custom'] { + get custom(): Metadata['custom'] { return { ...this.metadataOverrides.custom, ...this.metadata.custom, // Keep our custom tags in case someone tries to override them From 2f8e0cc029ec0fc3dbf5217d3e2fc89baee78a57 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Fri, 17 May 2024 10:20:15 +0400 Subject: [PATCH 15/25] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b1bd84..c73057b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Updated Conviva types to the latest version and fixed some type issues +- `updateContentMetadata` accepts `Conviva.ContentMetadata` instead of a `Metadata` (the same structurally) ### Deprecated - Removed `framework` and `frameworkVersion` custom metadata fields (custom tags) +- Removed `CustomContentMetadata`, use `Metadata['custom']` instead ## 4.2.0 - 2023-08-24 ### Added From d710a74253475df430c0d89c3433d5dfde01a4c0 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Fri, 17 May 2024 10:21:59 +0400 Subject: [PATCH 16/25] Update types --- src/ts/ConvivaAnalytics.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ts/ConvivaAnalytics.ts b/src/ts/ConvivaAnalytics.ts index 67c7ce1..8a8b474 100644 --- a/src/ts/ConvivaAnalytics.ts +++ b/src/ts/ConvivaAnalytics.ts @@ -24,7 +24,7 @@ import { Html5Storage } from './Html5Storage'; import { Html5Time } from './Html5Time'; import { Html5Timer } from './Html5Timer'; import { Timeout } from 'bitmovin-player-ui/dist/js/framework/timeout'; -import { ContentMetadataBuilder } from './ContentMetadataBuilder'; +import { ContentMetadataBuilder, Metadata } from './ContentMetadataBuilder'; import { ObjectUtils } from './helper/ObjectUtils'; import { BrowserUtils } from './helper/BrowserUtils'; import { ArrayUtils } from 'bitmovin-player-ui/dist/js/framework/arrayutils'; @@ -319,7 +319,7 @@ export class ConvivaAnalytics { * @param metadataOverrides Metadata attributes which will be used to track to conviva. * @see ContentMetadataBuilder for more information about permitted attributes */ - public updateContentMetadata(metadataOverrides: Partial) { + public updateContentMetadata(metadataOverrides: Partial) { this.internalUpdateContentMetadata(metadataOverrides); } @@ -402,7 +402,7 @@ export class ConvivaAnalytics { } } - private internalUpdateContentMetadata(metadataOverrides: Partial) { + private internalUpdateContentMetadata(metadataOverrides: Partial) { this.contentMetadataBuilder.setOverrides(metadataOverrides); if (!this.isSessionActive()) { From 2210ed12f859055e445fa126e0364048fbbc47e7 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Fri, 17 May 2024 10:22:33 +0400 Subject: [PATCH 17/25] Update CHANGELOG.md --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c73057b..daf3d5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Updated Conviva types to the latest version and fixed some type issues -- `updateContentMetadata` accepts `Conviva.ContentMetadata` instead of a `Metadata` (the same structurally) ### Deprecated - Removed `framework` and `frameworkVersion` custom metadata fields (custom tags) From bbf4ac855e67db7b2a566d2a625b67f900d708ce Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Fri, 17 May 2024 10:25:07 +0400 Subject: [PATCH 18/25] Fix build --- src/ts/ContentMetadataBuilder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index 72cd944..8e5c0ea 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -6,7 +6,7 @@ type ReservedContentMetadata = NoStringIndex; export type Metadata = Conviva.ContentMetadata & { // TODO extend it with additional standard tags -} +}; export class ContentMetadataBuilder { private readonly logger: Conviva.LoggingInterface; From a45d7519e3882583e59ad0383acce6d1bf0e801a Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Fri, 17 May 2024 15:43:48 +0400 Subject: [PATCH 19/25] Clean up --- src/ts/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ts/index.ts b/src/ts/index.ts index 476916a..a671bcb 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -2,3 +2,4 @@ import './conviva/ConvivaExtension'; export { ConvivaAnalytics, ConvivaAnalyticsConfiguration, EventAttributes } from './ConvivaAnalytics'; +export { Metadata } from './ContentMetadataBuilder'; From cce84d26764897d099617e79b7bee9d625809b41 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Mon, 20 May 2024 12:33:07 +0400 Subject: [PATCH 20/25] Update CHANGELOG.md --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index daf3d5c..339fa77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Deprecated - Removed `framework` and `frameworkVersion` custom metadata fields (custom tags) -- Removed `CustomContentMetadata`, use `Metadata['custom']` instead + +### Removed +- `CustomContentMetadata`, use `Metadata['custom']` instead ## 4.2.0 - 2023-08-24 ### Added From 70cad66a428f20a7bfbb2d0616c9387fe878b848 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Mon, 20 May 2024 12:34:17 +0400 Subject: [PATCH 21/25] Update a comment --- src/ts/ContentMetadataBuilder.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index 8e5c0ea..2a1fe95 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -57,9 +57,9 @@ export class ContentMetadataBuilder { metadata.duration = this.metadataOverrides.duration || this.metadata.duration; metadata.custom = this.custom; - } - // If the playback has been started, the values cannot be changed and the latest values before the playback started has to be used - else { + } else { + // If the playback has been started, the values cannot be changed and the latest values before the playback started has to be used + metadata.assetName = this.latestBuiltMetadata.assetName; metadata.viewerId = this.latestBuiltMetadata.viewerId; metadata.streamType = this.latestBuiltMetadata.streamType; From c560691e614fdd9a01041493253c90ad67d95b83 Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Mon, 20 May 2024 12:36:42 +0400 Subject: [PATCH 22/25] Update a comment --- src/ts/ContentMetadataBuilder.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index 2a1fe95..f947dbb 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -95,6 +95,7 @@ export class ContentMetadataBuilder { [Conviva.Constants.STREAM_URL]: newMetadata.streamUrl, [Conviva.Constants.IS_LIVE]: newMetadata.streamType, [Conviva.Constants.VIEWER_ID]: newMetadata.viewerId || 'GET_VIEWER_ID_FROM_PLAYER', + // It's not a mistake, "Application name" and "Player name" are referenced interchangeably on Conviva in some places [Conviva.Constants.PLAYER_NAME]: newMetadata.applicationName || 'GET_PLAYER_NAME_OR_TYPE', }; From 06cd7394d6fe438d8208460283162123d847bf9f Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Mon, 20 May 2024 12:40:51 +0400 Subject: [PATCH 23/25] Add a comment --- src/ts/ContentMetadataBuilder.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index f947dbb..3174aa6 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -93,6 +93,9 @@ export class ContentMetadataBuilder { [Conviva.Constants.DURATION]: newMetadata.duration, [Conviva.Constants.DEFAULT_RESOURCE]: newMetadata.defaultResource, [Conviva.Constants.STREAM_URL]: newMetadata.streamUrl, + // If you follow the `IS_LIVE` constant you will find out that it's mapped to `Conviva.streamType`. + // That's why we set `streamType` here. It's not a mistake. + // Conviva automatically infers "Is live" from the stream type on their side. [Conviva.Constants.IS_LIVE]: newMetadata.streamType, [Conviva.Constants.VIEWER_ID]: newMetadata.viewerId || 'GET_VIEWER_ID_FROM_PLAYER', // It's not a mistake, "Application name" and "Player name" are referenced interchangeably on Conviva in some places From 15c36c2e8d05e0e2bce32ea5aeba472b9d8fc14a Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Mon, 20 May 2024 12:50:43 +0400 Subject: [PATCH 24/25] Fix a typo --- src/ts/ContentMetadataBuilder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ts/ContentMetadataBuilder.ts b/src/ts/ContentMetadataBuilder.ts index 3174aa6..a5b57fc 100644 --- a/src/ts/ContentMetadataBuilder.ts +++ b/src/ts/ContentMetadataBuilder.ts @@ -58,7 +58,7 @@ export class ContentMetadataBuilder { metadata.custom = this.custom; } else { - // If the playback has been started, the values cannot be changed and the latest values before the playback started has to be used + // If the playback has been started, the values cannot be changed and the latest values before the playback started have to be used metadata.assetName = this.latestBuiltMetadata.assetName; metadata.viewerId = this.latestBuiltMetadata.viewerId; From ecc72d42be7f23f5579bb033c41b7adb0e0dac6c Mon Sep 17 00:00:00 2001 From: Kirill Karpov Date: Tue, 21 May 2024 11:29:41 +0400 Subject: [PATCH 25/25] Update CHANGELOG.md --- CHANGELOG.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 339fa77..dca6f6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Updated Conviva types to the latest version and fixed some type issues -### Deprecated -- Removed `framework` and `frameworkVersion` custom metadata fields (custom tags) - ### Removed +- `framework` and `frameworkVersion` custom metadata fields (custom tags) - `CustomContentMetadata`, use `Metadata['custom']` instead ## 4.2.0 - 2023-08-24