2
2
import * as React from 'react' ;
3
3
import { AppState } from 'react-native' ;
4
4
5
- import { useGlobalSelector , useDispatch } from '../react-redux' ;
5
+ import { useGlobalSelector , useSelector , useDispatch } from '../react-redux' ;
6
6
import { getHasAuth } from '../account/accountsSelectors' ;
7
7
import { reportPresence } from '../actions' ;
8
8
import Heartbeat from './heartbeat' ;
9
+ import { getPresence } from './presenceModel' ;
9
10
10
11
type Props = $ReadOnly < { || } > ;
11
12
@@ -16,6 +17,7 @@ type Props = $ReadOnly<{||}>;
16
17
export default function PresenceHeartbeat ( props : Props ) : React . Node {
17
18
const dispatch = useDispatch ( ) ;
18
19
const hasAuth = useGlobalSelector ( getHasAuth ) ; // a job for withHaveServerDataGate?
20
+ const pingIntervalSeconds = useSelector ( state => getPresence ( state ) . pingIntervalSeconds ) ;
19
21
20
22
React . useEffect ( ( ) => {
21
23
if ( ! hasAuth ) {
@@ -26,8 +28,7 @@ export default function PresenceHeartbeat(props: Props): React.Node {
26
28
// TODO(#5005): should ensure this gets the intended account
27
29
dispatch ( reportPresence ( true ) ) ;
28
30
} ;
29
- // TODO(#5669): get heartbeat interval from PresenceState
30
- const heartbeat = new Heartbeat ( onHeartbeat , 1000 * 60 ) ;
31
+ const heartbeat = new Heartbeat ( onHeartbeat , pingIntervalSeconds * 1000 ) ;
31
32
32
33
// React to any state change.
33
34
const updateHeartbeatState = ( ) => {
@@ -42,7 +43,7 @@ export default function PresenceHeartbeat(props: Props): React.Node {
42
43
sub . remove ( ) ;
43
44
heartbeat . stop ( ) ; // unconditional stop
44
45
} ;
45
- } , [ dispatch , hasAuth ] ) ;
46
+ } , [ dispatch , hasAuth , pingIntervalSeconds ] ) ;
46
47
47
48
return null ;
48
49
}
0 commit comments