Files
Shade/packages/shade-media/src/browser/sw.ts

26 lines
1005 B
TypeScript
Raw Normal View History

/**
* Service Worker: makes a sealed file look like a normal one to the browser.
*
* The page points `<video src>` (or `<audio>`, `<img>`, a download link) at
* `<scope>media/<mediaId>`. This worker answers those requests itself —
* Range requests included, so seeking works — by fetching only the sealed
* segments under the requested range from wherever the grant says the file
* lives, verifying and decrypting them, and streaming the plaintext back.
*
* Keys live in this worker's memory only. A worker the browser stopped
* forgets them; it then asks the page (which still holds the grant) again.
*/
import { installShadeMedia } from './worker.js';
import type { WorkerScope } from './worker.js';
declare const self: WorkerScope;
// Standalone: this worker owns its scope and takes over open pages at once.
self.addEventListener('install', () => {
void self.skipWaiting();
});
self.addEventListener('activate', (e) => e.waitUntil(self.clients.claim()));
installShadeMedia(self);