Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove CONTENT- and MEDIAPLAYHEAD macro and fix timecode generation #358

Merged
merged 7 commits into from
May 4, 2020

Conversation

klipstein
Copy link
Contributor

Description

While playing around with this library, I tested it by accident with a VAST that contained the macro [CONTENTPLAYHEAD] and I've wondered why it was filled with such a value: 0.0011111111111111111%3A0.06666666666666667%3A4.65.

I also wondered why the CONTENTPLAYHEAD was continuously updated whereas it should be set to the content playhead where the ad started. Same also for the MEDIAPLAYHEAD and I think those two macros can only be set from the outside to the VAST Tracker. Another finding was, that the macros which get passed into the click method get mutated in two places, once for the click-tracking and once for calculating the click-through URL. This can lead to double-encoded macro values.

This pull request tries to fix the mentioned issues.

Type

  • Breaking change
  • Enhancement
  • Fix
  • Documentation
  • Tooling

Copy link
Contributor

@ZacharieTFR ZacharieTFR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing @klipstein ! Actually you're right CONTENTPLAYHEAD and MEDIAPLAYHEAD can only be set by the player as we do not have the value for it in the tracker. Good catch for the double encoding 👍. Let's wait for another approval

src/util/util.js Outdated
Comment on lines 179 to 183
function leftpad(str, len) {
str = String(str);
if (str.length < len) {
return (
range(0, 8 - str.length, false)
range(0, len - str.length, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all thank you for this PR, and for the contribution.
WDYT to put the second parameter as optional ? with value to 8, as before ?
Also I think we shouldn't reaffect str
I would like to propose this, if you are ok:

function leftpad(input, len = 8) { const str = String(input);

Then the previous call to leftpad stay the same (and if anyone was using this outside the library, it will not break the code)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that those utils are an implementation detail of vast-client and are not exposed. Your proposal makes sense and I'll adjust the pull as suggested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted it.

@@ -532,16 +531,16 @@ export class VASTTracker extends EventEmitter {
// Use the provided fallbackClickThroughURL as a fallback
const clickThroughURLTemplate =
this.clickThroughURLTemplate || fallbackClickThroughURL;
// clone second usage of macros, which get mutated inside resolveURLTemplates
const clonedMacros = JSON.parse(JSON.stringify(macros));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As macros is 1 level plain object, what about using destruct to clone the object ?

Suggested change
const clonedMacros = JSON.parse(JSON.stringify(macros));
const clonedMacros = {...macros};

Performance wise it's better I think.

Copy link
Contributor Author

@klipstein klipstein Apr 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to use {...macros} but eslint complained with Unexpected token ... and I did not wanted to fiddle with the eslint config. I'll give it a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've upgraded eslint dependencies and used babel-eslint as parser so that the spread syntax is now supported. Also had to disable the rule no-prototype-builtins because some parts of the code conflict with this newly enabled rule (see https://eslint.org/docs/rules/no-prototype-builtins) and I didn't want to touch that.

Eslint complained about `Unexpected token ...` so I've upgraded eslint
and switched to babel-eslint parser
Copy link
Contributor

@rumesh rumesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@rumesh rumesh merged commit 9f4703b into dailymotion:3.0-version May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

3 participants