@ipcom/asterisk-ari 0.0.38 → 0.0.40
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 +57 -36
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +57 -36
- package/dist/esm/index.js.map +2 -2
- package/dist/types/ari-client/ariClient.d.ts +9 -2
- package/dist/types/ari-client/ariClient.d.ts.map +1 -1
- package/dist/types/ari-client/interfaces/events.types.d.ts +6 -0
- package/dist/types/ari-client/interfaces/events.types.d.ts.map +1 -1
- package/dist/types/ari-client/interfaces/index.d.ts +1 -1
- package/dist/types/ari-client/interfaces/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1718,7 +1718,7 @@ var AriClient = class {
|
|
|
1718
1718
|
async connectWebSocket(app, subscribedEvents) {
|
|
1719
1719
|
if (!app) {
|
|
1720
1720
|
throw new Error(
|
|
1721
|
-
"
|
|
1721
|
+
"O par\xE2metro 'app' \xE9 obrigat\xF3rio para conectar ao WebSocket."
|
|
1722
1722
|
);
|
|
1723
1723
|
}
|
|
1724
1724
|
if (this.webSocketReady) {
|
|
@@ -1729,16 +1729,14 @@ var AriClient = class {
|
|
|
1729
1729
|
try {
|
|
1730
1730
|
if (this.isReconnecting) {
|
|
1731
1731
|
console.warn(
|
|
1732
|
-
"
|
|
1732
|
+
"J\xE1 est\xE1 tentando reconectar. Ignorando esta tentativa."
|
|
1733
1733
|
);
|
|
1734
1734
|
return;
|
|
1735
1735
|
}
|
|
1736
1736
|
this.isReconnecting = true;
|
|
1737
1737
|
const eventsParam = subscribedEvents && subscribedEvents.length > 0 ? `&event=${subscribedEvents.join(",")}` : "&subscribeAll=true";
|
|
1738
1738
|
const protocol = this.config.secure ? "wss" : "ws";
|
|
1739
|
-
const wsUrl = `${protocol}://${encodeURIComponent(
|
|
1740
|
-
this.config.username
|
|
1741
|
-
)}:${encodeURIComponent(this.config.password)}@${this.config.host}:${this.config.port}/ari/events?app=${app}${eventsParam}`;
|
|
1739
|
+
const wsUrl = `${protocol}://${encodeURIComponent(this.config.username)}:${encodeURIComponent(this.config.password)}@${this.config.host}:${this.config.port}/ari/events?app=${app}${eventsParam}`;
|
|
1742
1740
|
const backoffOptions = {
|
|
1743
1741
|
delayFirstAttempt: false,
|
|
1744
1742
|
startingDelay: 1e3,
|
|
@@ -1766,6 +1764,7 @@ var AriClient = class {
|
|
|
1766
1764
|
console.log(`WebSocket conectado para o app: ${app}`);
|
|
1767
1765
|
await this.ensureAppRegistered(app);
|
|
1768
1766
|
this.processPendingListeners();
|
|
1767
|
+
this.isWebSocketConnectedFlag = true;
|
|
1769
1768
|
}, backoffOptions);
|
|
1770
1769
|
resolve();
|
|
1771
1770
|
} catch (err) {
|
|
@@ -1791,46 +1790,30 @@ var AriClient = class {
|
|
|
1791
1790
|
);
|
|
1792
1791
|
}
|
|
1793
1792
|
const eventHandlers = {
|
|
1794
|
-
|
|
1793
|
+
PlaybackStarted: (data) => {
|
|
1795
1794
|
if ("playbackId" in data) {
|
|
1796
|
-
|
|
1795
|
+
console.log(`[${app}] PlaybackStarted:`, data);
|
|
1797
1796
|
}
|
|
1798
|
-
console.log(`[${app}] PlaybackFinished:`, data);
|
|
1799
|
-
this.emitGlobalEvent(data);
|
|
1800
1797
|
},
|
|
1801
|
-
|
|
1802
|
-
if ("
|
|
1803
|
-
console.log(`[${app}]
|
|
1804
|
-
this.channels.emitChannelEvent("ChannelStateChange", data);
|
|
1805
|
-
}
|
|
1806
|
-
this.emitGlobalEvent(data);
|
|
1807
|
-
},
|
|
1808
|
-
BridgeDestroyed: (data) => {
|
|
1809
|
-
if ("bridge" in data) {
|
|
1810
|
-
console.log(`[${app}] Bridge destru\xEDda:`, data.bridge);
|
|
1798
|
+
PlaybackFinished: (data) => {
|
|
1799
|
+
if ("playbackId" in data) {
|
|
1800
|
+
console.log(`[${app}] PlaybackFinished:`, data);
|
|
1811
1801
|
}
|
|
1812
|
-
this.emitGlobalEvent(data);
|
|
1813
1802
|
},
|
|
1814
1803
|
ChannelDtmfReceived: (data) => {
|
|
1815
|
-
if ("
|
|
1816
|
-
console.log(`[${app}] DTMF recebido
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
EndpointStateChange: (data) => {
|
|
1823
|
-
if ("endpoint" in data) {
|
|
1824
|
-
console.log(`[${app}] Estado do endpoint alterado:`, data.endpoint);
|
|
1804
|
+
if (data.type === "ChannelDtmfReceived" && "digit" in data) {
|
|
1805
|
+
console.log(`[${app}] DTMF recebido: ${data.digit}`);
|
|
1806
|
+
} else {
|
|
1807
|
+
console.warn(
|
|
1808
|
+
`[${app}] Evento inesperado em ChannelDtmfReceived`,
|
|
1809
|
+
data
|
|
1810
|
+
);
|
|
1825
1811
|
}
|
|
1826
|
-
this.emitGlobalEvent(data);
|
|
1827
1812
|
},
|
|
1828
|
-
|
|
1813
|
+
ChannelStateChange: (data) => {
|
|
1829
1814
|
if ("channel" in data) {
|
|
1830
|
-
console.log(`[${app}]
|
|
1831
|
-
this.channels.emitChannelEvent("ChannelHangupRequest", data);
|
|
1815
|
+
console.log(`[${app}] Estado do canal alterado:`, data.channel);
|
|
1832
1816
|
}
|
|
1833
|
-
this.emitGlobalEvent(data);
|
|
1834
1817
|
}
|
|
1835
1818
|
};
|
|
1836
1819
|
for (const [eventType, handler] of Object.entries(eventHandlers)) {
|
|
@@ -1874,6 +1857,17 @@ var AriClient = class {
|
|
|
1874
1857
|
unregisterPlaybackListener(eventType, playbackId, callback) {
|
|
1875
1858
|
this.playbacks.unregisterListener(eventType, playbackId, callback);
|
|
1876
1859
|
}
|
|
1860
|
+
registerListener(eventType, condition, callback) {
|
|
1861
|
+
if (!this.isWebSocketConnected()) {
|
|
1862
|
+
throw new Error("WebSocket n\xE3o est\xE1 conectado.");
|
|
1863
|
+
}
|
|
1864
|
+
const handler = (eventData) => {
|
|
1865
|
+
if (eventData.type === eventType && condition(eventData)) {
|
|
1866
|
+
callback(eventData);
|
|
1867
|
+
}
|
|
1868
|
+
};
|
|
1869
|
+
this.wsClient?.on(eventType, handler);
|
|
1870
|
+
}
|
|
1877
1871
|
/**
|
|
1878
1872
|
* Registers a listener for playback events.
|
|
1879
1873
|
* The listener is triggered for events such as "PlaybackFinished".
|
|
@@ -1883,7 +1877,34 @@ var AriClient = class {
|
|
|
1883
1877
|
* @param callback - The callback function to execute when the event occurs.
|
|
1884
1878
|
*/
|
|
1885
1879
|
registerPlaybackListener(eventType, playbackId, callback) {
|
|
1886
|
-
this.
|
|
1880
|
+
if (!this.isWebSocketConnected()) {
|
|
1881
|
+
throw new Error("WebSocket n\xE3o est\xE1 conectado.");
|
|
1882
|
+
}
|
|
1883
|
+
console.log(
|
|
1884
|
+
`Registrando listener para evento ${eventType} com playbackId ${playbackId}`
|
|
1885
|
+
);
|
|
1886
|
+
const handler = (eventData) => {
|
|
1887
|
+
if ("playbackId" in eventData && eventData.playbackId === playbackId) {
|
|
1888
|
+
callback(eventData);
|
|
1889
|
+
}
|
|
1890
|
+
};
|
|
1891
|
+
this.wsClient?.on(eventType, handler);
|
|
1892
|
+
}
|
|
1893
|
+
registerChannelListener(eventType, channelId, callback) {
|
|
1894
|
+
if (!this.isWebSocketConnected()) {
|
|
1895
|
+
throw new Error("WebSocket n\xE3o est\xE1 conectado.");
|
|
1896
|
+
}
|
|
1897
|
+
console.log(
|
|
1898
|
+
`Registrando listener para evento ${eventType} com channelId ${channelId}`
|
|
1899
|
+
);
|
|
1900
|
+
const handler = (eventData) => {
|
|
1901
|
+
if (eventData.type === eventType && "channel" in eventData && eventData.channel?.id === channelId) {
|
|
1902
|
+
callback(
|
|
1903
|
+
eventData
|
|
1904
|
+
);
|
|
1905
|
+
}
|
|
1906
|
+
};
|
|
1907
|
+
this.wsClient?.on(eventType, handler);
|
|
1887
1908
|
}
|
|
1888
1909
|
/**
|
|
1889
1910
|
* Checks if a listener is already registered for a specific event and playback.
|