@@ -18,6 +18,9 @@ let comScore = 0;
18
18
let youSymbol = undefined ;
19
19
let comSymbol = undefined ;
20
20
let shootCount = 0 ;
21
+ let loaded = false ;
22
+ let timer = undefined ;
23
+ let pBarWidth = 0 ;
21
24
22
25
function drawKeypoints ( ctx , keypoints ) {
23
26
function drawPoint ( ctx , y , x , r ) {
@@ -64,7 +67,7 @@ async function setupCamera() {
64
67
65
68
const video = document . getElementById ( 'video' ) ;
66
69
video . onloadeddata = ( event ) => {
67
- document . getElementById ( 'loading' ) . innerHTML = '<div class="spinner-grow text-primary null-spinner" role="status"><span class="sr-only">Loading...</span></div>' ;
70
+ loaded = true ;
68
71
document . getElementById ( 'gameInfo' ) . style . display = 'block' ;
69
72
} ;
70
73
const stream = await navigator . mediaDevices . getUserMedia ( {
@@ -98,7 +101,7 @@ const main =
98
101
try {
99
102
video = await loadVideo ( ) ;
100
103
} catch ( e ) {
101
- document . getElementById ( 'loading' ) . innerHTML = '<div class="spinner-grow text-primary null-spinner" role="status"><span class="sr-only">Loading...</span></div>' ;
104
+ loaded = true ;
102
105
let info = document . getElementById ( 'info' ) ;
103
106
info . textContent = e . message ;
104
107
info . style . display = 'block' ;
@@ -147,7 +150,7 @@ const landmarksRealTime = async (video) => {
147
150
if ( r . symbol === 'shoot' ) {
148
151
shootCount ++ ;
149
152
}
150
-
153
+
151
154
if ( r . symbol === 'shoot' && shootCount >= shootThreshold && youSymbol ) {
152
155
comSymbol = getComputerSymbol ( ) ;
153
156
const winner = getWinner ( youSymbol , comSymbol ) ;
@@ -568,6 +571,27 @@ function updateLastSymbols() {
568
571
}
569
572
}
570
573
574
+ function startProgressBar ( ) {
575
+ function doCheck ( ) {
576
+ const pbar = document . getElementById ( 'pBar' ) ;
577
+
578
+ if ( loaded ) {
579
+ clearInterval ( timer ) ;
580
+ pbar . style = `width: 100%` ;
581
+ } else {
582
+ pBarWidth += 10 ;
583
+ if ( pBarWidth > 100 ) {
584
+ pBarWidth = 0 ;
585
+ }
586
+ pbar . style = `width: ${ pBarWidth } %` ;
587
+ }
588
+ }
589
+
590
+ timer = setInterval ( doCheck , 500 ) ;
591
+ }
592
+
593
+ startProgressBar ( ) ;
594
+
571
595
navigator . getUserMedia = navigator . getUserMedia ||
572
596
navigator . webkitGetUserMedia || navigator . mozGetUserMedia ;
573
597
0 commit comments