@ipcom/asterisk-ari 0.0.27 → 0.0.29

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,22 +860,111 @@ var import_events = require("events");
860
860
  function toQueryParams2(options) {
861
861
  return new URLSearchParams(
862
862
  Object.entries(options).filter(([, value]) => value !== void 0).map(([key, value]) => [key, value])
863
- // Garante que value é string
864
863
  ).toString();
865
864
  }
866
- var Channels = class extends import_events.EventEmitter {
867
- constructor(client) {
865
+ var ChannelInstance = class extends import_events.EventEmitter {
866
+ constructor(client, baseClient, channelId) {
868
867
  super();
869
868
  this.client = client;
869
+ this.baseClient = baseClient;
870
+ this.channelId = channelId;
870
871
  }
872
+ channelData = null;
871
873
  /**
872
- * Emits a specific channel-related event.
873
- *
874
- * This method is called by the WebSocket client to notify about channel-related events.
875
- * It will emit events like "ChannelDtmfReceived" to registered listeners.
874
+ * Origina um canal físico no Asterisk.
875
+ */
876
+ async originate(data) {
877
+ if (this.channelData) {
878
+ throw new Error("O canal j\xE1 foi criado.");
879
+ }
880
+ const channel = await this.baseClient.post("/channels", data);
881
+ this.channelData = channel;
882
+ this.emit("ChannelCreated", channel, this);
883
+ return channel;
884
+ }
885
+ /**
886
+ * Obtém os detalhes do canal.
887
+ */
888
+ async getDetails() {
889
+ if (!this.channelId && !this.channelData) {
890
+ throw new Error("Nenhum canal est\xE1 associado a esta inst\xE2ncia.");
891
+ }
892
+ const id = this.channelId || this.channelData?.id;
893
+ const details = await this.baseClient.get(`/channels/${id}`);
894
+ this.channelData = details;
895
+ return details;
896
+ }
897
+ /**
898
+ * Encerra o canal, se ele já foi criado.
899
+ */
900
+ async hangup() {
901
+ if (!this.channelData) {
902
+ throw new Error("O canal ainda n\xE3o foi criado.");
903
+ }
904
+ await this.baseClient.delete(`/channels/${this.channelData.id}`);
905
+ this.emit("ChannelHungUp", this.channelData);
906
+ }
907
+ /**
908
+ * Toca um arquivo de mídia no canal.
876
909
  *
877
- * @param eventType - The type of WebSocket event to emit.
878
- * @param data - The data associated with the event.
910
+ * @param options - Opções para o playback, incluindo mídia e idioma.
911
+ * @param playback - (Opcional) Uma instância de `PlaybackInstance` para gerenciar o playback. Se não fornecido, será criada uma nova.
912
+ * @returns Uma instância de `PlaybackInstance` associada ao playback.
913
+ */
914
+ async play(options, playback) {
915
+ if (!playback) {
916
+ playback = this.client.Playback();
917
+ }
918
+ await this.baseClient.post(
919
+ `/channels/${this.channelData?.id}/play/${playback.id}`,
920
+ // Agora o ID é garantido
921
+ options
922
+ );
923
+ return playback;
924
+ }
925
+ /**
926
+ * Adiciona um listener para eventos de canal.
927
+ */
928
+ on(event, callback) {
929
+ super.on(event, callback);
930
+ return this;
931
+ }
932
+ /**
933
+ * Adiciona um listener para ser chamado apenas uma vez.
934
+ */
935
+ once(event, callback) {
936
+ super.once(event, callback);
937
+ return this;
938
+ }
939
+ /**
940
+ * Remove um listener específico.
941
+ */
942
+ off(event, callback) {
943
+ super.off(event, callback);
944
+ return this;
945
+ }
946
+ };
947
+ var Channels = class extends import_events.EventEmitter {
948
+ constructor(baseClient, client, channelId) {
949
+ super();
950
+ this.baseClient = baseClient;
951
+ this.client = client;
952
+ this.channelId = channelId;
953
+ }
954
+ /**
955
+ * Cria uma nova instância de `ChannelInstance` sem originar um canal físico.
956
+ */
957
+ createChannelInstance(channelId) {
958
+ return new ChannelInstance(this.client, this.baseClient, channelId);
959
+ }
960
+ /**
961
+ * Origina um canal físico diretamente, sem uma instância de `ChannelInstance`.
962
+ */
963
+ async originate(data) {
964
+ return this.baseClient.post("/channels", data);
965
+ }
966
+ /**
967
+ * Lida com eventos relacionados ao canal e os emite para listeners registrados.
879
968
  */
880
969
  emitChannelEvent(eventType, data) {
881
970
  if ("channel" in data) {
@@ -887,149 +976,184 @@ var Channels = class extends import_events.EventEmitter {
887
976
  this.emit(eventType, data);
888
977
  }
889
978
  /**
890
- * Registers a listener for a specific channel-related event.
891
- *
892
- * @param eventType - The type of WebSocket event to listen for.
893
- * @param channelId - The ID of the channel to listen for.
894
- * @param callback - The callback function to execute when the event occurs.
979
+ * Registra um listener para eventos de canal específicos.
895
980
  */
896
981
  registerChannelListener(eventType, channelId, callback) {
897
982
  this.on(`${eventType}:${channelId}`, callback);
898
983
  }
899
984
  /**
900
- * Unregisters a listener for a specific channel-related event.
901
- *
902
- * @param eventType - The type of WebSocket event to stop listening for.
903
- * @param channelId - The ID of the channel to stop listening for.
904
- * @param callback - The callback function to remove.
985
+ * Remove um listener específico de eventos de canal.
905
986
  */
906
987
  unregisterChannelListener(eventType, channelId, callback) {
907
988
  this.off(`${eventType}:${channelId}`, callback);
908
989
  }
909
990
  /**
910
- * Checks if a listener is already registered for a specific channel event.
911
- *
912
- * @param eventType - The type of event to check.
913
- * @param channelId - The channel ID associated with the listener.
914
- * @returns True if a listener is already registered, false otherwise.
991
+ * Verifica se um listener está registrado para um evento de canal.
915
992
  */
916
993
  isChannelListenerRegistered(eventType, channelId) {
917
994
  return this.listenerCount(`${eventType}:${channelId}`) > 0;
918
995
  }
919
996
  /**
920
- * Lists all active channels.
997
+ * Lista todos os canais ativos.
921
998
  */
922
999
  async list() {
923
- const channels = await this.client.get("/channels");
1000
+ const channels = await this.baseClient.get("/channels");
924
1001
  if (!Array.isArray(channels)) {
925
1002
  throw new Error("Resposta da API /channels n\xE3o \xE9 um array.");
926
1003
  }
927
1004
  return channels;
928
1005
  }
929
1006
  /**
930
- * Creates a new channel.
931
- */
932
- async originate(data) {
933
- return this.client.post("/channels", data);
934
- }
935
- /**
936
- * Retrieves details of a specific channel.
1007
+ * Obtém detalhes de um canal específico.
937
1008
  */
938
1009
  async getDetails(channelId) {
939
- return this.client.get(`/channels/${channelId}`);
940
- }
941
- /**
942
- * Creates a channel and places it in a Stasis app without dialing it.
943
- */
944
- async createChannel(data) {
945
- return this.client.post("/channels/create", data);
1010
+ return this.baseClient.get(`/channels/${channelId}`);
946
1011
  }
947
1012
  /**
948
- * Creates a new channel with a specific ID and originates a call.
1013
+ * Reproduz mídia em um canal.
949
1014
  */
950
- async originateWithId(channelId, data) {
951
- return this.client.post(`/channels/${channelId}`, data);
1015
+ async playMedia(channelId, media, options) {
1016
+ const queryParams = options ? `?${new URLSearchParams(options).toString()}` : "";
1017
+ return this.baseClient.post(
1018
+ `/channels/${channelId}/play${queryParams}`,
1019
+ { media }
1020
+ );
952
1021
  }
953
1022
  /**
954
- * Hangs up (terminates) a specific channel.
955
- */
956
- /**
957
- * Hangs up a specific channel with optional reason or reason code.
1023
+ * Encerra um canal específico.
958
1024
  */
959
1025
  async hangup(channelId, options) {
960
1026
  const queryParams = new URLSearchParams({
961
1027
  ...options?.reason_code && { reason_code: options.reason_code },
962
1028
  ...options?.reason && { reason: options.reason }
963
1029
  });
964
- return this.client.delete(
1030
+ return this.baseClient.delete(
965
1031
  `/channels/${channelId}?${queryParams.toString()}`
966
1032
  );
967
1033
  }
968
1034
  /**
969
- * Continues the dialplan for a specific channel.
1035
+ * Inicia a escuta em um canal.
970
1036
  */
971
- async continueDialplan(channelId, context, extension, priority, label) {
972
- return this.client.post(`/channels/${channelId}/continue`, {
973
- context,
974
- extension,
975
- priority,
976
- label
1037
+ async snoopChannel(channelId, options) {
1038
+ const queryParams = toQueryParams2(options);
1039
+ return this.baseClient.post(
1040
+ `/channels/${channelId}/snoop?${queryParams}`
1041
+ );
1042
+ }
1043
+ async startSilence(channelId) {
1044
+ return this.baseClient.post(`/channels/${channelId}/silence`);
1045
+ }
1046
+ async stopSilence(channelId) {
1047
+ return this.baseClient.delete(`/channels/${channelId}/silence`);
1048
+ }
1049
+ async getRTPStatistics(channelId) {
1050
+ return this.baseClient.get(
1051
+ `/channels/${channelId}/rtp_statistics`
1052
+ );
1053
+ }
1054
+ async createExternalMedia(options) {
1055
+ const queryParams = new URLSearchParams(options);
1056
+ return this.baseClient.post(
1057
+ `/channels/externalMedia?${queryParams.toString()}`
1058
+ );
1059
+ }
1060
+ async playWithId(channelId, playbackId, media, options) {
1061
+ const queryParams = options ? `?${new URLSearchParams(options).toString()}` : "";
1062
+ return this.baseClient.post(
1063
+ `/channels/${channelId}/play/${playbackId}${queryParams}`,
1064
+ { media }
1065
+ );
1066
+ }
1067
+ async snoopChannelWithId(channelId, snoopId, options) {
1068
+ const queryParams = new URLSearchParams(options);
1069
+ return this.baseClient.post(
1070
+ `/channels/${channelId}/snoop/${snoopId}?${queryParams.toString()}`
1071
+ );
1072
+ }
1073
+ async startMohWithClass(channelId, mohClass) {
1074
+ const queryParams = `mohClass=${encodeURIComponent(mohClass)}`;
1075
+ return this.baseClient.post(
1076
+ `/channels/${channelId}/moh?${queryParams}`
1077
+ );
1078
+ }
1079
+ /**
1080
+ * Gets the value of a channel variable or function.
1081
+ *
1082
+ * @param channelId - The ID of the channel.
1083
+ * @param variable - The name of the channel variable or function to retrieve.
1084
+ * @returns A promise that resolves to the value of the variable.
1085
+ * @throws Will throw an error if the variable is missing or the channel is not found.
1086
+ */
1087
+ async getChannelVariable(channelId, variable) {
1088
+ if (!variable) {
1089
+ throw new Error("The 'variable' parameter is required.");
1090
+ }
1091
+ return this.baseClient.get(
1092
+ `/channels/${channelId}/variable?variable=${encodeURIComponent(variable)}`
1093
+ );
1094
+ }
1095
+ /**
1096
+ * Sets the value of a channel variable or function.
1097
+ *
1098
+ * @param channelId - The ID of the channel.
1099
+ * @param variable - The name of the channel variable or function to set.
1100
+ * @param value - The value to set the variable to.
1101
+ * @returns A promise that resolves when the variable is successfully set.
1102
+ * @throws Will throw an error if the variable is missing or the channel is not found.
1103
+ */
1104
+ async setChannelVariable(channelId, variable, value) {
1105
+ if (!variable) {
1106
+ throw new Error("The 'variable' parameter is required.");
1107
+ }
1108
+ const queryParams = new URLSearchParams({
1109
+ variable,
1110
+ ...value && { value }
977
1111
  });
1112
+ await this.baseClient.post(
1113
+ `/channels/${channelId}/variable?${queryParams.toString()}`
1114
+ );
978
1115
  }
979
1116
  /**
980
1117
  * Moves the channel to another Stasis application.
981
1118
  */
982
1119
  async moveToApplication(channelId, app, appArgs) {
983
- return this.client.post(`/channels/${channelId}/move`, {
1120
+ return this.baseClient.post(`/channels/${channelId}/move`, {
984
1121
  app,
985
1122
  appArgs
986
1123
  });
987
1124
  }
988
1125
  /**
989
- * Sets a channel variable.
1126
+ * Continues the dialplan for a specific channel.
990
1127
  */
991
- async setVariable(channelId, variable, value) {
992
- return this.client.post(`/channels/${channelId}/variable`, {
993
- variable,
994
- value
1128
+ async continueDialplan(channelId, context, extension, priority, label) {
1129
+ return this.baseClient.post(`/channels/${channelId}/continue`, {
1130
+ context,
1131
+ extension,
1132
+ priority,
1133
+ label
995
1134
  });
996
1135
  }
997
1136
  /**
998
- * Gets a channel variable.
999
- */
1000
- async getVariable(channelId, variable) {
1001
- return this.client.get(
1002
- `/channels/${channelId}/variable?variable=${encodeURIComponent(variable)}`
1003
- );
1004
- }
1005
- /**
1006
- * Plays a media file to a channel.
1137
+ * Stops music on hold (MOH) for a channel.
1007
1138
  */
1008
- async playMedia(channelId, media, options) {
1009
- const queryParams = options ? `?${new URLSearchParams(options).toString()}` : "";
1010
- return this.client.post(
1011
- `/channels/${channelId}/play${queryParams}`,
1012
- { media }
1013
- );
1139
+ async stopMusicOnHold(channelId) {
1140
+ return this.baseClient.delete(`/channels/${channelId}/moh`);
1014
1141
  }
1015
1142
  /**
1016
1143
  * Starts music on hold (MOH) for a channel.
1017
1144
  */
1018
1145
  async startMusicOnHold(channelId) {
1019
- return this.client.post(`/channels/${channelId}/moh`);
1146
+ return this.baseClient.post(`/channels/${channelId}/moh`);
1020
1147
  }
1021
1148
  /**
1022
- * Stops music on hold (MOH) for a channel.
1149
+ * Starts playback of a media file on a channel.
1023
1150
  */
1024
- async stopMusicOnHold(channelId) {
1025
- return this.client.delete(`/channels/${channelId}/moh`);
1026
- }
1027
1151
  /**
1028
1152
  * Starts playback of a media file on a channel.
1029
1153
  */
1030
1154
  async startPlayback(channelId, media, options) {
1031
1155
  const queryParams = options ? `?${new URLSearchParams(options).toString()}` : "";
1032
- return this.client.post(
1156
+ return this.baseClient.post(
1033
1157
  `/channels/${channelId}/play${queryParams}`,
1034
1158
  { media }
1035
1159
  );
@@ -1038,7 +1162,7 @@ var Channels = class extends import_events.EventEmitter {
1038
1162
  * Stops playback of a media file on a channel.
1039
1163
  */
1040
1164
  async stopPlayback(channelId, playbackId) {
1041
- return this.client.delete(
1165
+ return this.baseClient.delete(
1042
1166
  `/channels/${channelId}/play/${playbackId}`
1043
1167
  );
1044
1168
  }
@@ -1046,7 +1170,7 @@ var Channels = class extends import_events.EventEmitter {
1046
1170
  * Pauses playback of a media file on a channel.
1047
1171
  */
1048
1172
  async pausePlayback(channelId, playbackId) {
1049
- return this.client.post(
1173
+ return this.baseClient.post(
1050
1174
  `/channels/${channelId}/play/${playbackId}/pause`
1051
1175
  );
1052
1176
  }
@@ -1054,7 +1178,7 @@ var Channels = class extends import_events.EventEmitter {
1054
1178
  * Resumes playback of a media file on a channel.
1055
1179
  */
1056
1180
  async resumePlayback(channelId, playbackId) {
1057
- return this.client.delete(
1181
+ return this.baseClient.delete(
1058
1182
  `/channels/${channelId}/play/${playbackId}/pause`
1059
1183
  );
1060
1184
  }
@@ -1062,7 +1186,7 @@ var Channels = class extends import_events.EventEmitter {
1062
1186
  * Rewinds playback of a media file on a channel.
1063
1187
  */
1064
1188
  async rewindPlayback(channelId, playbackId, skipMs) {
1065
- return this.client.post(
1189
+ return this.baseClient.post(
1066
1190
  `/channels/${channelId}/play/${playbackId}/rewind`,
1067
1191
  { skipMs }
1068
1192
  );
@@ -1071,7 +1195,7 @@ var Channels = class extends import_events.EventEmitter {
1071
1195
  * Fast-forwards playback of a media file on a channel.
1072
1196
  */
1073
1197
  async fastForwardPlayback(channelId, playbackId, skipMs) {
1074
- return this.client.post(
1198
+ return this.baseClient.post(
1075
1199
  `/channels/${channelId}/play/${playbackId}/forward`,
1076
1200
  { skipMs }
1077
1201
  );
@@ -1085,28 +1209,10 @@ var Channels = class extends import_events.EventEmitter {
1085
1209
  ([, value]) => value !== void 0
1086
1210
  )
1087
1211
  );
1088
- return this.client.post(
1212
+ return this.baseClient.post(
1089
1213
  `/channels/${channelId}/record?${queryParams.toString()}`
1090
1214
  );
1091
1215
  }
1092
- /**
1093
- * Starts snooping on a channel.
1094
- */
1095
- async snoopChannel(channelId, options) {
1096
- const queryParams = toQueryParams2(options);
1097
- return this.client.post(
1098
- `/channels/${channelId}/snoop?${queryParams}`
1099
- );
1100
- }
1101
- /**
1102
- * Starts snooping on a channel with a specific snoop ID.
1103
- */
1104
- async snoopChannelWithId(channelId, snoopId, options) {
1105
- const queryParams = new URLSearchParams(options);
1106
- return this.client.post(
1107
- `/channels/${channelId}/snoop/${snoopId}?${queryParams.toString()}`
1108
- );
1109
- }
1110
1216
  /**
1111
1217
  * Dials a created channel.
1112
1218
  */
@@ -1115,30 +1221,15 @@ var Channels = class extends import_events.EventEmitter {
1115
1221
  ...caller && { caller },
1116
1222
  ...timeout && { timeout: timeout.toString() }
1117
1223
  });
1118
- return this.client.post(
1224
+ return this.baseClient.post(
1119
1225
  `/channels/${channelId}/dial?${queryParams.toString()}`
1120
1226
  );
1121
1227
  }
1122
- /**
1123
- * Retrieves RTP statistics for a channel.
1124
- */
1125
- async getRTPStatistics(channelId) {
1126
- return this.client.get(`/channels/${channelId}/rtp_statistics`);
1127
- }
1128
- /**
1129
- * Creates a channel to an external media source/sink.
1130
- */
1131
- async createExternalMedia(options) {
1132
- const queryParams = new URLSearchParams(options);
1133
- return this.client.post(
1134
- `/channels/externalMedia?${queryParams.toString()}`
1135
- );
1136
- }
1137
1228
  /**
1138
1229
  * Redirects the channel to a different location.
1139
1230
  */
1140
1231
  async redirectChannel(channelId, endpoint) {
1141
- return this.client.post(
1232
+ return this.baseClient.post(
1142
1233
  `/channels/${channelId}/redirect?endpoint=${encodeURIComponent(endpoint)}`
1143
1234
  );
1144
1235
  }
@@ -1146,19 +1237,19 @@ var Channels = class extends import_events.EventEmitter {
1146
1237
  * Answers a channel.
1147
1238
  */
1148
1239
  async answerChannel(channelId) {
1149
- return this.client.post(`/channels/${channelId}/answer`);
1240
+ return this.baseClient.post(`/channels/${channelId}/answer`);
1150
1241
  }
1151
1242
  /**
1152
1243
  * Sends a ringing indication to a channel.
1153
1244
  */
1154
1245
  async ringChannel(channelId) {
1155
- return this.client.post(`/channels/${channelId}/ring`);
1246
+ return this.baseClient.post(`/channels/${channelId}/ring`);
1156
1247
  }
1157
1248
  /**
1158
1249
  * Stops ringing indication on a channel.
1159
1250
  */
1160
1251
  async stopRingChannel(channelId) {
1161
- return this.client.delete(`/channels/${channelId}/ring`);
1252
+ return this.baseClient.delete(`/channels/${channelId}/ring`);
1162
1253
  }
1163
1254
  /**
1164
1255
  * Sends DTMF to a channel.
@@ -1171,7 +1262,7 @@ var Channels = class extends import_events.EventEmitter {
1171
1262
  ...options?.duration && { duration: options.duration.toString() },
1172
1263
  ...options?.after && { after: options.after.toString() }
1173
1264
  });
1174
- return this.client.post(
1265
+ return this.baseClient.post(
1175
1266
  `/channels/${channelId}/dtmf?${queryParams.toString()}`
1176
1267
  );
1177
1268
  }
@@ -1179,7 +1270,7 @@ var Channels = class extends import_events.EventEmitter {
1179
1270
  * Mutes a channel.
1180
1271
  */
1181
1272
  async muteChannel(channelId, direction = "both") {
1182
- return this.client.post(
1273
+ return this.baseClient.post(
1183
1274
  `/channels/${channelId}/mute?direction=${direction}`
1184
1275
  );
1185
1276
  }
@@ -1187,7 +1278,7 @@ var Channels = class extends import_events.EventEmitter {
1187
1278
  * Unmutes a channel.
1188
1279
  */
1189
1280
  async unmuteChannel(channelId, direction = "both") {
1190
- return this.client.delete(
1281
+ return this.baseClient.delete(
1191
1282
  `/channels/${channelId}/mute?direction=${direction}`
1192
1283
  );
1193
1284
  }
@@ -1195,13 +1286,25 @@ var Channels = class extends import_events.EventEmitter {
1195
1286
  * Puts a channel on hold.
1196
1287
  */
1197
1288
  async holdChannel(channelId) {
1198
- return this.client.post(`/channels/${channelId}/hold`);
1289
+ return this.baseClient.post(`/channels/${channelId}/hold`);
1199
1290
  }
1200
1291
  /**
1201
1292
  * Removes a channel from hold.
1202
1293
  */
1203
1294
  async unholdChannel(channelId) {
1204
- return this.client.delete(`/channels/${channelId}/hold`);
1295
+ return this.baseClient.delete(`/channels/${channelId}/hold`);
1296
+ }
1297
+ /**
1298
+ * Creates a channel and places it in a Stasis app without dialing it.
1299
+ */
1300
+ async createChannel(data) {
1301
+ return this.baseClient.post("/channels/create", data);
1302
+ }
1303
+ /**
1304
+ * Creates a new channel with a specific ID and originates a call.
1305
+ */
1306
+ async originateWithId(channelId, data) {
1307
+ return this.baseClient.post(`/channels/${channelId}`, data);
1205
1308
  }
1206
1309
  };
1207
1310
 
@@ -1253,11 +1356,96 @@ var Endpoints = class {
1253
1356
 
1254
1357
  // src/ari-client/resources/playbacks.ts
1255
1358
  var import_events2 = require("events");
1359
+ var PlaybackInstance = class extends import_events2.EventEmitter {
1360
+ // Garantimos que o ID esteja disponível
1361
+ constructor(baseClient, playbackId) {
1362
+ super();
1363
+ this.baseClient = baseClient;
1364
+ this.playbackId = playbackId;
1365
+ this.id = playbackId || `playback-${Date.now()}`;
1366
+ }
1367
+ playbackData = null;
1368
+ id;
1369
+ /**
1370
+ * Obtém os detalhes do playback.
1371
+ */
1372
+ async getDetails() {
1373
+ if (!this.playbackId && !this.playbackData) {
1374
+ throw new Error("Nenhum playback associado a esta inst\xE2ncia.");
1375
+ }
1376
+ const id = this.playbackId || this.playbackData?.id;
1377
+ const details = await this.baseClient.get(`/playbacks/${id}`);
1378
+ this.playbackData = details;
1379
+ return details;
1380
+ }
1381
+ /**
1382
+ * Controla o playback.
1383
+ */
1384
+ async control(operation) {
1385
+ if (!this.playbackId) {
1386
+ throw new Error("Nenhum playback associado para controlar.");
1387
+ }
1388
+ await this.baseClient.post(`/playbacks/${this.playbackId}/control`, {
1389
+ operation
1390
+ });
1391
+ }
1392
+ /**
1393
+ * Encerra o playback.
1394
+ */
1395
+ async stop() {
1396
+ if (!this.playbackId) {
1397
+ throw new Error("Nenhum playback associado para encerrar.");
1398
+ }
1399
+ await this.baseClient.post(`/playbacks/${this.playbackId}/stop`);
1400
+ this.emit("PlaybackStopped", this.playbackData);
1401
+ }
1402
+ /**
1403
+ * Adiciona um listener para eventos de playback.
1404
+ */
1405
+ on(event, callback) {
1406
+ super.on(event, callback);
1407
+ return this;
1408
+ }
1409
+ /**
1410
+ * Adiciona um listener para ser chamado apenas uma vez.
1411
+ */
1412
+ once(event, callback) {
1413
+ super.once(event, callback);
1414
+ return this;
1415
+ }
1416
+ /**
1417
+ * Remove um listener específico.
1418
+ */
1419
+ off(event, callback) {
1420
+ super.off(event, callback);
1421
+ return this;
1422
+ }
1423
+ };
1256
1424
  var Playbacks = class extends import_events2.EventEmitter {
1257
1425
  constructor(client) {
1258
1426
  super();
1259
1427
  this.client = client;
1260
1428
  }
1429
+ /**
1430
+ * Inicializa uma nova instância de `PlaybackInstance`.
1431
+ */
1432
+ Playback(playbackId) {
1433
+ const id = playbackId || `playback-${Date.now()}`;
1434
+ return new PlaybackInstance(this.client, id);
1435
+ }
1436
+ /**
1437
+ * Emite eventos de playback.
1438
+ * Atualizado para gerenciar eventos específicos para `PlaybackInstance`.
1439
+ */
1440
+ emitPlaybackEvent(eventType, data) {
1441
+ if ("playbackId" in data) {
1442
+ const playbackId = data.playbackId;
1443
+ if (playbackId) {
1444
+ this.emit(`${eventType}:${playbackId}`, data);
1445
+ }
1446
+ }
1447
+ this.emit(eventType, data);
1448
+ }
1261
1449
  /**
1262
1450
  * Retrieves details of a specific playback.
1263
1451
  *
@@ -1325,19 +1513,6 @@ var Playbacks = class extends import_events2.EventEmitter {
1325
1513
  isListenerRegistered(eventType, playbackId) {
1326
1514
  return this.listenerCount(`${eventType}:${playbackId}`) > 0;
1327
1515
  }
1328
- /**
1329
- * Emits playback events received via WebSocket.
1330
- * This method should be called by the WebSocket client when playback events occur.
1331
- *
1332
- * @param eventType - The type of the WebSocket event.
1333
- * @param data - The data associated with the event.
1334
- */
1335
- emitPlaybackEvent(eventType, data) {
1336
- if ("playbackId" in data) {
1337
- this.emit(`${eventType}:${data.playbackId}`, data);
1338
- }
1339
- this.emit(eventType, data);
1340
- }
1341
1516
  };
1342
1517
 
1343
1518
  // src/ari-client/resources/sounds.ts
@@ -1502,7 +1677,7 @@ var AriClient = class {
1502
1677
  const normalizedHost = config.host.replace(/^https?:\/\//, "");
1503
1678
  const baseUrl = `${httpProtocol}://${normalizedHost}:${config.port}/ari`;
1504
1679
  this.baseClient = new BaseClient(baseUrl, config.username, config.password);
1505
- this.channels = new Channels(this.baseClient);
1680
+ this.channels = new Channels(this.baseClient, this);
1506
1681
  this.endpoints = new Endpoints(this.baseClient);
1507
1682
  this.applications = new Applications(this.baseClient);
1508
1683
  this.playbacks = new Playbacks(this.baseClient);
@@ -1837,13 +2012,13 @@ var AriClient = class {
1837
2012
  * Sets a channel variable.
1838
2013
  */
1839
2014
  async setChannelVariable(channelId, variable, value) {
1840
- return this.channels.setVariable(channelId, variable, value);
2015
+ return this.channels.setChannelVariable(channelId, variable, value);
1841
2016
  }
1842
2017
  /**
1843
2018
  * Gets a channel variable.
1844
2019
  */
1845
2020
  async getChannelVariable(channelId, variable) {
1846
- return this.channels.getVariable(channelId, variable);
2021
+ return this.channels.getChannelVariable(channelId, variable);
1847
2022
  }
1848
2023
  /**
1849
2024
  * Plays a media file to a channel.
@@ -2314,6 +2489,24 @@ var AriClient = class {
2314
2489
  async setGlobalVariable(variableName, value) {
2315
2490
  return this.asterisk.setGlobalVariable(variableName, value);
2316
2491
  }
2492
+ /**
2493
+ * Inicializa uma nova instância de `ChannelInstance` para manipular canais localmente.
2494
+ *
2495
+ * @param channelId - O ID do canal, se disponível. Caso contrário, a instância será para um canal ainda não criado.
2496
+ * @returns Uma instância de `ChannelInstance` vinculada ao cliente atual.
2497
+ */
2498
+ Channel(channelId) {
2499
+ return this.channels.createChannelInstance(channelId);
2500
+ }
2501
+ /**
2502
+ * Inicializa uma nova instância de `PlaybackInstance` para manipular playbacks.
2503
+ *
2504
+ * @param playbackId - O ID do playback, se disponível. Caso contrário, a instância será para um playback ainda não inicializado.
2505
+ * @returns Uma instância de `PlaybackInstance` vinculada ao cliente atual.
2506
+ */
2507
+ Playback(playbackId) {
2508
+ return this.playbacks.Playback(playbackId);
2509
+ }
2317
2510
  };
2318
2511
  // Annotate the CommonJS export names for ESM import in node:
2319
2512
  0 && (module.exports = {