Porting Media Source Extension (MSE) Players to Vega
The following are general guidelines for porting your Media Source Extension (MSE) player to Vega:
- Replace XMLHttpRequest (XHR) objects with the Fetch API.
- Do not use the ReadableStream interface in the Fetch API and use asynchronous full read.
- Work around Document Object Model (DOM) dependencies.
- Implement polyfills where necessary.
Shaka player
Make the following modifications to your Shaka player to run with Vega.
-
Pollyfill the W3CMedia’s Media Source API.
Example:
global.window.MediaSource=global.MediaSource=MediaSource; global.HTMLMediaElement=HTMLMediaElement;
-
In place of the DOMParser, use the XMLDOM npm package, and specify the window for fetch.
Modified
navigator.userAgent
example:import{DOMParser}from"xmldom"; (global as any).navigator.userAgent ="kepler"; (global as any).window.DOMParser=DOMParser; (global as any).window.fetch= fetch;
-
Modify the Document object with a pollyfill. As the Video RN component is created and destroyed,
global.gvideo
is set or cleared.Example:
class Document { createElement = (name: string) => { console.log(`document.createElement ${name}`); return global.gvideo; } getElementsByTagName = (name: string) => { console.log(`document.getElementsByTagName ${name}`); return global.gvideo; } static install() { console.log("Installing Document polyfill"); global.document = new Document(); } }
-
Disable the Node interface in
xml_util.js
.Example:
-if(child instanceofElement&& child.tagName == name){ +if(child.nodeName == name){
Dash.js player
Make the following modifications to your dash.js player to run with Vega.
- Before you import any
dash.js
modules, you must initialize:(global as any).dashjs ={};
-
In the
HTTPLoader.js
, change the check to use fetch instead ofXMLHTTPRequest
. Some checks in the code lead to usage ofXMLHTTPRequest
, which couldn’t download the segments (0 byte segments were downloaded).Example:
if (/* request.hasOwnProperty('availabilityTimeComplete') && request.availabilityTimeC (request.type ===HTTPRequest.MEDIA_SEGMENT_TYPE|| request.type ===HTTPRequ console.log(`dashjs:HTTPLoader:using fetch loader`); loader =FetchLoader(context).create({ ....... else { console.log(`dashjs:HTTPLoader:using XHRLoader loader`); loader =XHRLoader(context).create({ ......... }
HLS.js player
Make the following modifications to your HLS.js player to run with Vega.
-
Apply the same polyfill classes that are applied for the forked Shaka Player to the HLS.js player.
-
Polyfill the
location.href
,DOMException
, andHTMLVideoElement
classes. -
Enable the fetch-loader plugin of
hls.js
. -
In the fetch-loader plugin, disable the
onProgress
callback (fetch.ReadableStream
is not supported). -
Disable progressive config (
fetch.ReadableStream
is not supported). -
Disable all subtitle configs (CUE API is not supported).
-
Patch the
SourceBuffer.appendBuffer
method to acceptUint8Array
. -
Disable workers (web workers (background process) is unsupported).
Last updated: Sep 30, 2025