@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.
@@ -611,13 +611,15 @@ var BaseClient = class {
611
611
  * @param {string} baseUrl - The base URL for the API
612
612
  * @param {string} username - Username for authentication
613
613
  * @param {string} password - Password for authentication
614
+ * @param {boolean} [secure=false] - Whether to use secure connections (HTTPS/WSS)
614
615
  * @param {number} [timeout=5000] - Request timeout in milliseconds
615
616
  * @throws {Error} If the base URL format is invalid
616
617
  */
617
- constructor(baseUrl, username, password, timeout = 5e3) {
618
+ constructor(baseUrl, username, password, secure = false, timeout = 5e3) {
618
619
  this.baseUrl = baseUrl;
619
620
  this.username = username;
620
621
  this.password = password;
622
+ this.secure = secure;
621
623
  if (!/^https?:\/\/.+/.test(baseUrl)) {
622
624
  throw new Error(
623
625
  "Invalid base URL. It must start with http:// or https://"
@@ -641,13 +643,15 @@ var BaseClient = class {
641
643
  return this.baseUrl;
642
644
  }
643
645
  /**
644
- * Gets the configured credentials.
646
+ * Gets the configured credentials including security settings.
647
+ * Used by WebSocketClient to determine authentication method.
645
648
  */
646
649
  getCredentials() {
647
650
  return {
648
651
  baseUrl: this.baseUrl,
649
652
  username: this.username,
650
- password: this.password
653
+ password: this.password,
654
+ secure: this.secure
651
655
  };
652
656
  }
653
657
  /**
@@ -3385,15 +3389,23 @@ var WebSocketClient = class extends import_events4.EventEmitter {
3385
3389
  }
3386
3390
  this.shouldReconnect = true;
3387
3391
  this.isConnecting = true;
3388
- const { baseUrl, username, password } = this.baseClient.getCredentials();
3389
- const protocol = baseUrl.startsWith("https") ? "wss" : "ws";
3392
+ const { baseUrl, username, password, secure } = this.baseClient.getCredentials();
3393
+ const protocol = secure ? "wss" : "ws";
3390
3394
  const normalizedHost = baseUrl.replace(/^https?:\/\//, "").replace(/\/ari$/, "");
3391
3395
  const queryParams = new URLSearchParams();
3396
+ if (!secure) {
3397
+ queryParams.append("api_key", `${username}:${password}`);
3398
+ }
3392
3399
  queryParams.append("app", this.apps.join(","));
3393
3400
  this.subscribedEvents?.forEach(
3394
3401
  (event) => queryParams.append("event", event)
3395
3402
  );
3396
- this.lastWsUrl = `${protocol}://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${normalizedHost}/ari/events?${queryParams.toString()}`;
3403
+ if (secure) {
3404
+ this.lastWsUrl = `${protocol}://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${normalizedHost}/ari/events?${queryParams.toString()}`;
3405
+ } else {
3406
+ this.lastWsUrl = `${protocol}://${normalizedHost}/ari/events?${queryParams.toString()}`;
3407
+ }
3408
+ console.log(`WebSocket URL: ${this.lastWsUrl.replace(/(api_key=)[^&]*/, "$1***")}`);
3397
3409
  try {
3398
3410
  await this.initializeWebSocket(this.lastWsUrl);
3399
3411
  } finally {
@@ -3841,7 +3853,7 @@ var AriClient = class {
3841
3853
  const httpProtocol = config.secure ? "https" : "http";
3842
3854
  const normalizedHost = config.host.replace(/^https?:\/\//, "");
3843
3855
  const baseUrl = `${httpProtocol}://${normalizedHost}:${config.port}/ari`;
3844
- this.baseClient = new BaseClient(baseUrl, config.username, config.password);
3856
+ this.baseClient = new BaseClient(baseUrl, config.username, config.password, config.secure || false);
3845
3857
  this.channels = new Channels(this.baseClient, this);
3846
3858
  this.playbacks = new Playbacks(this.baseClient, this);
3847
3859
  this.bridges = new Bridges(this.baseClient, this);