diff --git a/src/components/LegacyMediaAnalytics/createMediaAnalyticsTracker.js b/src/components/LegacyMediaAnalytics/createMediaAnalyticsTracker.js index 4ca69ce2c..d613df252 100644 --- a/src/components/LegacyMediaAnalytics/createMediaAnalyticsTracker.js +++ b/src/components/LegacyMediaAnalytics/createMediaAnalyticsTracker.js @@ -20,9 +20,9 @@ import { PlayerState, StreamType, VideoMetadataKeys -} from "./Media/constants"; +} from "./media/constants"; import { deepAssign, isEmptyObject, isNumber } from "../../utils"; -import { adsToXdmKeys, mediaToXdmKeys } from "./Media/mediaKeysToXdmConverter"; +import { adsToXdmKeys, mediaToXdmKeys } from "./media/mediaKeysToXdmConverter"; import { createMediaObject, createAdBreakObject, diff --git a/src/components/LegacyMediaAnalytics/Media/constants.js b/src/components/LegacyMediaAnalytics/media/constants.js similarity index 100% rename from src/components/LegacyMediaAnalytics/Media/constants.js rename to src/components/LegacyMediaAnalytics/media/constants.js diff --git a/src/components/LegacyMediaAnalytics/Media/mediaKeysToXdmConverter.js b/src/components/LegacyMediaAnalytics/media/mediaKeysToXdmConverter.js similarity index 100% rename from src/components/LegacyMediaAnalytics/Media/mediaKeysToXdmConverter.js rename to src/components/LegacyMediaAnalytics/media/mediaKeysToXdmConverter.js diff --git a/src/components/MediaCollection/createHeartbeatEngine.js b/src/components/MediaCollection/createHeartbeatEngine.js index bcf864533..4b86e9966 100644 --- a/src/components/MediaCollection/createHeartbeatEngine.js +++ b/src/components/MediaCollection/createHeartbeatEngine.js @@ -10,37 +10,36 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -import toInteger from "../../../libEs6/utils/toInteger"; +import toInteger from "../../utils/toInteger"; export default ({ config, mediaEventManager, mediaSessionCacheManager }) => { return ({ playerId, sessionId, onBeforeMediaEvent }) => { const currentTime = Date.now(); const { mainPingInterval } = config.mediaCollection; - return mediaSessionCacheManager.getSession(playerId).then(session => { - if ( - Math.abs(currentTime - session.latestTriggeredEvent) / 1000 > - mainPingInterval - ) { - const { playhead } = onBeforeMediaEvent(playerId); - const xdm = { - eventType: "media.ping", - mediaCollection: { - playhead: toInteger(playhead), - sessionID: sessionId - } - }; - const event = mediaEventManager.createMediaEvent({ options: { xdm } }); - return mediaEventManager - .trackMediaEvent({ - event - }) - .then(() => { - mediaSessionCacheManager.updateLastTriggeredEventTS({ playerId }); - }); - } - - return Promise.resolve(); - }); + const playerSession = mediaSessionCacheManager.getSession(playerId); + if ( + Math.abs(currentTime - playerSession.latestTriggeredEvent) / 1000 > + mainPingInterval + ) { + const { playhead, qoeDataDetails } = onBeforeMediaEvent(playerId); + const xdm = { + eventType: "media.ping", + mediaCollection: { + playhead: toInteger(playhead), + sessionID: sessionId, + qoeDataDetails + } + }; + const event = mediaEventManager.createMediaEvent({ options: { xdm } }); + return mediaEventManager + .trackMediaEvent({ + event + }) + .then(() => { + mediaSessionCacheManager.updateLastTriggeredEventTS({ playerId }); + }); + } + return Promise.resolve(); }; }; diff --git a/src/components/MediaCollection/createMediaEventManager.js b/src/components/MediaCollection/createMediaEventManager.js index a39182425..5a9902df4 100644 --- a/src/components/MediaCollection/createMediaEventManager.js +++ b/src/components/MediaCollection/createMediaEventManager.js @@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -import MediaEvents from "./MediaConstants/mediaEvents"; +import MediaEvents from "./mediaConstants/mediaEvents"; import createMediaRequestPayload from "./createMediaRequestPayload"; import createMediaRequest from "./createMediaRequest"; import injectTimestamp from "../Context/injectTimestamp"; @@ -30,7 +30,7 @@ export default ({ config, eventManager, consent, sendEdgeNetworkRequest }) => { createMediaSession(options) { const { playerName, channel, version } = config.mediaCollection; const event = eventManager.createEvent(); - event.mergeXdm(options.xdm); + event.setUserXdm(options.xdm); event.mergeXdm({ eventType: MediaEvents.SESSION_START, mediaCollection: { diff --git a/src/components/MediaCollection/createMediaRequest.js b/src/components/MediaCollection/createMediaRequest.js index 415cbc162..980c8449c 100644 --- a/src/components/MediaCollection/createMediaRequest.js +++ b/src/components/MediaCollection/createMediaRequest.js @@ -20,7 +20,7 @@ export default ({ mediaRequestPayload, action }) => { return action; }, getUseSendBeacon() { - return true; + return false; } }); }; diff --git a/src/components/MediaCollection/createMediaSessionCacheManager.js b/src/components/MediaCollection/createMediaSessionCacheManager.js index f13e9cb88..6d2e01b04 100644 --- a/src/components/MediaCollection/createMediaSessionCacheManager.js +++ b/src/components/MediaCollection/createMediaSessionCacheManager.js @@ -10,16 +10,11 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -import { defer } from "../../utils"; - export default () => { let mediaSessionCache; - const sessionStorageDeferred = defer(); const getSession = playerId => { - return sessionStorageDeferred.promise.then(() => { - return mediaSessionCache[playerId] || {}; - }); + return mediaSessionCache[playerId] || {}; }; const saveHeartbeat = ({ playerId, heartbeatId }) => { @@ -52,7 +47,6 @@ export default () => { mediaSessionCache = {}; } mediaSessionCache[playerId] = sessionDetails; - sessionStorageDeferred.resolve(); }; return { diff --git a/src/components/MediaCollection/createUpdateMediaSessionState.js b/src/components/MediaCollection/createUpdateMediaSessionState.js index b701e9728..19cff7a8f 100644 --- a/src/components/MediaCollection/createUpdateMediaSessionState.js +++ b/src/components/MediaCollection/createUpdateMediaSessionState.js @@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -import MediaEvents from "./MediaConstants/mediaEvents"; +import MediaEvents from "./mediaConstants/mediaEvents"; export default ({ mediaSessionCacheManager }) => { return ({ playerId, xdm }) => { diff --git a/src/components/MediaCollection/index.js b/src/components/MediaCollection/index.js index 0ab478e52..d3b21b596 100644 --- a/src/components/MediaCollection/index.js +++ b/src/components/MediaCollection/index.js @@ -47,8 +47,7 @@ const createMediaCollection = ({ return { lifecycle: { - onBeforeEvent({ otherOptions, onResponse = noop }) { - const { playerId, onBeforeMediaEvent } = otherOptions; + onBeforeEvent({ playerId, onBeforeMediaEvent, onResponse = noop }) { onResponse(({ response }) => { const sessionId = response.getPayloadsByType( "media-analytics:new-session" @@ -109,25 +108,24 @@ const createMediaCollection = ({ const event = mediaEventManager.createMediaEvent({ options }); const { playerId } = options; - return mediaSessionCacheManager - .getSession(playerId) - .then(sessionDetails => { - const { onBeforeMediaEvent, sessionPromise } = sessionDetails; - sessionPromise.then(result => { - const finalEvent = mediaEventManager.augmentMediaEvent({ - event, - playerId, - onBeforeMediaEvent, - sessionID: result.sessionId - }); + const { + onBeforeMediaEvent, + sessionPromise + } = mediaSessionCacheManager.getSession(playerId); + sessionPromise.then(result => { + const finalEvent = mediaEventManager.augmentMediaEvent({ + event, + playerId, + onBeforeMediaEvent, + sessionID: result.sessionId + }); - return mediaEventManager - .trackMediaEvent({ event: finalEvent }) - .then(() => { - updateMediaSessionState({ playerId, xdm: finalEvent.xdm }); - }); + return mediaEventManager + .trackMediaEvent({ event: finalEvent }) + .then(() => { + updateMediaSessionState({ playerId, xdm: finalEvent.xdm }); }); - }); + }); } } } @@ -153,6 +151,6 @@ createMediaCollection.configValidators = objectOf({ .minimum(10) .maximum(60) .default(10) - }) + }).noUnknownFields() }); export default createMediaCollection; diff --git a/src/components/MediaCollection/MediaConstants/mediaEvents.js b/src/components/MediaCollection/mediaConstants/mediaEvents.js similarity index 100% rename from src/components/MediaCollection/MediaConstants/mediaEvents.js rename to src/components/MediaCollection/mediaConstants/mediaEvents.js diff --git a/src/components/MediaCollection/validateMediaEventOptions.js b/src/components/MediaCollection/validateMediaEventOptions.js index a90e6aa6e..5769c817d 100644 --- a/src/components/MediaCollection/validateMediaEventOptions.js +++ b/src/components/MediaCollection/validateMediaEventOptions.js @@ -35,7 +35,7 @@ export default ({ options }) => { .integer() .required(), sessionID: string().required() - }) + }).required() }).required() }).required() ], diff --git a/src/utils/validation/createMaximumValidator.js b/src/utils/validation/createMaximumValidator.js index 85ece5677..70c8be97b 100644 --- a/src/utils/validation/createMaximumValidator.js +++ b/src/utils/validation/createMaximumValidator.js @@ -16,7 +16,7 @@ export default (typeName, maximum) => (value, path) => { value <= maximum, value, path, - `${typeName} lower than or equal to ${maximum}` + `${typeName} less than or equal to ${maximum}` ); return value; };