UNPKG

webrtc-samples

Version:

Project checking for WebRTC GitHub samples repo

56 lines (45 loc) 1.71 kB
/* * Copyright (c) 2015 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. */ /* global AudioContext, SoundMeter */ 'use strict'; var instantMeter = document.querySelector('#instant meter'); var slowMeter = document.querySelector('#slow meter'); var clipMeter = document.querySelector('#clip meter'); var instantValueDisplay = document.querySelector('#instant .value'); var slowValueDisplay = document.querySelector('#slow .value'); var clipValueDisplay = document.querySelector('#clip .value'); try { window.AudioContext = window.AudioContext || window.webkitAudioContext; window.audioContext = new AudioContext(); } catch (e) { alert('Web Audio API not supported.'); } // Put variables in global scope to make them available to the browser console. var constraints = window.constraints = { audio: true, video: false }; function successCallback(stream) { // Put variables in global scope to make them available to the // browser console. window.stream = stream; var soundMeter = window.soundMeter = new SoundMeter(window.audioContext); soundMeter.connectToSource(stream); setInterval(function() { instantMeter.value = instantValueDisplay.innerText = soundMeter.instant.toFixed(2); slowMeter.value = slowValueDisplay.innerText = soundMeter.slow.toFixed(2); clipMeter.value = clipValueDisplay.innerText = soundMeter.clip; }, 200); } function errorCallback(error) { console.log('navigator.getUserMedia error: ', error); } navigator.getUserMedia(constraints, successCallback, errorCallback);