@ipcom/asterisk-ari 0.0.23 → 0.0.25

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.
@@ -582,6 +582,7 @@ __export(src_exports, {
582
582
  Applications: () => Applications,
583
583
  AriClient: () => AriClient,
584
584
  Asterisk: () => Asterisk,
585
+ Bridges: () => Bridges,
585
586
  Channels: () => Channels,
586
587
  Endpoints: () => Endpoints,
587
588
  Playbacks: () => Playbacks,
@@ -709,11 +710,27 @@ var Asterisk = class {
709
710
  }
710
711
  /**
711
712
  * Manages a specific module in the Asterisk server.
713
+ *
714
+ * @param moduleName - The name of the module to manage.
715
+ * @param action - The action to perform on the module: "load", "unload", or "reload".
716
+ * @returns A promise that resolves when the action is completed successfully.
717
+ * @throws {Error} Throws an error if the HTTP method or action is invalid.
712
718
  */
713
719
  async manageModule(moduleName, action) {
714
- return this.client.post(
715
- `/asterisk/modules/${moduleName}?action=${encodeURIComponent(action)}`
716
- );
720
+ const url = `/asterisk/modules/${moduleName}`;
721
+ switch (action) {
722
+ case "load":
723
+ await this.client.post(`${url}?action=load`);
724
+ break;
725
+ case "unload":
726
+ await this.client.delete(url);
727
+ break;
728
+ case "reload":
729
+ await this.client.put(url, {});
730
+ break;
731
+ default:
732
+ throw new Error(`A\xE7\xE3o inv\xE1lida: ${action}`);
733
+ }
717
734
  }
718
735
  /**
719
736
  * Retrieves all configured logging channels.
@@ -748,6 +765,95 @@ var Asterisk = class {
748
765
  }
749
766
  };
750
767
 
768
+ // src/ari-client/resources/bridges.ts
769
+ var Bridges = class {
770
+ constructor(client) {
771
+ this.client = client;
772
+ }
773
+ /**
774
+ * Lists all active bridges.
775
+ */
776
+ async list() {
777
+ return this.client.get("/bridges");
778
+ }
779
+ /**
780
+ * Creates a new bridge.
781
+ */
782
+ async createBridge(request) {
783
+ return this.client.post("/bridges", request);
784
+ }
785
+ /**
786
+ * Retrieves details of a specific bridge.
787
+ */
788
+ async getDetails(bridgeId) {
789
+ return this.client.get(`/bridges/${bridgeId}`);
790
+ }
791
+ /**
792
+ * Destroys (deletes) a specific bridge.
793
+ */
794
+ async destroy(bridgeId) {
795
+ return this.client.delete(`/bridges/${bridgeId}`);
796
+ }
797
+ /**
798
+ * Adds a channel or multiple channels to a bridge.
799
+ */
800
+ async addChannels(bridgeId, request) {
801
+ const queryParams = new URLSearchParams({
802
+ channel: Array.isArray(request.channel) ? request.channel.join(",") : request.channel,
803
+ ...request.role && { role: request.role }
804
+ }).toString();
805
+ await this.client.post(
806
+ `/bridges/${bridgeId}/addChannel?${queryParams}`
807
+ );
808
+ }
809
+ /**
810
+ * Removes a channel or multiple channels from a bridge.
811
+ */
812
+ async removeChannels(bridgeId, request) {
813
+ const queryParams = new URLSearchParams({
814
+ channel: Array.isArray(request.channel) ? request.channel.join(",") : request.channel
815
+ }).toString();
816
+ await this.client.post(
817
+ `/bridges/${bridgeId}/removeChannel?${queryParams}`
818
+ );
819
+ }
820
+ /**
821
+ * Plays media to a bridge.
822
+ */
823
+ async playMedia(bridgeId, request) {
824
+ const queryParams = new URLSearchParams({
825
+ ...request.lang && { lang: request.lang },
826
+ ...request.offsetms && { offsetms: request.offsetms.toString() },
827
+ ...request.skipms && { skipms: request.skipms.toString() },
828
+ ...request.playbackId && { playbackId: request.playbackId }
829
+ }).toString();
830
+ return this.client.post(
831
+ `/bridges/${bridgeId}/play?${queryParams}`,
832
+ { media: request.media }
833
+ );
834
+ }
835
+ /**
836
+ * Stops media playback on a bridge.
837
+ */
838
+ async stopPlayback(bridgeId, playbackId) {
839
+ await this.client.delete(`/bridges/${bridgeId}/play/${playbackId}`);
840
+ }
841
+ /**
842
+ * Sets the video source for a bridge.
843
+ */
844
+ async setVideoSource(bridgeId, channelId) {
845
+ await this.client.post(
846
+ `/bridges/${bridgeId}/videoSource?channelId=${encodeURIComponent(channelId)}`
847
+ );
848
+ }
849
+ /**
850
+ * Clears the video source for a bridge.
851
+ */
852
+ async clearVideoSource(bridgeId) {
853
+ await this.client.delete(`/bridges/${bridgeId}/videoSource`);
854
+ }
855
+ };
856
+
751
857
  // src/ari-client/resources/channels.ts
752
858
  function toQueryParams2(options) {
753
859
  return new URLSearchParams(
@@ -1109,17 +1215,22 @@ var Playbacks = class {
1109
1215
  return this.client.get(`/playbacks/${playbackId}`);
1110
1216
  }
1111
1217
  /**
1112
- * Controls a specific playback (e.g., pause, resume, rewind, forward, stop).
1218
+ * Controls a specific playback by performing various operations such as pause, resume, restart, reverse, forward, or stop.
1113
1219
  *
1114
1220
  * @param playbackId - The unique identifier of the playback to control.
1115
- * @param controlRequest - The PlaybackControlRequest containing the control operation.
1221
+ * @param operation - The operation to perform on the playback. Possible values are:
1222
+ * - "pause": Pauses the playback.
1223
+ * - "unpause": Resumes a paused playback.
1224
+ * - "restart": Restarts the playback from the beginning.
1225
+ * - "reverse": Reverses the playback direction.
1226
+ * - "forward": Moves the playback forward.
1227
+ * - "stop": Stops the playback.
1116
1228
  * @returns A promise that resolves when the control operation is successfully executed.
1117
1229
  */
1118
- async control(playbackId, controlRequest) {
1119
- await this.client.post(
1120
- `/playbacks/${playbackId}/control`,
1121
- controlRequest
1122
- );
1230
+ async control(playbackId, operation) {
1231
+ await this.client.post(`/playbacks/${playbackId}/control`, {
1232
+ operation
1233
+ });
1123
1234
  }
1124
1235
  /**
1125
1236
  * Stops a specific playback.
@@ -1265,6 +1376,7 @@ var AriClient = class {
1265
1376
  this.playbacks = new Playbacks(this.baseClient);
1266
1377
  this.sounds = new Sounds(this.baseClient);
1267
1378
  this.asterisk = new Asterisk(this.baseClient);
1379
+ this.bridges = new Bridges(this.baseClient);
1268
1380
  }
1269
1381
  wsClient = null;
1270
1382
  baseClient;
@@ -1275,10 +1387,12 @@ var AriClient = class {
1275
1387
  playbacks;
1276
1388
  sounds;
1277
1389
  asterisk;
1390
+ bridges;
1278
1391
  /**
1279
1392
  * Connects to the ARI WebSocket for a specific application.
1280
1393
  *
1281
1394
  * @param app - The application name to connect to.
1395
+ * @param subscribedEvents
1282
1396
  * @returns {Promise<void>} Resolves when the WebSocket connects successfully.
1283
1397
  */
1284
1398
  async connectWebSocket(app, subscribedEvents) {
@@ -1785,14 +1899,23 @@ var AriClient = class {
1785
1899
  return this.playbacks.getDetails(playbackId);
1786
1900
  }
1787
1901
  /**
1788
- * Controls a specific playback in the Asterisk server.
1789
- *
1790
- * @param playbackId - The unique identifier of the playback to control.
1791
- * @param controlRequest - An object containing the control operation details.
1792
- * @returns A Promise that resolves when the control operation is successfully executed.
1793
- */
1902
+ * Controls a specific playback in the Asterisk server.
1903
+ * This function allows manipulation of an ongoing playback, such as pausing, resuming, or skipping.
1904
+ *
1905
+ * @param playbackId - The unique identifier of the playback to control.
1906
+ * This should be a string that uniquely identifies the playback in the Asterisk system.
1907
+ * @param controlRequest - An object containing the control operation details.
1908
+ * This object should conform to the PlaybackControlRequest interface,
1909
+ * which includes an 'operation' property specifying the control action to perform.
1910
+ * @returns A Promise that resolves when the control operation is successfully executed.
1911
+ * The promise resolves to void, indicating no specific return value.
1912
+ * If an error occurs during the operation, the promise will be rejected with an error object.
1913
+ * @throws Will throw an error if the playback control operation fails, e.g., if the playback doesn't exist
1914
+ * or the requested operation is invalid.
1915
+ */
1794
1916
  async controlPlayback(playbackId, controlRequest) {
1795
- return this.playbacks.control(playbackId, controlRequest);
1917
+ const { operation } = controlRequest;
1918
+ return this.playbacks.control(playbackId, operation);
1796
1919
  }
1797
1920
  /**
1798
1921
  * Stops a specific playback in the Asterisk server.
@@ -1907,6 +2030,7 @@ var AriClient = class {
1907
2030
  Applications,
1908
2031
  AriClient,
1909
2032
  Asterisk,
2033
+ Bridges,
1910
2034
  Channels,
1911
2035
  Endpoints,
1912
2036
  Playbacks,