Skip to content

Commit 0dcf309

Browse files
Revert "fix(service-worker): update service worker to handle seeking better for videos (#60029)" (#62422)
This reverts commit c663277. PR Close #62422
1 parent 1cc1500 commit 0dcf309

2 files changed

Lines changed: 1 addition & 64 deletions

File tree

‎packages/examples/service-worker/push/ngsw-worker.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright Google LLC All Rights Reserved.
44
*
55
* Use of this source code is governed by an MIT-style license that can be
6-
* found in the LICENSE file at https://angular.dev/license.
6+
* found in the LICENSE file at https://angular.dev/license
77
*/
88

99
// Mock `ngsw-worker.js` used for testing the examples.

‎packages/service-worker/worker/src/driver.ts‎

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,6 @@ export class Driver implements Debuggable, UpdateSource {
224224
return;
225225
}
226226

227-
// Calls range request handler
228-
if (req.headers.has('range')) {
229-
event.respondWith(this.handleRangeRequest(req));
230-
return;
231-
}
232-
233227
// The only thing that is served unconditionally is the debug page.
234228
if (requestUrlObj.path === this.ngswStatePath) {
235229
// Allow the debugger to handle the request, but don't affect SW state in any other way.
@@ -283,63 +277,6 @@ export class Driver implements Debuggable, UpdateSource {
283277
event.respondWith(this.handleFetch(event));
284278
}
285279

286-
// function to handle Range requests
287-
private async handleRangeRequest(req: Request): Promise<Response> {
288-
try {
289-
const response = await fetch(req);
290-
const contentType = response.headers.get('Content-Type');
291-
292-
// Only apply logic to content that is a video
293-
if (!contentType || !contentType.startsWith('video/')) {
294-
return response;
295-
}
296-
297-
const rangeHeader = req.headers.get('range');
298-
if (!rangeHeader) {
299-
return new Response(null, {
300-
status: 416,
301-
statusText: 'Range Not Satisfiable',
302-
});
303-
}
304-
305-
const rangeMatch = /bytes=(\d+)-(\d+)?/.exec(rangeHeader);
306-
if (!rangeMatch) {
307-
return new Response(null, {
308-
status: 416,
309-
statusText: 'Range Not Satisfiable',
310-
});
311-
}
312-
313-
const start = Number(rangeMatch[1]);
314-
const end = rangeMatch[2] ? Number(rangeMatch[2]) : undefined;
315-
316-
const buffer = await response.arrayBuffer();
317-
const contentLength = buffer.byteLength;
318-
319-
const chunk = buffer.slice(start, end ? end + 1 : contentLength);
320-
const chunkLength = chunk.byteLength;
321-
322-
const headers = new Headers(response.headers);
323-
headers.set(
324-
'Content-Range',
325-
`bytes ${start}-${end ? end : contentLength - 1}/${contentLength}`,
326-
);
327-
headers.set('Content-Length', chunkLength.toString());
328-
headers.set('Accept-Ranges', 'bytes');
329-
330-
return new Response(chunk, {
331-
status: 206,
332-
statusText: 'Partial Content',
333-
headers: headers,
334-
});
335-
} catch (error) {
336-
return new Response(null, {
337-
status: 500,
338-
statusText: 'Internal Server Error',
339-
});
340-
}
341-
}
342-
343280
/**
344281
* The handler for message events.
345282
*/

0 commit comments

Comments
 (0)