From 9730c0ebedb10bc79afc28cfe8e57bd832ded259 Mon Sep 17 00:00:00 2001 From: stevium Date: Sat, 19 Mar 2022 23:04:06 +0100 Subject: [PATCH] Change initial Sockette.timer value from 1 to -1 Since first call to window.setTimeout or window.setInterval is returning handle with ID 1 calling Sockette.close would unexpectedly clear that timeout, because timer=1 is still a valid handle ID. This commit fixes this by setting timer value to -1 which will still enable normal functionality of Sockette.reconnect, but at the same time it will not by mistake clear any other timeouts/intervals. --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 594bd8a..f656f79 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,7 @@ function noop() {} export default function (url, opts) { opts = opts || {}; - var ws, num=0, timer=1, $={}; + var ws, num=0, timer=-1, $={}; var max = opts.maxAttempts || Infinity; $.open = function () {