Skip to content

Commit

Permalink
#58: ClickThrough example (#59)
Browse files Browse the repository at this point in the history
* fix: typo

* fix: ensure that all exceptions thrown are dropped to stderr

* fix: if you are using variables in the catch block it needs to be defined outside the try closure

* feat: #58: add example of clickthrough element in VAST
  • Loading branch information
birme authored Oct 5, 2021
1 parent 087ee4e commit d759fce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
34 changes: 18 additions & 16 deletions api/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ module.exports = (fastify, opt, next) => {
const sessionList = await DBAdapter.getAllSessions(options);
reply.code(200).send(sessionList);
} catch (exc) {
console.error(exc);
logger.error(exc, { label: req.headers['host'] });
reply.code(500).send({ message: exc.message });
}
Expand All @@ -528,9 +529,9 @@ module.exports = (fastify, opt, next) => {
"/sessions/:sessionId",
{ schema: schemas["GET/sessions/:sessionId"] },
async (req, reply) => {
const sessionId = req.params.sessionId;
try {
const sessionId = req.params.sessionId;
const session = await DBAdapter.getSession(sessionId);
const session = await DBAdapter.getSession(sessionId);
if (!session) {
reply.code(404).send({
message: `Session with ID: '${sessionId}' was not found`,
Expand All @@ -547,6 +548,7 @@ module.exports = (fastify, opt, next) => {
reply.code(200).send(payload);
}
} catch (exc) {
console.error(exc);
logger.error(exc, { label: req.headers['host'], sessionId: sessionId });
reply.code(500).send({ message: exc.message });
}
Expand All @@ -557,9 +559,9 @@ module.exports = (fastify, opt, next) => {
"/sessions/:sessionId",
{ schema: schemas["DELETE/sessions/:sessionId"] },
async (req, reply) => {
const sessionId = req.params.sessionId;
try {
const sessionId = req.params.sessionId;
const session = await DBAdapter.getSession(sessionId);
const session = await DBAdapter.getSession(sessionId);
if (!session) {
reply.code(404).send({
message: `Session with ID: '${sessionId}' was not found`,
Expand All @@ -569,6 +571,7 @@ module.exports = (fastify, opt, next) => {
reply.send(204);
}
} catch (exc) {
console.error(exc);
logger.error(exc, { label: req.headers['host'], sessionId: sessionId });
reply.code(500).send({ message: exc.message });
}
Expand All @@ -579,12 +582,12 @@ module.exports = (fastify, opt, next) => {
"/sessions/:sessionId/tracking",
{ schema: schemas["GET/sessions/:sessionId/tracking"] },
async (req, reply) => {
const sessionId = req.params.sessionId;
const adId = req.query.adId;
const viewProgress = req.query.progress;
const userAgent = req.headers['user-agent'] || "Not Found";
try {
// Get path parameters and query parameters.
const sessionId = req.params.sessionId;
const adId = req.query.adId;
const viewProgress = req.query.progress;
const userAgent = req.headers['user-agent'] || "Not Found";
const eventNames = {
0: "start",
25: "firstQuartile",
Expand Down Expand Up @@ -625,6 +628,7 @@ module.exports = (fastify, opt, next) => {
});
}
} catch (exc) {
console.error(exc);
logger.error(exc, { label: req.headers['host'], sessionId: sessionId });
reply.code(500).send({ message: exc.message });
}
Expand All @@ -635,10 +639,9 @@ module.exports = (fastify, opt, next) => {
"/sessions/:sessionId/events",
{ schema: schemas["GET/sessions/:sessionId/events"] },
async (req, reply) => {
// Get path parameters and query parameters.
const sessionId = req.params.sessionId;
try {
// Get path parameters and query parameters.
const sessionId = req.params.sessionId;

// Check if session exists.
const session = await DBAdapter.getSession(sessionId);
if (!session) {
Expand All @@ -652,6 +655,7 @@ module.exports = (fastify, opt, next) => {
reply.code(200).send(eventsList);
}
} catch (exc) {
console.error(exc);
logger.error(exc, { label: req.headers['host'], sessionId: sessionId });
reply.code(500).send({ message: exc.message });
}
Expand Down Expand Up @@ -690,6 +694,7 @@ module.exports = (fastify, opt, next) => {
reply.code(200).send(sessionList);
}
} catch (exc) {
console.error(exc);
logger.error(exc, { label: req.headers['host'] });
reply.code(500).send({ message: exc.message });
}
Expand Down Expand Up @@ -771,11 +776,8 @@ module.exports = (fastify, opt, next) => {
reply.code(200).send(vast_xml);
}
} catch (exc) {
if (session) {
logger.error(exc, { label: req.headers['host'], sessionId: session.sessionId });
} else {
logger.error(exc, { label: req.headers['host'] });
}
console.error(exc);
logger.error(exc, { label: req.headers['host'] });
reply.code(500).send({ message: exc.message });
}
});
Expand Down
8 changes: 7 additions & 1 deletion utils/vast-maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ function AttachStandAloneAds(vast4, ads, params, podSize) {
{ event: 'complete' }
)
.and()
.attachVideoClicks()
.addClickThrough("https://github.com/Eyevinn/test-adserver", { id: "Eyevinn Test AdServer" })
.and()
.addDuration(ads[i].duration)
.attachMediaFiles()
.attachMediaFile(ads[i].url, {
Expand All @@ -186,7 +189,7 @@ function AttachPodAds(vast4, podAds, params) {
.addAdTitle(`Ad That Test-Adserver Wants Player To See #${i + 1}`)
.attachCreatives()
.attachCreative({
id: `CRETIVE-ID_00${i + 1}`,
id: `CREATIVE-ID_00${i + 1}`,
adId: `${podAds[i].id}_${i + 1}`,
sequence: `${i + 1}`,
})
Expand Down Expand Up @@ -230,6 +233,9 @@ function AttachPodAds(vast4, podAds, params) {
{ event: 'complete' }
)
.and()
.attachVideoClicks()
.addClickThrough("https://github.com/Eyevinn/test-adserver", { id: "Eyevinn Test AdServer" })
.and()
.addDuration(podAds[i].duration)
.attachMediaFiles()
.attachMediaFile(podAds[i].url, {
Expand Down

0 comments on commit d759fce

Please sign in to comment.