tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

serialization.crossAgentCluster.serviceworker.js (1494B)


      1 let videoFrameMap = new Map();
      2 let encodedVideoChunkMap = new Map();
      3 
      4 self.onmessage = (e) => {
      5  if (e.data == 'create-VideoFrame') {
      6    let frameOrError = null;
      7    try {
      8      frameOrError = new VideoFrame(
      9        new Uint8Array([
     10          1, 2, 3, 4, 5, 6, 7, 8,
     11          9, 10, 11, 12, 13, 14, 15, 16,
     12        ]), {
     13        timestamp: 0,
     14        codedWidth: 2,
     15        codedHeight: 2,
     16        format: 'RGBA',
     17      });
     18    } catch (error) {
     19      frameOrError = error
     20    }
     21    e.source.postMessage(frameOrError);
     22    return;
     23  }
     24 
     25  if (e.data == 'create-EncodedVideoChunk') {
     26    let chunkOrError = null;
     27    try {
     28      chunkOrError = new EncodedVideoChunk({
     29        type: 'key',
     30        timestamp: 0,
     31        duration: 1,
     32        data: new Uint8Array([2, 3, 4, 5])
     33      });
     34    } catch (error) {
     35      chunkOrError = error
     36    }
     37    e.source.postMessage(chunkOrError);
     38    return;
     39  }
     40 
     41  if (e.data.hasOwnProperty('videoFrameId')) {
     42    e.source.postMessage(
     43      videoFrameMap.get(e.data.videoFrameId) ? 'RECEIVED' : 'NOT_RECEIVED');
     44    return;
     45  }
     46 
     47  if (e.data.hasOwnProperty('encodedVideoChunkId')) {
     48    e.source.postMessage(
     49      encodedVideoChunkMap.get(e.data.encodedVideoChunkId) ? 'RECEIVED' : 'NOT_RECEIVED');
     50    return;
     51  }
     52 
     53  if (e.data.toString() == '[object VideoFrame]') {
     54    videoFrameMap.set(e.data.timestamp, e.data);
     55    return;
     56  }
     57 
     58  if (e.data.toString() == '[object EncodedVideoChunk]') {
     59    encodedVideoChunkMap.set(e.data.timestamp, e.data);
     60  }
     61 };