Skip to content

Commit 6739e87

Browse files
committed
presence: Use server's ping interval
1 parent 47a8b3f commit 6739e87

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/presence/PresenceHeartbeat.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import * as React from 'react';
33
import { AppState } from 'react-native';
44

5-
import { useGlobalSelector, useDispatch } from '../react-redux';
5+
import { useGlobalSelector, useSelector, useDispatch } from '../react-redux';
66
import { getHasAuth } from '../account/accountsSelectors';
77
import { reportPresence } from '../actions';
88
import Heartbeat from './heartbeat';
9+
import { getPresence } from './presenceModel';
910

1011
type Props = $ReadOnly<{||}>;
1112

@@ -16,6 +17,7 @@ type Props = $ReadOnly<{||}>;
1617
export default function PresenceHeartbeat(props: Props): React.Node {
1718
const dispatch = useDispatch();
1819
const hasAuth = useGlobalSelector(getHasAuth); // a job for withHaveServerDataGate?
20+
const pingIntervalSeconds = useSelector(state => getPresence(state).pingIntervalSeconds);
1921

2022
React.useEffect(() => {
2123
if (!hasAuth) {
@@ -26,8 +28,7 @@ export default function PresenceHeartbeat(props: Props): React.Node {
2628
// TODO(#5005): should ensure this gets the intended account
2729
dispatch(reportPresence(true));
2830
};
29-
// TODO(#5669): get heartbeat interval from PresenceState
30-
const heartbeat = new Heartbeat(onHeartbeat, 1000 * 60);
31+
const heartbeat = new Heartbeat(onHeartbeat, pingIntervalSeconds * 1000);
3132

3233
// React to any state change.
3334
const updateHeartbeatState = () => {
@@ -42,7 +43,7 @@ export default function PresenceHeartbeat(props: Props): React.Node {
4243
sub.remove();
4344
heartbeat.stop(); // unconditional stop
4445
};
45-
}, [dispatch, hasAuth]);
46+
}, [dispatch, hasAuth, pingIntervalSeconds]);
4647

4748
return null;
4849
}

0 commit comments

Comments
 (0)