fluid-player displays the "skip ad" button if the ad has an attribute skipoffset (see here). I'm trying to create client code that injects a default skipoffset to the ad so that I show the skip button even if the ad doesn't have a pre-configured skip interval.
I tried overriding the player's functions onBeforeXMLHttpRequestOpen and onBeforeXMLHttpRequest, and using those to inject a value to the responseXML, but because request.onreadystatechange() handles the skipoffset extraction, and onreadystatechange calls into private methods of the playerInstance, I can't override it through the external api onBeforeXMLHttpRequestOpen or onBeforeXMLHttpRequest.
Any thoughts on where I can inject this default value?
So I managed to figure out the missing bit:
I was attempting to override the provided onreadystatechange by re-assigning this method with my own function, and than calling into the provided method.
onBeforeXMLHttpRequestOpen: request => {
let defaultOnReadyStateChange = request.onreadystatechange;
request.onreadystatechange = function () {
if (request.responseXML != null) {
let linearElements = request.responseXML.getElementsByTagName('Linear');
if (linearElements != null && linearElements.length) {
linearElements[0].setAttribute('skipoffset', '00:00:05');
}
}
defaultOnReadyStateChange();
};
By doing so I would get an error because when calling into defaultOnReadyStateChange, the context of the call would change and internal attributes for xmlHttpRequest would be missing.
The solution would be the above code, but the 2nd line should be
let defaultOnReadyStateChange = request.onreadystatechange.bind(request);
This works for me just fine.