app.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // 别间隔时间(毫秒), 识别服务地址
  2. const webAR = new WebAR(1000, '/webar/recognize');
  3. // 列出并打开设备上的摄像头
  4. document.querySelector('#openCamera').addEventListener('click', function () {
  5. const videoSelect = document.querySelector('#videoDevice');
  6. webAR.listCamera(videoSelect)
  7. .then(msg => {
  8. // 隐藏"打开摄像头"按钮
  9. this.style.display = 'none';
  10. videoSelect.style.display = 'inline-block';
  11. document.querySelector('#start').style.display = 'inline-block';
  12. document.querySelector('#stop').style.display = 'inline-block';
  13. videoSelect.onchange = () => {
  14. webAR.openCamera(JSON.parse(videoSelect.value));
  15. };
  16. // 打开摄像头
  17. // 打开后置摄像头参数: {audio: false, video: {facingMode: {exact: 'environment'}}}
  18. webAR.openCamera(JSON.parse(videoSelect.value))
  19. .then(msg => {
  20. console.info(msg);
  21. }).catch(err => {
  22. console.info(err);
  23. });
  24. })
  25. .catch(err => {
  26. // 没有找到摄像头
  27. console.info(err);
  28. });
  29. });
  30. // 开启识别
  31. document.querySelector('#start').addEventListener('click', () => {
  32. webAR.startRecognize((msg) => {
  33. console.info(msg);
  34. alert('识别成功');
  35. });
  36. }, false);
  37. // 暂停识别
  38. document.querySelector('#stop').addEventListener('click', () => {
  39. webAR.stopRecognize();
  40. }, false);
  41. //# sourceMappingURL=app.js.map