Skip to content
Open
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
11 changes: 9 additions & 2 deletions src/media-segment-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,22 @@ const handleSegmentResponse = ({
return finishProcessingFn(errorObj, segment);
}
triggerSegmentEventFn({ type: 'segmentloaded', segment });
const newBytes =

let newBytes;
// because the 'response' property from XMLHttpRequest is readonly,
// can add customize read-write 'videojsCustomizedResponse' property to request object via the onResponse method.
if (('videojsCustomizedResponse' in request) && request.videojsCustomizedResponse) {
newBytes = request.videojsCustomizedResponse;
} else {
// although responseText "should" exist, this guard serves to prevent an error being
// thrown for two primary cases:
// 1. the mime type override stops working, or is not implemented for a specific
// browser
// 2. when using mock XHR libraries like sinon that do not allow the override behavior
(responseType === 'arraybuffer' || !request.responseText) ?
newBytes = (responseType === 'arraybuffer' || !request.responseText) ?
request.response :
stringToArrayBuffer(request.responseText.substring(segment.lastReachedChar || 0));
}

segment.stats = getRequestStats(request);

Expand Down