Table of contents of this page:

Welcome to Viblast Documentation

Everything you need to know about Viblast Solutions. For more information contact us.

Viblast Documentation

XHR Manipulation

Viblast exposes the xhrBeforeSend and xhrBeforeCreate callbacks that can be used to manipulate an XHR object before it is created or sent. Use xhrBeforeSend to set custom headers etc. Use xhrBeforeCreate to change the request url or method. Here is their general form:

viblast("#playid").setup({
  // as usual
  xhrBeforeCreate: function(ev) {
    console.log('About to create a ', ev.method, 'request to ', ev.url, 'by Viblast instance', ev.target);
    //to change the url:
    ev.url = 'the_new_url';
    ev.method = 'new_method'; //one of the 'GET', 'PUT', 'POST', 'DELETE'
  },
  xhrBeforeSend: function(ev) {
    console.log('Sending a ', ev.method, 'request to ', ev.url, 'by Viblast instance', ev.target);
  }
});

The single argument passed to xhrBeforeSend has the following properties: * target - the viblast instance * xhr - the XMLHttpRequest itself * method - the method of the HTTP request * url - the URL of the HTTP request

The single argument passed to xhrBeforeCreate has the following properties:

  • target - the viblast instance
  • method - the method of the HTTP request
  • url - the URL of the HTTP request

video.js

Using xhrBeforeSend and xhrBeforeCreate with video.js is very similar:

videojs("playerid", {
  viblast: {
    // as usual
    xhrBeforeCreate: function(ev) {
      console.log('About to create a ', ev.method, 'request to ', ev.url, 'by Viblast instance', ev.target);
      //to change the url:
      ev.url = 'the_new_url';
      ev.method = 'new_method'; //one of the 'GET', 'PUT', 'POST', 'DELETE'
    },
    xhrBeforeSend: function(ev) {
      console.log('Sending a ', ev.method, 'request to ', ev.url, 'by Viblast instance', ev.target);
    }
  }
});

As always you can find an example in our Codepen page.

Beware

Use this API with caution. Don't override things like responseType because viblast.js will break.