@ipcom/asterisk-ari 0.0.162 → 0.0.164
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 +19 -7
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +19 -7
- package/dist/esm/index.js.map +2 -2
- package/dist/types/ari-client/baseClient.d.ts +6 -2
- package/dist/types/ari-client/baseClient.d.ts.map +1 -1
- package/dist/types/ari-client/interfaces/events.types.d.ts +105 -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/ari-client/websocketClient.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
|
@@ -590,13 +590,15 @@ var BaseClient = class {
|
|
|
590
590
|
* @param {string} baseUrl - The base URL for the API
|
|
591
591
|
* @param {string} username - Username for authentication
|
|
592
592
|
* @param {string} password - Password for authentication
|
|
593
|
+
* @param {boolean} [secure=false] - Whether to use secure connections (HTTPS/WSS)
|
|
593
594
|
* @param {number} [timeout=5000] - Request timeout in milliseconds
|
|
594
595
|
* @throws {Error} If the base URL format is invalid
|
|
595
596
|
*/
|
|
596
|
-
constructor(baseUrl, username, password, timeout = 5e3) {
|
|
597
|
+
constructor(baseUrl, username, password, secure = false, timeout = 5e3) {
|
|
597
598
|
this.baseUrl = baseUrl;
|
|
598
599
|
this.username = username;
|
|
599
600
|
this.password = password;
|
|
601
|
+
this.secure = secure;
|
|
600
602
|
if (!/^https?:\/\/.+/.test(baseUrl)) {
|
|
601
603
|
throw new Error(
|
|
602
604
|
"Invalid base URL. It must start with http:// or https://"
|
|
@@ -620,13 +622,15 @@ var BaseClient = class {
|
|
|
620
622
|
return this.baseUrl;
|
|
621
623
|
}
|
|
622
624
|
/**
|
|
623
|
-
* Gets the configured credentials.
|
|
625
|
+
* Gets the configured credentials including security settings.
|
|
626
|
+
* Used by WebSocketClient to determine authentication method.
|
|
624
627
|
*/
|
|
625
628
|
getCredentials() {
|
|
626
629
|
return {
|
|
627
630
|
baseUrl: this.baseUrl,
|
|
628
631
|
username: this.username,
|
|
629
|
-
password: this.password
|
|
632
|
+
password: this.password,
|
|
633
|
+
secure: this.secure
|
|
630
634
|
};
|
|
631
635
|
}
|
|
632
636
|
/**
|
|
@@ -3364,15 +3368,23 @@ var WebSocketClient = class extends EventEmitter4 {
|
|
|
3364
3368
|
}
|
|
3365
3369
|
this.shouldReconnect = true;
|
|
3366
3370
|
this.isConnecting = true;
|
|
3367
|
-
const { baseUrl, username, password } = this.baseClient.getCredentials();
|
|
3368
|
-
const protocol =
|
|
3371
|
+
const { baseUrl, username, password, secure } = this.baseClient.getCredentials();
|
|
3372
|
+
const protocol = secure ? "wss" : "ws";
|
|
3369
3373
|
const normalizedHost = baseUrl.replace(/^https?:\/\//, "").replace(/\/ari$/, "");
|
|
3370
3374
|
const queryParams = new URLSearchParams();
|
|
3375
|
+
if (!secure) {
|
|
3376
|
+
queryParams.append("api_key", `${username}:${password}`);
|
|
3377
|
+
}
|
|
3371
3378
|
queryParams.append("app", this.apps.join(","));
|
|
3372
3379
|
this.subscribedEvents?.forEach(
|
|
3373
3380
|
(event) => queryParams.append("event", event)
|
|
3374
3381
|
);
|
|
3375
|
-
|
|
3382
|
+
if (secure) {
|
|
3383
|
+
this.lastWsUrl = `${protocol}://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${normalizedHost}/ari/events?${queryParams.toString()}`;
|
|
3384
|
+
} else {
|
|
3385
|
+
this.lastWsUrl = `${protocol}://${normalizedHost}/ari/events?${queryParams.toString()}`;
|
|
3386
|
+
}
|
|
3387
|
+
console.log(`WebSocket URL: ${this.lastWsUrl.replace(/(api_key=)[^&]*/, "$1***")}`);
|
|
3376
3388
|
try {
|
|
3377
3389
|
await this.initializeWebSocket(this.lastWsUrl);
|
|
3378
3390
|
} finally {
|
|
@@ -3820,7 +3832,7 @@ var AriClient = class {
|
|
|
3820
3832
|
const httpProtocol = config.secure ? "https" : "http";
|
|
3821
3833
|
const normalizedHost = config.host.replace(/^https?:\/\//, "");
|
|
3822
3834
|
const baseUrl = `${httpProtocol}://${normalizedHost}:${config.port}/ari`;
|
|
3823
|
-
this.baseClient = new BaseClient(baseUrl, config.username, config.password);
|
|
3835
|
+
this.baseClient = new BaseClient(baseUrl, config.username, config.password, config.secure || false);
|
|
3824
3836
|
this.channels = new Channels(this.baseClient, this);
|
|
3825
3837
|
this.playbacks = new Playbacks(this.baseClient, this);
|
|
3826
3838
|
this.bridges = new Bridges(this.baseClient, this);
|