@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.
package/dist/esm/index.js CHANGED
@@ -840,22 +840,111 @@ import { EventEmitter } from "events";
840
840
  function toQueryParams2(options) {
841
841
  return new URLSearchParams(
842
842
  Object.entries(options).filter(([, value]) => value !== void 0).map(([key, value]) => [key, value])
843
- // Garante que value é string
844
843
  ).toString();
845
844
  }
846
- var Channels = class extends EventEmitter {
847
- constructor(client) {
845
+ var ChannelInstance = class extends EventEmitter {
846
+ constructor(client, baseClient, channelId) {
848
847
  super();
849
848
  this.client = client;
849
+ this.baseClient = baseClient;
850
+ this.channelId = channelId;
850
851
  }
852
+ channelData = null;
851
853
  /**
852
- * Emits a specific channel-related event.
853
- *
854
- * This method is called by the WebSocket client to notify about channel-related events.
855
- * It will emit events like "ChannelDtmfReceived" to registered listeners.
854
+ * Origina um canal físico no Asterisk.
855
+ */
856
+ async originate(data) {
857
+ if (this.channelData) {
858
+ throw new Error("O canal j\xE1 foi criado.");
859
+ }
860
+ const channel = await this.baseClient.post("/channels", data);
861
+ this.channelData = channel;
862
+ this.emit("ChannelCreated", channel, this);
863
+ return channel;
864
+ }
865
+ /**
866
+ * Obtém os detalhes do canal.
867
+ */
868
+ async getDetails() {
869
+ if (!this.channelId && !this.channelData) {
870
+ throw new Error("Nenhum canal est\xE1 associado a esta inst\xE2ncia.");
871
+ }
872
+ const id = this.channelId || this.channelData?.id;
873
+ const details = await this.baseClient.get(`/channels/${id}`);
874
+ this.channelData = details;
875
+ return details;
876
+ }
877
+ /**
878
+ * Encerra o canal, se ele já foi criado.
879
+ */
880
+ async hangup() {
881
+ if (!this.channelData) {
882
+ throw new Error("O canal ainda n\xE3o foi criado.");
883
+ }
884
+ await this.baseClient.delete(`/channels/${this.channelData.id}`);
885
+ this.emit("ChannelHungUp", this.channelData);
886
+ }
887
+ /**
888
+ * Toca um arquivo de mídia no canal.
856
889
  *
857
- * @param eventType - The type of WebSocket event to emit.
858
- * @param data - The data associated with the event.
890
+ * @param options - Opções para o playback, incluindo mídia e idioma.
891
+ * @param playback - (Opcional) Uma instância de `PlaybackInstance` para gerenciar o playback. Se não fornecido, será criada uma nova.
892
+ * @returns Uma instância de `PlaybackInstance` associada ao playback.
893
+ */
894
+ async play(options, playback) {
895
+ if (!playback) {
896
+ playback = this.client.Playback();
897
+ }
898
+ await this.baseClient.post(
899
+ `/channels/${this.channelData?.id}/play/${playback.id}`,
900
+ // Agora o ID é garantido
901
+ options
902
+ );
903
+ return playback;
904
+ }
905
+ /**
906
+ * Adiciona um listener para eventos de canal.
907
+ */
908
+ on(event, callback) {
909
+ super.on(event, callback);
910
+ return this;
911
+ }
912
+ /**
913
+ * Adiciona um listener para ser chamado apenas uma vez.
914
+ */
915
+ once(event, callback) {
916
+ super.once(event, callback);
917
+ return this;
918
+ }
919
+ /**
920
+ * Remove um listener específico.
921
+ */
922
+ off(event, callback) {
923
+ super.off(event, callback);
924
+ return this;
925
+ }
926
+ };
927
+ var Channels = class extends EventEmitter {
928
+ constructor(baseClient, client, channelId) {
929
+ super();
930
+ this.baseClient = baseClient;
931
+ this.client = client;
932
+ this.channelId = channelId;
933
+ }
934
+ /**
935
+ * Cria uma nova instância de `ChannelInstance` sem originar um canal físico.
936
+ */
937
+ createChannelInstance(channelId) {
938
+ return new ChannelInstance(this.client, this.baseClient, channelId);
939
+ }
940
+ /**
941
+ * Origina um canal físico diretamente, sem uma instância de `ChannelInstance`.
942
+ */
943
+ async originate(data) {
944
+ return this.baseClient.post("/channels", data);
945
+ }
946
+ /**
947
+ * Lida com eventos relacionados ao canal e os emite para listeners registrados.
859
948
  */
860
949
  emitChannelEvent(eventType, data) {
861
950
  if ("channel" in data) {
@@ -867,149 +956,184 @@ var Channels = class extends EventEmitter {
867
956
  this.emit(eventType, data);
868
957
  }
869
958
  /**
870
- * Registers a listener for a specific channel-related event.
871
- *
872
- * @param eventType - The type of WebSocket event to listen for.
873
- * @param channelId - The ID of the channel to listen for.
874
- * @param callback - The callback function to execute when the event occurs.
959
+ * Registra um listener para eventos de canal específicos.
875
960
  */
876
961
  registerChannelListener(eventType, channelId, callback) {
877
962
  this.on(`${eventType}:${channelId}`, callback);
878
963
  }
879
964
  /**
880
- * Unregisters a listener for a specific channel-related event.
881
- *
882
- * @param eventType - The type of WebSocket event to stop listening for.
883
- * @param channelId - The ID of the channel to stop listening for.
884
- * @param callback - The callback function to remove.
965
+ * Remove um listener específico de eventos de canal.
885
966
  */
886
967
  unregisterChannelListener(eventType, channelId, callback) {
887
968
  this.off(`${eventType}:${channelId}`, callback);
888
969
  }
889
970
  /**
890
- * Checks if a listener is already registered for a specific channel event.
891
- *
892
- * @param eventType - The type of event to check.
893
- * @param channelId - The channel ID associated with the listener.
894
- * @returns True if a listener is already registered, false otherwise.
971
+ * Verifica se um listener está registrado para um evento de canal.
895
972
  */
896
973
  isChannelListenerRegistered(eventType, channelId) {
897
974
  return this.listenerCount(`${eventType}:${channelId}`) > 0;
898
975
  }
899
976
  /**
900
- * Lists all active channels.
977
+ * Lista todos os canais ativos.
901
978
  */
902
979
  async list() {
903
- const channels = await this.client.get("/channels");
980
+ const channels = await this.baseClient.get("/channels");
904
981
  if (!Array.isArray(channels)) {
905
982
  throw new Error("Resposta da API /channels n\xE3o \xE9 um array.");
906
983
  }
907
984
  return channels;
908
985
  }
909
986
  /**
910
- * Creates a new channel.
911
- */
912
- async originate(data) {
913
- return this.client.post("/channels", data);
914
- }
915
- /**
916
- * Retrieves details of a specific channel.
987
+ * Obtém detalhes de um canal específico.
917
988
  */
918
989
  async getDetails(channelId) {
919
- return this.client.get(`/channels/${channelId}`);
920
- }
921
- /**
922
- * Creates a channel and places it in a Stasis app without dialing it.
923
- */
924
- async createChannel(data) {
925
- return this.client.post("/channels/create", data);
990
+ return this.baseClient.get(`/channels/${channelId}`);
926
991
  }
927
992
  /**
928
- * Creates a new channel with a specific ID and originates a call.
993
+ * Reproduz mídia em um canal.
929
994
  */
930
- async originateWithId(channelId, data) {
931
- return this.client.post(`/channels/${channelId}`, data);
995
+ async playMedia(channelId, media, options) {
996
+ const queryParams = options ? `?${new URLSearchParams(options).toString()}` : "";
997
+ return this.baseClient.post(
998
+ `/channels/${channelId}/play${queryParams}`,
999
+ { media }
1000
+ );
932
1001
  }
933
1002
  /**
934
- * Hangs up (terminates) a specific channel.
935
- */
936
- /**
937
- * Hangs up a specific channel with optional reason or reason code.
1003
+ * Encerra um canal específico.
938
1004
  */
939
1005
  async hangup(channelId, options) {
940
1006
  const queryParams = new URLSearchParams({
941
1007
  ...options?.reason_code && { reason_code: options.reason_code },
942
1008
  ...options?.reason && { reason: options.reason }
943
1009
  });
944
- return this.client.delete(
1010
+ return this.baseClient.delete(
945
1011
  `/channels/${channelId}?${queryParams.toString()}`
946
1012
  );
947
1013
  }
948
1014
  /**
949
- * Continues the dialplan for a specific channel.
1015
+ * Inicia a escuta em um canal.
950
1016
  */
951
- async continueDialplan(channelId, context, extension, priority, label) {
952
- return this.client.post(`/channels/${channelId}/continue`, {
953
- context,
954
- extension,
955
- priority,
956
- label
1017
+ async snoopChannel(channelId, options) {
1018
+ const queryParams = toQueryParams2(options);
1019
+ return this.baseClient.post(
1020
+ `/channels/${channelId}/snoop?${queryParams}`
1021
+ );
1022
+ }
1023
+ async startSilence(channelId) {
1024
+ return this.baseClient.post(`/channels/${channelId}/silence`);
1025
+ }
1026
+ async stopSilence(channelId) {
1027
+ return this.baseClient.delete(`/channels/${channelId}/silence`);
1028
+ }
1029
+ async getRTPStatistics(channelId) {
1030
+ return this.baseClient.get(
1031
+ `/channels/${channelId}/rtp_statistics`
1032
+ );
1033
+ }
1034
+ async createExternalMedia(options) {
1035
+ const queryParams = new URLSearchParams(options);
1036
+ return this.baseClient.post(
1037
+ `/channels/externalMedia?${queryParams.toString()}`
1038
+ );
1039
+ }
1040
+ async playWithId(channelId, playbackId, media, options) {
1041
+ const queryParams = options ? `?${new URLSearchParams(options).toString()}` : "";
1042
+ return this.baseClient.post(
1043
+ `/channels/${channelId}/play/${playbackId}${queryParams}`,
1044
+ { media }
1045
+ );
1046
+ }
1047
+ async snoopChannelWithId(channelId, snoopId, options) {
1048
+ const queryParams = new URLSearchParams(options);
1049
+ return this.baseClient.post(
1050
+ `/channels/${channelId}/snoop/${snoopId}?${queryParams.toString()}`
1051
+ );
1052
+ }
1053
+ async startMohWithClass(channelId, mohClass) {
1054
+ const queryParams = `mohClass=${encodeURIComponent(mohClass)}`;
1055
+ return this.baseClient.post(
1056
+ `/channels/${channelId}/moh?${queryParams}`
1057
+ );
1058
+ }
1059
+ /**
1060
+ * Gets the value of a channel variable or function.
1061
+ *
1062
+ * @param channelId - The ID of the channel.
1063
+ * @param variable - The name of the channel variable or function to retrieve.
1064
+ * @returns A promise that resolves to the value of the variable.
1065
+ * @throws Will throw an error if the variable is missing or the channel is not found.
1066
+ */
1067
+ async getChannelVariable(channelId, variable) {
1068
+ if (!variable) {
1069
+ throw new Error("The 'variable' parameter is required.");
1070
+ }
1071
+ return this.baseClient.get(
1072
+ `/channels/${channelId}/variable?variable=${encodeURIComponent(variable)}`
1073
+ );
1074
+ }
1075
+ /**
1076
+ * Sets the value of a channel variable or function.
1077
+ *
1078
+ * @param channelId - The ID of the channel.
1079
+ * @param variable - The name of the channel variable or function to set.
1080
+ * @param value - The value to set the variable to.
1081
+ * @returns A promise that resolves when the variable is successfully set.
1082
+ * @throws Will throw an error if the variable is missing or the channel is not found.
1083
+ */
1084
+ async setChannelVariable(channelId, variable, value) {
1085
+ if (!variable) {
1086
+ throw new Error("The 'variable' parameter is required.");
1087
+ }
1088
+ const queryParams = new URLSearchParams({
1089
+ variable,
1090
+ ...value && { value }
957
1091
  });
1092
+ await this.baseClient.post(
1093
+ `/channels/${channelId}/variable?${queryParams.toString()}`
1094
+ );
958
1095
  }
959
1096
  /**
960
1097
  * Moves the channel to another Stasis application.
961
1098
  */
962
1099
  async moveToApplication(channelId, app, appArgs) {
963
- return this.client.post(`/channels/${channelId}/move`, {
1100
+ return this.baseClient.post(`/channels/${channelId}/move`, {
964
1101
  app,
965
1102
  appArgs
966
1103
  });
967
1104
  }
968
1105
  /**
969
- * Sets a channel variable.
1106
+ * Continues the dialplan for a specific channel.
970
1107
  */
971
- async setVariable(channelId, variable, value) {
972
- return this.client.post(`/channels/${channelId}/variable`, {
973
- variable,
974
- value
1108
+ async continueDialplan(channelId, context, extension, priority, label) {
1109
+ return this.baseClient.post(`/channels/${channelId}/continue`, {
1110
+ context,
1111
+ extension,
1112
+ priority,
1113
+ label
975
1114
  });
976
1115
  }
977
1116
  /**
978
- * Gets a channel variable.
979
- */
980
- async getVariable(channelId, variable) {
981
- return this.client.get(
982
- `/channels/${channelId}/variable?variable=${encodeURIComponent(variable)}`
983
- );
984
- }
985
- /**
986
- * Plays a media file to a channel.
1117
+ * Stops music on hold (MOH) for a channel.
987
1118
  */
988
- async playMedia(channelId, media, options) {
989
- const queryParams = options ? `?${new URLSearchParams(options).toString()}` : "";
990
- return this.client.post(
991
- `/channels/${channelId}/play${queryParams}`,
992
- { media }
993
- );
1119
+ async stopMusicOnHold(channelId) {
1120
+ return this.baseClient.delete(`/channels/${channelId}/moh`);
994
1121
  }
995
1122
  /**
996
1123
  * Starts music on hold (MOH) for a channel.
997
1124
  */
998
1125
  async startMusicOnHold(channelId) {
999
- return this.client.post(`/channels/${channelId}/moh`);
1126
+ return this.baseClient.post(`/channels/${channelId}/moh`);
1000
1127
  }
1001
1128
  /**
1002
- * Stops music on hold (MOH) for a channel.
1129
+ * Starts playback of a media file on a channel.
1003
1130
  */
1004
- async stopMusicOnHold(channelId) {
1005
- return this.client.delete(`/channels/${channelId}/moh`);
1006
- }
1007
1131
  /**
1008
1132
  * Starts playback of a media file on a channel.
1009
1133
  */
1010
1134
  async startPlayback(channelId, media, options) {
1011
1135
  const queryParams = options ? `?${new URLSearchParams(options).toString()}` : "";
1012
- return this.client.post(
1136
+ return this.baseClient.post(
1013
1137
  `/channels/${channelId}/play${queryParams}`,
1014
1138
  { media }
1015
1139
  );
@@ -1018,7 +1142,7 @@ var Channels = class extends EventEmitter {
1018
1142
  * Stops playback of a media file on a channel.
1019
1143
  */
1020
1144
  async stopPlayback(channelId, playbackId) {
1021
- return this.client.delete(
1145
+ return this.baseClient.delete(
1022
1146
  `/channels/${channelId}/play/${playbackId}`
1023
1147
  );
1024
1148
  }
@@ -1026,7 +1150,7 @@ var Channels = class extends EventEmitter {
1026
1150
  * Pauses playback of a media file on a channel.
1027
1151
  */
1028
1152
  async pausePlayback(channelId, playbackId) {
1029
- return this.client.post(
1153
+ return this.baseClient.post(
1030
1154
  `/channels/${channelId}/play/${playbackId}/pause`
1031
1155
  );
1032
1156
  }
@@ -1034,7 +1158,7 @@ var Channels = class extends EventEmitter {
1034
1158
  * Resumes playback of a media file on a channel.
1035
1159
  */
1036
1160
  async resumePlayback(channelId, playbackId) {
1037
- return this.client.delete(
1161
+ return this.baseClient.delete(
1038
1162
  `/channels/${channelId}/play/${playbackId}/pause`
1039
1163
  );
1040
1164
  }
@@ -1042,7 +1166,7 @@ var Channels = class extends EventEmitter {
1042
1166
  * Rewinds playback of a media file on a channel.
1043
1167
  */
1044
1168
  async rewindPlayback(channelId, playbackId, skipMs) {
1045
- return this.client.post(
1169
+ return this.baseClient.post(
1046
1170
  `/channels/${channelId}/play/${playbackId}/rewind`,
1047
1171
  { skipMs }
1048
1172
  );
@@ -1051,7 +1175,7 @@ var Channels = class extends EventEmitter {
1051
1175
  * Fast-forwards playback of a media file on a channel.
1052
1176
  */
1053
1177
  async fastForwardPlayback(channelId, playbackId, skipMs) {
1054
- return this.client.post(
1178
+ return this.baseClient.post(
1055
1179
  `/channels/${channelId}/play/${playbackId}/forward`,
1056
1180
  { skipMs }
1057
1181
  );
@@ -1065,28 +1189,10 @@ var Channels = class extends EventEmitter {
1065
1189
  ([, value]) => value !== void 0
1066
1190
  )
1067
1191
  );
1068
- return this.client.post(
1192
+ return this.baseClient.post(
1069
1193
  `/channels/${channelId}/record?${queryParams.toString()}`
1070
1194
  );
1071
1195
  }
1072
- /**
1073
- * Starts snooping on a channel.
1074
- */
1075
- async snoopChannel(channelId, options) {
1076
- const queryParams = toQueryParams2(options);
1077
- return this.client.post(
1078
- `/channels/${channelId}/snoop?${queryParams}`
1079
- );
1080
- }
1081
- /**
1082
- * Starts snooping on a channel with a specific snoop ID.
1083
- */
1084
- async snoopChannelWithId(channelId, snoopId, options) {
1085
- const queryParams = new URLSearchParams(options);
1086
- return this.client.post(
1087
- `/channels/${channelId}/snoop/${snoopId}?${queryParams.toString()}`
1088
- );
1089
- }
1090
1196
  /**
1091
1197
  * Dials a created channel.
1092
1198
  */
@@ -1095,30 +1201,15 @@ var Channels = class extends EventEmitter {
1095
1201
  ...caller && { caller },
1096
1202
  ...timeout && { timeout: timeout.toString() }
1097
1203
  });
1098
- return this.client.post(
1204
+ return this.baseClient.post(
1099
1205
  `/channels/${channelId}/dial?${queryParams.toString()}`
1100
1206
  );
1101
1207
  }
1102
- /**
1103
- * Retrieves RTP statistics for a channel.
1104
- */
1105
- async getRTPStatistics(channelId) {
1106
- return this.client.get(`/channels/${channelId}/rtp_statistics`);
1107
- }
1108
- /**
1109
- * Creates a channel to an external media source/sink.
1110
- */
1111
- async createExternalMedia(options) {
1112
- const queryParams = new URLSearchParams(options);
1113
- return this.client.post(
1114
- `/channels/externalMedia?${queryParams.toString()}`
1115
- );
1116
- }
1117
1208
  /**
1118
1209
  * Redirects the channel to a different location.
1119
1210
  */
1120
1211
  async redirectChannel(channelId, endpoint) {
1121
- return this.client.post(
1212
+ return this.baseClient.post(
1122
1213
  `/channels/${channelId}/redirect?endpoint=${encodeURIComponent(endpoint)}`
1123
1214
  );
1124
1215
  }
@@ -1126,19 +1217,19 @@ var Channels = class extends EventEmitter {
1126
1217
  * Answers a channel.
1127
1218
  */
1128
1219
  async answerChannel(channelId) {
1129
- return this.client.post(`/channels/${channelId}/answer`);
1220
+ return this.baseClient.post(`/channels/${channelId}/answer`);
1130
1221
  }
1131
1222
  /**
1132
1223
  * Sends a ringing indication to a channel.
1133
1224
  */
1134
1225
  async ringChannel(channelId) {
1135
- return this.client.post(`/channels/${channelId}/ring`);
1226
+ return this.baseClient.post(`/channels/${channelId}/ring`);
1136
1227
  }
1137
1228
  /**
1138
1229
  * Stops ringing indication on a channel.
1139
1230
  */
1140
1231
  async stopRingChannel(channelId) {
1141
- return this.client.delete(`/channels/${channelId}/ring`);
1232
+ return this.baseClient.delete(`/channels/${channelId}/ring`);
1142
1233
  }
1143
1234
  /**
1144
1235
  * Sends DTMF to a channel.
@@ -1151,7 +1242,7 @@ var Channels = class extends EventEmitter {
1151
1242
  ...options?.duration && { duration: options.duration.toString() },
1152
1243
  ...options?.after && { after: options.after.toString() }
1153
1244
  });
1154
- return this.client.post(
1245
+ return this.baseClient.post(
1155
1246
  `/channels/${channelId}/dtmf?${queryParams.toString()}`
1156
1247
  );
1157
1248
  }
@@ -1159,7 +1250,7 @@ var Channels = class extends EventEmitter {
1159
1250
  * Mutes a channel.
1160
1251
  */
1161
1252
  async muteChannel(channelId, direction = "both") {
1162
- return this.client.post(
1253
+ return this.baseClient.post(
1163
1254
  `/channels/${channelId}/mute?direction=${direction}`
1164
1255
  );
1165
1256
  }
@@ -1167,7 +1258,7 @@ var Channels = class extends EventEmitter {
1167
1258
  * Unmutes a channel.
1168
1259
  */
1169
1260
  async unmuteChannel(channelId, direction = "both") {
1170
- return this.client.delete(
1261
+ return this.baseClient.delete(
1171
1262
  `/channels/${channelId}/mute?direction=${direction}`
1172
1263
  );
1173
1264
  }
@@ -1175,13 +1266,25 @@ var Channels = class extends EventEmitter {
1175
1266
  * Puts a channel on hold.
1176
1267
  */
1177
1268
  async holdChannel(channelId) {
1178
- return this.client.post(`/channels/${channelId}/hold`);
1269
+ return this.baseClient.post(`/channels/${channelId}/hold`);
1179
1270
  }
1180
1271
  /**
1181
1272
  * Removes a channel from hold.
1182
1273
  */
1183
1274
  async unholdChannel(channelId) {
1184
- return this.client.delete(`/channels/${channelId}/hold`);
1275
+ return this.baseClient.delete(`/channels/${channelId}/hold`);
1276
+ }
1277
+ /**
1278
+ * Creates a channel and places it in a Stasis app without dialing it.
1279
+ */
1280
+ async createChannel(data) {
1281
+ return this.baseClient.post("/channels/create", data);
1282
+ }
1283
+ /**
1284
+ * Creates a new channel with a specific ID and originates a call.
1285
+ */
1286
+ async originateWithId(channelId, data) {
1287
+ return this.baseClient.post(`/channels/${channelId}`, data);
1185
1288
  }
1186
1289
  };
1187
1290
 
@@ -1233,11 +1336,96 @@ var Endpoints = class {
1233
1336
 
1234
1337
  // src/ari-client/resources/playbacks.ts
1235
1338
  import { EventEmitter as EventEmitter2 } from "events";
1339
+ var PlaybackInstance = class extends EventEmitter2 {
1340
+ // Garantimos que o ID esteja disponível
1341
+ constructor(baseClient, playbackId) {
1342
+ super();
1343
+ this.baseClient = baseClient;
1344
+ this.playbackId = playbackId;
1345
+ this.id = playbackId || `playback-${Date.now()}`;
1346
+ }
1347
+ playbackData = null;
1348
+ id;
1349
+ /**
1350
+ * Obtém os detalhes do playback.
1351
+ */
1352
+ async getDetails() {
1353
+ if (!this.playbackId && !this.playbackData) {
1354
+ throw new Error("Nenhum playback associado a esta inst\xE2ncia.");
1355
+ }
1356
+ const id = this.playbackId || this.playbackData?.id;
1357
+ const details = await this.baseClient.get(`/playbacks/${id}`);
1358
+ this.playbackData = details;
1359
+ return details;
1360
+ }
1361
+ /**
1362
+ * Controla o playback.
1363
+ */
1364
+ async control(operation) {
1365
+ if (!this.playbackId) {
1366
+ throw new Error("Nenhum playback associado para controlar.");
1367
+ }
1368
+ await this.baseClient.post(`/playbacks/${this.playbackId}/control`, {
1369
+ operation
1370
+ });
1371
+ }
1372
+ /**
1373
+ * Encerra o playback.
1374
+ */
1375
+ async stop() {
1376
+ if (!this.playbackId) {
1377
+ throw new Error("Nenhum playback associado para encerrar.");
1378
+ }
1379
+ await this.baseClient.post(`/playbacks/${this.playbackId}/stop`);
1380
+ this.emit("PlaybackStopped", this.playbackData);
1381
+ }
1382
+ /**
1383
+ * Adiciona um listener para eventos de playback.
1384
+ */
1385
+ on(event, callback) {
1386
+ super.on(event, callback);
1387
+ return this;
1388
+ }
1389
+ /**
1390
+ * Adiciona um listener para ser chamado apenas uma vez.
1391
+ */
1392
+ once(event, callback) {
1393
+ super.once(event, callback);
1394
+ return this;
1395
+ }
1396
+ /**
1397
+ * Remove um listener específico.
1398
+ */
1399
+ off(event, callback) {
1400
+ super.off(event, callback);
1401
+ return this;
1402
+ }
1403
+ };
1236
1404
  var Playbacks = class extends EventEmitter2 {
1237
1405
  constructor(client) {
1238
1406
  super();
1239
1407
  this.client = client;
1240
1408
  }
1409
+ /**
1410
+ * Inicializa uma nova instância de `PlaybackInstance`.
1411
+ */
1412
+ Playback(playbackId) {
1413
+ const id = playbackId || `playback-${Date.now()}`;
1414
+ return new PlaybackInstance(this.client, id);
1415
+ }
1416
+ /**
1417
+ * Emite eventos de playback.
1418
+ * Atualizado para gerenciar eventos específicos para `PlaybackInstance`.
1419
+ */
1420
+ emitPlaybackEvent(eventType, data) {
1421
+ if ("playbackId" in data) {
1422
+ const playbackId = data.playbackId;
1423
+ if (playbackId) {
1424
+ this.emit(`${eventType}:${playbackId}`, data);
1425
+ }
1426
+ }
1427
+ this.emit(eventType, data);
1428
+ }
1241
1429
  /**
1242
1430
  * Retrieves details of a specific playback.
1243
1431
  *
@@ -1305,19 +1493,6 @@ var Playbacks = class extends EventEmitter2 {
1305
1493
  isListenerRegistered(eventType, playbackId) {
1306
1494
  return this.listenerCount(`${eventType}:${playbackId}`) > 0;
1307
1495
  }
1308
- /**
1309
- * Emits playback events received via WebSocket.
1310
- * This method should be called by the WebSocket client when playback events occur.
1311
- *
1312
- * @param eventType - The type of the WebSocket event.
1313
- * @param data - The data associated with the event.
1314
- */
1315
- emitPlaybackEvent(eventType, data) {
1316
- if ("playbackId" in data) {
1317
- this.emit(`${eventType}:${data.playbackId}`, data);
1318
- }
1319
- this.emit(eventType, data);
1320
- }
1321
1496
  };
1322
1497
 
1323
1498
  // src/ari-client/resources/sounds.ts
@@ -1482,7 +1657,7 @@ var AriClient = class {
1482
1657
  const normalizedHost = config.host.replace(/^https?:\/\//, "");
1483
1658
  const baseUrl = `${httpProtocol}://${normalizedHost}:${config.port}/ari`;
1484
1659
  this.baseClient = new BaseClient(baseUrl, config.username, config.password);
1485
- this.channels = new Channels(this.baseClient);
1660
+ this.channels = new Channels(this.baseClient, this);
1486
1661
  this.endpoints = new Endpoints(this.baseClient);
1487
1662
  this.applications = new Applications(this.baseClient);
1488
1663
  this.playbacks = new Playbacks(this.baseClient);
@@ -1817,13 +1992,13 @@ var AriClient = class {
1817
1992
  * Sets a channel variable.
1818
1993
  */
1819
1994
  async setChannelVariable(channelId, variable, value) {
1820
- return this.channels.setVariable(channelId, variable, value);
1995
+ return this.channels.setChannelVariable(channelId, variable, value);
1821
1996
  }
1822
1997
  /**
1823
1998
  * Gets a channel variable.
1824
1999
  */
1825
2000
  async getChannelVariable(channelId, variable) {
1826
- return this.channels.getVariable(channelId, variable);
2001
+ return this.channels.getChannelVariable(channelId, variable);
1827
2002
  }
1828
2003
  /**
1829
2004
  * Plays a media file to a channel.
@@ -2294,6 +2469,24 @@ var AriClient = class {
2294
2469
  async setGlobalVariable(variableName, value) {
2295
2470
  return this.asterisk.setGlobalVariable(variableName, value);
2296
2471
  }
2472
+ /**
2473
+ * Inicializa uma nova instância de `ChannelInstance` para manipular canais localmente.
2474
+ *
2475
+ * @param channelId - O ID do canal, se disponível. Caso contrário, a instância será para um canal ainda não criado.
2476
+ * @returns Uma instância de `ChannelInstance` vinculada ao cliente atual.
2477
+ */
2478
+ Channel(channelId) {
2479
+ return this.channels.createChannelInstance(channelId);
2480
+ }
2481
+ /**
2482
+ * Inicializa uma nova instância de `PlaybackInstance` para manipular playbacks.
2483
+ *
2484
+ * @param playbackId - O ID do playback, se disponível. Caso contrário, a instância será para um playback ainda não inicializado.
2485
+ * @returns Uma instância de `PlaybackInstance` vinculada ao cliente atual.
2486
+ */
2487
+ Playback(playbackId) {
2488
+ return this.playbacks.Playback(playbackId);
2489
+ }
2297
2490
  };
2298
2491
  export {
2299
2492
  Applications,