@ipcom/asterisk-ari 0.0.126 → 0.0.127

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.
@@ -860,6 +860,51 @@ var Bridges = class {
860
860
  // src/ari-client/resources/channels.ts
861
861
  var import_events = require("events");
862
862
 
863
+ // node_modules/uuid/dist/esm/stringify.js
864
+ var byteToHex = [];
865
+ for (let i = 0; i < 256; ++i) {
866
+ byteToHex.push((i + 256).toString(16).slice(1));
867
+ }
868
+ function unsafeStringify(arr, offset = 0) {
869
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
870
+ }
871
+
872
+ // node_modules/uuid/dist/esm/rng.js
873
+ var import_crypto = require("crypto");
874
+ var rnds8Pool = new Uint8Array(256);
875
+ var poolPtr = rnds8Pool.length;
876
+ function rng() {
877
+ if (poolPtr > rnds8Pool.length - 16) {
878
+ (0, import_crypto.randomFillSync)(rnds8Pool);
879
+ poolPtr = 0;
880
+ }
881
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
882
+ }
883
+
884
+ // node_modules/uuid/dist/esm/native.js
885
+ var import_crypto2 = require("crypto");
886
+ var native_default = { randomUUID: import_crypto2.randomUUID };
887
+
888
+ // node_modules/uuid/dist/esm/v4.js
889
+ function v4(options, buf, offset) {
890
+ if (native_default.randomUUID && !buf && !options) {
891
+ return native_default.randomUUID();
892
+ }
893
+ options = options || {};
894
+ const rnds = options.random || (options.rng || rng)();
895
+ rnds[6] = rnds[6] & 15 | 64;
896
+ rnds[8] = rnds[8] & 63 | 128;
897
+ if (buf) {
898
+ offset = offset || 0;
899
+ for (let i = 0; i < 16; ++i) {
900
+ buf[offset + i] = rnds[i];
901
+ }
902
+ return buf;
903
+ }
904
+ return unsafeStringify(rnds);
905
+ }
906
+ var v4_default = v4;
907
+
863
908
  // src/ari-client/utils.ts
864
909
  function toQueryParams2(options) {
865
910
  return new URLSearchParams(
@@ -910,12 +955,6 @@ var ChannelInstance = class extends import_events.EventEmitter {
910
955
  );
911
956
  }
912
957
  });
913
- this.on("removeListener", (eventName) => {
914
- if (this.eventNames().length === 0 || this.listenerCount(eventName) === 0) {
915
- wsClient.removeScopedMessageListeners(this.id, this.app);
916
- console.log(`Listeners escopados removidos para canal '${this.id}'.`);
917
- }
918
- });
919
958
  }
920
959
  channelData = null;
921
960
  id;
@@ -1031,14 +1070,12 @@ var ChannelInstance = class extends import_events.EventEmitter {
1031
1070
  /**
1032
1071
  * Reproduz mídia no canal.
1033
1072
  */
1034
- async play(options, playback) {
1073
+ async play(options, playbackId) {
1035
1074
  if (!this.channelData) {
1036
1075
  console.log("Canal n\xE3o inicializado, buscando detalhes...");
1037
1076
  this.channelData = await this.getDetails();
1038
1077
  }
1039
- if (!playback) {
1040
- playback = this.client.Playback();
1041
- }
1078
+ const playback = this.client.Playback(playbackId || v4_default(), this.app);
1042
1079
  if (!this.channelData?.id) {
1043
1080
  throw new Error("N\xE3o foi poss\xEDvel inicializar o canal. ID inv\xE1lido.");
1044
1081
  }
@@ -1046,6 +1083,12 @@ var ChannelInstance = class extends import_events.EventEmitter {
1046
1083
  `/channels/${this.channelData.id}/play/${playback.id}`,
1047
1084
  options
1048
1085
  );
1086
+ playback.once("PlaybackFinished", async () => {
1087
+ console.log(
1088
+ `Playback '${playback.id}' finalizado no canal '${this.id}'.`
1089
+ );
1090
+ this.client.getWebSocketClients().get(this.app)?.removeScopedMessageListeners(playback.id, this.app);
1091
+ });
1049
1092
  return playback;
1050
1093
  }
1051
1094
  /**