@@ -79,8 +79,8 @@ window.Worker = class Worker extends oldWorker {
7979 }
8080 `
8181
82- var arrayBuffer = `
83- Response.prototype.arrayBuffer = function() {
82+ var filteredArrayBuffer = `
83+ Response.prototype.filteredArrayBuffer = function() {
8484 return this.text().then((text) => {
8585 var ret;
8686
@@ -99,30 +99,14 @@ window.Worker = class Worker extends oldWorker {
9999 };
100100 `
101101
102- var body = `
103- var oldBody = Object.getOwnPropertyDescriptor(Response.prototype, 'body');
104- Object.defineProperty(Response.prototype, 'body', {
105- get: function() {
106- if (this.url.endsWith('m3u8')) {
107- if (!this._gotData) {
108- this._gotData = true;
109- this.body._data = this.arrayBuffer();
110- this.body._dataRead = false;
111- }
112- }
113- return oldBody.get.call(this);
114- },
115- set: function(val) {
116- oldBody.set.call(this, val);
117- }
118- });
119- `
120-
121102 var reader = `
122- var oldReader = ReadableStream.prototype.getReader;
103+ // Firefox doesn't have ReadableStream
104+ self.ReadableStream = function () { };
105+ ReadableStream.prototype.cancel = function () { };
106+ ReadableStream.prototype.locked = false;
123107 ReadableStream.prototype.getReader = function() {
124108 if (this._dataRead === undefined) {
125- return oldReader.apply(this, arguments) ;
109+ return;
126110 }
127111
128112 var ret = Object.create(null);
@@ -153,6 +137,34 @@ window.Worker = class Worker extends oldWorker {
153137 }
154138 `
155139
140+ var body = `
141+ Object.defineProperty(Response.prototype, 'body', {
142+ get: function() {
143+ if (!this._rs) {
144+ this._rs = new ReadableStream();
145+ } else {
146+ return this._rs;
147+ }
148+
149+ if (!this._gotData) {
150+ this._gotData = true;
151+
152+ if (this.url.endsWith('m3u8')) {
153+ this._rs._data = this.filteredArrayBuffer();
154+ } else {
155+ this._rs._data = this.arrayBuffer();
156+ }
157+ this._rs._dataRead = false;
158+ }
159+
160+ return this._rs;
161+ },
162+ set: function(val) {
163+ this._rs = val;
164+ }
165+ });
166+ `
167+
156168 var e = `
157169 var Module = {
158170 WASM_BINARY_URL: 'https://cvp.twitch.tv/2.6.7/wasmworker.min.wasm',
@@ -165,10 +177,10 @@ window.Worker = class Worker extends oldWorker {
165177
166178 ${ stripAds }
167179
168- ${ arrayBuffer }
169-
170180 ${ body }
171181
182+ ${ filteredArrayBuffer }
183+
172184 ${ reader }
173185
174186 importScripts('https://cvp.twitch.tv/2.6.7/wasmworker.min.js');
0 commit comments