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

Fix React Native createObjectURL polyfill incompatibility #1845

Merged
merged 1 commit into from
Mar 20, 2019
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
12 changes: 11 additions & 1 deletion lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ shaka.media.MediaSourceEngine = function(
};


/**
* Internal reference to window.URL.createObjectURL function to avoid
* compatibility issues with other libraries and frameworks such as React
* Native. For use in unit tests only, not meant for external use.
*
* @type {function(?):string}
*/
shaka.media.MediaSourceEngine.createObjectURL = window.URL.createObjectURL;


/**
* Create a MediaSource object, attach it to the video element, and return it.
* Resolves the given promise when the MediaSource is ready.
Expand All @@ -107,7 +117,7 @@ shaka.media.MediaSourceEngine.prototype.createMediaSource = function(p) {

// Set up MediaSource on the video element.
this.eventManager_.listenOnce(mediaSource, 'sourceopen', p.resolve);
this.video_.src = window.URL.createObjectURL(mediaSource);
this.video_.src = shaka.media.MediaSourceEngine.createObjectURL(mediaSource);

return mediaSource;
};
Expand Down
8 changes: 5 additions & 3 deletions test/media/media_source_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ describe('MediaSourceEngine', function() {
});

describe('constructor', function() {
const originalCreateObjectURL = window.URL.createObjectURL;
const originalCreateObjectURL =
shaka.media.MediaSourceEngine.createObjectURL;
const originalMediaSource = window.MediaSource;
/** @type {jasmine.Spy} */
let createObjectURLSpy;
Expand All @@ -176,7 +177,8 @@ describe('MediaSourceEngine', function() {

createObjectURLSpy = jasmine.createSpy('createObjectURL');
createObjectURLSpy.and.returnValue('blob:foo');
window.URL.createObjectURL = Util.spyFunc(createObjectURLSpy);
shaka.media.MediaSourceEngine.createObjectURL =
Util.spyFunc(createObjectURLSpy);

let mediaSourceSpy = jasmine.createSpy('MediaSource').and.callFake(() => {
return mockMediaSource;
Expand All @@ -187,7 +189,7 @@ describe('MediaSourceEngine', function() {
});

afterAll(function() {
window.URL.createObjectURL = originalCreateObjectURL;
shaka.media.MediaSourceEngine.createObjectURL = originalCreateObjectURL;
window.MediaSource = originalMediaSource;
});

Expand Down