Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/violet-signs-go.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@adobe/alloy-core": patch
---

Fixed regression causing errors when using streaming media events
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default ({
createMediaEvent({ options }) {
const event = eventManager.createEvent();
const { xdm } = options;
setTimestamp(xdm);
setTimestamp(event);
event.setUserXdm(xdm);

if (xdm.eventType === MediaEvents.AD_START) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"requestId": "media-session-request-id",
"handle": [
{
"payload": [
{
"sessionId": "test-session-id-12345"
}
],
"type": "media-analytics:new-session"
}
]
}
27 changes: 27 additions & 0 deletions packages/core/test/integration/helpers/mswjs/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,30 @@ export const setConsentHandler = http.post(
throw new Error("Handler not configured properly");
},
);

export const mediaSessionHandler = http.post(
/https:\/\/edge.adobedc.net\/ee\/.*\/?v1\/interact/,

async (req) => {
const url = new URL(req.request.url);
const configId = url.searchParams.get("configId");

if (configId === "bc1a10e0-aee4-4e0e-ac5b-cdbb9abbec83") {
return HttpResponse.text(
await readFile(
`${server.config.root}/packages/core/test/integration/helpers/mocks/mediaSessionResponse.json`,
),
);
}

throw new Error("Handler not configured properly");
},
);

export const mediaEventHandler = http.post(
/https:\/\/edge.adobedc.net\/ee(\/[^/]+)?\/va\/v1\//,

async () => {
return new HttpResponse(null, { status: 204 });
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright 2025 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
import { test, expect, describe } from "../../helpers/testsSetup/extend.js";
import {
mediaSessionHandler,
mediaEventHandler,
} from "../../helpers/mswjs/handlers.js";
import alloyConfig from "../../helpers/alloy/config.js";

const streamingMediaConfig = {
...alloyConfig,
streamingMedia: {
channel: "test channel",
playerName: "test player",
},
};

describe("Streaming Media Events", () => {
test("media events include timestamp in xdm", async ({
alloy,
worker,
networkRecorder,
}) => {
worker.use(mediaSessionHandler, mediaEventHandler);

await alloy("configure", streamingMediaConfig);

await alloy("createMediaSession", {
playerId: "player1",
xdm: {
mediaCollection: {
sessionDetails: {
length: 60,
contentType: "VOD",
name: "test video",
},
},
},
getPlayerDetails: () => ({
playhead: 10,
qoeDataDetails: {
bitrate: 1000,
droppedFrames: 0,
framesPerSecond: 30,
timeToStart: 100,
},
}),
});

const sessionCall = await networkRecorder.findCall(/edge\.adobedc\.net/);
expect(sessionCall).toBeDefined();
expect(sessionCall.request.body.events[0].xdm.timestamp).toBeDefined();
expect(sessionCall.request.body.events[0].xdm.eventType).toBe(
"media.sessionStart",
);

await alloy("sendMediaEvent", {
playerId: "player1",
xdm: {
eventType: "media.play",
},
});

const mediaEventCalls = await networkRecorder.findCalls(/\/va\//);
expect(mediaEventCalls.length).toBeGreaterThan(0);

const playEvent = mediaEventCalls[0];
expect(playEvent.request.body.events[0].xdm.timestamp).toBeDefined();
expect(playEvent.request.body.events[0].xdm.eventType).toBe("media.play");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ describe("StreamingMedia::createMediaEventManager", () => {
setTimestamp,
});
});
it("should create a media event with user xdm", () => {
it("should create a media event with user xdm and call setTimestamp with the event", () => {
const options = {
xdm: {},
};
const event = {
setUserXdm: vi.fn(),
mergeXdm: vi.fn(),
toJSON: () => ({
a: 1,
}),
Expand All @@ -62,6 +63,7 @@ describe("StreamingMedia::createMediaEventManager", () => {
options,
});
expect(result.toJSON()).toEqual(event.toJSON());
expect(setTimestamp).toHaveBeenCalledWith(event);
});
it("should create a media session with player name, channel, and version", () => {
const options = {
Expand Down
Loading