comunic/assets/js/webrtc_main.js

47 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2016-11-19 11:08:12 +00:00
/*
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree.
*/
'use strict';
// Put variables in global scope to make them available to the browser console.
var canvas = window.canvas = document.querySelector('canvas');
canvas.width = 480;
canvas.height = 360;
var button = document.getElementById('bouton_prendre_photo');
button.onclick = function() {
canvas.getContext('2d').
drawImage(video, 0, 0, canvas.width, canvas.height);
};
var video = document.querySelector('video');
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
var constraints = {
audio: false,
video: true
};
function successCallback(stream) {
window.stream = stream; // make stream available to browser console
if (window.URL) {
video.src = window.URL.createObjectURL(stream);
} else {
video.src = stream;
}
}
function errorCallback(error) {
console.log('navigator.getUserMedia error: ', error);
}
// Activation automatique de la demande de la webcam (désactivé)
// navigator.getUserMedia(constraints, successCallback, errorCallback);