Skip to content

Commit

Permalink
feat: send hello ech 10 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien committed Apr 30, 2024
1 parent 3933478 commit 6161b90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import globals from "globals";
import pluginJs from "@eslint/js";

export default [
{ files: ["**/*.js"], languageOptions: { sourceType: "commonjs" }, },
{ files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } },
{ languageOptions: { globals: globals.node } },
pluginJs.configs.recommended,
];
21 changes: 11 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,29 @@ function broadcastMessage(message) {
}

wss.on("connection", function connection(ws /*, req*/) {
//console.log('New connection');

/*ws.on('open', function incoming(open) {
//console.log('Open : %s', message);
});*/

const interval_id = setInterval(function () {
ws.send(
JSON.stringify({
msg_type: "control:hello",
connection_timeout: 10000,
}),
);
}, 10000);

ws.on("message", function incoming(message) {
console.log("Data : %s", message);
const js = JSON.parse(message);
if (js.msg_type == "data:subscribe_oauth") {
tags[js.tag] = ws;
}
ws.send(
JSON.stringify({
msg_type: "control:hello",
connection_timeout: 600000,
}),
);
});

ws.on("close", function close() {
//console.log('Close');
ws.once("close", function close() {
clearInterval(interval_id);
let keys = Object.keys(tags);
for (let i = 0; i < keys.length; i++) {
if (this == tags[keys[i]]) {
Expand Down

0 comments on commit 6161b90

Please sign in to comment.