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

Commit 87eeb1f

Browse files
Hubert KosterHubert Koster
authored andcommitted
chore: refactoring more
1 parent 690d422 commit 87eeb1f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

examples/keep_alive/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const connection = new WebSocket(`wss://ws.binaryws.com/websockets/v3?app_id=${a
55

66
const api = new DerivAPIBasic({ connection });
77

8-
const keepAlive = () => {
8+
const proposal = () => {
99
api.subscribe({
1010
proposal: 1,
1111
subscribe: 1,
@@ -20,15 +20,15 @@ const keepAlive = () => {
2020
});
2121
};
2222

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.
23+
// Send a ping every 30 seconds to keep the connection alive
24+
// Needs to use the same websocket connection as the one you want to maintain.
2525
const ping = () => {
2626
setInterval(() => {
2727
api.ping();
2828
}, 30000);
2929
};
3030

31-
const keepAliveRes = async (res) => {
31+
const wsResponse = async (res) => {
3232
const data = JSON.parse(res.data);
3333
if (data.error !== undefined) {
3434
console.log('Error: %s ', data.error.message);
@@ -45,14 +45,14 @@ const keepAliveRes = async (res) => {
4545
};
4646

4747
const checkSignal = () => {
48-
keepAlive();
48+
proposal();
4949
ping();
50-
connection.addEventListener('message', keepAliveRes);
50+
connection.addEventListener('message', wsResponse);
5151
};
5252

5353
const endCall = () => {
54-
connection.removeEventListener('message', keepAliveRes, false);
55-
keepAlive().unsubscribe();
54+
connection.removeEventListener('message', wsResponse, false);
55+
proposal().unsubscribe();
5656
};
5757

5858
const keep_alive_button = document.querySelector('#keep_alive');

0 commit comments

Comments
 (0)