@@ -18,6 +18,9 @@ let comScore = 0;
1818let youSymbol = undefined ;
1919let comSymbol = undefined ;
2020let shootCount = 0 ;
21+ let loaded = false ;
22+ let timer = undefined ;
23+ let pBarWidth = 0 ;
2124
2225function drawKeypoints ( ctx , keypoints ) {
2326 function drawPoint ( ctx , y , x , r ) {
@@ -64,7 +67,7 @@ async function setupCamera() {
6467
6568 const video = document . getElementById ( 'video' ) ;
6669 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 ;
6871 document . getElementById ( 'gameInfo' ) . style . display = 'block' ;
6972 } ;
7073 const stream = await navigator . mediaDevices . getUserMedia ( {
@@ -98,7 +101,7 @@ const main =
98101 try {
99102 video = await loadVideo ( ) ;
100103 } 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 ;
102105 let info = document . getElementById ( 'info' ) ;
103106 info . textContent = e . message ;
104107 info . style . display = 'block' ;
@@ -147,7 +150,7 @@ const landmarksRealTime = async (video) => {
147150 if ( r . symbol === 'shoot' ) {
148151 shootCount ++ ;
149152 }
150-
153+
151154 if ( r . symbol === 'shoot' && shootCount >= shootThreshold && youSymbol ) {
152155 comSymbol = getComputerSymbol ( ) ;
153156 const winner = getWinner ( youSymbol , comSymbol ) ;
@@ -568,6 +571,27 @@ function updateLastSymbols() {
568571 }
569572}
570573
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+
571595navigator . getUserMedia = navigator . getUserMedia ||
572596 navigator . webkitGetUserMedia || navigator . mozGetUserMedia ;
573597
0 commit comments