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

feat: add request types #1479

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading