@ipcom/asterisk-ari 0.0.77 → 0.0.78
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/cjs/index.cjs +683 -545
- package/dist/cjs/index.cjs.map +4 -4
- package/dist/esm/index.js +706 -545
- package/dist/esm/index.js.map +4 -4
- package/dist/types/ari-client/ariClient.d.ts +2 -377
- package/dist/types/ari-client/ariClient.d.ts.map +1 -1
- package/dist/types/ari-client/interfaces/events.types.d.ts +3 -5
- package/dist/types/ari-client/interfaces/events.types.d.ts.map +1 -1
- package/dist/types/ari-client/resources/channels.d.ts +1 -1
- package/dist/types/ari-client/resources/channels.d.ts.map +1 -1
- package/dist/types/ari-client/resources/playbacks.d.ts +10 -15
- package/dist/types/ari-client/resources/playbacks.d.ts.map +1 -1
- package/dist/types/ari-client/utils.d.ts +3 -0
- package/dist/types/ari-client/utils.d.ts.map +1 -1
- package/dist/types/ari-client/websocketClient.d.ts +3 -0
- package/dist/types/ari-client/websocketClient.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
8
11
|
var __export = (target, all) => {
|
|
9
12
|
for (var name in all)
|
|
10
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -27,6 +30,552 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
30
|
));
|
|
28
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
32
|
|
|
33
|
+
// node_modules/exponential-backoff/dist/options.js
|
|
34
|
+
var require_options = __commonJS({
|
|
35
|
+
"node_modules/exponential-backoff/dist/options.js"(exports2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
var __assign = exports2 && exports2.__assign || function() {
|
|
38
|
+
__assign = Object.assign || function(t) {
|
|
39
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
40
|
+
s = arguments[i];
|
|
41
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
42
|
+
t[p] = s[p];
|
|
43
|
+
}
|
|
44
|
+
return t;
|
|
45
|
+
};
|
|
46
|
+
return __assign.apply(this, arguments);
|
|
47
|
+
};
|
|
48
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
49
|
+
var defaultOptions = {
|
|
50
|
+
delayFirstAttempt: false,
|
|
51
|
+
jitter: "none",
|
|
52
|
+
maxDelay: Infinity,
|
|
53
|
+
numOfAttempts: 10,
|
|
54
|
+
retry: function() {
|
|
55
|
+
return true;
|
|
56
|
+
},
|
|
57
|
+
startingDelay: 100,
|
|
58
|
+
timeMultiple: 2
|
|
59
|
+
};
|
|
60
|
+
function getSanitizedOptions(options) {
|
|
61
|
+
var sanitized = __assign(__assign({}, defaultOptions), options);
|
|
62
|
+
if (sanitized.numOfAttempts < 1) {
|
|
63
|
+
sanitized.numOfAttempts = 1;
|
|
64
|
+
}
|
|
65
|
+
return sanitized;
|
|
66
|
+
}
|
|
67
|
+
exports2.getSanitizedOptions = getSanitizedOptions;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// node_modules/exponential-backoff/dist/jitter/full/full.jitter.js
|
|
72
|
+
var require_full_jitter = __commonJS({
|
|
73
|
+
"node_modules/exponential-backoff/dist/jitter/full/full.jitter.js"(exports2) {
|
|
74
|
+
"use strict";
|
|
75
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
76
|
+
function fullJitter(delay) {
|
|
77
|
+
var jitteredDelay = Math.random() * delay;
|
|
78
|
+
return Math.round(jitteredDelay);
|
|
79
|
+
}
|
|
80
|
+
exports2.fullJitter = fullJitter;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// node_modules/exponential-backoff/dist/jitter/no/no.jitter.js
|
|
85
|
+
var require_no_jitter = __commonJS({
|
|
86
|
+
"node_modules/exponential-backoff/dist/jitter/no/no.jitter.js"(exports2) {
|
|
87
|
+
"use strict";
|
|
88
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
89
|
+
function noJitter(delay) {
|
|
90
|
+
return delay;
|
|
91
|
+
}
|
|
92
|
+
exports2.noJitter = noJitter;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// node_modules/exponential-backoff/dist/jitter/jitter.factory.js
|
|
97
|
+
var require_jitter_factory = __commonJS({
|
|
98
|
+
"node_modules/exponential-backoff/dist/jitter/jitter.factory.js"(exports2) {
|
|
99
|
+
"use strict";
|
|
100
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
101
|
+
var full_jitter_1 = require_full_jitter();
|
|
102
|
+
var no_jitter_1 = require_no_jitter();
|
|
103
|
+
function JitterFactory(options) {
|
|
104
|
+
switch (options.jitter) {
|
|
105
|
+
case "full":
|
|
106
|
+
return full_jitter_1.fullJitter;
|
|
107
|
+
case "none":
|
|
108
|
+
default:
|
|
109
|
+
return no_jitter_1.noJitter;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports2.JitterFactory = JitterFactory;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// node_modules/exponential-backoff/dist/delay/delay.base.js
|
|
117
|
+
var require_delay_base = __commonJS({
|
|
118
|
+
"node_modules/exponential-backoff/dist/delay/delay.base.js"(exports2) {
|
|
119
|
+
"use strict";
|
|
120
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
121
|
+
var jitter_factory_1 = require_jitter_factory();
|
|
122
|
+
var Delay = (
|
|
123
|
+
/** @class */
|
|
124
|
+
function() {
|
|
125
|
+
function Delay2(options) {
|
|
126
|
+
this.options = options;
|
|
127
|
+
this.attempt = 0;
|
|
128
|
+
}
|
|
129
|
+
Delay2.prototype.apply = function() {
|
|
130
|
+
var _this = this;
|
|
131
|
+
return new Promise(function(resolve) {
|
|
132
|
+
return setTimeout(resolve, _this.jitteredDelay);
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
Delay2.prototype.setAttemptNumber = function(attempt) {
|
|
136
|
+
this.attempt = attempt;
|
|
137
|
+
};
|
|
138
|
+
Object.defineProperty(Delay2.prototype, "jitteredDelay", {
|
|
139
|
+
get: function() {
|
|
140
|
+
var jitter = jitter_factory_1.JitterFactory(this.options);
|
|
141
|
+
return jitter(this.delay);
|
|
142
|
+
},
|
|
143
|
+
enumerable: true,
|
|
144
|
+
configurable: true
|
|
145
|
+
});
|
|
146
|
+
Object.defineProperty(Delay2.prototype, "delay", {
|
|
147
|
+
get: function() {
|
|
148
|
+
var constant = this.options.startingDelay;
|
|
149
|
+
var base = this.options.timeMultiple;
|
|
150
|
+
var power = this.numOfDelayedAttempts;
|
|
151
|
+
var delay = constant * Math.pow(base, power);
|
|
152
|
+
return Math.min(delay, this.options.maxDelay);
|
|
153
|
+
},
|
|
154
|
+
enumerable: true,
|
|
155
|
+
configurable: true
|
|
156
|
+
});
|
|
157
|
+
Object.defineProperty(Delay2.prototype, "numOfDelayedAttempts", {
|
|
158
|
+
get: function() {
|
|
159
|
+
return this.attempt;
|
|
160
|
+
},
|
|
161
|
+
enumerable: true,
|
|
162
|
+
configurable: true
|
|
163
|
+
});
|
|
164
|
+
return Delay2;
|
|
165
|
+
}()
|
|
166
|
+
);
|
|
167
|
+
exports2.Delay = Delay;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// node_modules/exponential-backoff/dist/delay/skip-first/skip-first.delay.js
|
|
172
|
+
var require_skip_first_delay = __commonJS({
|
|
173
|
+
"node_modules/exponential-backoff/dist/delay/skip-first/skip-first.delay.js"(exports2) {
|
|
174
|
+
"use strict";
|
|
175
|
+
var __extends = exports2 && exports2.__extends || /* @__PURE__ */ function() {
|
|
176
|
+
var extendStatics = function(d, b) {
|
|
177
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
178
|
+
d2.__proto__ = b2;
|
|
179
|
+
} || function(d2, b2) {
|
|
180
|
+
for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p];
|
|
181
|
+
};
|
|
182
|
+
return extendStatics(d, b);
|
|
183
|
+
};
|
|
184
|
+
return function(d, b) {
|
|
185
|
+
extendStatics(d, b);
|
|
186
|
+
function __() {
|
|
187
|
+
this.constructor = d;
|
|
188
|
+
}
|
|
189
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
190
|
+
};
|
|
191
|
+
}();
|
|
192
|
+
var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
193
|
+
function adopt(value) {
|
|
194
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
195
|
+
resolve(value);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
199
|
+
function fulfilled(value) {
|
|
200
|
+
try {
|
|
201
|
+
step(generator.next(value));
|
|
202
|
+
} catch (e) {
|
|
203
|
+
reject(e);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function rejected(value) {
|
|
207
|
+
try {
|
|
208
|
+
step(generator["throw"](value));
|
|
209
|
+
} catch (e) {
|
|
210
|
+
reject(e);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function step(result) {
|
|
214
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
215
|
+
}
|
|
216
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
var __generator = exports2 && exports2.__generator || function(thisArg, body) {
|
|
220
|
+
var _ = { label: 0, sent: function() {
|
|
221
|
+
if (t[0] & 1) throw t[1];
|
|
222
|
+
return t[1];
|
|
223
|
+
}, trys: [], ops: [] }, f, y, t, g;
|
|
224
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
225
|
+
return this;
|
|
226
|
+
}), g;
|
|
227
|
+
function verb(n) {
|
|
228
|
+
return function(v) {
|
|
229
|
+
return step([n, v]);
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function step(op) {
|
|
233
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
234
|
+
while (_) try {
|
|
235
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
236
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
237
|
+
switch (op[0]) {
|
|
238
|
+
case 0:
|
|
239
|
+
case 1:
|
|
240
|
+
t = op;
|
|
241
|
+
break;
|
|
242
|
+
case 4:
|
|
243
|
+
_.label++;
|
|
244
|
+
return { value: op[1], done: false };
|
|
245
|
+
case 5:
|
|
246
|
+
_.label++;
|
|
247
|
+
y = op[1];
|
|
248
|
+
op = [0];
|
|
249
|
+
continue;
|
|
250
|
+
case 7:
|
|
251
|
+
op = _.ops.pop();
|
|
252
|
+
_.trys.pop();
|
|
253
|
+
continue;
|
|
254
|
+
default:
|
|
255
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
256
|
+
_ = 0;
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
260
|
+
_.label = op[1];
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
264
|
+
_.label = t[1];
|
|
265
|
+
t = op;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
if (t && _.label < t[2]) {
|
|
269
|
+
_.label = t[2];
|
|
270
|
+
_.ops.push(op);
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
if (t[2]) _.ops.pop();
|
|
274
|
+
_.trys.pop();
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
op = body.call(thisArg, _);
|
|
278
|
+
} catch (e) {
|
|
279
|
+
op = [6, e];
|
|
280
|
+
y = 0;
|
|
281
|
+
} finally {
|
|
282
|
+
f = t = 0;
|
|
283
|
+
}
|
|
284
|
+
if (op[0] & 5) throw op[1];
|
|
285
|
+
return { value: op[0] ? op[1] : void 0, done: true };
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
289
|
+
var delay_base_1 = require_delay_base();
|
|
290
|
+
var SkipFirstDelay = (
|
|
291
|
+
/** @class */
|
|
292
|
+
function(_super) {
|
|
293
|
+
__extends(SkipFirstDelay2, _super);
|
|
294
|
+
function SkipFirstDelay2() {
|
|
295
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
296
|
+
}
|
|
297
|
+
SkipFirstDelay2.prototype.apply = function() {
|
|
298
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
299
|
+
return __generator(this, function(_a) {
|
|
300
|
+
return [2, this.isFirstAttempt ? true : _super.prototype.apply.call(this)];
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
Object.defineProperty(SkipFirstDelay2.prototype, "isFirstAttempt", {
|
|
305
|
+
get: function() {
|
|
306
|
+
return this.attempt === 0;
|
|
307
|
+
},
|
|
308
|
+
enumerable: true,
|
|
309
|
+
configurable: true
|
|
310
|
+
});
|
|
311
|
+
Object.defineProperty(SkipFirstDelay2.prototype, "numOfDelayedAttempts", {
|
|
312
|
+
get: function() {
|
|
313
|
+
return this.attempt - 1;
|
|
314
|
+
},
|
|
315
|
+
enumerable: true,
|
|
316
|
+
configurable: true
|
|
317
|
+
});
|
|
318
|
+
return SkipFirstDelay2;
|
|
319
|
+
}(delay_base_1.Delay)
|
|
320
|
+
);
|
|
321
|
+
exports2.SkipFirstDelay = SkipFirstDelay;
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// node_modules/exponential-backoff/dist/delay/always/always.delay.js
|
|
326
|
+
var require_always_delay = __commonJS({
|
|
327
|
+
"node_modules/exponential-backoff/dist/delay/always/always.delay.js"(exports2) {
|
|
328
|
+
"use strict";
|
|
329
|
+
var __extends = exports2 && exports2.__extends || /* @__PURE__ */ function() {
|
|
330
|
+
var extendStatics = function(d, b) {
|
|
331
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
332
|
+
d2.__proto__ = b2;
|
|
333
|
+
} || function(d2, b2) {
|
|
334
|
+
for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p];
|
|
335
|
+
};
|
|
336
|
+
return extendStatics(d, b);
|
|
337
|
+
};
|
|
338
|
+
return function(d, b) {
|
|
339
|
+
extendStatics(d, b);
|
|
340
|
+
function __() {
|
|
341
|
+
this.constructor = d;
|
|
342
|
+
}
|
|
343
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
344
|
+
};
|
|
345
|
+
}();
|
|
346
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
347
|
+
var delay_base_1 = require_delay_base();
|
|
348
|
+
var AlwaysDelay = (
|
|
349
|
+
/** @class */
|
|
350
|
+
function(_super) {
|
|
351
|
+
__extends(AlwaysDelay2, _super);
|
|
352
|
+
function AlwaysDelay2() {
|
|
353
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
354
|
+
}
|
|
355
|
+
return AlwaysDelay2;
|
|
356
|
+
}(delay_base_1.Delay)
|
|
357
|
+
);
|
|
358
|
+
exports2.AlwaysDelay = AlwaysDelay;
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// node_modules/exponential-backoff/dist/delay/delay.factory.js
|
|
363
|
+
var require_delay_factory = __commonJS({
|
|
364
|
+
"node_modules/exponential-backoff/dist/delay/delay.factory.js"(exports2) {
|
|
365
|
+
"use strict";
|
|
366
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
367
|
+
var skip_first_delay_1 = require_skip_first_delay();
|
|
368
|
+
var always_delay_1 = require_always_delay();
|
|
369
|
+
function DelayFactory(options, attempt) {
|
|
370
|
+
var delay = initDelayClass(options);
|
|
371
|
+
delay.setAttemptNumber(attempt);
|
|
372
|
+
return delay;
|
|
373
|
+
}
|
|
374
|
+
exports2.DelayFactory = DelayFactory;
|
|
375
|
+
function initDelayClass(options) {
|
|
376
|
+
if (!options.delayFirstAttempt) {
|
|
377
|
+
return new skip_first_delay_1.SkipFirstDelay(options);
|
|
378
|
+
}
|
|
379
|
+
return new always_delay_1.AlwaysDelay(options);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// node_modules/exponential-backoff/dist/backoff.js
|
|
385
|
+
var require_backoff = __commonJS({
|
|
386
|
+
"node_modules/exponential-backoff/dist/backoff.js"(exports2) {
|
|
387
|
+
"use strict";
|
|
388
|
+
var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
389
|
+
function adopt(value) {
|
|
390
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
391
|
+
resolve(value);
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
395
|
+
function fulfilled(value) {
|
|
396
|
+
try {
|
|
397
|
+
step(generator.next(value));
|
|
398
|
+
} catch (e) {
|
|
399
|
+
reject(e);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function rejected(value) {
|
|
403
|
+
try {
|
|
404
|
+
step(generator["throw"](value));
|
|
405
|
+
} catch (e) {
|
|
406
|
+
reject(e);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function step(result) {
|
|
410
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
411
|
+
}
|
|
412
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
var __generator = exports2 && exports2.__generator || function(thisArg, body) {
|
|
416
|
+
var _ = { label: 0, sent: function() {
|
|
417
|
+
if (t[0] & 1) throw t[1];
|
|
418
|
+
return t[1];
|
|
419
|
+
}, trys: [], ops: [] }, f, y, t, g;
|
|
420
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
421
|
+
return this;
|
|
422
|
+
}), g;
|
|
423
|
+
function verb(n) {
|
|
424
|
+
return function(v) {
|
|
425
|
+
return step([n, v]);
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function step(op) {
|
|
429
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
430
|
+
while (_) try {
|
|
431
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
432
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
433
|
+
switch (op[0]) {
|
|
434
|
+
case 0:
|
|
435
|
+
case 1:
|
|
436
|
+
t = op;
|
|
437
|
+
break;
|
|
438
|
+
case 4:
|
|
439
|
+
_.label++;
|
|
440
|
+
return { value: op[1], done: false };
|
|
441
|
+
case 5:
|
|
442
|
+
_.label++;
|
|
443
|
+
y = op[1];
|
|
444
|
+
op = [0];
|
|
445
|
+
continue;
|
|
446
|
+
case 7:
|
|
447
|
+
op = _.ops.pop();
|
|
448
|
+
_.trys.pop();
|
|
449
|
+
continue;
|
|
450
|
+
default:
|
|
451
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
452
|
+
_ = 0;
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
456
|
+
_.label = op[1];
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
460
|
+
_.label = t[1];
|
|
461
|
+
t = op;
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
if (t && _.label < t[2]) {
|
|
465
|
+
_.label = t[2];
|
|
466
|
+
_.ops.push(op);
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
if (t[2]) _.ops.pop();
|
|
470
|
+
_.trys.pop();
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
op = body.call(thisArg, _);
|
|
474
|
+
} catch (e) {
|
|
475
|
+
op = [6, e];
|
|
476
|
+
y = 0;
|
|
477
|
+
} finally {
|
|
478
|
+
f = t = 0;
|
|
479
|
+
}
|
|
480
|
+
if (op[0] & 5) throw op[1];
|
|
481
|
+
return { value: op[0] ? op[1] : void 0, done: true };
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
485
|
+
var options_1 = require_options();
|
|
486
|
+
var delay_factory_1 = require_delay_factory();
|
|
487
|
+
function backOff3(request, options) {
|
|
488
|
+
if (options === void 0) {
|
|
489
|
+
options = {};
|
|
490
|
+
}
|
|
491
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
492
|
+
var sanitizedOptions, backOff4;
|
|
493
|
+
return __generator(this, function(_a) {
|
|
494
|
+
switch (_a.label) {
|
|
495
|
+
case 0:
|
|
496
|
+
sanitizedOptions = options_1.getSanitizedOptions(options);
|
|
497
|
+
backOff4 = new BackOff(request, sanitizedOptions);
|
|
498
|
+
return [4, backOff4.execute()];
|
|
499
|
+
case 1:
|
|
500
|
+
return [2, _a.sent()];
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
exports2.backOff = backOff3;
|
|
506
|
+
var BackOff = (
|
|
507
|
+
/** @class */
|
|
508
|
+
function() {
|
|
509
|
+
function BackOff2(request, options) {
|
|
510
|
+
this.request = request;
|
|
511
|
+
this.options = options;
|
|
512
|
+
this.attemptNumber = 0;
|
|
513
|
+
}
|
|
514
|
+
BackOff2.prototype.execute = function() {
|
|
515
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
516
|
+
var e_1, shouldRetry;
|
|
517
|
+
return __generator(this, function(_a) {
|
|
518
|
+
switch (_a.label) {
|
|
519
|
+
case 0:
|
|
520
|
+
if (!!this.attemptLimitReached) return [3, 7];
|
|
521
|
+
_a.label = 1;
|
|
522
|
+
case 1:
|
|
523
|
+
_a.trys.push([1, 4, , 6]);
|
|
524
|
+
return [4, this.applyDelay()];
|
|
525
|
+
case 2:
|
|
526
|
+
_a.sent();
|
|
527
|
+
return [4, this.request()];
|
|
528
|
+
case 3:
|
|
529
|
+
return [2, _a.sent()];
|
|
530
|
+
case 4:
|
|
531
|
+
e_1 = _a.sent();
|
|
532
|
+
this.attemptNumber++;
|
|
533
|
+
return [4, this.options.retry(e_1, this.attemptNumber)];
|
|
534
|
+
case 5:
|
|
535
|
+
shouldRetry = _a.sent();
|
|
536
|
+
if (!shouldRetry || this.attemptLimitReached) {
|
|
537
|
+
throw e_1;
|
|
538
|
+
}
|
|
539
|
+
return [3, 6];
|
|
540
|
+
case 6:
|
|
541
|
+
return [3, 0];
|
|
542
|
+
case 7:
|
|
543
|
+
throw new Error("Something went wrong.");
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
};
|
|
548
|
+
Object.defineProperty(BackOff2.prototype, "attemptLimitReached", {
|
|
549
|
+
get: function() {
|
|
550
|
+
return this.attemptNumber >= this.options.numOfAttempts;
|
|
551
|
+
},
|
|
552
|
+
enumerable: true,
|
|
553
|
+
configurable: true
|
|
554
|
+
});
|
|
555
|
+
BackOff2.prototype.applyDelay = function() {
|
|
556
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
557
|
+
var delay;
|
|
558
|
+
return __generator(this, function(_a) {
|
|
559
|
+
switch (_a.label) {
|
|
560
|
+
case 0:
|
|
561
|
+
delay = delay_factory_1.DelayFactory(this.options, this.attemptNumber);
|
|
562
|
+
return [4, delay.apply()];
|
|
563
|
+
case 1:
|
|
564
|
+
_a.sent();
|
|
565
|
+
return [
|
|
566
|
+
2
|
|
567
|
+
/*return*/
|
|
568
|
+
];
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
};
|
|
573
|
+
return BackOff2;
|
|
574
|
+
}()
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
|
|
30
579
|
// src/index.ts
|
|
31
580
|
var src_exports = {};
|
|
32
581
|
__export(src_exports, {
|
|
@@ -43,6 +592,9 @@ __export(src_exports, {
|
|
|
43
592
|
});
|
|
44
593
|
module.exports = __toCommonJS(src_exports);
|
|
45
594
|
|
|
595
|
+
// src/ari-client/ariClient.ts
|
|
596
|
+
var import_exponential_backoff2 = __toESM(require_backoff(), 1);
|
|
597
|
+
|
|
46
598
|
// src/ari-client/baseClient.ts
|
|
47
599
|
var import_events = require("events");
|
|
48
600
|
var import_axios = __toESM(require("axios"), 1);
|
|
@@ -368,6 +920,9 @@ function toQueryParams2(options) {
|
|
|
368
920
|
Object.entries(options).filter(([, value]) => value !== void 0).map(([key, value]) => [key, value])
|
|
369
921
|
).toString();
|
|
370
922
|
}
|
|
923
|
+
function isPlaybackEvent(event, playbackId) {
|
|
924
|
+
return event.type.startsWith("Playback") && "playbackId" in event && event.playbackId !== void 0 && (!playbackId || event.playbackId === playbackId);
|
|
925
|
+
}
|
|
371
926
|
function isChannelEvent(event, channelId) {
|
|
372
927
|
const hasChannel = "channel" in event && event.channel?.id !== void 0;
|
|
373
928
|
const matchesChannelId = hasChannel && (!channelId || event.channel?.id === channelId);
|
|
@@ -614,7 +1169,7 @@ var Channels = class extends import_events2.EventEmitter {
|
|
|
614
1169
|
this.baseClient = baseClient;
|
|
615
1170
|
this.client = client;
|
|
616
1171
|
}
|
|
617
|
-
|
|
1172
|
+
Channel(channelId) {
|
|
618
1173
|
return new ChannelInstance(this.client, this.baseClient, channelId);
|
|
619
1174
|
}
|
|
620
1175
|
/**
|
|
@@ -845,14 +1400,15 @@ var Endpoints = class {
|
|
|
845
1400
|
var import_events3 = require("events");
|
|
846
1401
|
var PlaybackInstance = class extends import_events3.EventEmitter {
|
|
847
1402
|
// Garantimos que o ID esteja disponível
|
|
848
|
-
constructor(baseClient, playbackId) {
|
|
1403
|
+
constructor(client, baseClient, playbackId) {
|
|
849
1404
|
super();
|
|
1405
|
+
this.client = client;
|
|
850
1406
|
this.baseClient = baseClient;
|
|
851
1407
|
this.playbackId = playbackId;
|
|
852
1408
|
this.id = playbackId || `playback-${Date.now()}`;
|
|
853
|
-
const wsClients = this.
|
|
1409
|
+
const wsClients = this.client.getWebSocketClients();
|
|
854
1410
|
const wsClient = Array.from(wsClients.values()).find(
|
|
855
|
-
(
|
|
1411
|
+
(client2) => client2.isConnected()
|
|
856
1412
|
);
|
|
857
1413
|
if (!wsClient) {
|
|
858
1414
|
throw new Error(
|
|
@@ -860,31 +1416,14 @@ var PlaybackInstance = class extends import_events3.EventEmitter {
|
|
|
860
1416
|
);
|
|
861
1417
|
}
|
|
862
1418
|
wsClient.on("message", (event) => {
|
|
863
|
-
if (
|
|
864
|
-
console.log(
|
|
865
|
-
`Evento recebido no PlaybackInstance: ${event.type}`,
|
|
866
|
-
event
|
|
867
|
-
);
|
|
1419
|
+
if (isPlaybackEvent(event, this.id)) {
|
|
1420
|
+
console.log(`Evento recebido no ChannelInstance: ${event.type}`, event);
|
|
868
1421
|
this.emit(event.type, event);
|
|
869
1422
|
}
|
|
870
1423
|
});
|
|
871
1424
|
}
|
|
872
1425
|
playbackData = null;
|
|
873
1426
|
id;
|
|
874
|
-
/**
|
|
875
|
-
* Verifica se o evento é relacionado a um playback.
|
|
876
|
-
*/
|
|
877
|
-
isPlaybackEvent(event) {
|
|
878
|
-
const isPlaybackType = event?.type.startsWith("Playback");
|
|
879
|
-
const isPlaybackEvent = isPlaybackType && "playbackId" in event && event.playbackId === this.id;
|
|
880
|
-
if (!isPlaybackEvent) {
|
|
881
|
-
console.log(
|
|
882
|
-
`Evento ignorado no isPlaybackEvent: tipo=${event.type}, playback esperado=${this.id}, evento recebido=`,
|
|
883
|
-
event
|
|
884
|
-
);
|
|
885
|
-
}
|
|
886
|
-
return isPlaybackEvent;
|
|
887
|
-
}
|
|
888
1427
|
/**
|
|
889
1428
|
* Obtém os detalhes do playback.
|
|
890
1429
|
*/
|
|
@@ -939,38 +1478,23 @@ var PlaybackInstance = class extends import_events3.EventEmitter {
|
|
|
939
1478
|
}
|
|
940
1479
|
};
|
|
941
1480
|
var Playbacks = class extends import_events3.EventEmitter {
|
|
942
|
-
constructor(client) {
|
|
1481
|
+
constructor(baseClient, client) {
|
|
943
1482
|
super();
|
|
1483
|
+
this.baseClient = baseClient;
|
|
944
1484
|
this.client = client;
|
|
945
|
-
this.client.onWebSocketEvent((event) => {
|
|
946
|
-
if (this.isPlaybackEvent(event)) {
|
|
947
|
-
const playbackId = event.playbackId;
|
|
948
|
-
if (playbackId) {
|
|
949
|
-
this.emit(`${event.type}:${playbackId}`, event);
|
|
950
|
-
}
|
|
951
|
-
this.emit(event.type, event);
|
|
952
|
-
}
|
|
953
|
-
});
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* Obtém os clientes WebSocket disponíveis.
|
|
957
|
-
*/
|
|
958
|
-
getWebSocketClients() {
|
|
959
|
-
return this.client.getWebSocketClients();
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* Verifica se o evento é relacionado a um playback.
|
|
963
|
-
*/
|
|
964
|
-
isPlaybackEvent(event) {
|
|
965
|
-
console.log({ eventAri: event });
|
|
966
|
-
return event && typeof event === "object" && "playbackId" in event;
|
|
967
1485
|
}
|
|
968
1486
|
/**
|
|
969
1487
|
* Inicializa uma nova instância de `PlaybackInstance`.
|
|
970
1488
|
*/
|
|
971
1489
|
Playback(playbackId) {
|
|
972
1490
|
const id = playbackId || `playback-${Date.now()}`;
|
|
973
|
-
return new PlaybackInstance(this.client, id);
|
|
1491
|
+
return new PlaybackInstance(this.client, this.baseClient, id);
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* Obtém os clientes WebSocket disponíveis.
|
|
1495
|
+
*/
|
|
1496
|
+
getWebSocketClients() {
|
|
1497
|
+
return this.client.getWebSocketClients();
|
|
974
1498
|
}
|
|
975
1499
|
/**
|
|
976
1500
|
* Emite eventos de playback.
|
|
@@ -992,7 +1516,7 @@ var Playbacks = class extends import_events3.EventEmitter {
|
|
|
992
1516
|
* @returns A promise that resolves to a Playback object containing the details of the specified playback.
|
|
993
1517
|
*/
|
|
994
1518
|
async getDetails(playbackId) {
|
|
995
|
-
return this.
|
|
1519
|
+
return this.baseClient.get(`/playbacks/${playbackId}`);
|
|
996
1520
|
}
|
|
997
1521
|
/**
|
|
998
1522
|
* Controls a specific playback by performing various operations such as pause, resume, restart, reverse, forward, or stop.
|
|
@@ -1008,7 +1532,7 @@ var Playbacks = class extends import_events3.EventEmitter {
|
|
|
1008
1532
|
* @returns A promise that resolves when the control operation is successfully executed.
|
|
1009
1533
|
*/
|
|
1010
1534
|
async control(playbackId, operation) {
|
|
1011
|
-
await this.
|
|
1535
|
+
await this.baseClient.post(
|
|
1012
1536
|
`/playbacks/${playbackId}/control?operation=${operation}`
|
|
1013
1537
|
);
|
|
1014
1538
|
}
|
|
@@ -1019,7 +1543,7 @@ var Playbacks = class extends import_events3.EventEmitter {
|
|
|
1019
1543
|
* @returns A promise that resolves when the playback is successfully stopped.
|
|
1020
1544
|
*/
|
|
1021
1545
|
async stop(playbackId) {
|
|
1022
|
-
await this.
|
|
1546
|
+
await this.baseClient.delete(`/playbacks/${playbackId}`);
|
|
1023
1547
|
}
|
|
1024
1548
|
/**
|
|
1025
1549
|
* Registers a listener for playback events.
|
|
@@ -1087,8 +1611,10 @@ var Sounds = class {
|
|
|
1087
1611
|
|
|
1088
1612
|
// src/ari-client/websocketClient.ts
|
|
1089
1613
|
var import_events4 = require("events");
|
|
1614
|
+
var import_exponential_backoff = __toESM(require_backoff(), 1);
|
|
1090
1615
|
var import_ws = __toESM(require("ws"), 1);
|
|
1091
1616
|
var WebSocketClient = class extends import_events4.EventEmitter {
|
|
1617
|
+
// Para gerenciar tentativas de reconexão
|
|
1092
1618
|
/**
|
|
1093
1619
|
* Creates a new WebSocketClient instance.
|
|
1094
1620
|
* @param url - The WebSocket server URL to connect to.
|
|
@@ -1101,6 +1627,44 @@ var WebSocketClient = class extends import_events4.EventEmitter {
|
|
|
1101
1627
|
isClosedManually = false;
|
|
1102
1628
|
isReconnecting = false;
|
|
1103
1629
|
messageListeners = [];
|
|
1630
|
+
maxReconnectAttempts = 30;
|
|
1631
|
+
reconnectAttempts = 0;
|
|
1632
|
+
async reconnect() {
|
|
1633
|
+
console.log("Iniciando processo de reconex\xE3o...");
|
|
1634
|
+
const backoffOptions = {
|
|
1635
|
+
delayFirstAttempt: false,
|
|
1636
|
+
startingDelay: 1e3,
|
|
1637
|
+
// 1 segundo inicial
|
|
1638
|
+
timeMultiple: 2,
|
|
1639
|
+
// Multiplicador exponencial
|
|
1640
|
+
maxDelay: 3e4,
|
|
1641
|
+
// 30 segundos de atraso máximo
|
|
1642
|
+
numOfAttempts: this.maxReconnectAttempts,
|
|
1643
|
+
// Limite de tentativas
|
|
1644
|
+
jitter: "full",
|
|
1645
|
+
retry: (error, attemptNumber) => {
|
|
1646
|
+
console.warn(
|
|
1647
|
+
`Tentativa ${attemptNumber} de reconex\xE3o falhou: ${error.message}`
|
|
1648
|
+
);
|
|
1649
|
+
return !this.isClosedManually;
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
try {
|
|
1653
|
+
await (0, import_exponential_backoff.backOff)(async () => {
|
|
1654
|
+
console.log(`Tentando reconectar (#${this.reconnectAttempts + 1})...`);
|
|
1655
|
+
await this.connect();
|
|
1656
|
+
console.log("Reconex\xE3o bem-sucedida.");
|
|
1657
|
+
}, backoffOptions);
|
|
1658
|
+
this.reconnectAttempts = 0;
|
|
1659
|
+
this.isReconnecting = false;
|
|
1660
|
+
} catch (error) {
|
|
1661
|
+
console.error(
|
|
1662
|
+
`Reconex\xE3o falhou ap\xF3s ${this.maxReconnectAttempts} tentativas.`,
|
|
1663
|
+
error
|
|
1664
|
+
);
|
|
1665
|
+
this.isReconnecting = false;
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1104
1668
|
/**
|
|
1105
1669
|
* Establishes a connection to the WebSocket server.
|
|
1106
1670
|
* @returns A Promise that resolves when the connection is established, or rejects if an error occurs.
|
|
@@ -1114,6 +1678,7 @@ var WebSocketClient = class extends import_events4.EventEmitter {
|
|
|
1114
1678
|
console.log("WebSocket conectado.");
|
|
1115
1679
|
this.isClosedManually = false;
|
|
1116
1680
|
this.isReconnecting = false;
|
|
1681
|
+
this.reconnectAttempts = 0;
|
|
1117
1682
|
resolve();
|
|
1118
1683
|
});
|
|
1119
1684
|
this.ws.on("error", (err) => {
|
|
@@ -1122,8 +1687,10 @@ var WebSocketClient = class extends import_events4.EventEmitter {
|
|
|
1122
1687
|
});
|
|
1123
1688
|
this.ws.on("close", (code, reason) => {
|
|
1124
1689
|
console.warn(`WebSocket desconectado: ${code} - ${reason}`);
|
|
1125
|
-
this.isReconnecting = false;
|
|
1126
1690
|
this.emit("close", { code, reason });
|
|
1691
|
+
if (!this.isClosedManually) {
|
|
1692
|
+
this.reconnect();
|
|
1693
|
+
}
|
|
1127
1694
|
});
|
|
1128
1695
|
this.ws.on("message", (rawData) => {
|
|
1129
1696
|
this.handleMessage(rawData);
|
|
@@ -1223,9 +1790,9 @@ var AriClient = class {
|
|
|
1223
1790
|
const baseUrl = `${httpProtocol}://${normalizedHost}:${config.port}/ari`;
|
|
1224
1791
|
this.baseClient = new BaseClient(baseUrl, config.username, config.password);
|
|
1225
1792
|
this.channels = new Channels(this.baseClient, this);
|
|
1793
|
+
this.playbacks = new Playbacks(this.baseClient, this);
|
|
1226
1794
|
this.endpoints = new Endpoints(this.baseClient);
|
|
1227
1795
|
this.applications = new Applications(this.baseClient);
|
|
1228
|
-
this.playbacks = new Playbacks(this.baseClient);
|
|
1229
1796
|
this.sounds = new Sounds(this.baseClient);
|
|
1230
1797
|
this.asterisk = new Asterisk(this.baseClient);
|
|
1231
1798
|
this.bridges = new Bridges(this.baseClient);
|
|
@@ -1248,11 +1815,27 @@ var AriClient = class {
|
|
|
1248
1815
|
}
|
|
1249
1816
|
while (this.pendingListeners.length > 0) {
|
|
1250
1817
|
const { event, callback } = this.pendingListeners.shift();
|
|
1818
|
+
if (wsClient.listenerCount(event) > 0) {
|
|
1819
|
+
console.log(
|
|
1820
|
+
`Listener j\xE1 registrado para o evento '${event}' no app '${app}'. Ignorando duplicata.`
|
|
1821
|
+
);
|
|
1822
|
+
continue;
|
|
1823
|
+
}
|
|
1251
1824
|
console.log(`Registrando listener para '${app}' no evento: ${event}`);
|
|
1252
1825
|
wsClient.on(event, callback);
|
|
1253
1826
|
}
|
|
1254
1827
|
}
|
|
1255
1828
|
}
|
|
1829
|
+
async reconnectWebSocket(app) {
|
|
1830
|
+
console.log(`Tentando reconectar o WebSocket para o app '${app}'...`);
|
|
1831
|
+
try {
|
|
1832
|
+
await this.connectSingleWebSocket(app);
|
|
1833
|
+
this.processPendingListeners();
|
|
1834
|
+
console.log(`Reconex\xE3o bem-sucedida para o app '${app}'.`);
|
|
1835
|
+
} catch (error) {
|
|
1836
|
+
console.error(`Erro ao reconectar o WebSocket para '${app}':`, error);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1256
1839
|
channels;
|
|
1257
1840
|
endpoints;
|
|
1258
1841
|
applications;
|
|
@@ -1264,24 +1847,6 @@ var AriClient = class {
|
|
|
1264
1847
|
getWebSocketClients() {
|
|
1265
1848
|
return this.wsClients;
|
|
1266
1849
|
}
|
|
1267
|
-
/**
|
|
1268
|
-
* Registra um listener para eventos de WebSocket relacionados a canais.
|
|
1269
|
-
* @param eventType Tipo de evento.
|
|
1270
|
-
* @param callback Callback a ser executado quando o evento for recebido.
|
|
1271
|
-
*/
|
|
1272
|
-
onChannelEvent(eventType, callback) {
|
|
1273
|
-
if (this.wsClients.size === 0) {
|
|
1274
|
-
console.warn(
|
|
1275
|
-
"Nenhuma conex\xE3o WebSocket est\xE1 ativa. O listener ser\xE1 pendente."
|
|
1276
|
-
);
|
|
1277
|
-
this.pendingListeners.push({ event: eventType, callback });
|
|
1278
|
-
return;
|
|
1279
|
-
}
|
|
1280
|
-
for (const [app, wsClient] of this.wsClients.entries()) {
|
|
1281
|
-
console.log(`Registrando evento '${eventType}' no app '${app}'`);
|
|
1282
|
-
wsClient.on(eventType, callback);
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
1850
|
/**
|
|
1286
1851
|
* Registra listeners globais para eventos de WebSocket.
|
|
1287
1852
|
*/
|
|
@@ -1319,7 +1884,7 @@ var AriClient = class {
|
|
|
1319
1884
|
}
|
|
1320
1885
|
// Método para criar uma instância de ChannelInstance
|
|
1321
1886
|
createChannelInstance(channelId) {
|
|
1322
|
-
return this.channels.
|
|
1887
|
+
return this.channels.Channel(channelId);
|
|
1323
1888
|
}
|
|
1324
1889
|
handleWebSocketEvent(event) {
|
|
1325
1890
|
console.log("Evento recebido no WebSocket:", event.type, event);
|
|
@@ -1383,26 +1948,58 @@ var AriClient = class {
|
|
|
1383
1948
|
if (!app) {
|
|
1384
1949
|
throw new Error("O nome do aplicativo \xE9 obrigat\xF3rio.");
|
|
1385
1950
|
}
|
|
1386
|
-
if (this.
|
|
1387
|
-
console.log(`Conex\xE3o WebSocket para '${app}' j\xE1
|
|
1388
|
-
return;
|
|
1951
|
+
if (this.webSocketReady.get(app)) {
|
|
1952
|
+
console.log(`Conex\xE3o WebSocket para '${app}' j\xE1 est\xE1 ativa.`);
|
|
1953
|
+
return this.webSocketReady.get(app);
|
|
1389
1954
|
}
|
|
1390
1955
|
const protocol = this.config.secure ? "wss" : "ws";
|
|
1391
1956
|
const eventsParam = subscribedEvents && subscribedEvents.length > 0 ? `&event=${subscribedEvents.join(",")}` : "&subscribeAll=true";
|
|
1392
1957
|
const wsUrl = `${protocol}://${encodeURIComponent(
|
|
1393
1958
|
this.config.username
|
|
1394
1959
|
)}:${encodeURIComponent(this.config.password)}@${this.config.host}:${this.config.port}/ari/events?app=${app}${eventsParam}`;
|
|
1395
|
-
const
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1960
|
+
const backoffOptions = {
|
|
1961
|
+
delayFirstAttempt: false,
|
|
1962
|
+
startingDelay: 1e3,
|
|
1963
|
+
timeMultiple: 2,
|
|
1964
|
+
maxDelay: 3e4,
|
|
1965
|
+
numOfAttempts: 10,
|
|
1966
|
+
jitter: "full",
|
|
1967
|
+
retry: (error, attemptNumber) => {
|
|
1968
|
+
console.warn(
|
|
1969
|
+
`Tentativa ${attemptNumber} falhou para '${app}': ${error.message}`
|
|
1970
|
+
);
|
|
1971
|
+
return !this.wsClients.has(app) || !this.wsClients.get(app)?.isConnected();
|
|
1972
|
+
}
|
|
1973
|
+
};
|
|
1974
|
+
const webSocketPromise = new Promise(async (resolve, reject) => {
|
|
1975
|
+
try {
|
|
1976
|
+
if (this.isReconnecting.get(app)) {
|
|
1977
|
+
console.warn(`J\xE1 est\xE1 tentando reconectar para o app '${app}'.`);
|
|
1978
|
+
return;
|
|
1979
|
+
}
|
|
1980
|
+
this.isReconnecting.set(app, true);
|
|
1981
|
+
const wsClient = new WebSocketClient(wsUrl);
|
|
1982
|
+
await (0, import_exponential_backoff2.backOff)(async () => {
|
|
1983
|
+
if (!wsClient) {
|
|
1984
|
+
throw new Error("WebSocketClient instance is null.");
|
|
1985
|
+
}
|
|
1986
|
+
await wsClient.connect();
|
|
1987
|
+
console.log(`WebSocket conectado para o app: ${app}`);
|
|
1988
|
+
this.integrateWebSocketEvents(app, wsClient);
|
|
1989
|
+
await this.ensureAppRegistered(app);
|
|
1990
|
+
this.wsClients.set(app, wsClient);
|
|
1991
|
+
this.processPendingListeners();
|
|
1992
|
+
}, backoffOptions);
|
|
1993
|
+
resolve();
|
|
1994
|
+
} catch (error) {
|
|
1995
|
+
console.error(`Erro ao conectar WebSocket para '${app}':`, error);
|
|
1996
|
+
reject(error);
|
|
1997
|
+
} finally {
|
|
1998
|
+
this.isReconnecting.delete(app);
|
|
1999
|
+
}
|
|
2000
|
+
});
|
|
2001
|
+
this.webSocketReady.set(app, webSocketPromise);
|
|
2002
|
+
return webSocketPromise;
|
|
1406
2003
|
}
|
|
1407
2004
|
/**
|
|
1408
2005
|
* Integrates WebSocket events with playback listeners.
|
|
@@ -1515,465 +2112,6 @@ var AriClient = class {
|
|
|
1515
2112
|
this.wsClients.clear();
|
|
1516
2113
|
console.log("Todos os WebSockets foram fechados.");
|
|
1517
2114
|
}
|
|
1518
|
-
/**
|
|
1519
|
-
* Retrieves a list of active channels from the Asterisk ARI.
|
|
1520
|
-
*
|
|
1521
|
-
* @returns {Promise<Channel[]>} A promise resolving to the list of active channels.
|
|
1522
|
-
*/
|
|
1523
|
-
/**
|
|
1524
|
-
* Lists all active channels.
|
|
1525
|
-
*/
|
|
1526
|
-
async listChannels() {
|
|
1527
|
-
return this.channels.list();
|
|
1528
|
-
}
|
|
1529
|
-
async hangupChannel(channelId) {
|
|
1530
|
-
return this.channels.hangup(channelId);
|
|
1531
|
-
}
|
|
1532
|
-
/**
|
|
1533
|
-
* Creates a new channel.
|
|
1534
|
-
*/
|
|
1535
|
-
async originateChannel(data) {
|
|
1536
|
-
return this.channels.originate(data);
|
|
1537
|
-
}
|
|
1538
|
-
/**
|
|
1539
|
-
* Continues the dialplan for a specific channel.
|
|
1540
|
-
*/
|
|
1541
|
-
async continueChannelDialplan(channelId, context, extension, priority, label) {
|
|
1542
|
-
return this.channels.continueDialplan(
|
|
1543
|
-
channelId,
|
|
1544
|
-
context,
|
|
1545
|
-
extension,
|
|
1546
|
-
priority,
|
|
1547
|
-
label
|
|
1548
|
-
);
|
|
1549
|
-
}
|
|
1550
|
-
/**
|
|
1551
|
-
* Moves a channel to another Stasis application.
|
|
1552
|
-
*/
|
|
1553
|
-
async moveChannelToApplication(channelId, app, appArgs) {
|
|
1554
|
-
return this.channels.moveToApplication(channelId, app, appArgs);
|
|
1555
|
-
}
|
|
1556
|
-
/**
|
|
1557
|
-
* Sets a channel variable.
|
|
1558
|
-
*/
|
|
1559
|
-
async setChannelVariable(channelId, variable, value) {
|
|
1560
|
-
return this.channels.setChannelVariable(channelId, variable, value);
|
|
1561
|
-
}
|
|
1562
|
-
/**
|
|
1563
|
-
* Gets a channel variable.
|
|
1564
|
-
*/
|
|
1565
|
-
async getChannelVariable(channelId, variable) {
|
|
1566
|
-
return this.channels.getChannelVariable(channelId, variable);
|
|
1567
|
-
}
|
|
1568
|
-
/**
|
|
1569
|
-
* Starts music on hold for a channel.
|
|
1570
|
-
*/
|
|
1571
|
-
async startChannelMusicOnHold(channelId) {
|
|
1572
|
-
return this.channels.startMusicOnHold(channelId);
|
|
1573
|
-
}
|
|
1574
|
-
/**
|
|
1575
|
-
* Stops music on hold for a channel.
|
|
1576
|
-
*/
|
|
1577
|
-
async stopChannelMusicOnHold(channelId) {
|
|
1578
|
-
return this.channels.stopMusicOnHold(channelId);
|
|
1579
|
-
}
|
|
1580
|
-
/**
|
|
1581
|
-
* Records audio from a channel.
|
|
1582
|
-
*/
|
|
1583
|
-
async recordAudio(channelId, options) {
|
|
1584
|
-
return this.channels.record(channelId, options);
|
|
1585
|
-
}
|
|
1586
|
-
/**
|
|
1587
|
-
* Starts snooping on a channel.
|
|
1588
|
-
*/
|
|
1589
|
-
async snoopChannel(channelId, options) {
|
|
1590
|
-
return this.channels.snoopChannel(channelId, options);
|
|
1591
|
-
}
|
|
1592
|
-
/**
|
|
1593
|
-
* Starts snooping on a channel with a specific snoop ID.
|
|
1594
|
-
*/
|
|
1595
|
-
async snoopChannelWithId(channelId, snoopId, options) {
|
|
1596
|
-
return this.channels.snoopChannelWithId(channelId, snoopId, options);
|
|
1597
|
-
}
|
|
1598
|
-
/**
|
|
1599
|
-
* Initiates a dial operation on a previously created channel.
|
|
1600
|
-
* This function attempts to connect the specified channel to its configured destination.
|
|
1601
|
-
*
|
|
1602
|
-
* @param channelId - The unique identifier of the channel to dial.
|
|
1603
|
-
* @param caller - Optional. The caller ID to use for the outgoing call. If not provided, the default caller ID for the channel will be used.
|
|
1604
|
-
* @param timeout - Optional. The maximum time in seconds to wait for the dial operation to complete. If not specified, the system's default timeout will be used.
|
|
1605
|
-
* @returns A Promise that resolves when the dial operation has been initiated successfully. Note that this does not guarantee that the call was answered, only that dialing has begun.
|
|
1606
|
-
* @throws Will throw an error if the dial operation fails, e.g., if the channel doesn't exist or is in an invalid state.
|
|
1607
|
-
*/
|
|
1608
|
-
async dialChannel(channelId, caller, timeout) {
|
|
1609
|
-
return this.channels.dial(channelId, caller, timeout);
|
|
1610
|
-
}
|
|
1611
|
-
/**
|
|
1612
|
-
* Retrieves RTP statistics for a channel.
|
|
1613
|
-
*/
|
|
1614
|
-
async getRTPStatistics(channelId) {
|
|
1615
|
-
return this.channels.getRTPStatistics(channelId);
|
|
1616
|
-
}
|
|
1617
|
-
/**
|
|
1618
|
-
* Creates a channel to an external media source/sink.
|
|
1619
|
-
*/
|
|
1620
|
-
async createExternalMedia(options) {
|
|
1621
|
-
return this.channels.createExternalMedia(options);
|
|
1622
|
-
}
|
|
1623
|
-
/**
|
|
1624
|
-
* Redirects a channel to a different location.
|
|
1625
|
-
*/
|
|
1626
|
-
async redirectChannel(channelId, endpoint) {
|
|
1627
|
-
return this.channels.redirectChannel(channelId, endpoint);
|
|
1628
|
-
}
|
|
1629
|
-
/**
|
|
1630
|
-
* Sends a ringing indication to a channel.
|
|
1631
|
-
*/
|
|
1632
|
-
async ringChannel(channelId) {
|
|
1633
|
-
return this.channels.ringChannel(channelId);
|
|
1634
|
-
}
|
|
1635
|
-
/**
|
|
1636
|
-
* Stops the ringing indication on a specified channel in the Asterisk system.
|
|
1637
|
-
*
|
|
1638
|
-
* This function sends a request to the Asterisk server to cease the ringing
|
|
1639
|
-
* indication on a particular channel. This is typically used when you want to
|
|
1640
|
-
* stop the ringing sound on a channel without answering or hanging up the call.
|
|
1641
|
-
*
|
|
1642
|
-
* @param channelId - The unique identifier of the channel on which to stop the ringing.
|
|
1643
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1644
|
-
*
|
|
1645
|
-
* @returns A Promise that resolves when the ringing has been successfully stopped on the specified channel.
|
|
1646
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1647
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1648
|
-
*/
|
|
1649
|
-
async stopRingChannel(channelId) {
|
|
1650
|
-
return this.channels.stopRingChannel(channelId);
|
|
1651
|
-
}
|
|
1652
|
-
/**
|
|
1653
|
-
* Sends DTMF (Dual-Tone Multi-Frequency) tones to a specified channel.
|
|
1654
|
-
*
|
|
1655
|
-
* This function allows sending DTMF tones to a channel, which can be used for various purposes
|
|
1656
|
-
* such as interacting with IVR systems or sending signals during a call.
|
|
1657
|
-
*
|
|
1658
|
-
* @param channelId - The unique identifier of the channel to send DTMF tones to.
|
|
1659
|
-
* @param dtmf - A string representing the DTMF tones to send (e.g., "123#").
|
|
1660
|
-
* @param options - Optional parameters to control the timing of DTMF tones.
|
|
1661
|
-
* @param options.before - The time (in milliseconds) to wait before sending DTMF.
|
|
1662
|
-
* @param options.between - The time (in milliseconds) to wait between each DTMF tone.
|
|
1663
|
-
* @param options.duration - The duration (in milliseconds) of each DTMF tone.
|
|
1664
|
-
* @param options.after - The time (in milliseconds) to wait after sending all DTMF tones.
|
|
1665
|
-
* @returns A Promise that resolves when the DTMF tones have been successfully sent.
|
|
1666
|
-
*/
|
|
1667
|
-
async sendDTMF(channelId, dtmf, options) {
|
|
1668
|
-
return this.channels.sendDTMF(channelId, dtmf, options);
|
|
1669
|
-
}
|
|
1670
|
-
/**
|
|
1671
|
-
* Mutes a channel in the Asterisk system.
|
|
1672
|
-
*
|
|
1673
|
-
* This function initiates a mute operation on the specified channel, preventing
|
|
1674
|
-
* audio transmission in the specified direction(s).
|
|
1675
|
-
*
|
|
1676
|
-
* @param channelId - The unique identifier of the channel to be muted.
|
|
1677
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1678
|
-
* @param direction - The direction of audio to mute. Can be one of:
|
|
1679
|
-
* - "both": Mute both incoming and outgoing audio (default)
|
|
1680
|
-
* - "in": Mute only incoming audio
|
|
1681
|
-
* - "out": Mute only outgoing audio
|
|
1682
|
-
*
|
|
1683
|
-
* @returns A Promise that resolves when the mute operation has been successfully completed.
|
|
1684
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1685
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1686
|
-
*/
|
|
1687
|
-
async muteChannel(channelId, direction = "both") {
|
|
1688
|
-
return this.channels.muteChannel(channelId, direction);
|
|
1689
|
-
}
|
|
1690
|
-
/**
|
|
1691
|
-
* Unmutes a channel in the Asterisk system.
|
|
1692
|
-
*
|
|
1693
|
-
* This function removes the mute status from a specified channel, allowing audio
|
|
1694
|
-
* transmission to resume in the specified direction(s).
|
|
1695
|
-
*
|
|
1696
|
-
* @param channelId - The unique identifier of the channel to be unmuted.
|
|
1697
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1698
|
-
* @param direction - The direction of audio to unmute. Can be one of:
|
|
1699
|
-
* - "both": Unmute both incoming and outgoing audio (default)
|
|
1700
|
-
* - "in": Unmute only incoming audio
|
|
1701
|
-
* - "out": Unmute only outgoing audio
|
|
1702
|
-
*
|
|
1703
|
-
* @returns A Promise that resolves when the unmute operation has been successfully completed.
|
|
1704
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1705
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1706
|
-
*/
|
|
1707
|
-
async unmuteChannel(channelId, direction = "both") {
|
|
1708
|
-
return this.channels.unmuteChannel(channelId, direction);
|
|
1709
|
-
}
|
|
1710
|
-
/**
|
|
1711
|
-
* Puts a specified channel on hold.
|
|
1712
|
-
*
|
|
1713
|
-
* This function initiates a hold operation on the specified channel in the Asterisk system.
|
|
1714
|
-
* When a channel is put on hold, typically the audio is muted or replaced with hold music,
|
|
1715
|
-
* depending on the system configuration.
|
|
1716
|
-
*
|
|
1717
|
-
* @param channelId - The unique identifier of the channel to be put on hold.
|
|
1718
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1719
|
-
*
|
|
1720
|
-
* @returns A Promise that resolves when the hold operation has been successfully initiated.
|
|
1721
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1722
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1723
|
-
*/
|
|
1724
|
-
async holdChannel(channelId) {
|
|
1725
|
-
return this.channels.holdChannel(channelId);
|
|
1726
|
-
}
|
|
1727
|
-
/**
|
|
1728
|
-
* Removes a specified channel from hold.
|
|
1729
|
-
*
|
|
1730
|
-
* This function initiates an unhold operation on the specified channel in the Asterisk system.
|
|
1731
|
-
* When a channel is taken off hold, it typically resumes normal audio transmission,
|
|
1732
|
-
* allowing the parties to continue their conversation.
|
|
1733
|
-
*
|
|
1734
|
-
* @param channelId - The unique identifier of the channel to be taken off hold.
|
|
1735
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1736
|
-
*
|
|
1737
|
-
* @returns A Promise that resolves when the unhold operation has been successfully initiated.
|
|
1738
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1739
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1740
|
-
*/
|
|
1741
|
-
async unholdChannel(channelId) {
|
|
1742
|
-
return this.channels.unholdChannel(channelId);
|
|
1743
|
-
}
|
|
1744
|
-
/**
|
|
1745
|
-
* Creates a new channel in the Asterisk system using the provided originate request data.
|
|
1746
|
-
* This function initiates a new communication channel based on the specified parameters.
|
|
1747
|
-
*
|
|
1748
|
-
* @param data - An object containing the originate request data for channel creation.
|
|
1749
|
-
* This includes details such as the endpoint to call, the context to use,
|
|
1750
|
-
* and any variables to set on the new channel.
|
|
1751
|
-
* @param data.endpoint - The endpoint to call (e.g., "SIP/1234").
|
|
1752
|
-
* @param data.extension - The extension to dial after the channel is created.
|
|
1753
|
-
* @param data.context - The dialplan context to use for the new channel.
|
|
1754
|
-
* @param data.priority - The priority to start at in the dialplan.
|
|
1755
|
-
* @param data.app - The application to execute on the channel (alternative to extension/context/priority).
|
|
1756
|
-
* @param data.appArgs - The arguments to pass to the application, if 'app' is specified.
|
|
1757
|
-
* @param data.callerId - The caller ID to set on the new channel.
|
|
1758
|
-
* @param data.timeout - The timeout (in seconds) to wait for the channel to be answered.
|
|
1759
|
-
* @param data.variables - An object containing key-value pairs of channel variables to set.
|
|
1760
|
-
* @param data.channelId - An optional ID to assign to the new channel.
|
|
1761
|
-
* @param data.otherChannelId - The ID of another channel to bridge with after creation.
|
|
1762
|
-
*
|
|
1763
|
-
* @returns A Promise that resolves to the created Channel object.
|
|
1764
|
-
* The Channel object contains details about the newly created channel,
|
|
1765
|
-
* such as its unique identifier, state, and other relevant information.
|
|
1766
|
-
*
|
|
1767
|
-
* @throws Will throw an error if the channel creation fails for any reason,
|
|
1768
|
-
* such as invalid parameters or system issues.
|
|
1769
|
-
*/
|
|
1770
|
-
async createChannel(data) {
|
|
1771
|
-
return this.channels.createChannel(data);
|
|
1772
|
-
}
|
|
1773
|
-
/**
|
|
1774
|
-
* Originates a new channel with a specified ID using the provided originate request data.
|
|
1775
|
-
*
|
|
1776
|
-
* @param channelId - The desired unique identifier for the new channel.
|
|
1777
|
-
* @param data - The originate request data containing channel creation parameters.
|
|
1778
|
-
* @returns A promise that resolves to the created Channel object.
|
|
1779
|
-
*/
|
|
1780
|
-
async originateWithId(channelId, data) {
|
|
1781
|
-
return this.channels.originateWithId(channelId, data);
|
|
1782
|
-
}
|
|
1783
|
-
// Métodos relacionados a endpoints:
|
|
1784
|
-
/**
|
|
1785
|
-
* Lists all endpoints.
|
|
1786
|
-
*
|
|
1787
|
-
* @returns {Promise<Endpoint[]>} A promise resolving to the list of endpoints.
|
|
1788
|
-
*/
|
|
1789
|
-
async listEndpoints() {
|
|
1790
|
-
return this.endpoints.list();
|
|
1791
|
-
}
|
|
1792
|
-
/**
|
|
1793
|
-
* Retrieves details of a specific endpoint.
|
|
1794
|
-
*
|
|
1795
|
-
* @param technology - The technology of the endpoint.
|
|
1796
|
-
* @param resource - The resource name of the endpoint.
|
|
1797
|
-
* @returns {Promise<EndpointDetails>} A promise resolving to the details of the endpoint.
|
|
1798
|
-
*/
|
|
1799
|
-
async getEndpointDetails(technology, resource) {
|
|
1800
|
-
return this.endpoints.getDetails(technology, resource);
|
|
1801
|
-
}
|
|
1802
|
-
/**
|
|
1803
|
-
* Sends a message to an endpoint.
|
|
1804
|
-
*
|
|
1805
|
-
* @param technology - The technology of the endpoint.
|
|
1806
|
-
* @param resource - The resource name of the endpoint.
|
|
1807
|
-
* @param body - The message body to send.
|
|
1808
|
-
* @returns {Promise<void>} A promise resolving when the message is sent.
|
|
1809
|
-
*/
|
|
1810
|
-
async sendMessageToEndpoint(technology, resource, body) {
|
|
1811
|
-
return this.endpoints.sendMessage(technology, resource, body);
|
|
1812
|
-
}
|
|
1813
|
-
// Métodos relacionados a applications
|
|
1814
|
-
/**
|
|
1815
|
-
* Lists all applications.
|
|
1816
|
-
*
|
|
1817
|
-
* @returns {Promise<Application[]>} A promise resolving to the list of applications.
|
|
1818
|
-
*/
|
|
1819
|
-
async listApplications() {
|
|
1820
|
-
return this.applications.list();
|
|
1821
|
-
}
|
|
1822
|
-
/**
|
|
1823
|
-
* Retrieves details of a specific application.
|
|
1824
|
-
*
|
|
1825
|
-
* @param appName - The name of the application.
|
|
1826
|
-
* @returns {Promise<ApplicationDetails>} A promise resolving to the application details.
|
|
1827
|
-
*/
|
|
1828
|
-
async getApplicationDetails(appName) {
|
|
1829
|
-
return this.applications.getDetails(appName);
|
|
1830
|
-
}
|
|
1831
|
-
/**
|
|
1832
|
-
* Sends a message to a specific application.
|
|
1833
|
-
*
|
|
1834
|
-
* @param appName - The name of the application.
|
|
1835
|
-
* @param body - The message body to send.
|
|
1836
|
-
* @returns {Promise<void>} A promise resolving when the message is sent successfully.
|
|
1837
|
-
*/
|
|
1838
|
-
async sendMessageToApplication(appName, body) {
|
|
1839
|
-
return this.applications.sendMessage(appName, body);
|
|
1840
|
-
}
|
|
1841
|
-
// Métodos relacionados a playbacks
|
|
1842
|
-
/**
|
|
1843
|
-
* Retrieves details of a specific playback.
|
|
1844
|
-
*
|
|
1845
|
-
* @param playbackId - The unique identifier of the playback.
|
|
1846
|
-
* @returns {Promise<Playback>} A promise resolving to the playback details.
|
|
1847
|
-
*/
|
|
1848
|
-
async getPlaybackDetails(playbackId) {
|
|
1849
|
-
return this.playbacks.getDetails(playbackId);
|
|
1850
|
-
}
|
|
1851
|
-
/**
|
|
1852
|
-
* Controls a specific playback in the Asterisk server.
|
|
1853
|
-
* This function allows manipulation of an ongoing playback, such as pausing, resuming, or skipping.
|
|
1854
|
-
*
|
|
1855
|
-
* @param playbackId - The unique identifier of the playback to control.
|
|
1856
|
-
* This should be a string that uniquely identifies the playback in the Asterisk system.
|
|
1857
|
-
* @param controlRequest - An object containing the control operation details.
|
|
1858
|
-
* This object should conform to the PlaybackControlRequest interface,
|
|
1859
|
-
* which includes an 'operation' property specifying the control action to perform.
|
|
1860
|
-
* @returns A Promise that resolves when the control operation is successfully executed.
|
|
1861
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1862
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1863
|
-
* @throws Will throw an error if the playback control operation fails, e.g., if the playback doesn't exist
|
|
1864
|
-
* or the requested operation is invalid.
|
|
1865
|
-
*/
|
|
1866
|
-
async controlPlayback(playbackId, controlRequest) {
|
|
1867
|
-
const { operation } = controlRequest;
|
|
1868
|
-
return this.playbacks.control(playbackId, operation);
|
|
1869
|
-
}
|
|
1870
|
-
/**
|
|
1871
|
-
* Stops a specific playback in the Asterisk server.
|
|
1872
|
-
*
|
|
1873
|
-
* @param playbackId - The unique identifier of the playback to stop.
|
|
1874
|
-
* @returns A Promise that resolves when the playback is successfully stopped.
|
|
1875
|
-
*/
|
|
1876
|
-
async stopPlayback(playbackId) {
|
|
1877
|
-
return this.playbacks.stop(playbackId);
|
|
1878
|
-
}
|
|
1879
|
-
/**
|
|
1880
|
-
* Retrieves a list of all available sounds in the Asterisk server.
|
|
1881
|
-
*
|
|
1882
|
-
* @param params - Optional parameters to filter the list of sounds.
|
|
1883
|
-
* @returns A Promise that resolves to an array of Sound objects representing the available sounds.
|
|
1884
|
-
*/
|
|
1885
|
-
async listSounds(params) {
|
|
1886
|
-
return this.sounds.list(params);
|
|
1887
|
-
}
|
|
1888
|
-
/**
|
|
1889
|
-
* Retrieves detailed information about a specific sound in the Asterisk server.
|
|
1890
|
-
*
|
|
1891
|
-
* @param soundId - The unique identifier of the sound to retrieve details for.
|
|
1892
|
-
* @returns A Promise that resolves to a Sound object containing the details of the specified sound.
|
|
1893
|
-
*/
|
|
1894
|
-
async getSoundDetails(soundId) {
|
|
1895
|
-
return this.sounds.getDetails(soundId);
|
|
1896
|
-
}
|
|
1897
|
-
/**
|
|
1898
|
-
* Retrieves general information about the Asterisk server.
|
|
1899
|
-
*
|
|
1900
|
-
* @returns A Promise that resolves to an AsteriskInfo object containing server information.
|
|
1901
|
-
*/
|
|
1902
|
-
async getAsteriskInfo() {
|
|
1903
|
-
return this.asterisk.getInfo();
|
|
1904
|
-
}
|
|
1905
|
-
/**
|
|
1906
|
-
* Retrieves a list of all loaded modules in the Asterisk server.
|
|
1907
|
-
*
|
|
1908
|
-
* @returns A Promise that resolves to an array of Module objects representing the loaded modules.
|
|
1909
|
-
*/
|
|
1910
|
-
async listModules() {
|
|
1911
|
-
return this.asterisk.listModules();
|
|
1912
|
-
}
|
|
1913
|
-
/**
|
|
1914
|
-
* Manages a specific module in the Asterisk server by loading, unloading, or reloading it.
|
|
1915
|
-
*
|
|
1916
|
-
* @param moduleName - The name of the module to manage.
|
|
1917
|
-
* @param action - The action to perform on the module: "load", "unload", or "reload".
|
|
1918
|
-
* @returns A Promise that resolves when the module management action is completed successfully.
|
|
1919
|
-
*/
|
|
1920
|
-
async manageModule(moduleName, action) {
|
|
1921
|
-
return this.asterisk.manageModule(moduleName, action);
|
|
1922
|
-
}
|
|
1923
|
-
/**
|
|
1924
|
-
* Retrieves a list of all configured logging channels in the Asterisk server.
|
|
1925
|
-
*
|
|
1926
|
-
* @returns A Promise that resolves to an array of Logging objects representing the configured logging channels.
|
|
1927
|
-
*/
|
|
1928
|
-
async listLoggingChannels() {
|
|
1929
|
-
return this.asterisk.listLoggingChannels();
|
|
1930
|
-
}
|
|
1931
|
-
/**
|
|
1932
|
-
* Adds or removes a log channel in the Asterisk server.
|
|
1933
|
-
*
|
|
1934
|
-
* @param logChannelName - The name of the log channel to manage.
|
|
1935
|
-
* @param action - The action to perform: "add" to create a new log channel or "remove" to delete an existing one.
|
|
1936
|
-
* @param configuration - Optional configuration object for adding a log channel. Ignored when removing a channel.
|
|
1937
|
-
* @param configuration.type - The type of the log channel.
|
|
1938
|
-
* @param configuration.configuration - Additional configuration details for the log channel.
|
|
1939
|
-
* @returns A Promise that resolves when the log channel management action is completed successfully.
|
|
1940
|
-
*/
|
|
1941
|
-
async manageLogChannel(logChannelName, action, configuration) {
|
|
1942
|
-
return this.asterisk.manageLogChannel(
|
|
1943
|
-
logChannelName,
|
|
1944
|
-
action,
|
|
1945
|
-
configuration
|
|
1946
|
-
);
|
|
1947
|
-
}
|
|
1948
|
-
/**
|
|
1949
|
-
* Retrieves the value of a global variable from the Asterisk server.
|
|
1950
|
-
*
|
|
1951
|
-
* @param variableName - The name of the global variable to retrieve.
|
|
1952
|
-
* @returns A Promise that resolves to a Variable object containing the name and value of the global variable.
|
|
1953
|
-
*/
|
|
1954
|
-
async getGlobalVariable(variableName) {
|
|
1955
|
-
return this.asterisk.getGlobalVariable(variableName);
|
|
1956
|
-
}
|
|
1957
|
-
/**
|
|
1958
|
-
* Sets a global variable in the Asterisk server.
|
|
1959
|
-
*
|
|
1960
|
-
* This function allows you to set or update the value of a global variable
|
|
1961
|
-
* in the Asterisk server. Global variables are accessible throughout the
|
|
1962
|
-
* entire Asterisk system and can be used for various purposes such as
|
|
1963
|
-
* configuration settings or sharing data between different parts of the system.
|
|
1964
|
-
*
|
|
1965
|
-
* @param variableName - The name of the global variable to set or update.
|
|
1966
|
-
* This should be a string identifying the variable uniquely.
|
|
1967
|
-
* @param value - The value to assign to the global variable. This can be any
|
|
1968
|
-
* string value, including empty strings.
|
|
1969
|
-
* @returns A Promise that resolves when the global variable has been successfully
|
|
1970
|
-
* set. The promise resolves to void, indicating no specific return value.
|
|
1971
|
-
* If an error occurs during the operation, the promise will be rejected
|
|
1972
|
-
* with an error object.
|
|
1973
|
-
*/
|
|
1974
|
-
async setGlobalVariable(variableName, value) {
|
|
1975
|
-
return this.asterisk.setGlobalVariable(variableName, value);
|
|
1976
|
-
}
|
|
1977
2115
|
/**
|
|
1978
2116
|
* Inicializa uma nova instância de `ChannelInstance` para manipular canais localmente.
|
|
1979
2117
|
*
|
|
@@ -1981,7 +2119,7 @@ var AriClient = class {
|
|
|
1981
2119
|
* @returns Uma instância de `ChannelInstance` vinculada ao cliente atual.
|
|
1982
2120
|
*/
|
|
1983
2121
|
Channel(channelId) {
|
|
1984
|
-
return this.channels.
|
|
2122
|
+
return this.channels.Channel(channelId);
|
|
1985
2123
|
}
|
|
1986
2124
|
/**
|
|
1987
2125
|
* Inicializa uma nova instância de `PlaybackInstance` para manipular playbacks.
|