Skip to content

Commit

Permalink
renaming, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Nina Ciocanu committed Dec 13, 2023
1 parent e8d2f12 commit 275123c
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
51 changes: 25 additions & 26 deletions src/components/MediaCollection/createHeartbeatEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
};
4 changes: 2 additions & 2 deletions src/components/MediaCollection/createMediaEventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/MediaCollection/createMediaRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default ({ mediaRequestPayload, action }) => {
return action;
},
getUseSendBeacon() {
return true;
return false;
}
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -52,7 +47,6 @@ export default () => {
mediaSessionCache = {};
}
mediaSessionCache[playerId] = sessionDetails;
sessionStorageDeferred.resolve();
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
38 changes: 18 additions & 20 deletions src/components/MediaCollection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 });
});
});
});
}
}
}
Expand All @@ -153,6 +151,6 @@ createMediaCollection.configValidators = objectOf({
.minimum(10)
.maximum(60)
.default(10)
})
}).noUnknownFields()
});
export default createMediaCollection;
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default ({ options }) => {
.integer()
.required(),
sessionID: string().required()
})
}).required()
}).required()
}).required()
],
Expand Down
2 changes: 1 addition & 1 deletion src/utils/validation/createMaximumValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 275123c

Please sign in to comment.