tor-browser

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

sources.js (2013B)


      1 function createAudioStream(t) {
      2  const ac = new AudioContext();
      3  const { stream } = ac.createMediaStreamDestination();
      4  const [track] = stream.getTracks();
      5  t.add_cleanup(() => {
      6    ac.close();
      7    track.stop();
      8  });
      9  return { stream };
     10 }
     11 
     12 function createFlowingAudioStream(t) {
     13  const ac = new AudioContext();
     14  const dest = ac.createMediaStreamDestination();
     15  const osc = ac.createOscillator();
     16  osc.connect(dest);
     17  osc.start();
     18  const [track] = dest.stream.getTracks();
     19  t.add_cleanup(() => {
     20    ac.close();
     21    track.stop();
     22  });
     23  return { stream: dest.stream };
     24 }
     25 
     26 function createVideoStream(t) {
     27  const canvas = document.createElement("canvas");
     28  canvas.id = "canvas";
     29  document.body.appendChild(canvas);
     30  const ctx = canvas.getContext("2d");
     31  const stream = canvas.captureStream();
     32  const [track] = stream.getTracks();
     33  t.add_cleanup(() => {
     34    document.body.removeChild(canvas);
     35    track.stop();
     36  });
     37  const addVideoFrame = () => {
     38    ctx.fillStyle = "red";
     39    ctx.fillRect(0, 0, canvas.width, canvas.height);
     40  };
     41  return { stream, control: { addVideoFrame } };
     42 }
     43 
     44 function createFlowingVideoStream(t) {
     45  const { stream } = createVideoStream(t);
     46  const [track] = stream.getTracks();
     47  const canvas = document.getElementById("canvas");
     48  const ctx = canvas.getContext("2d");
     49  ctx.fillStyle = "green";
     50  requestAnimationFrame(function draw() {
     51    ctx.fillRect(0, 0, canvas.width, canvas.height);
     52    if (track.readyState == "live") {
     53      requestAnimationFrame(draw);
     54    }
     55  });
     56  return { stream };
     57 }
     58 
     59 function createAudioVideoStream(t) {
     60  const { stream: audio } = createAudioStream(t);
     61  const { stream: video, control } = createVideoStream(t);
     62  return {
     63    stream: new MediaStream([...audio.getTracks(), ...video.getTracks()]),
     64    control,
     65  };
     66 }
     67 
     68 function createFlowingAudioVideoStream(t) {
     69  return {
     70    stream: new MediaStream([
     71      ...createFlowingAudioStream(t).stream.getTracks(),
     72      ...createFlowingVideoStream(t).stream.getTracks(),
     73    ]),
     74  };
     75 }