Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 690d422

Browse files
Hubert KosterHubert Koster
authored andcommitted
chore: refactoring keep alive example
1 parent e836274 commit 690d422

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

examples/keep_alive/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ const keepAlive = () => {
1818
symbol: 'R_100',
1919
barrier: '+0.1',
2020
});
21-
/*
22-
* Send a ping ever 30 seconds to keep the connection alive, needs to use the same
23-
* websocket connection as the one you want to maintain.
24-
*/
21+
};
22+
23+
// Send a ping ever 30 seconds to keep the connection alive, needs to use the same
24+
// websocket connection as the one you want to maintain.
25+
const ping = () => {
26+
setInterval(() => {
27+
api.ping();
28+
}, 30000);
2529
};
2630

2731
const keepAliveRes = async (res) => {
@@ -40,8 +44,9 @@ const keepAliveRes = async (res) => {
4044
}
4145
};
4246

43-
const checkSignal = async () => {
44-
await keepAlive();
47+
const checkSignal = () => {
48+
keepAlive();
49+
ping();
4550
connection.addEventListener('message', keepAliveRes);
4651
};
4752

0 commit comments

Comments
 (0)