@ipcom/asterisk-ari 0.0.34 → 0.0.35
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/cjs/index.cjs +25 -18
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +25 -18
- package/dist/esm/index.js.map +2 -2
- package/dist/types/ari-client/ariClient.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1724,19 +1724,14 @@ var AriClient = class {
|
|
|
1724
1724
|
"The 'app' parameter is required to connect to the WebSocket."
|
|
1725
1725
|
);
|
|
1726
1726
|
}
|
|
1727
|
+
if (this.isReconnecting) {
|
|
1728
|
+
console.warn("Already attempting to reconnect. Skipping this attempt.");
|
|
1729
|
+
return;
|
|
1730
|
+
}
|
|
1731
|
+
this.isReconnecting = true;
|
|
1727
1732
|
const eventsParam = subscribedEvents && subscribedEvents.length > 0 ? `&event=${subscribedEvents.join(",")}` : "&subscribeAll=true";
|
|
1728
1733
|
const protocol = this.config.secure ? "wss" : "ws";
|
|
1729
|
-
const wsUrl = `${protocol}://${encodeURIComponent(
|
|
1730
|
-
this.config.username
|
|
1731
|
-
)}:${encodeURIComponent(this.config.password)}@${this.config.host}:${this.config.port}/ari/events?app=${app}${eventsParam}`;
|
|
1732
|
-
if (this.wsConnections.has(app)) {
|
|
1733
|
-
const existingWsClient = this.wsConnections.get(app);
|
|
1734
|
-
console.log(`WebSocket j\xE1 conectado para o app: ${app}. Reiniciando...`);
|
|
1735
|
-
existingWsClient?.removeAllListeners();
|
|
1736
|
-
existingWsClient?.close();
|
|
1737
|
-
}
|
|
1738
|
-
const wsClient = new WebSocketClient(wsUrl);
|
|
1739
|
-
this.wsConnections.set(app, wsClient);
|
|
1734
|
+
const wsUrl = `${protocol}://${encodeURIComponent(this.config.username)}:${encodeURIComponent(this.config.password)}@${this.config.host}:${this.config.port}/ari/events?app=${app}${eventsParam}`;
|
|
1740
1735
|
const backoffOptions = {
|
|
1741
1736
|
delayFirstAttempt: false,
|
|
1742
1737
|
startingDelay: 1e3,
|
|
@@ -1746,27 +1741,39 @@ var AriClient = class {
|
|
|
1746
1741
|
jitter: "full",
|
|
1747
1742
|
retry: (error, attemptNumber) => {
|
|
1748
1743
|
console.warn(`Tentativa ${attemptNumber} falhou: ${error.message}`);
|
|
1749
|
-
return !wsClient
|
|
1744
|
+
return !this.wsClient?.isConnected();
|
|
1750
1745
|
}
|
|
1751
1746
|
};
|
|
1747
|
+
if (this.wsClient?.isConnected()) {
|
|
1748
|
+
console.log("WebSocket j\xE1 conectado. Removendo listeners antigos...");
|
|
1749
|
+
this.wsClient.removeAllListeners();
|
|
1750
|
+
this.wsClient.close();
|
|
1751
|
+
}
|
|
1752
|
+
if (!this.wsClient) {
|
|
1753
|
+
console.log("Criando nova inst\xE2ncia do WebSocketClient...");
|
|
1754
|
+
this.wsClient = new WebSocketClient(wsUrl);
|
|
1755
|
+
}
|
|
1752
1756
|
try {
|
|
1753
1757
|
await (0, import_exponential_backoff.backOff)(async () => {
|
|
1754
1758
|
if (!this.wsClient) {
|
|
1755
1759
|
throw new Error("WebSocketClient instance is null.");
|
|
1756
1760
|
}
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
await this.ensureAppRegistered(app);
|
|
1761
|
+
if (!this.wsClient.isConnected()) {
|
|
1762
|
+
console.log("Tentando conectar ao WebSocket...");
|
|
1763
|
+
await this.wsClient.connect();
|
|
1764
|
+
}
|
|
1762
1765
|
}, backoffOptions);
|
|
1766
|
+
this.integrateWebSocketEvents(app, this.wsClient);
|
|
1767
|
+
console.log(`WebSocket conectado para o app: ${app}`);
|
|
1768
|
+
await this.ensureAppRegistered(app);
|
|
1763
1769
|
} catch (err) {
|
|
1764
|
-
this.isWebSocketConnectedFlag = false;
|
|
1765
1770
|
console.error(
|
|
1766
1771
|
"N\xE3o foi poss\xEDvel conectar ao WebSocket ap\xF3s m\xFAltiplas tentativas:",
|
|
1767
1772
|
err
|
|
1768
1773
|
);
|
|
1769
1774
|
throw err;
|
|
1775
|
+
} finally {
|
|
1776
|
+
this.isReconnecting = false;
|
|
1770
1777
|
}
|
|
1771
1778
|
}
|
|
1772
1779
|
/**
|