@pulso/companion 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +16 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1315,11 +1315,13 @@ var ws = null;
|
|
|
1315
1315
|
var reconnectTimer = null;
|
|
1316
1316
|
var heartbeatTimer = null;
|
|
1317
1317
|
var HEARTBEAT_INTERVAL = 3e4;
|
|
1318
|
+
var reconnectAttempts = 0;
|
|
1318
1319
|
function connect() {
|
|
1319
1320
|
console.log("\u{1F50C} Connecting to Pulso...");
|
|
1320
1321
|
console.log(` ${WS_URL.replace(/token=.*/, "token=***")}`);
|
|
1321
1322
|
ws = new WebSocket(WS_URL);
|
|
1322
1323
|
ws.on("open", () => {
|
|
1324
|
+
reconnectAttempts = 0;
|
|
1323
1325
|
console.log("\u2705 Connected to Pulso!");
|
|
1324
1326
|
console.log(`\u{1F5A5}\uFE0F Companion is active \u2014 ${ACCESS_LEVEL === "full" ? "full device access" : "sandboxed mode"}`);
|
|
1325
1327
|
console.log("");
|
|
@@ -1370,12 +1372,20 @@ function connect() {
|
|
|
1370
1372
|
}
|
|
1371
1373
|
});
|
|
1372
1374
|
ws.on("close", (code, reason) => {
|
|
1375
|
+
const reasonStr = reason.toString() || "unknown";
|
|
1373
1376
|
console.log(`
|
|
1374
|
-
\u{1F50C} Disconnected (${code}: ${
|
|
1377
|
+
\u{1F50C} Disconnected (${code}: ${reasonStr})`);
|
|
1375
1378
|
if (heartbeatTimer) {
|
|
1376
1379
|
clearInterval(heartbeatTimer);
|
|
1377
1380
|
heartbeatTimer = null;
|
|
1378
1381
|
}
|
|
1382
|
+
if (reasonStr === "New connection from same user") {
|
|
1383
|
+
console.log("\n\u26A0\uFE0F Another Pulso Companion instance is already connected.");
|
|
1384
|
+
console.log(" This instance will exit. Only one companion per account is supported.");
|
|
1385
|
+
console.log(" If this is unexpected, close other terminals running Pulso Companion.\n");
|
|
1386
|
+
process.exit(0);
|
|
1387
|
+
return;
|
|
1388
|
+
}
|
|
1379
1389
|
scheduleReconnect();
|
|
1380
1390
|
});
|
|
1381
1391
|
ws.on("error", (err) => {
|
|
@@ -1384,15 +1394,17 @@ function connect() {
|
|
|
1384
1394
|
}
|
|
1385
1395
|
function scheduleReconnect() {
|
|
1386
1396
|
if (reconnectTimer) return;
|
|
1387
|
-
|
|
1397
|
+
reconnectAttempts++;
|
|
1398
|
+
const delay = Math.min(RECONNECT_DELAY * Math.pow(2, reconnectAttempts - 1), 6e4);
|
|
1399
|
+
console.log(` Reconnecting in ${(delay / 1e3).toFixed(0)}s... (attempt ${reconnectAttempts})`);
|
|
1388
1400
|
reconnectTimer = setTimeout(() => {
|
|
1389
1401
|
reconnectTimer = null;
|
|
1390
1402
|
connect();
|
|
1391
|
-
},
|
|
1403
|
+
}, delay);
|
|
1392
1404
|
}
|
|
1393
1405
|
console.log("");
|
|
1394
1406
|
console.log(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557");
|
|
1395
|
-
console.log(" \u2551 \u{1FAC0} Pulso Mac Companion v0.1
|
|
1407
|
+
console.log(" \u2551 \u{1FAC0} Pulso Mac Companion v0.2.1 \u2551");
|
|
1396
1408
|
console.log(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D");
|
|
1397
1409
|
console.log("");
|
|
1398
1410
|
setupPermissions().then(() => {
|