Skip to content

Commit

Permalink
feat: add request types (#1479)
Browse files Browse the repository at this point in the history
Co-authored-by: Dzianis Dashkevich <ddashkevich@brightcove.com>
  • Loading branch information
dzianis-dashkevich and Dzianis Dashkevich committed Jan 24, 2024
1 parent ceb780a commit 5b87f69
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/content-steering-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ export default class ContentSteeringController extends videojs.EventTarget {
}

this.request_ = this.xhr_({
uri
uri,
requestType: 'content-steering-manifest'
}, (error, errorInfo) => {
if (error) {
// If the client receives HTTP 410 Gone in response to a manifest request,
Expand Down
6 changes: 4 additions & 2 deletions src/dash-playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,8 @@ export default class DashPlaylistLoader extends EventTarget {
requestMain_(cb) {
this.request = this.vhs_.xhr({
uri: this.mainPlaylistLoader_.srcUrl,
withCredentials: this.withCredentials
withCredentials: this.withCredentials,
requestType: 'dash-manifest'
}, (error, req) => {
if (this.requestErrored_(error, req)) {
if (this.state === 'HAVE_NOTHING') {
Expand Down Expand Up @@ -695,7 +696,8 @@ export default class DashPlaylistLoader extends EventTarget {
this.request = this.vhs_.xhr({
uri: resolveUrl(this.mainPlaylistLoader_.srcUrl, utcTiming.value),
method: utcTiming.method,
withCredentials: this.withCredentials
withCredentials: this.withCredentials,
requestType: 'dash-clock-sync'
}, (error, req) => {
// disposed
if (!this.request) {
Expand Down
12 changes: 8 additions & 4 deletions src/media-segment-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,8 @@ export const mediaSegmentRequest = ({
}
const keyRequestOptions = merge(xhrOptions, {
uri: segment.key.resolvedUri,
responseType: 'arraybuffer'
responseType: 'arraybuffer',
requestType: 'segment-key'
});
const keyRequestCallback = handleKeyResponse(segment, objects, finishProcessingFn);
const keyXhr = xhr(keyRequestOptions, keyRequestCallback);
Expand All @@ -1003,7 +1004,8 @@ export const mediaSegmentRequest = ({
if (differentMapKey) {
const mapKeyRequestOptions = merge(xhrOptions, {
uri: segment.map.key.resolvedUri,
responseType: 'arraybuffer'
responseType: 'arraybuffer',
requestType: 'segment-key'
});
const mapKeyRequestCallback = handleKeyResponse(segment, [segment.map.key], finishProcessingFn);
const mapKeyXhr = xhr(mapKeyRequestOptions, mapKeyRequestCallback);
Expand All @@ -1013,7 +1015,8 @@ export const mediaSegmentRequest = ({
const initSegmentOptions = merge(xhrOptions, {
uri: segment.map.resolvedUri,
responseType: 'arraybuffer',
headers: segmentXhrHeaders(segment.map)
headers: segmentXhrHeaders(segment.map),
requestType: 'segment-media-initialization'
});
const initSegmentRequestCallback = handleInitSegmentResponse({segment, finishProcessingFn});
const initSegmentXhr = xhr(initSegmentOptions, initSegmentRequestCallback);
Expand All @@ -1024,7 +1027,8 @@ export const mediaSegmentRequest = ({
const segmentRequestOptions = merge(xhrOptions, {
uri: segment.part && segment.part.resolvedUri || segment.resolvedUri,
responseType: 'arraybuffer',
headers: segmentXhrHeaders(segment)
headers: segmentXhrHeaders(segment),
requestType: 'segment'
});

const segmentRequestCallback = handleSegmentResponse({
Expand Down
9 changes: 6 additions & 3 deletions src/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ export default class PlaylistLoader extends EventTarget {

this.request = this.vhs_.xhr({
uri,
withCredentials: this.withCredentials
withCredentials: this.withCredentials,
requestType: 'hls-playlist'
}, (error, req) => {
// disposed
if (!this.request) {
Expand Down Expand Up @@ -689,7 +690,8 @@ export default class PlaylistLoader extends EventTarget {

this.request = this.vhs_.xhr({
uri: playlist.resolvedUri,
withCredentials: this.withCredentials
withCredentials: this.withCredentials,
requestType: 'hls-playlist'
}, (error, req) => {
// disposed
if (!this.request) {
Expand Down Expand Up @@ -835,7 +837,8 @@ export default class PlaylistLoader extends EventTarget {
// request the specified URL
this.request = this.vhs_.xhr({
uri: this.src,
withCredentials: this.withCredentials
withCredentials: this.withCredentials,
requestType: 'hls-playlist'
}, (error, req) => {
// disposed
if (!this.request) {
Expand Down
6 changes: 1 addition & 5 deletions src/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import videojs from 'video.js';
import window from 'global/window';
import {merge} from './util/vjs-compat';

const {
xhr: videojsXHR
} = videojs;

const callbackWrapper = function(request, error, response, callback) {
const reqResponse = request.responseType === 'arraybuffer' ? request.response : request.responseText;

Expand Down Expand Up @@ -115,7 +111,7 @@ const xhrFactory = function() {

// Use the standard videojs.xhr() method unless `videojs.Vhs.xhr` has been overriden
// TODO: switch back to videojs.Vhs.xhr.name === 'XhrFunction' when we drop IE11
const xhrMethod = videojs.Vhs.xhr.original === true ? videojsXHR : videojs.Vhs.xhr;
const xhrMethod = videojs.Vhs.xhr.original === true ? videojs.xhr : videojs.Vhs.xhr;

// call all registered onRequest hooks, assign new options.
const beforeRequestOptions = callAllRequestHooks(_requestCallbackSet, options);
Expand Down

0 comments on commit 5b87f69

Please sign in to comment.