summaryrefslogtreecommitdiffstats
path: root/mobile/android/geckoview/src/androidTest/assets/www/getusermedia_xorigin_iframe.html
blob: 3649167c255c2ef8b18bc53ac06ad8aabdb94597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<html>
  <head>
    <meta charset="utf-8" />
    <title>GetUserMedia from cross-origin iframe: the iframe document</title>
  </head>
  <body>
    <script>
      "use strict";

      let stream;
      window.addEventListener(
        "message",
        async ({ data: { name, gen, constraints } }) => {
          if (name == "start") {
            try {
              stream = await navigator.mediaDevices.getUserMedia(constraints);
              Send({ gen, result: "ok" });
            } catch (e) {
              Send({ gen, result: `${e}` });
            }
          } else if (name == "stop") {
            const result = !!stream;
            if (stream) {
              for (const t of stream.getTracks()) {
                t.stop();
              }
              stream = undefined;
            }
            Send({ gen, result });
          }
        }
      );

      function Send(obj) {
        window.parent.postMessage(obj, "http://localhost:4245");
      }
    </script>
  </body>
</html>