• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html>
3<head><title>getUserMedia sanity test</title></head>
4<body>
5  <video id="localVideo" width="1280" height="720" autoplay muted></video>
6<script>
7
8var testStatus = 'running';
9
10function getStatus() {
11  return testStatus;
12}
13
14function runTest() {
15  var test = new SanityTest();
16  test.start();
17}
18
19function SanityTest() {
20  this.localVideo = document.getElementById("localVideo");
21}
22
23SanityTest.prototype = {
24  start: function() {
25    this.localVideo.addEventListener('play',
26        this.onVideoPlaying.bind(this), false);
27    navigator.getUserMedia = navigator.getUserMedia ||
28        navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
29    navigator.getUserMedia({audio: true, video: true},
30        this.gotLocalStream.bind(this),
31        this.gotUserMediaError.bind(this));
32  },
33
34  gotLocalStream: function(stream) {
35    console.log('Attaching video stream to video tag, waiting for onplay()');
36    this.localVideo.src = window.URL.createObjectURL(stream);
37  },
38
39  gotUserMediaError: function(error) {
40    console.error('navigator.getUserMedia error: ', error);
41    testStatus = 'navigator.getUserMedia error: ' + error.toString();
42  },
43
44  onVideoPlaying: function() {
45    testStatus = 'ok-video-playing';
46  }
47}
48
49window.onload = runTest;
50window.onerror = function (message, filename, lineno, colno, error) {
51  console.log("Something went wrong, here is the stack trace --> %s",
52      error.stack);
53  testStatus = 'exception-in-test-page: ' + error.stack
54};
55</script>
56</body>
57</html>
58