@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.
package/dist/esm/index.js CHANGED
@@ -690,11 +690,27 @@ var Asterisk = class {
690
690
  }
691
691
  /**
692
692
  * Manages a specific module in the Asterisk server.
693
+ *
694
+ * @param moduleName - The name of the module to manage.
695
+ * @param action - The action to perform on the module: "load", "unload", or "reload".
696
+ * @returns A promise that resolves when the action is completed successfully.
697
+ * @throws {Error} Throws an error if the HTTP method or action is invalid.
693
698
  */
694
699
  async manageModule(moduleName, action) {
695
- return this.client.post(
696
- `/asterisk/modules/${moduleName}?action=${encodeURIComponent(action)}`
697
- );
700
+ const url = `/asterisk/modules/${moduleName}`;
701
+ switch (action) {
702
+ case "load":
703
+ await this.client.post(`${url}?action=load`);
704
+ break;
705
+ case "unload":
706
+ await this.client.delete(url);
707
+ break;
708
+ case "reload":
709
+ await this.client.put(url, {});
710
+ break;
711
+ default:
712
+ throw new Error(`A\xE7\xE3o inv\xE1lida: ${action}`);
713
+ }
698
714
  }
699
715
  /**
700
716
  * Retrieves all configured logging channels.
@@ -729,6 +745,95 @@ var Asterisk = class {
729
745
  }
730
746
  };
731
747
 
748
+ // src/ari-client/resources/bridges.ts
749
+ var Bridges = class {
750
+ constructor(client) {
751
+ this.client = client;
752
+ }
753
+ /**
754
+ * Lists all active bridges.
755
+ */
756
+ async list() {
757
+ return this.client.get("/bridges");
758
+ }
759
+ /**
760
+ * Creates a new bridge.
761
+ */
762
+ async createBridge(request) {
763
+ return this.client.post("/bridges", request);
764
+ }
765
+ /**
766
+ * Retrieves details of a specific bridge.
767
+ */
768
+ async getDetails(bridgeId) {
769
+ return this.client.get(`/bridges/${bridgeId}`);
770
+ }
771
+ /**
772
+ * Destroys (deletes) a specific bridge.
773
+ */
774
+ async destroy(bridgeId) {
775
+ return this.client.delete(`/bridges/${bridgeId}`);
776
+ }
777
+ /**
778
+ * Adds a channel or multiple channels to a bridge.
779
+ */
780
+ async addChannels(bridgeId, request) {
781
+ const queryParams = new URLSearchParams({
782
+ channel: Array.isArray(request.channel) ? request.channel.join(",") : request.channel,
783
+ ...request.role && { role: request.role }
784
+ }).toString();
785
+ await this.client.post(
786
+ `/bridges/${bridgeId}/addChannel?${queryParams}`
787
+ );
788
+ }
789
+ /**
790
+ * Removes a channel or multiple channels from a bridge.
791
+ */
792
+ async removeChannels(bridgeId, request) {
793
+ const queryParams = new URLSearchParams({
794
+ channel: Array.isArray(request.channel) ? request.channel.join(",") : request.channel
795
+ }).toString();
796
+ await this.client.post(
797
+ `/bridges/${bridgeId}/removeChannel?${queryParams}`
798
+ );
799
+ }
800
+ /**
801
+ * Plays media to a bridge.
802
+ */
803
+ async playMedia(bridgeId, request) {
804
+ const queryParams = new URLSearchParams({
805
+ ...request.lang && { lang: request.lang },
806
+ ...request.offsetms && { offsetms: request.offsetms.toString() },
807
+ ...request.skipms && { skipms: request.skipms.toString() },
808
+ ...request.playbackId && { playbackId: request.playbackId }
809
+ }).toString();
810
+ return this.client.post(
811
+ `/bridges/${bridgeId}/play?${queryParams}`,
812
+ { media: request.media }
813
+ );
814
+ }
815
+ /**
816
+ * Stops media playback on a bridge.
817
+ */
818
+ async stopPlayback(bridgeId, playbackId) {
819
+ await this.client.delete(`/bridges/${bridgeId}/play/${playbackId}`);
820
+ }
821
+ /**
822
+ * Sets the video source for a bridge.
823
+ */
824
+ async setVideoSource(bridgeId, channelId) {
825
+ await this.client.post(
826
+ `/bridges/${bridgeId}/videoSource?channelId=${encodeURIComponent(channelId)}`
827
+ );
828
+ }
829
+ /**
830
+ * Clears the video source for a bridge.
831
+ */
832
+ async clearVideoSource(bridgeId) {
833
+ await this.client.delete(`/bridges/${bridgeId}/videoSource`);
834
+ }
835
+ };
836
+
732
837
  // src/ari-client/resources/channels.ts
733
838
  function toQueryParams2(options) {
734
839
  return new URLSearchParams(
@@ -1090,17 +1195,22 @@ var Playbacks = class {
1090
1195
  return this.client.get(`/playbacks/${playbackId}`);
1091
1196
  }
1092
1197
  /**
1093
- * Controls a specific playback (e.g., pause, resume, rewind, forward, stop).
1198
+ * Controls a specific playback by performing various operations such as pause, resume, restart, reverse, forward, or stop.
1094
1199
  *
1095
1200
  * @param playbackId - The unique identifier of the playback to control.
1096
- * @param controlRequest - The PlaybackControlRequest containing the control operation.
1201
+ * @param operation - The operation to perform on the playback. Possible values are:
1202
+ * - "pause": Pauses the playback.
1203
+ * - "unpause": Resumes a paused playback.
1204
+ * - "restart": Restarts the playback from the beginning.
1205
+ * - "reverse": Reverses the playback direction.
1206
+ * - "forward": Moves the playback forward.
1207
+ * - "stop": Stops the playback.
1097
1208
  * @returns A promise that resolves when the control operation is successfully executed.
1098
1209
  */
1099
- async control(playbackId, controlRequest) {
1100
- await this.client.post(
1101
- `/playbacks/${playbackId}/control`,
1102
- controlRequest
1103
- );
1210
+ async control(playbackId, operation) {
1211
+ await this.client.post(`/playbacks/${playbackId}/control`, {
1212
+ operation
1213
+ });
1104
1214
  }
1105
1215
  /**
1106
1216
  * Stops a specific playback.
@@ -1246,6 +1356,7 @@ var AriClient = class {
1246
1356
  this.playbacks = new Playbacks(this.baseClient);
1247
1357
  this.sounds = new Sounds(this.baseClient);
1248
1358
  this.asterisk = new Asterisk(this.baseClient);
1359
+ this.bridges = new Bridges(this.baseClient);
1249
1360
  }
1250
1361
  wsClient = null;
1251
1362
  baseClient;
@@ -1256,10 +1367,12 @@ var AriClient = class {
1256
1367
  playbacks;
1257
1368
  sounds;
1258
1369
  asterisk;
1370
+ bridges;
1259
1371
  /**
1260
1372
  * Connects to the ARI WebSocket for a specific application.
1261
1373
  *
1262
1374
  * @param app - The application name to connect to.
1375
+ * @param subscribedEvents
1263
1376
  * @returns {Promise<void>} Resolves when the WebSocket connects successfully.
1264
1377
  */
1265
1378
  async connectWebSocket(app, subscribedEvents) {
@@ -1766,14 +1879,23 @@ var AriClient = class {
1766
1879
  return this.playbacks.getDetails(playbackId);
1767
1880
  }
1768
1881
  /**
1769
- * Controls a specific playback in the Asterisk server.
1770
- *
1771
- * @param playbackId - The unique identifier of the playback to control.
1772
- * @param controlRequest - An object containing the control operation details.
1773
- * @returns A Promise that resolves when the control operation is successfully executed.
1774
- */
1882
+ * Controls a specific playback in the Asterisk server.
1883
+ * This function allows manipulation of an ongoing playback, such as pausing, resuming, or skipping.
1884
+ *
1885
+ * @param playbackId - The unique identifier of the playback to control.
1886
+ * This should be a string that uniquely identifies the playback in the Asterisk system.
1887
+ * @param controlRequest - An object containing the control operation details.
1888
+ * This object should conform to the PlaybackControlRequest interface,
1889
+ * which includes an 'operation' property specifying the control action to perform.
1890
+ * @returns A Promise that resolves when the control operation is successfully executed.
1891
+ * The promise resolves to void, indicating no specific return value.
1892
+ * If an error occurs during the operation, the promise will be rejected with an error object.
1893
+ * @throws Will throw an error if the playback control operation fails, e.g., if the playback doesn't exist
1894
+ * or the requested operation is invalid.
1895
+ */
1775
1896
  async controlPlayback(playbackId, controlRequest) {
1776
- return this.playbacks.control(playbackId, controlRequest);
1897
+ const { operation } = controlRequest;
1898
+ return this.playbacks.control(playbackId, operation);
1777
1899
  }
1778
1900
  /**
1779
1901
  * Stops a specific playback in the Asterisk server.
@@ -1887,6 +2009,7 @@ export {
1887
2009
  Applications,
1888
2010
  AriClient,
1889
2011
  Asterisk,
2012
+ Bridges,
1890
2013
  Channels,
1891
2014
  Endpoints,
1892
2015
  Playbacks,