diff --git a/comscore/src/integration/ComscoreContentMetadata.ts b/comscore/src/integration/ComscoreContentMetadata.ts index 519f0f69..0f6ddd1d 100644 --- a/comscore/src/integration/ComscoreContentMetadata.ts +++ b/comscore/src/integration/ComscoreContentMetadata.ts @@ -1,7 +1,17 @@ -import { ComscoreDeliveryAdvertisementCapability, ComscoreDeliveryComposition, ComscoreDeliveryMode, ComscoreDeliverySubscriptionType, ComscoreDistributionModel, ComscoreFeedType, ComscoreMediaFormat, ComscoreMediaType, ComscoreMetadata } from "../api/ComscoreMetadata"; +import { + ComscoreDeliveryAdvertisementCapability, + ComscoreDeliveryComposition, + ComscoreDeliveryMode, + ComscoreDeliverySubscriptionType, + ComscoreDistributionModel, + ComscoreFeedType, + ComscoreMediaFormat, + ComscoreMediaType, + ComscoreMetadata +} from '../api/ComscoreMetadata'; export const buildContentMetadata = (metadata: ComscoreMetadata): ns_.analytics.StreamingAnalytics.ContentMetadata => { - const contentMetadata = new ns_.analytics.StreamingAnalytics.ContentMetadata() + const contentMetadata = new ns_.analytics.StreamingAnalytics.ContentMetadata(); const { mediaType, uniqueId, @@ -41,268 +51,282 @@ export const buildContentMetadata = (metadata: ComscoreMetadata): ns_.analytics. totalSegments, clipUrl, videoDimension, - customLabels, - } = metadata - contentMetadata.setMediaType(mapMediaType(mediaType)) - contentMetadata.setUniqueId(uniqueId) - contentMetadata.setLength(length) - if(c3) { - contentMetadata.setDictionaryClassificationC3(c3) + customLabels + } = metadata; + contentMetadata.setMediaType(mapMediaType(mediaType)); + contentMetadata.setUniqueId(uniqueId); + contentMetadata.setLength(length); + if (c3) { + contentMetadata.setDictionaryClassificationC3(c3); } - if(c4) { - contentMetadata.setDictionaryClassificationC4(c4) + if (c4) { + contentMetadata.setDictionaryClassificationC4(c4); } - if(c6) { - contentMetadata.setDictionaryClassificationC6(c6) + if (c6) { + contentMetadata.setDictionaryClassificationC6(c6); } - contentMetadata.setStationTitle(stationTitle) - if(stationCode) { - contentMetadata.setStationCode(stationCode) + contentMetadata.setStationTitle(stationTitle); + if (stationCode) { + contentMetadata.setStationCode(stationCode); } - if(networkAffiliate) { - contentMetadata.setNetworkAffiliate(networkAffiliate) + if (networkAffiliate) { + contentMetadata.setNetworkAffiliate(networkAffiliate); } - if(publisherName) { - contentMetadata.setPublisherName(publisherName) + if (publisherName) { + contentMetadata.setPublisherName(publisherName); } - contentMetadata.setProgramTitle(programTitle) - if(programId) { - contentMetadata.setProgramId(programId) + contentMetadata.setProgramTitle(programTitle); + if (programId) { + contentMetadata.setProgramId(programId); } - contentMetadata.setEpisodeTitle(episodeTitle) - if(episodeId) { - contentMetadata.setEpisodeId(episodeId) + contentMetadata.setEpisodeTitle(episodeTitle); + if (episodeId) { + contentMetadata.setEpisodeId(episodeId); } - if(episodeSeasonNumber) { - contentMetadata.setEpisodeSeasonNumber(episodeSeasonNumber) + if (episodeSeasonNumber) { + contentMetadata.setEpisodeSeasonNumber(episodeSeasonNumber); } - if(episodeNumber) { - contentMetadata.setEpisodeNumber(episodeNumber) + if (episodeNumber) { + contentMetadata.setEpisodeNumber(episodeNumber); } - contentMetadata.setGenreName(genreName) - if(genreId) { - contentMetadata.setGenreId(genreId) + contentMetadata.setGenreName(genreName); + if (genreId) { + contentMetadata.setGenreId(genreId); } - if(carryTvAdvertisementLoad) { - contentMetadata.carryTvAdvertisementLoad(carryTvAdvertisementLoad) + if (carryTvAdvertisementLoad) { + contentMetadata.carryTvAdvertisementLoad(carryTvAdvertisementLoad); } - if(classifyAsCompleteEpisode) { - contentMetadata.classifyAsCompleteEpisode(classifyAsCompleteEpisode) + if (classifyAsCompleteEpisode) { + contentMetadata.classifyAsCompleteEpisode(classifyAsCompleteEpisode); } - if(dateOfProduction) { - const { year, month, day } = dateOfProduction - contentMetadata.setDateOfProduction(year,month,day) + if (dateOfProduction) { + const { year, month, day } = dateOfProduction; + contentMetadata.setDateOfProduction(year, month, day); } - if(timeOfProduction) { - const { hours, minutes } = timeOfProduction - contentMetadata.setTimeOfProduction(hours,minutes) + if (timeOfProduction) { + const { hours, minutes } = timeOfProduction; + contentMetadata.setTimeOfProduction(hours, minutes); } - if(dateOfTvAiring) { - const { year, month, day } = dateOfTvAiring - contentMetadata.setDateOfTvAiring(year,month,day) + if (dateOfTvAiring) { + const { year, month, day } = dateOfTvAiring; + contentMetadata.setDateOfTvAiring(year, month, day); } - if(timeOfTvAiring) { - const { hours, minutes } = timeOfTvAiring - contentMetadata.setTimeOfTvAiring(hours,minutes) + if (timeOfTvAiring) { + const { hours, minutes } = timeOfTvAiring; + contentMetadata.setTimeOfTvAiring(hours, minutes); } - if(dateOfDigitalAiring) { - const { year, month, day } = dateOfDigitalAiring - contentMetadata.setDateOfDigitalAiring(year,month,day) + if (dateOfDigitalAiring) { + const { year, month, day } = dateOfDigitalAiring; + contentMetadata.setDateOfDigitalAiring(year, month, day); } - if(timeOfDigitalAiring) { - const { hours, minutes } = timeOfDigitalAiring - contentMetadata.setTimeOfDigitalAiring(hours,minutes) + if (timeOfDigitalAiring) { + const { hours, minutes } = timeOfDigitalAiring; + contentMetadata.setTimeOfDigitalAiring(hours, minutes); } - if(feedType) { - contentMetadata.setFeedType(mapFeedType(feedType)) + if (feedType) { + contentMetadata.setFeedType(mapFeedType(feedType)); } - contentMetadata.classifyAsAudioStream(classifyAsAudioStream) - if(deliveryMode) { - contentMetadata.setDeliveryMode(mapDeliveryMode(deliveryMode)) + contentMetadata.classifyAsAudioStream(classifyAsAudioStream); + if (deliveryMode) { + contentMetadata.setDeliveryMode(mapDeliveryMode(deliveryMode)); } - if(deliverySubscriptionType) { - contentMetadata.setDeliverySubscriptionType(mapDeliverySubscriptionType(deliverySubscriptionType)) + if (deliverySubscriptionType) { + contentMetadata.setDeliverySubscriptionType(mapDeliverySubscriptionType(deliverySubscriptionType)); } - if(deliveryComposition) { - contentMetadata.setDeliveryComposition(mapDeliveryComposition(deliveryComposition)) + if (deliveryComposition) { + contentMetadata.setDeliveryComposition(mapDeliveryComposition(deliveryComposition)); } - if(deliveryAdvertisementCapability) { - contentMetadata.setDeliveryAdvertisementCapability(mapDeliveryAdvertisementCapability(deliveryAdvertisementCapability)) + if (deliveryAdvertisementCapability) { + contentMetadata.setDeliveryAdvertisementCapability( + mapDeliveryAdvertisementCapability(deliveryAdvertisementCapability) + ); } - if(mediaFormat) { - contentMetadata.setMediaFormat(mapMediaFormat(mediaFormat)) + if (mediaFormat) { + contentMetadata.setMediaFormat(mapMediaFormat(mediaFormat)); } - if(distributionModel) { - contentMetadata.setDistributionModel(mapDistributionModel(distributionModel)) + if (distributionModel) { + contentMetadata.setDistributionModel(mapDistributionModel(distributionModel)); } - if(playlistTitle) { - contentMetadata.setPlaylistTitle(playlistTitle) + if (playlistTitle) { + contentMetadata.setPlaylistTitle(playlistTitle); } - if(totalSegments) { - contentMetadata.setTotalSegments(totalSegments) + if (totalSegments) { + contentMetadata.setTotalSegments(totalSegments); } - if(clipUrl) { - contentMetadata.setClipUrl(clipUrl) + if (clipUrl) { + contentMetadata.setClipUrl(clipUrl); } - if(videoDimension) { - const { width, height } = videoDimension - contentMetadata.setVideoDimensions(width,height) + if (videoDimension) { + const { width, height } = videoDimension; + contentMetadata.setVideoDimensions(width, height); } - if(customLabels) { - contentMetadata.addCustomLabels(customLabels) + if (customLabels) { + contentMetadata.addCustomLabels(customLabels); } - return contentMetadata - -} + return contentMetadata; +}; const mapMediaType = (mediaType: ComscoreMediaType): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType => { - switch(mediaType){ + switch (mediaType) { case ComscoreMediaType.bumper: return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.BUMPER; case ComscoreMediaType.live: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.LIVE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.LIVE; case ComscoreMediaType.longFormOnDemand: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.LONG_FORM_ON_DEMAND + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.LONG_FORM_ON_DEMAND; case ComscoreMediaType.other: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.OTHER + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.OTHER; case ComscoreMediaType.shortFormOnDemand: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.SHORT_FORM_ON_DEMAND + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.SHORT_FORM_ON_DEMAND; case ComscoreMediaType.userGeneratedLive: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.USER_GENERATED_LIVE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.USER_GENERATED_LIVE; case ComscoreMediaType.userGeneratedLongFormOnDemand: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.USER_GENERATED_LONG_FORM_ON_DEMAND + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.USER_GENERATED_LONG_FORM_ON_DEMAND; case ComscoreMediaType.userGeneratedShortFormOnDemand: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.USER_GENERATED_SHORT_FORM_ON_DEMAND + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.USER_GENERATED_SHORT_FORM_ON_DEMAND; default: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.OTHER + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentType.OTHER; } -} +}; const mapFeedType = (feedType: ComscoreFeedType): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentFeedType => { - switch(feedType){ + switch (feedType) { case ComscoreFeedType.eastHD: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentFeedType.EAST_HD + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentFeedType.EAST_HD; case ComscoreFeedType.westHD: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentFeedType.WEST_HD + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentFeedType.WEST_HD; case ComscoreFeedType.eastSD: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentFeedType.EAST_SD + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentFeedType.EAST_SD; case ComscoreFeedType.westSD: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentFeedType.WEST_SD + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentFeedType.WEST_SD; default: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentFeedType.OTHER + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentFeedType.OTHER; } -} +}; -const mapDeliveryMode = (deliveryMode: ComscoreDeliveryMode): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryMode => { - switch(deliveryMode){ +const mapDeliveryMode = ( + deliveryMode: ComscoreDeliveryMode +): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryMode => { + switch (deliveryMode) { case ComscoreDeliveryMode.linear: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryMode.LINEAR + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryMode.LINEAR; case ComscoreDeliveryMode.ondemand: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryMode.ON_DEMAND + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryMode.ON_DEMAND; default: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryMode.ON_DEMAND + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryMode.ON_DEMAND; } -} +}; -const mapDeliverySubscriptionType = (deliverySubscriptionType: ComscoreDeliverySubscriptionType): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType => { - switch(deliverySubscriptionType){ +const mapDeliverySubscriptionType = ( + deliverySubscriptionType: ComscoreDeliverySubscriptionType +): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType => { + switch (deliverySubscriptionType) { case ComscoreDeliverySubscriptionType.traditionalMvpd: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.TRADITIONAL_MVPD + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.TRADITIONAL_MVPD; case ComscoreDeliverySubscriptionType.virtualMvpd: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.VIRTUAL_MVPD + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.VIRTUAL_MVPD; case ComscoreDeliverySubscriptionType.subscription: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.SUBSCRIPTION + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.SUBSCRIPTION; case ComscoreDeliverySubscriptionType.transactional: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.TRANSACTIONAL + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.TRANSACTIONAL; case ComscoreDeliverySubscriptionType.advertising: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.ADVERTISING + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.ADVERTISING; case ComscoreDeliverySubscriptionType.premium: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.PREMIUM + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.PREMIUM; default: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.SUBSCRIPTION + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliverySubscriptionType.SUBSCRIPTION; } -} +}; -const mapDeliveryComposition = (deliveryComposition: ComscoreDeliveryComposition): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryComposition => { - switch(deliveryComposition){ +const mapDeliveryComposition = ( + deliveryComposition: ComscoreDeliveryComposition +): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryComposition => { + switch (deliveryComposition) { case ComscoreDeliveryComposition.clean: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryComposition.CLEAN + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryComposition.CLEAN; case ComscoreDeliveryComposition.embed: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryComposition.EMBED + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryComposition.EMBED; default: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryComposition.EMBED + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryComposition.EMBED; } -} +}; -const mapDeliveryAdvertisementCapability = (deliveryAdvertisementCapability: ComscoreDeliveryAdvertisementCapability): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability => { - switch(deliveryAdvertisementCapability){ +const mapDeliveryAdvertisementCapability = ( + deliveryAdvertisementCapability: ComscoreDeliveryAdvertisementCapability +): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability => { + switch (deliveryAdvertisementCapability) { case ComscoreDeliveryAdvertisementCapability.none: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.NONE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.NONE; case ComscoreDeliveryAdvertisementCapability.dynamicLoad: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.DYNAMIC_LOAD + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.DYNAMIC_LOAD; case ComscoreDeliveryAdvertisementCapability.dynamicReplacement: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.DYNAMIC_REPLACEMENT + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability + .DYNAMIC_REPLACEMENT; case ComscoreDeliveryAdvertisementCapability.linear1day: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_1DAY + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_1DAY; case ComscoreDeliveryAdvertisementCapability.linear2day: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_2DAY + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_2DAY; case ComscoreDeliveryAdvertisementCapability.linear3day: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_3DAY + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_3DAY; case ComscoreDeliveryAdvertisementCapability.linear4day: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_4DAY + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_4DAY; case ComscoreDeliveryAdvertisementCapability.linear5day: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_5DAY + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_5DAY; case ComscoreDeliveryAdvertisementCapability.linear6day: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_6DAY + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_6DAY; case ComscoreDeliveryAdvertisementCapability.linear7day: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_7DAY + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.LINEAR_7DAY; default: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.NONE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDeliveryAdvertisementCapability.NONE; } -} +}; -const mapMediaFormat = (mediaFormat: ComscoreMediaFormat): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat => { - switch(mediaFormat){ +const mapMediaFormat = ( + mediaFormat: ComscoreMediaFormat +): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat => { + switch (mediaFormat) { case ComscoreMediaFormat.fullContentEpisode: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.FULL_CONTENT_EPISODE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.FULL_CONTENT_EPISODE; case ComscoreMediaFormat.fullContentMovie: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.FULL_CONTENT_MOVIE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.FULL_CONTENT_MOVIE; case ComscoreMediaFormat.fullContentPodcast: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.FULL_CONTENT_GENERIC + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.FULL_CONTENT_GENERIC; case ComscoreMediaFormat.fullContentGeneric: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.FULL_CONTENT_GENERIC + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.FULL_CONTENT_GENERIC; case ComscoreMediaFormat.partialContentEpisode: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PARTIAL_CONTENT_EPISODE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PARTIAL_CONTENT_EPISODE; case ComscoreMediaFormat.partialContentMovie: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PARTIAL_CONTENT_MOVIE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PARTIAL_CONTENT_MOVIE; case ComscoreMediaFormat.partialContentPodcast: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PARTIAL_CONTENT_GENERIC + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PARTIAL_CONTENT_GENERIC; case ComscoreMediaFormat.partialContentGeneric: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PARTIAL_CONTENT_GENERIC + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PARTIAL_CONTENT_GENERIC; case ComscoreMediaFormat.previewEpisode: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PREVIEW_EPISODE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PREVIEW_EPISODE; case ComscoreMediaFormat.previewMovie: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PREVIEW_MOVIE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PREVIEW_MOVIE; case ComscoreMediaFormat.previewGeneric: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PREVIEW_GENERIC + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.PREVIEW_GENERIC; case ComscoreMediaFormat.extraEpisode: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.EXTRA_EPISODE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.EXTRA_EPISODE; case ComscoreMediaFormat.extraMovie: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.EXTRA_MOVIE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.EXTRA_MOVIE; case ComscoreMediaFormat.extraGeneric: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.EXTRA_GENERIC + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.EXTRA_GENERIC; default: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.FULL_CONTENT_GENERIC + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentMediaFormat.FULL_CONTENT_GENERIC; } -} +}; -const mapDistributionModel = (distributionModel: ComscoreDistributionModel): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDistributionModel => { - switch(distributionModel) { +const mapDistributionModel = ( + distributionModel: ComscoreDistributionModel +): ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDistributionModel => { + switch (distributionModel) { case ComscoreDistributionModel.tvAndOnline: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDistributionModel.TV_AND_ONLINE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDistributionModel.TV_AND_ONLINE; case ComscoreDistributionModel.exclusivelyOnline: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDistributionModel.EXCLUSIVELY_ONLINE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDistributionModel.EXCLUSIVELY_ONLINE; default: - return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDistributionModel.EXCLUSIVELY_ONLINE + return ns_.analytics.StreamingAnalytics.ContentMetadata.ContentDistributionModel.EXCLUSIVELY_ONLINE; } -} +}; diff --git a/comscore/src/integration/ComscoreStreamingAnalyticsTHEOIntegration.ts b/comscore/src/integration/ComscoreStreamingAnalyticsTHEOIntegration.ts index 436e41a4..352905db 100644 --- a/comscore/src/integration/ComscoreStreamingAnalyticsTHEOIntegration.ts +++ b/comscore/src/integration/ComscoreStreamingAnalyticsTHEOIntegration.ts @@ -1,19 +1,35 @@ -import { AdBreakEvent, AdEvent, ChromelessPlayer, EndedEvent, LoadedMetadataEvent, PauseEvent, PlayEvent, PlayingEvent, RateChangeEvent, SeekedEvent, SeekingEvent, SourceChangeEvent, WaitingEvent, ErrorEvent, version } from "theoplayer"; -import { ComscoreConfiguration } from "../api/ComscoreConfiguration"; -import { ComscoreMetadata } from "../api/ComscoreMetadata"; -import { buildContentMetadata } from "./ComscoreContentMetadata"; +import { + AdBreakEvent, + AdEvent, + ChromelessPlayer, + EndedEvent, + LoadedMetadataEvent, + PauseEvent, + PlayEvent, + PlayingEvent, + RateChangeEvent, + SeekedEvent, + SeekingEvent, + SourceChangeEvent, + WaitingEvent, + ErrorEvent, + version +} from 'theoplayer'; +import { ComscoreConfiguration } from '../api/ComscoreConfiguration'; +import { ComscoreMetadata } from '../api/ComscoreMetadata'; +import { buildContentMetadata } from './ComscoreContentMetadata'; const LOG_STATE_CHANGES = true; -const LOG_THEOPLAYER_EVENTS = true -const LOG_STREAMINGANALYTICS = true +const LOG_THEOPLAYER_EVENTS = true; +const LOG_STREAMINGANALYTICS = true; enum ComscoreState { - INITIALIZED = "INITIALIZED", - ADVERTISEMENT = "ADVERTISEMENT", - ADVERTISEMENT_PAUSED = "ADVERTISEMENT_PAUSED", - VIDEO = "VIDEO", - VIDEO_PAUSED = "VIDEO_PAUSED", - STOPPED = "STOPPED" + INITIALIZED = 'INITIALIZED', + ADVERTISEMENT = 'ADVERTISEMENT', + ADVERTISEMENT_PAUSED = 'ADVERTISEMENT_PAUSED', + VIDEO = 'VIDEO', + VIDEO_PAUSED = 'VIDEO_PAUSED', + STOPPED = 'STOPPED' } enum AdBreakType { @@ -29,9 +45,9 @@ export class ComscoreStreamingAnalyticsTHEOIntegration { private metadata: ComscoreMetadata; // Playback state managed by the integration - private state: ComscoreState = ComscoreState.INITIALIZED - private buffering: boolean = false - private ended: boolean = false + private state: ComscoreState = ComscoreState.INITIALIZED; + private buffering: boolean = false; + private ended: boolean = false; // Comscore library handles private analytics = ns_.analytics; @@ -41,28 +57,26 @@ export class ComscoreStreamingAnalyticsTHEOIntegration { private contentMetadata: ns_.analytics.StreamingAnalytics.ContentMetadata | null = null; // Advertisement related fields for use outside of ad event handlers - private inAd: boolean = false - private lastAdId: string | undefined = undefined - private lastAdDuration: number | undefined = undefined - private lastAdBreakType: AdBreakType | undefined = undefined - + private inAd: boolean = false; + private lastAdId: string | undefined = undefined; + private lastAdDuration: number | undefined = undefined; + private lastAdBreakType: AdBreakType | undefined = undefined; constructor(player: ChromelessPlayer, configuration: ComscoreConfiguration, metadata: ComscoreMetadata) { - this.player = player - this.configuration = configuration - this.metadata = metadata + this.player = player; + this.configuration = configuration; + this.metadata = metadata; - this.streamingAnalytics.setMediaPlayerName("THEOplayer") - this.streamingAnalytics.setMediaPlayerVersion(version) + this.streamingAnalytics.setMediaPlayerName('THEOplayer'); + this.streamingAnalytics.setMediaPlayerVersion(version); - this.addListeners() + this.addListeners(); } - // PUBLIC methods public update(metadata: ComscoreMetadata) { this.metadata = metadata; - this.contentMetadata = null + this.contentMetadata = null; } public destroy() { @@ -70,100 +84,108 @@ export class ComscoreStreamingAnalyticsTHEOIntegration { } private addListeners(): void { - this.player.addEventListener("sourcechange", this.onSourceChange); - this.player.addEventListener("play", this.onPlay); - this.player.addEventListener("ended", this.onEnded); - this.player.addEventListener("error", this.onError); - this.player.addEventListener("loadedmetadata", this.onLoadedMetadata); - this.player.addEventListener("playing", this.onPlaying); - this.player.addEventListener("seeking", this.onSeeking); - this.player.addEventListener("seeked", this.onSeeked); - this.player.addEventListener("pause", this.onPause); - this.player.addEventListener("ratechange", this.onRateChange); - this.player.addEventListener("waiting", this.onWaiting); + this.player.addEventListener('sourcechange', this.onSourceChange); + this.player.addEventListener('play', this.onPlay); + this.player.addEventListener('ended', this.onEnded); + this.player.addEventListener('error', this.onError); + this.player.addEventListener('loadedmetadata', this.onLoadedMetadata); + this.player.addEventListener('playing', this.onPlaying); + this.player.addEventListener('seeking', this.onSeeking); + this.player.addEventListener('seeked', this.onSeeked); + this.player.addEventListener('pause', this.onPause); + this.player.addEventListener('ratechange', this.onRateChange); + this.player.addEventListener('waiting', this.onWaiting); if (this.player.ads) { - this.player.ads.addEventListener("adbegin", this.onAdBegin); - this.player.ads.addEventListener("adbreakend", this.onAdBreakEnd); + this.player.ads.addEventListener('adbegin', this.onAdBegin); + this.player.ads.addEventListener('adbreakend', this.onAdBreakEnd); } } private removeListeners(): void { - this.player.removeEventListener("sourcechange", this.onSourceChange); - this.player.removeEventListener("play", this.onPlay); - this.player.removeEventListener("ended", this.onEnded); - this.player.removeEventListener("error", this.onError); - this.player.removeEventListener("loadedmetadata", this.onLoadedMetadata); - this.player.removeEventListener("playing", this.onPlaying); - this.player.removeEventListener("seeking", this.onSeeking); - this.player.removeEventListener("seeked", this.onSeeked); - this.player.removeEventListener("pause", this.onPause); - this.player.removeEventListener("ratechange", this.onRateChange); - this.player.removeEventListener("waiting", this.onWaiting); + this.player.removeEventListener('sourcechange', this.onSourceChange); + this.player.removeEventListener('play', this.onPlay); + this.player.removeEventListener('ended', this.onEnded); + this.player.removeEventListener('error', this.onError); + this.player.removeEventListener('loadedmetadata', this.onLoadedMetadata); + this.player.removeEventListener('playing', this.onPlaying); + this.player.removeEventListener('seeking', this.onSeeking); + this.player.removeEventListener('seeked', this.onSeeked); + this.player.removeEventListener('pause', this.onPause); + this.player.removeEventListener('ratechange', this.onRateChange); + this.player.removeEventListener('waiting', this.onWaiting); if (this.player.ads) { - this.player.ads.removeEventListener("adbegin", this.onAdBegin); - this.player.ads.removeEventListener("adbreakend", this.onAdBreakEnd); + this.player.ads.removeEventListener('adbegin', this.onAdBegin); + this.player.ads.removeEventListener('adbreakend', this.onAdBreakEnd); } } private setContentMetadata(): void { - const contentMetadata = buildContentMetadata(this.metadata) - this.contentMetadata = contentMetadata + const contentMetadata = buildContentMetadata(this.metadata); + this.contentMetadata = contentMetadata; if (this.configuration.debug && LOG_STREAMINGANALYTICS) { - console.log(`[COMSCORE - StreamingAnalytics] setMetadata (content)`, contentMetadata.getMetadataLabels()) + console.log(`[COMSCORE - StreamingAnalytics] setMetadata (content)`, contentMetadata.getMetadataLabels()); } - this.streamingAnalytics.setMetadata(contentMetadata) - + this.streamingAnalytics.setMetadata(contentMetadata); } private setAdMetadata(adDuration: number, adBreakType: AdBreakType, adId: string): void { - const adMetadata = new this.analytics.StreamingAnalytics.AdvertisementMetadata() + const adMetadata = new this.analytics.StreamingAnalytics.AdvertisementMetadata(); if (this.player.duration === Infinity) { - adMetadata.setMediaType(this.analytics.StreamingAnalytics.AdvertisementMetadata.AdvertisementType.LIVE) + adMetadata.setMediaType(this.analytics.StreamingAnalytics.AdvertisementMetadata.AdvertisementType.LIVE); } else if (adBreakType === AdBreakType.PRE_ROLL) { - adMetadata.setMediaType(this.analytics.StreamingAnalytics.AdvertisementMetadata.AdvertisementType.ON_DEMAND_PRE_ROLL) + adMetadata.setMediaType( + this.analytics.StreamingAnalytics.AdvertisementMetadata.AdvertisementType.ON_DEMAND_PRE_ROLL + ); } else if (adBreakType === AdBreakType.POST_ROLL) { - adMetadata.setMediaType(this.analytics.StreamingAnalytics.AdvertisementMetadata.AdvertisementType.ON_DEMAND_POST_ROLL) + adMetadata.setMediaType( + this.analytics.StreamingAnalytics.AdvertisementMetadata.AdvertisementType.ON_DEMAND_POST_ROLL + ); } else { - adMetadata.setMediaType(this.analytics.StreamingAnalytics.AdvertisementMetadata.AdvertisementType.ON_DEMAND_MID_ROLL) + adMetadata.setMediaType( + this.analytics.StreamingAnalytics.AdvertisementMetadata.AdvertisementType.ON_DEMAND_MID_ROLL + ); } - adMetadata.setUniqueId(adId) - adMetadata.setLength(adDuration) + adMetadata.setUniqueId(adId); + adMetadata.setLength(adDuration); - if (!this.contentMetadata) buildContentMetadata(this.metadata) - adMetadata.setRelatedContentMetadata(this.contentMetadata) + if (!this.contentMetadata) buildContentMetadata(this.metadata); + adMetadata.setRelatedContentMetadata(this.contentMetadata); if (this.configuration.debug && LOG_STREAMINGANALYTICS) { - console.log(`[COMSCORE - StreamingAnalytics] setMetadata (advertisement)`, adMetadata.getMetadataLabels()) + console.log(`[COMSCORE - StreamingAnalytics] setMetadata (advertisement)`, adMetadata.getMetadataLabels()); } - this.streamingAnalytics.setMetadata(adMetadata) - - + this.streamingAnalytics.setMetadata(adMetadata); } // STATE TRANSITIONS private transitionToVideo(): void { - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] Trying to transition to VIDEO while in ${this.state}`); - switch(this.state) { + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] Trying to transition to VIDEO while in ${this.state}`); + switch (this.state) { case ComscoreState.INITIALIZED: - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] State change ${this.state} -> VIDEO`); - this.state = ComscoreState.VIDEO - this.setContentMetadata() + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] State change ${this.state} -> VIDEO`); + this.state = ComscoreState.VIDEO; + this.setContentMetadata(); break; case ComscoreState.ADVERTISEMENT: case ComscoreState.ADVERTISEMENT_PAUSED: case ComscoreState.STOPPED: this.transitionToStopped(); - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] State change ${this.state} -> VIDEO`); - this.state = ComscoreState.VIDEO - this.setContentMetadata() + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] State change ${this.state} -> VIDEO`); + this.state = ComscoreState.VIDEO; + this.setContentMetadata(); break; case ComscoreState.VIDEO_PAUSED: - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] State change ${this.state} -> VIDEO`); - this.state = ComscoreState.VIDEO + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] State change ${this.state} -> VIDEO`); + this.state = ComscoreState.VIDEO; break; case ComscoreState.VIDEO: - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] Ignoring transition from ${this.state} -> VIDEO`); + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] Ignoring transition from ${this.state} -> VIDEO`); break; default: break; @@ -171,266 +193,329 @@ export class ComscoreStreamingAnalyticsTHEOIntegration { } private transitionToAdvertisement(): void { - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] Trying to transition to ADVERTISEMENT while in ${this.state}`); - switch(this.state) { + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] Trying to transition to ADVERTISEMENT while in ${this.state}`); + switch (this.state) { case ComscoreState.INITIALIZED: - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] State change ${this.state} -> ADVERTISEMENT`); - this.state = ComscoreState.ADVERTISEMENT - this.setAdMetadata(this.lastAdDuration ?? 0, this.lastAdBreakType ?? AdBreakType.PRE_ROLL, this.lastAdId ?? "") + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] State change ${this.state} -> ADVERTISEMENT`); + this.state = ComscoreState.ADVERTISEMENT; + this.setAdMetadata( + this.lastAdDuration ?? 0, + this.lastAdBreakType ?? AdBreakType.PRE_ROLL, + this.lastAdId ?? '' + ); break; case ComscoreState.VIDEO: case ComscoreState.VIDEO_PAUSED: case ComscoreState.STOPPED: this.transitionToStopped(); - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] State change ${this.state} -> ADVERTISEMENT`); - this.state = ComscoreState.ADVERTISEMENT - this.setAdMetadata(this.lastAdDuration ?? 0, this.lastAdBreakType ?? AdBreakType.PRE_ROLL, this.lastAdId ?? "") + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] State change ${this.state} -> ADVERTISEMENT`); + this.state = ComscoreState.ADVERTISEMENT; + this.setAdMetadata( + this.lastAdDuration ?? 0, + this.lastAdBreakType ?? AdBreakType.PRE_ROLL, + this.lastAdId ?? '' + ); break; case ComscoreState.ADVERTISEMENT_PAUSED: - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] State change ${this.state} -> ADVERTISEMENT`); - this.state = ComscoreState.ADVERTISEMENT + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] State change ${this.state} -> ADVERTISEMENT`); + this.state = ComscoreState.ADVERTISEMENT; break; case ComscoreState.ADVERTISEMENT: - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] Ignoring transition from ${this.state} -> ADVERTISEMENT`); + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] Ignoring transition from ${this.state} -> ADVERTISEMENT`); break; default: break; } - } private transitionToPaused(): void { - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] Trying to transition to XXXXX_PAUSED while in ${this.state}`); - switch(this.state) { + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] Trying to transition to XXXXX_PAUSED while in ${this.state}`); + switch (this.state) { case ComscoreState.VIDEO: - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] State change ${this.state} -> VIDEO_PAUSED`); - this.state = ComscoreState.VIDEO_PAUSED - this.streamingAnalytics.notifyPause() - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] notifyPause`); + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] State change ${this.state} -> VIDEO_PAUSED`); + this.state = ComscoreState.VIDEO_PAUSED; + this.streamingAnalytics.notifyPause(); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log(`[COMSCORE - StreamingAnalytics] notifyPause`); break; case ComscoreState.ADVERTISEMENT: - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] State change ${this.state} -> ADVERTISEMENT_PAUSED`); - this.state = ComscoreState.ADVERTISEMENT_PAUSED - this.streamingAnalytics.notifyPause() - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] notifyPause`); + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] State change ${this.state} -> ADVERTISEMENT_PAUSED`); + this.state = ComscoreState.ADVERTISEMENT_PAUSED; + this.streamingAnalytics.notifyPause(); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log(`[COMSCORE - StreamingAnalytics] notifyPause`); break; default: - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] Ignoring transition from ${this.state} -> XXXXX_PAUSED`); + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] Ignoring transition from ${this.state} -> XXXXX_PAUSED`); } - } private transitionToStopped(): void { - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] Trying to transition to STOPPED while in ${this.state}`); + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] Trying to transition to STOPPED while in ${this.state}`); switch (this.state) { case ComscoreState.STOPPED: - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] Ignoring transition from ${this.state} -> STOPPED`); + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] Ignoring transition from ${this.state} -> STOPPED`); break; - default: - if (this.configuration.debug && LOG_STATE_CHANGES) console.log(`[COMSCORE - STATE] State change ${this.state} -> STOPPED`); + default: + if (this.configuration.debug && LOG_STATE_CHANGES) + console.log(`[COMSCORE - STATE] State change ${this.state} -> STOPPED`); this.state = ComscoreState.STOPPED; - this.streamingAnalytics.notifyEnd() - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] notifyEnd`); - } + this.streamingAnalytics.notifyEnd(); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log(`[COMSCORE - StreamingAnalytics] notifyEnd`); + } } // EVENT HANDLERS private onSourceChange = (event: SourceChangeEvent) => { - if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); + if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) + console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); this.state = ComscoreState.INITIALIZED; this.contentMetadata = null; this.streamingAnalytics.createPlaybackSession(); - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] createPlaybackSession`); - - } + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log(`[COMSCORE - StreamingAnalytics] createPlaybackSession`); + }; private onPlay = (event: PlayEvent) => { - if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`) + if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) + console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); if (this.ended) { - this.ended = false - if (this.configuration.debug) console.log(`[COMSCORE] play event after the stream ended`) - this.streamingAnalytics.createPlaybackSession() - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] createPlaybackSession`); + this.ended = false; + if (this.configuration.debug) console.log(`[COMSCORE] play event after the stream ended`); + this.streamingAnalytics.createPlaybackSession(); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log(`[COMSCORE - StreamingAnalytics] createPlaybackSession`); } - } + }; private onPlaying = (event: PlayingEvent) => { - if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`) + if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) + console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); if (this.buffering) { - this.buffering = false - this.streamingAnalytics.notifyBufferStop() - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] notifyBufferStop`) + this.buffering = false; + this.streamingAnalytics.notifyBufferStop(); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log(`[COMSCORE - StreamingAnalytics] notifyBufferStop`); } - const { currentTime } = event + const { currentTime } = event; if (this.inAd) { - this.transitionToAdvertisement() + this.transitionToAdvertisement(); } else if (this.isAfterPostRoll()) { - if (this.configuration.debug) console.log(`[COMSCORE] Ignore playing event after post-roll (currentTime ${currentTime})`) - return + if (this.configuration.debug) + console.log(`[COMSCORE] Ignore playing event after post-roll (currentTime ${currentTime})`); + return; } else if (this.isBeforePreRoll()) { - if (this.configuration.debug) console.log(`[COMSCORE] Ignore playing event before pre-roll (currentTime ${currentTime})`) - return + if (this.configuration.debug) + console.log(`[COMSCORE] Ignore playing event before pre-roll (currentTime ${currentTime})`); + return; } else if (currentTime < 1 && this.ended === true) { - this.ended = false - if (this.configuration.debug) console.log(`[COMSCORE] playing event after the stream ended`) - this.streamingAnalytics.createPlaybackSession() - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] createPlaybackSession`); - this.transitionToVideo() + this.ended = false; + if (this.configuration.debug) console.log(`[COMSCORE] playing event after the stream ended`); + this.streamingAnalytics.createPlaybackSession(); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log(`[COMSCORE - StreamingAnalytics] createPlaybackSession`); + this.transitionToVideo(); } else { - this.transitionToVideo() - + this.transitionToVideo(); } - this.streamingAnalytics.notifyPlay() - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] notifyPlay`) - } + this.streamingAnalytics.notifyPlay(); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log(`[COMSCORE - StreamingAnalytics] notifyPlay`); + }; private onEnded = (event: EndedEvent) => { - if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`) - this.transitionToStopped() - this.ended = true - } + if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) + console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); + this.transitionToStopped(); + this.ended = true; + }; private onError = (event: ErrorEvent) => { - if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`) - this.transitionToStopped() - } + if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) + console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); + this.transitionToStopped(); + }; private onLoadedMetadata = (event: LoadedMetadataEvent) => { - if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`) + if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) + console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); if (!this.inAd && this.state === ComscoreState.ADVERTISEMENT && !this.isAfterPostRoll()) { - this.transitionToVideo() + this.transitionToVideo(); } if (this.metadata.length === 0 && !this.inAd) { - if (this.configuration.debug) console.log(`[COMSCORE] LIVE stream detected`) + if (this.configuration.debug) console.log(`[COMSCORE] LIVE stream detected`); try { - const { seekable } = this.player + const { seekable } = this.player; if (seekable.length) { - const dvrWindowEnd = seekable.end(seekable.length - 1) - const dvrWindowStart = seekable.start(0) - const dvrWindowLengthInSeconds = dvrWindowEnd - dvrWindowStart + const dvrWindowEnd = seekable.end(seekable.length - 1); + const dvrWindowStart = seekable.start(0); + const dvrWindowLengthInSeconds = dvrWindowEnd - dvrWindowStart; if (dvrWindowLengthInSeconds) { - this.streamingAnalytics.setDvrWindowLength(dvrWindowLengthInSeconds * 1000) - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] setDvrWindowLength ${dvrWindowLengthInSeconds * 1000}`) - } else if (this.configuration.debug) console.log(`[COMSCORE] DVR window length was not > 0`) + this.streamingAnalytics.setDvrWindowLength(dvrWindowLengthInSeconds * 1000); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log( + `[COMSCORE - StreamingAnalytics] setDvrWindowLength ${dvrWindowLengthInSeconds * 1000}` + ); + } else if (this.configuration.debug) console.log(`[COMSCORE] DVR window length was not > 0`); } } catch (error) { - if (this.configuration.debug) console.log(`[COMSCORE] There was a problem inspecting the seekable ranges on the loadedmetadata event`) + if (this.configuration.debug) + console.log( + `[COMSCORE] There was a problem inspecting the seekable ranges on the loadedmetadata event` + ); } } - } + }; private onSeeking = (event: SeekingEvent) => { - if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`) - this.streamingAnalytics.notifySeekStart() - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] notifySeekStart`) - } + if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) + console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); + this.streamingAnalytics.notifySeekStart(); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log(`[COMSCORE - StreamingAnalytics] notifySeekStart`); + }; private onSeeked = (event: SeekedEvent) => { - if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`) + if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) + console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); if (!this.inAd && this.state === ComscoreState.ADVERTISEMENT) { - this.transitionToVideo() + this.transitionToVideo(); } - const { currentTime } = event + const { currentTime } = event; if (this.player.duration === Infinity) { - if (this.configuration.debug) console.log(`[COMSCORE] seeked in a LIVE stream`) - const { seekable } = this.player + if (this.configuration.debug) console.log(`[COMSCORE] seeked in a LIVE stream`); + const { seekable } = this.player; if (!seekable.length) { - if (this.configuration.debug) console.log(`[COMSCORE] no seekable ranges found when determining DVR window offset`) - return + if (this.configuration.debug) + console.log(`[COMSCORE] no seekable ranges found when determining DVR window offset`); + return; } - const dvrWindowEnd = seekable.end(seekable.length - 1) - const dvrWindowOffsetInSeconds = dvrWindowEnd - currentTime - this.streamingAnalytics.startFromDvrWindowOffset(dvrWindowOffsetInSeconds * 1000) - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] startFromDvrWindowOffset ${dvrWindowOffsetInSeconds * 1000}`) + const dvrWindowEnd = seekable.end(seekable.length - 1); + const dvrWindowOffsetInSeconds = dvrWindowEnd - currentTime; + this.streamingAnalytics.startFromDvrWindowOffset(dvrWindowOffsetInSeconds * 1000); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log( + `[COMSCORE - StreamingAnalytics] startFromDvrWindowOffset ${dvrWindowOffsetInSeconds * 1000}` + ); } else { - if (this.configuration.debug) console.log(`[COMSCORE] seeked in a VOD stream`) - this.streamingAnalytics.startFromPosition(currentTime * 1000) - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] startFromPosition ${currentTime * 1000}`) + if (this.configuration.debug) console.log(`[COMSCORE] seeked in a VOD stream`); + this.streamingAnalytics.startFromPosition(currentTime * 1000); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log(`[COMSCORE - StreamingAnalytics] startFromPosition ${currentTime * 1000}`); } - } + }; private onPause = (event: PauseEvent) => { - if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`) - this.transitionToPaused() - } - - private onAdBegin = (event: AdEvent<"adbegin">) => { - if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`) - const { ad } = event - const { adIdProcessor } = this.configuration - - this.inAd = true - this.lastAdBreakType = this.findAdBreakType(ad.adBreak.timeOffset, ad.adBreak.maxDuration ?? 0, ad.adBreak.integration ?? "") - this.lastAdId = adIdProcessor ? adIdProcessor(ad) : ad.id - this.lastAdDuration = ad.duration + if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) + console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); + this.transitionToPaused(); + }; + + private onAdBegin = (event: AdEvent<'adbegin'>) => { + if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) + console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); + const { ad } = event; + const { adIdProcessor } = this.configuration; + + this.inAd = true; + this.lastAdBreakType = this.findAdBreakType( + ad.adBreak.timeOffset, + ad.adBreak.maxDuration ?? 0, + ad.adBreak.integration ?? '' + ); + this.lastAdId = adIdProcessor ? adIdProcessor(ad) : ad.id; + this.lastAdDuration = ad.duration; if (!this.lastAdDuration && this.configuration.debug) { - console.log("[COMSCORE] AD_BEGIN event with an ad duration of 0 found. Please check the ad configuration") + console.log('[COMSCORE] AD_BEGIN event with an ad duration of 0 found. Please check the ad configuration'); } if (!this.lastAdId && this.configuration.debug) { - console.log("[COMSCORE] AD_BEGIN event with an empty ad id found. Please check the ad configuration") + console.log('[COMSCORE] AD_BEGIN event with an empty ad id found. Please check the ad configuration'); } - if (this.isPlayingGoogleDAISource()){ - this.transitionToAdvertisement() - this.streamingAnalytics.notifyPlay() - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] notifyPlay`) + if (this.isPlayingGoogleDAISource()) { + this.transitionToAdvertisement(); + this.streamingAnalytics.notifyPlay(); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log(`[COMSCORE - StreamingAnalytics] notifyPlay`); } - - } + }; - private onAdBreakEnd = (event: AdBreakEvent<"adbreakend">) => { - if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`) - this.inAd = false - } + private onAdBreakEnd = (event: AdBreakEvent<'adbreakend'>) => { + if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) + console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); + this.inAd = false; + }; private onRateChange = (event: RateChangeEvent) => { - if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`) - this.streamingAnalytics.notifyChangePlaybackRate(event.playbackRate) - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] notifyChangePlaybackRate ${event.playbackRate}`) - } + if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) + console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); + this.streamingAnalytics.notifyChangePlaybackRate(event.playbackRate); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log(`[COMSCORE - StreamingAnalytics] notifyChangePlaybackRate ${event.playbackRate}`); + }; private onWaiting = (event: WaitingEvent) => { - if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`) - if ((this.state === ComscoreState.ADVERTISEMENT && this.inAd) || (this.state === ComscoreState.VIDEO && !this.inAd)) { - this.buffering = true - this.streamingAnalytics.notifyBufferStart() - if (this.configuration.debug && LOG_STREAMINGANALYTICS) console.log(`[COMSCORE - StreamingAnalytics] notifyBufferStart`) + if (this.configuration.debug && LOG_THEOPLAYER_EVENTS) + console.log(`[COMSCORE - THEOplayer EVENTS] ${event.type} event`); + if ( + (this.state === ComscoreState.ADVERTISEMENT && this.inAd) || + (this.state === ComscoreState.VIDEO && !this.inAd) + ) { + this.buffering = true; + this.streamingAnalytics.notifyBufferStart(); + if (this.configuration.debug && LOG_STREAMINGANALYTICS) + console.log(`[COMSCORE - StreamingAnalytics] notifyBufferStart`); } - } + }; - private findAdBreakType = (offset: number, maxDuration: number, integration: string ): AdBreakType => { + private findAdBreakType = (offset: number, maxDuration: number, integration: string): AdBreakType => { if (offset === 0) { - if (this.configuration.debug) console.log('[COMSCORE] Mark as PRE_ROLL') - return AdBreakType.PRE_ROLL + if (this.configuration.debug) console.log('[COMSCORE] Mark as PRE_ROLL'); + return AdBreakType.PRE_ROLL; } switch (integration) { - case "google-ima": - case "theo": + case 'google-ima': + case 'theo': if (offset === -1) { - if (this.configuration.debug) console.log('[COMSCORE] Mark as POST_ROLL') - return AdBreakType.POST_ROLL - } - if (this.configuration.debug) console.log('[COMSCORE] Mark as MID_ROLL') - return AdBreakType.MID_ROLL - case "google-dai": + if (this.configuration.debug) console.log('[COMSCORE] Mark as POST_ROLL'); + return AdBreakType.POST_ROLL; + } + if (this.configuration.debug) console.log('[COMSCORE] Mark as MID_ROLL'); + return AdBreakType.MID_ROLL; + case 'google-dai': if (this.player.duration - (offset + maxDuration) <= 0) { - if (this.configuration.debug) console.log('[COMSCORE] Mark as POST_ROLL') - return AdBreakType.POST_ROLL - } - if (this.configuration.debug) console.log('[COMSCORE] Mark as MID_ROLL') - return AdBreakType.MID_ROLL - + if (this.configuration.debug) console.log('[COMSCORE] Mark as POST_ROLL'); + return AdBreakType.POST_ROLL; + } + if (this.configuration.debug) console.log('[COMSCORE] Mark as MID_ROLL'); + return AdBreakType.MID_ROLL; + default: - if (this.configuration.debug) console.log('[COMSCORE] Untested ad integration used, please contact THEOplayer') - return AdBreakType.MID_ROLL + if (this.configuration.debug) + console.log('[COMSCORE] Untested ad integration used, please contact THEOplayer'); + return AdBreakType.MID_ROLL; } - } + }; - private isBeforePreRoll = (): boolean => this.player.ads?.scheduledAdBreaks.length ? this.player.ads?.scheduledAdBreaks[0].timeOffset === 0 : false + private isBeforePreRoll = (): boolean => + this.player.ads?.scheduledAdBreaks.length ? this.player.ads?.scheduledAdBreaks[0].timeOffset === 0 : false; // private isAfterPostRoll = () => this.lastAdBreakOffset && this.lastAdBreakOffset < 0 && this.player.duration - this.player.currentTime < 1 - private isAfterPostRoll = (): boolean => this.lastAdBreakType ? this.lastAdBreakType === AdBreakType.POST_ROLL : false - private isPlayingGoogleDAISource = (): boolean => this.player.ads?.currentAdBreak?.integration === "google-dai" -} \ No newline at end of file + private isAfterPostRoll = (): boolean => + this.lastAdBreakType ? this.lastAdBreakType === AdBreakType.POST_ROLL : false; + private isPlayingGoogleDAISource = (): boolean => this.player.ads?.currentAdBreak?.integration === 'google-dai'; +}