File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 1
1
const hr = document . getElementById ( "hr" )
2
2
const heartImg = document . getElementById ( "pulsingheart" )
3
3
let isConnected = false ;
4
+ let currentHR = 0 ;
4
5
5
6
const params = new URLSearchParams ( window . location . search ) ;
6
7
const ip = params . get ( "ip" ) || "localhost" ;
@@ -16,16 +17,22 @@ function connect() {
16
17
socket . addEventListener ( 'message' , function ( event ) {
17
18
var message = JSON . parse ( event . data ) ;
18
19
if ( message . hr ) {
20
+ let spb = 1 / ( message . hr / 60 ) ;
21
+ if ( currentHR == 0 ) heartImg . style . animation = "pulse " + spb + "s infinite" ;
19
22
hr . innerText = message . hr ;
20
- var spb = 1 / ( message . hr / 60 )
21
- heartImg . style . animation = "pulse " + spb + "s infinite"
23
+ currentHR = message . hr ;
22
24
}
23
25
} ) ;
26
+ heartImg . addEventListener ( 'animationiteration' , ( ) => {
27
+ let spb = 1 / ( currentHR / 60 ) ;
28
+ heartImg . style . animation = "pulse " + spb + "s infinite" ;
29
+ } ) ;
24
30
}
25
31
26
32
function resetConnection ( ) {
27
33
hr . innerText = "0" ;
28
34
heartImg . style . animation = "" ;
35
+ currentHR = 0
29
36
isConnected = false ;
30
37
}
31
38
You can’t perform that action at this time.
0 commit comments