@ipcom/asterisk-ari 0.0.77 → 0.0.79
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 +684 -553
- package/dist/cjs/index.cjs.map +4 -4
- package/dist/esm/index.js +707 -553
- 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/esm/index.js
CHANGED
|
@@ -1,3 +1,578 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// node_modules/exponential-backoff/dist/options.js
|
|
28
|
+
var require_options = __commonJS({
|
|
29
|
+
"node_modules/exponential-backoff/dist/options.js"(exports) {
|
|
30
|
+
"use strict";
|
|
31
|
+
var __assign = exports && exports.__assign || function() {
|
|
32
|
+
__assign = Object.assign || function(t) {
|
|
33
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
34
|
+
s = arguments[i];
|
|
35
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
36
|
+
t[p] = s[p];
|
|
37
|
+
}
|
|
38
|
+
return t;
|
|
39
|
+
};
|
|
40
|
+
return __assign.apply(this, arguments);
|
|
41
|
+
};
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
var defaultOptions = {
|
|
44
|
+
delayFirstAttempt: false,
|
|
45
|
+
jitter: "none",
|
|
46
|
+
maxDelay: Infinity,
|
|
47
|
+
numOfAttempts: 10,
|
|
48
|
+
retry: function() {
|
|
49
|
+
return true;
|
|
50
|
+
},
|
|
51
|
+
startingDelay: 100,
|
|
52
|
+
timeMultiple: 2
|
|
53
|
+
};
|
|
54
|
+
function getSanitizedOptions(options) {
|
|
55
|
+
var sanitized = __assign(__assign({}, defaultOptions), options);
|
|
56
|
+
if (sanitized.numOfAttempts < 1) {
|
|
57
|
+
sanitized.numOfAttempts = 1;
|
|
58
|
+
}
|
|
59
|
+
return sanitized;
|
|
60
|
+
}
|
|
61
|
+
exports.getSanitizedOptions = getSanitizedOptions;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// node_modules/exponential-backoff/dist/jitter/full/full.jitter.js
|
|
66
|
+
var require_full_jitter = __commonJS({
|
|
67
|
+
"node_modules/exponential-backoff/dist/jitter/full/full.jitter.js"(exports) {
|
|
68
|
+
"use strict";
|
|
69
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
70
|
+
function fullJitter(delay) {
|
|
71
|
+
var jitteredDelay = Math.random() * delay;
|
|
72
|
+
return Math.round(jitteredDelay);
|
|
73
|
+
}
|
|
74
|
+
exports.fullJitter = fullJitter;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// node_modules/exponential-backoff/dist/jitter/no/no.jitter.js
|
|
79
|
+
var require_no_jitter = __commonJS({
|
|
80
|
+
"node_modules/exponential-backoff/dist/jitter/no/no.jitter.js"(exports) {
|
|
81
|
+
"use strict";
|
|
82
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
83
|
+
function noJitter(delay) {
|
|
84
|
+
return delay;
|
|
85
|
+
}
|
|
86
|
+
exports.noJitter = noJitter;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// node_modules/exponential-backoff/dist/jitter/jitter.factory.js
|
|
91
|
+
var require_jitter_factory = __commonJS({
|
|
92
|
+
"node_modules/exponential-backoff/dist/jitter/jitter.factory.js"(exports) {
|
|
93
|
+
"use strict";
|
|
94
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
95
|
+
var full_jitter_1 = require_full_jitter();
|
|
96
|
+
var no_jitter_1 = require_no_jitter();
|
|
97
|
+
function JitterFactory(options) {
|
|
98
|
+
switch (options.jitter) {
|
|
99
|
+
case "full":
|
|
100
|
+
return full_jitter_1.fullJitter;
|
|
101
|
+
case "none":
|
|
102
|
+
default:
|
|
103
|
+
return no_jitter_1.noJitter;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.JitterFactory = JitterFactory;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// node_modules/exponential-backoff/dist/delay/delay.base.js
|
|
111
|
+
var require_delay_base = __commonJS({
|
|
112
|
+
"node_modules/exponential-backoff/dist/delay/delay.base.js"(exports) {
|
|
113
|
+
"use strict";
|
|
114
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
115
|
+
var jitter_factory_1 = require_jitter_factory();
|
|
116
|
+
var Delay = (
|
|
117
|
+
/** @class */
|
|
118
|
+
function() {
|
|
119
|
+
function Delay2(options) {
|
|
120
|
+
this.options = options;
|
|
121
|
+
this.attempt = 0;
|
|
122
|
+
}
|
|
123
|
+
Delay2.prototype.apply = function() {
|
|
124
|
+
var _this = this;
|
|
125
|
+
return new Promise(function(resolve) {
|
|
126
|
+
return setTimeout(resolve, _this.jitteredDelay);
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
Delay2.prototype.setAttemptNumber = function(attempt) {
|
|
130
|
+
this.attempt = attempt;
|
|
131
|
+
};
|
|
132
|
+
Object.defineProperty(Delay2.prototype, "jitteredDelay", {
|
|
133
|
+
get: function() {
|
|
134
|
+
var jitter = jitter_factory_1.JitterFactory(this.options);
|
|
135
|
+
return jitter(this.delay);
|
|
136
|
+
},
|
|
137
|
+
enumerable: true,
|
|
138
|
+
configurable: true
|
|
139
|
+
});
|
|
140
|
+
Object.defineProperty(Delay2.prototype, "delay", {
|
|
141
|
+
get: function() {
|
|
142
|
+
var constant = this.options.startingDelay;
|
|
143
|
+
var base = this.options.timeMultiple;
|
|
144
|
+
var power = this.numOfDelayedAttempts;
|
|
145
|
+
var delay = constant * Math.pow(base, power);
|
|
146
|
+
return Math.min(delay, this.options.maxDelay);
|
|
147
|
+
},
|
|
148
|
+
enumerable: true,
|
|
149
|
+
configurable: true
|
|
150
|
+
});
|
|
151
|
+
Object.defineProperty(Delay2.prototype, "numOfDelayedAttempts", {
|
|
152
|
+
get: function() {
|
|
153
|
+
return this.attempt;
|
|
154
|
+
},
|
|
155
|
+
enumerable: true,
|
|
156
|
+
configurable: true
|
|
157
|
+
});
|
|
158
|
+
return Delay2;
|
|
159
|
+
}()
|
|
160
|
+
);
|
|
161
|
+
exports.Delay = Delay;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// node_modules/exponential-backoff/dist/delay/skip-first/skip-first.delay.js
|
|
166
|
+
var require_skip_first_delay = __commonJS({
|
|
167
|
+
"node_modules/exponential-backoff/dist/delay/skip-first/skip-first.delay.js"(exports) {
|
|
168
|
+
"use strict";
|
|
169
|
+
var __extends = exports && exports.__extends || /* @__PURE__ */ function() {
|
|
170
|
+
var extendStatics = function(d, b) {
|
|
171
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
172
|
+
d2.__proto__ = b2;
|
|
173
|
+
} || function(d2, b2) {
|
|
174
|
+
for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p];
|
|
175
|
+
};
|
|
176
|
+
return extendStatics(d, b);
|
|
177
|
+
};
|
|
178
|
+
return function(d, b) {
|
|
179
|
+
extendStatics(d, b);
|
|
180
|
+
function __() {
|
|
181
|
+
this.constructor = d;
|
|
182
|
+
}
|
|
183
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
184
|
+
};
|
|
185
|
+
}();
|
|
186
|
+
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
187
|
+
function adopt(value) {
|
|
188
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
189
|
+
resolve(value);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
193
|
+
function fulfilled(value) {
|
|
194
|
+
try {
|
|
195
|
+
step(generator.next(value));
|
|
196
|
+
} catch (e) {
|
|
197
|
+
reject(e);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function rejected(value) {
|
|
201
|
+
try {
|
|
202
|
+
step(generator["throw"](value));
|
|
203
|
+
} catch (e) {
|
|
204
|
+
reject(e);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function step(result) {
|
|
208
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
209
|
+
}
|
|
210
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
var __generator = exports && exports.__generator || function(thisArg, body) {
|
|
214
|
+
var _ = { label: 0, sent: function() {
|
|
215
|
+
if (t[0] & 1) throw t[1];
|
|
216
|
+
return t[1];
|
|
217
|
+
}, trys: [], ops: [] }, f, y, t, g;
|
|
218
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
219
|
+
return this;
|
|
220
|
+
}), g;
|
|
221
|
+
function verb(n) {
|
|
222
|
+
return function(v) {
|
|
223
|
+
return step([n, v]);
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function step(op) {
|
|
227
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
228
|
+
while (_) try {
|
|
229
|
+
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;
|
|
230
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
231
|
+
switch (op[0]) {
|
|
232
|
+
case 0:
|
|
233
|
+
case 1:
|
|
234
|
+
t = op;
|
|
235
|
+
break;
|
|
236
|
+
case 4:
|
|
237
|
+
_.label++;
|
|
238
|
+
return { value: op[1], done: false };
|
|
239
|
+
case 5:
|
|
240
|
+
_.label++;
|
|
241
|
+
y = op[1];
|
|
242
|
+
op = [0];
|
|
243
|
+
continue;
|
|
244
|
+
case 7:
|
|
245
|
+
op = _.ops.pop();
|
|
246
|
+
_.trys.pop();
|
|
247
|
+
continue;
|
|
248
|
+
default:
|
|
249
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
250
|
+
_ = 0;
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
254
|
+
_.label = op[1];
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
258
|
+
_.label = t[1];
|
|
259
|
+
t = op;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
if (t && _.label < t[2]) {
|
|
263
|
+
_.label = t[2];
|
|
264
|
+
_.ops.push(op);
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
if (t[2]) _.ops.pop();
|
|
268
|
+
_.trys.pop();
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
op = body.call(thisArg, _);
|
|
272
|
+
} catch (e) {
|
|
273
|
+
op = [6, e];
|
|
274
|
+
y = 0;
|
|
275
|
+
} finally {
|
|
276
|
+
f = t = 0;
|
|
277
|
+
}
|
|
278
|
+
if (op[0] & 5) throw op[1];
|
|
279
|
+
return { value: op[0] ? op[1] : void 0, done: true };
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
283
|
+
var delay_base_1 = require_delay_base();
|
|
284
|
+
var SkipFirstDelay = (
|
|
285
|
+
/** @class */
|
|
286
|
+
function(_super) {
|
|
287
|
+
__extends(SkipFirstDelay2, _super);
|
|
288
|
+
function SkipFirstDelay2() {
|
|
289
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
290
|
+
}
|
|
291
|
+
SkipFirstDelay2.prototype.apply = function() {
|
|
292
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
293
|
+
return __generator(this, function(_a) {
|
|
294
|
+
return [2, this.isFirstAttempt ? true : _super.prototype.apply.call(this)];
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
Object.defineProperty(SkipFirstDelay2.prototype, "isFirstAttempt", {
|
|
299
|
+
get: function() {
|
|
300
|
+
return this.attempt === 0;
|
|
301
|
+
},
|
|
302
|
+
enumerable: true,
|
|
303
|
+
configurable: true
|
|
304
|
+
});
|
|
305
|
+
Object.defineProperty(SkipFirstDelay2.prototype, "numOfDelayedAttempts", {
|
|
306
|
+
get: function() {
|
|
307
|
+
return this.attempt - 1;
|
|
308
|
+
},
|
|
309
|
+
enumerable: true,
|
|
310
|
+
configurable: true
|
|
311
|
+
});
|
|
312
|
+
return SkipFirstDelay2;
|
|
313
|
+
}(delay_base_1.Delay)
|
|
314
|
+
);
|
|
315
|
+
exports.SkipFirstDelay = SkipFirstDelay;
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// node_modules/exponential-backoff/dist/delay/always/always.delay.js
|
|
320
|
+
var require_always_delay = __commonJS({
|
|
321
|
+
"node_modules/exponential-backoff/dist/delay/always/always.delay.js"(exports) {
|
|
322
|
+
"use strict";
|
|
323
|
+
var __extends = exports && exports.__extends || /* @__PURE__ */ function() {
|
|
324
|
+
var extendStatics = function(d, b) {
|
|
325
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
326
|
+
d2.__proto__ = b2;
|
|
327
|
+
} || function(d2, b2) {
|
|
328
|
+
for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p];
|
|
329
|
+
};
|
|
330
|
+
return extendStatics(d, b);
|
|
331
|
+
};
|
|
332
|
+
return function(d, b) {
|
|
333
|
+
extendStatics(d, b);
|
|
334
|
+
function __() {
|
|
335
|
+
this.constructor = d;
|
|
336
|
+
}
|
|
337
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
338
|
+
};
|
|
339
|
+
}();
|
|
340
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
341
|
+
var delay_base_1 = require_delay_base();
|
|
342
|
+
var AlwaysDelay = (
|
|
343
|
+
/** @class */
|
|
344
|
+
function(_super) {
|
|
345
|
+
__extends(AlwaysDelay2, _super);
|
|
346
|
+
function AlwaysDelay2() {
|
|
347
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
348
|
+
}
|
|
349
|
+
return AlwaysDelay2;
|
|
350
|
+
}(delay_base_1.Delay)
|
|
351
|
+
);
|
|
352
|
+
exports.AlwaysDelay = AlwaysDelay;
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
// node_modules/exponential-backoff/dist/delay/delay.factory.js
|
|
357
|
+
var require_delay_factory = __commonJS({
|
|
358
|
+
"node_modules/exponential-backoff/dist/delay/delay.factory.js"(exports) {
|
|
359
|
+
"use strict";
|
|
360
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
361
|
+
var skip_first_delay_1 = require_skip_first_delay();
|
|
362
|
+
var always_delay_1 = require_always_delay();
|
|
363
|
+
function DelayFactory(options, attempt) {
|
|
364
|
+
var delay = initDelayClass(options);
|
|
365
|
+
delay.setAttemptNumber(attempt);
|
|
366
|
+
return delay;
|
|
367
|
+
}
|
|
368
|
+
exports.DelayFactory = DelayFactory;
|
|
369
|
+
function initDelayClass(options) {
|
|
370
|
+
if (!options.delayFirstAttempt) {
|
|
371
|
+
return new skip_first_delay_1.SkipFirstDelay(options);
|
|
372
|
+
}
|
|
373
|
+
return new always_delay_1.AlwaysDelay(options);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
// node_modules/exponential-backoff/dist/backoff.js
|
|
379
|
+
var require_backoff = __commonJS({
|
|
380
|
+
"node_modules/exponential-backoff/dist/backoff.js"(exports) {
|
|
381
|
+
"use strict";
|
|
382
|
+
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
383
|
+
function adopt(value) {
|
|
384
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
385
|
+
resolve(value);
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
389
|
+
function fulfilled(value) {
|
|
390
|
+
try {
|
|
391
|
+
step(generator.next(value));
|
|
392
|
+
} catch (e) {
|
|
393
|
+
reject(e);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function rejected(value) {
|
|
397
|
+
try {
|
|
398
|
+
step(generator["throw"](value));
|
|
399
|
+
} catch (e) {
|
|
400
|
+
reject(e);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function step(result) {
|
|
404
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
405
|
+
}
|
|
406
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
407
|
+
});
|
|
408
|
+
};
|
|
409
|
+
var __generator = exports && exports.__generator || function(thisArg, body) {
|
|
410
|
+
var _ = { label: 0, sent: function() {
|
|
411
|
+
if (t[0] & 1) throw t[1];
|
|
412
|
+
return t[1];
|
|
413
|
+
}, trys: [], ops: [] }, f, y, t, g;
|
|
414
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
415
|
+
return this;
|
|
416
|
+
}), g;
|
|
417
|
+
function verb(n) {
|
|
418
|
+
return function(v) {
|
|
419
|
+
return step([n, v]);
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function step(op) {
|
|
423
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
424
|
+
while (_) try {
|
|
425
|
+
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;
|
|
426
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
427
|
+
switch (op[0]) {
|
|
428
|
+
case 0:
|
|
429
|
+
case 1:
|
|
430
|
+
t = op;
|
|
431
|
+
break;
|
|
432
|
+
case 4:
|
|
433
|
+
_.label++;
|
|
434
|
+
return { value: op[1], done: false };
|
|
435
|
+
case 5:
|
|
436
|
+
_.label++;
|
|
437
|
+
y = op[1];
|
|
438
|
+
op = [0];
|
|
439
|
+
continue;
|
|
440
|
+
case 7:
|
|
441
|
+
op = _.ops.pop();
|
|
442
|
+
_.trys.pop();
|
|
443
|
+
continue;
|
|
444
|
+
default:
|
|
445
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
446
|
+
_ = 0;
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
450
|
+
_.label = op[1];
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
454
|
+
_.label = t[1];
|
|
455
|
+
t = op;
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
if (t && _.label < t[2]) {
|
|
459
|
+
_.label = t[2];
|
|
460
|
+
_.ops.push(op);
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
if (t[2]) _.ops.pop();
|
|
464
|
+
_.trys.pop();
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
op = body.call(thisArg, _);
|
|
468
|
+
} catch (e) {
|
|
469
|
+
op = [6, e];
|
|
470
|
+
y = 0;
|
|
471
|
+
} finally {
|
|
472
|
+
f = t = 0;
|
|
473
|
+
}
|
|
474
|
+
if (op[0] & 5) throw op[1];
|
|
475
|
+
return { value: op[0] ? op[1] : void 0, done: true };
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
479
|
+
var options_1 = require_options();
|
|
480
|
+
var delay_factory_1 = require_delay_factory();
|
|
481
|
+
function backOff3(request, options) {
|
|
482
|
+
if (options === void 0) {
|
|
483
|
+
options = {};
|
|
484
|
+
}
|
|
485
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
486
|
+
var sanitizedOptions, backOff4;
|
|
487
|
+
return __generator(this, function(_a) {
|
|
488
|
+
switch (_a.label) {
|
|
489
|
+
case 0:
|
|
490
|
+
sanitizedOptions = options_1.getSanitizedOptions(options);
|
|
491
|
+
backOff4 = new BackOff(request, sanitizedOptions);
|
|
492
|
+
return [4, backOff4.execute()];
|
|
493
|
+
case 1:
|
|
494
|
+
return [2, _a.sent()];
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
exports.backOff = backOff3;
|
|
500
|
+
var BackOff = (
|
|
501
|
+
/** @class */
|
|
502
|
+
function() {
|
|
503
|
+
function BackOff2(request, options) {
|
|
504
|
+
this.request = request;
|
|
505
|
+
this.options = options;
|
|
506
|
+
this.attemptNumber = 0;
|
|
507
|
+
}
|
|
508
|
+
BackOff2.prototype.execute = function() {
|
|
509
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
510
|
+
var e_1, shouldRetry;
|
|
511
|
+
return __generator(this, function(_a) {
|
|
512
|
+
switch (_a.label) {
|
|
513
|
+
case 0:
|
|
514
|
+
if (!!this.attemptLimitReached) return [3, 7];
|
|
515
|
+
_a.label = 1;
|
|
516
|
+
case 1:
|
|
517
|
+
_a.trys.push([1, 4, , 6]);
|
|
518
|
+
return [4, this.applyDelay()];
|
|
519
|
+
case 2:
|
|
520
|
+
_a.sent();
|
|
521
|
+
return [4, this.request()];
|
|
522
|
+
case 3:
|
|
523
|
+
return [2, _a.sent()];
|
|
524
|
+
case 4:
|
|
525
|
+
e_1 = _a.sent();
|
|
526
|
+
this.attemptNumber++;
|
|
527
|
+
return [4, this.options.retry(e_1, this.attemptNumber)];
|
|
528
|
+
case 5:
|
|
529
|
+
shouldRetry = _a.sent();
|
|
530
|
+
if (!shouldRetry || this.attemptLimitReached) {
|
|
531
|
+
throw e_1;
|
|
532
|
+
}
|
|
533
|
+
return [3, 6];
|
|
534
|
+
case 6:
|
|
535
|
+
return [3, 0];
|
|
536
|
+
case 7:
|
|
537
|
+
throw new Error("Something went wrong.");
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
};
|
|
542
|
+
Object.defineProperty(BackOff2.prototype, "attemptLimitReached", {
|
|
543
|
+
get: function() {
|
|
544
|
+
return this.attemptNumber >= this.options.numOfAttempts;
|
|
545
|
+
},
|
|
546
|
+
enumerable: true,
|
|
547
|
+
configurable: true
|
|
548
|
+
});
|
|
549
|
+
BackOff2.prototype.applyDelay = function() {
|
|
550
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
551
|
+
var delay;
|
|
552
|
+
return __generator(this, function(_a) {
|
|
553
|
+
switch (_a.label) {
|
|
554
|
+
case 0:
|
|
555
|
+
delay = delay_factory_1.DelayFactory(this.options, this.attemptNumber);
|
|
556
|
+
return [4, delay.apply()];
|
|
557
|
+
case 1:
|
|
558
|
+
_a.sent();
|
|
559
|
+
return [
|
|
560
|
+
2
|
|
561
|
+
/*return*/
|
|
562
|
+
];
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
};
|
|
567
|
+
return BackOff2;
|
|
568
|
+
}()
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
// src/ari-client/ariClient.ts
|
|
574
|
+
var import_exponential_backoff2 = __toESM(require_backoff(), 1);
|
|
575
|
+
|
|
1
576
|
// src/ari-client/baseClient.ts
|
|
2
577
|
import { EventEmitter } from "events";
|
|
3
578
|
import axios from "axios";
|
|
@@ -323,16 +898,12 @@ function toQueryParams2(options) {
|
|
|
323
898
|
Object.entries(options).filter(([, value]) => value !== void 0).map(([key, value]) => [key, value])
|
|
324
899
|
).toString();
|
|
325
900
|
}
|
|
901
|
+
function isPlaybackEvent(event, playbackId) {
|
|
902
|
+
return event.type.startsWith("Playback") && "playbackId" in event && event.playbackId !== void 0 && (!playbackId || event.playbackId === playbackId);
|
|
903
|
+
}
|
|
326
904
|
function isChannelEvent(event, channelId) {
|
|
327
905
|
const hasChannel = "channel" in event && event.channel?.id !== void 0;
|
|
328
|
-
|
|
329
|
-
if (!hasChannel || channelId && !matchesChannelId) {
|
|
330
|
-
console.log(
|
|
331
|
-
`Evento ignorado no isChannelEvent: tipo=${event.type}, canal esperado=${channelId}, evento recebido=`,
|
|
332
|
-
event
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
return matchesChannelId;
|
|
906
|
+
return hasChannel && (!channelId || event.channel?.id === channelId);
|
|
336
907
|
}
|
|
337
908
|
|
|
338
909
|
// src/ari-client/resources/channels.ts
|
|
@@ -569,7 +1140,7 @@ var Channels = class extends EventEmitter2 {
|
|
|
569
1140
|
this.baseClient = baseClient;
|
|
570
1141
|
this.client = client;
|
|
571
1142
|
}
|
|
572
|
-
|
|
1143
|
+
Channel(channelId) {
|
|
573
1144
|
return new ChannelInstance(this.client, this.baseClient, channelId);
|
|
574
1145
|
}
|
|
575
1146
|
/**
|
|
@@ -800,14 +1371,15 @@ var Endpoints = class {
|
|
|
800
1371
|
import { EventEmitter as EventEmitter3 } from "events";
|
|
801
1372
|
var PlaybackInstance = class extends EventEmitter3 {
|
|
802
1373
|
// Garantimos que o ID esteja disponível
|
|
803
|
-
constructor(baseClient, playbackId) {
|
|
1374
|
+
constructor(client, baseClient, playbackId) {
|
|
804
1375
|
super();
|
|
1376
|
+
this.client = client;
|
|
805
1377
|
this.baseClient = baseClient;
|
|
806
1378
|
this.playbackId = playbackId;
|
|
807
1379
|
this.id = playbackId || `playback-${Date.now()}`;
|
|
808
|
-
const wsClients = this.
|
|
1380
|
+
const wsClients = this.client.getWebSocketClients();
|
|
809
1381
|
const wsClient = Array.from(wsClients.values()).find(
|
|
810
|
-
(
|
|
1382
|
+
(client2) => client2.isConnected()
|
|
811
1383
|
);
|
|
812
1384
|
if (!wsClient) {
|
|
813
1385
|
throw new Error(
|
|
@@ -815,31 +1387,14 @@ var PlaybackInstance = class extends EventEmitter3 {
|
|
|
815
1387
|
);
|
|
816
1388
|
}
|
|
817
1389
|
wsClient.on("message", (event) => {
|
|
818
|
-
if (
|
|
819
|
-
console.log(
|
|
820
|
-
`Evento recebido no PlaybackInstance: ${event.type}`,
|
|
821
|
-
event
|
|
822
|
-
);
|
|
1390
|
+
if (isPlaybackEvent(event, this.id)) {
|
|
1391
|
+
console.log(`Evento recebido no ChannelInstance: ${event.type}`, event);
|
|
823
1392
|
this.emit(event.type, event);
|
|
824
1393
|
}
|
|
825
1394
|
});
|
|
826
1395
|
}
|
|
827
1396
|
playbackData = null;
|
|
828
1397
|
id;
|
|
829
|
-
/**
|
|
830
|
-
* Verifica se o evento é relacionado a um playback.
|
|
831
|
-
*/
|
|
832
|
-
isPlaybackEvent(event) {
|
|
833
|
-
const isPlaybackType = event?.type.startsWith("Playback");
|
|
834
|
-
const isPlaybackEvent = isPlaybackType && "playbackId" in event && event.playbackId === this.id;
|
|
835
|
-
if (!isPlaybackEvent) {
|
|
836
|
-
console.log(
|
|
837
|
-
`Evento ignorado no isPlaybackEvent: tipo=${event.type}, playback esperado=${this.id}, evento recebido=`,
|
|
838
|
-
event
|
|
839
|
-
);
|
|
840
|
-
}
|
|
841
|
-
return isPlaybackEvent;
|
|
842
|
-
}
|
|
843
1398
|
/**
|
|
844
1399
|
* Obtém os detalhes do playback.
|
|
845
1400
|
*/
|
|
@@ -894,38 +1449,23 @@ var PlaybackInstance = class extends EventEmitter3 {
|
|
|
894
1449
|
}
|
|
895
1450
|
};
|
|
896
1451
|
var Playbacks = class extends EventEmitter3 {
|
|
897
|
-
constructor(client) {
|
|
1452
|
+
constructor(baseClient, client) {
|
|
898
1453
|
super();
|
|
1454
|
+
this.baseClient = baseClient;
|
|
899
1455
|
this.client = client;
|
|
900
|
-
this.client.onWebSocketEvent((event) => {
|
|
901
|
-
if (this.isPlaybackEvent(event)) {
|
|
902
|
-
const playbackId = event.playbackId;
|
|
903
|
-
if (playbackId) {
|
|
904
|
-
this.emit(`${event.type}:${playbackId}`, event);
|
|
905
|
-
}
|
|
906
|
-
this.emit(event.type, event);
|
|
907
|
-
}
|
|
908
|
-
});
|
|
909
|
-
}
|
|
910
|
-
/**
|
|
911
|
-
* Obtém os clientes WebSocket disponíveis.
|
|
912
|
-
*/
|
|
913
|
-
getWebSocketClients() {
|
|
914
|
-
return this.client.getWebSocketClients();
|
|
915
|
-
}
|
|
916
|
-
/**
|
|
917
|
-
* Verifica se o evento é relacionado a um playback.
|
|
918
|
-
*/
|
|
919
|
-
isPlaybackEvent(event) {
|
|
920
|
-
console.log({ eventAri: event });
|
|
921
|
-
return event && typeof event === "object" && "playbackId" in event;
|
|
922
1456
|
}
|
|
923
1457
|
/**
|
|
924
1458
|
* Inicializa uma nova instância de `PlaybackInstance`.
|
|
925
1459
|
*/
|
|
926
1460
|
Playback(playbackId) {
|
|
927
1461
|
const id = playbackId || `playback-${Date.now()}`;
|
|
928
|
-
return new PlaybackInstance(this.client, id);
|
|
1462
|
+
return new PlaybackInstance(this.client, this.baseClient, id);
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* Obtém os clientes WebSocket disponíveis.
|
|
1466
|
+
*/
|
|
1467
|
+
getWebSocketClients() {
|
|
1468
|
+
return this.client.getWebSocketClients();
|
|
929
1469
|
}
|
|
930
1470
|
/**
|
|
931
1471
|
* Emite eventos de playback.
|
|
@@ -947,7 +1487,7 @@ var Playbacks = class extends EventEmitter3 {
|
|
|
947
1487
|
* @returns A promise that resolves to a Playback object containing the details of the specified playback.
|
|
948
1488
|
*/
|
|
949
1489
|
async getDetails(playbackId) {
|
|
950
|
-
return this.
|
|
1490
|
+
return this.baseClient.get(`/playbacks/${playbackId}`);
|
|
951
1491
|
}
|
|
952
1492
|
/**
|
|
953
1493
|
* Controls a specific playback by performing various operations such as pause, resume, restart, reverse, forward, or stop.
|
|
@@ -963,7 +1503,7 @@ var Playbacks = class extends EventEmitter3 {
|
|
|
963
1503
|
* @returns A promise that resolves when the control operation is successfully executed.
|
|
964
1504
|
*/
|
|
965
1505
|
async control(playbackId, operation) {
|
|
966
|
-
await this.
|
|
1506
|
+
await this.baseClient.post(
|
|
967
1507
|
`/playbacks/${playbackId}/control?operation=${operation}`
|
|
968
1508
|
);
|
|
969
1509
|
}
|
|
@@ -974,7 +1514,7 @@ var Playbacks = class extends EventEmitter3 {
|
|
|
974
1514
|
* @returns A promise that resolves when the playback is successfully stopped.
|
|
975
1515
|
*/
|
|
976
1516
|
async stop(playbackId) {
|
|
977
|
-
await this.
|
|
1517
|
+
await this.baseClient.delete(`/playbacks/${playbackId}`);
|
|
978
1518
|
}
|
|
979
1519
|
/**
|
|
980
1520
|
* Registers a listener for playback events.
|
|
@@ -1041,9 +1581,11 @@ var Sounds = class {
|
|
|
1041
1581
|
};
|
|
1042
1582
|
|
|
1043
1583
|
// src/ari-client/websocketClient.ts
|
|
1584
|
+
var import_exponential_backoff = __toESM(require_backoff(), 1);
|
|
1044
1585
|
import { EventEmitter as EventEmitter4 } from "events";
|
|
1045
1586
|
import WebSocket from "ws";
|
|
1046
1587
|
var WebSocketClient = class extends EventEmitter4 {
|
|
1588
|
+
// Para gerenciar tentativas de reconexão
|
|
1047
1589
|
/**
|
|
1048
1590
|
* Creates a new WebSocketClient instance.
|
|
1049
1591
|
* @param url - The WebSocket server URL to connect to.
|
|
@@ -1056,6 +1598,44 @@ var WebSocketClient = class extends EventEmitter4 {
|
|
|
1056
1598
|
isClosedManually = false;
|
|
1057
1599
|
isReconnecting = false;
|
|
1058
1600
|
messageListeners = [];
|
|
1601
|
+
maxReconnectAttempts = 30;
|
|
1602
|
+
reconnectAttempts = 0;
|
|
1603
|
+
async reconnect() {
|
|
1604
|
+
console.log("Iniciando processo de reconex\xE3o...");
|
|
1605
|
+
const backoffOptions = {
|
|
1606
|
+
delayFirstAttempt: false,
|
|
1607
|
+
startingDelay: 1e3,
|
|
1608
|
+
// 1 segundo inicial
|
|
1609
|
+
timeMultiple: 2,
|
|
1610
|
+
// Multiplicador exponencial
|
|
1611
|
+
maxDelay: 3e4,
|
|
1612
|
+
// 30 segundos de atraso máximo
|
|
1613
|
+
numOfAttempts: this.maxReconnectAttempts,
|
|
1614
|
+
// Limite de tentativas
|
|
1615
|
+
jitter: "full",
|
|
1616
|
+
retry: (error, attemptNumber) => {
|
|
1617
|
+
console.warn(
|
|
1618
|
+
`Tentativa ${attemptNumber} de reconex\xE3o falhou: ${error.message}`
|
|
1619
|
+
);
|
|
1620
|
+
return !this.isClosedManually;
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
try {
|
|
1624
|
+
await (0, import_exponential_backoff.backOff)(async () => {
|
|
1625
|
+
console.log(`Tentando reconectar (#${this.reconnectAttempts + 1})...`);
|
|
1626
|
+
await this.connect();
|
|
1627
|
+
console.log("Reconex\xE3o bem-sucedida.");
|
|
1628
|
+
}, backoffOptions);
|
|
1629
|
+
this.reconnectAttempts = 0;
|
|
1630
|
+
this.isReconnecting = false;
|
|
1631
|
+
} catch (error) {
|
|
1632
|
+
console.error(
|
|
1633
|
+
`Reconex\xE3o falhou ap\xF3s ${this.maxReconnectAttempts} tentativas.`,
|
|
1634
|
+
error
|
|
1635
|
+
);
|
|
1636
|
+
this.isReconnecting = false;
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1059
1639
|
/**
|
|
1060
1640
|
* Establishes a connection to the WebSocket server.
|
|
1061
1641
|
* @returns A Promise that resolves when the connection is established, or rejects if an error occurs.
|
|
@@ -1069,6 +1649,7 @@ var WebSocketClient = class extends EventEmitter4 {
|
|
|
1069
1649
|
console.log("WebSocket conectado.");
|
|
1070
1650
|
this.isClosedManually = false;
|
|
1071
1651
|
this.isReconnecting = false;
|
|
1652
|
+
this.reconnectAttempts = 0;
|
|
1072
1653
|
resolve();
|
|
1073
1654
|
});
|
|
1074
1655
|
this.ws.on("error", (err) => {
|
|
@@ -1077,8 +1658,10 @@ var WebSocketClient = class extends EventEmitter4 {
|
|
|
1077
1658
|
});
|
|
1078
1659
|
this.ws.on("close", (code, reason) => {
|
|
1079
1660
|
console.warn(`WebSocket desconectado: ${code} - ${reason}`);
|
|
1080
|
-
this.isReconnecting = false;
|
|
1081
1661
|
this.emit("close", { code, reason });
|
|
1662
|
+
if (!this.isClosedManually) {
|
|
1663
|
+
this.reconnect();
|
|
1664
|
+
}
|
|
1082
1665
|
});
|
|
1083
1666
|
this.ws.on("message", (rawData) => {
|
|
1084
1667
|
this.handleMessage(rawData);
|
|
@@ -1178,9 +1761,9 @@ var AriClient = class {
|
|
|
1178
1761
|
const baseUrl = `${httpProtocol}://${normalizedHost}:${config.port}/ari`;
|
|
1179
1762
|
this.baseClient = new BaseClient(baseUrl, config.username, config.password);
|
|
1180
1763
|
this.channels = new Channels(this.baseClient, this);
|
|
1764
|
+
this.playbacks = new Playbacks(this.baseClient, this);
|
|
1181
1765
|
this.endpoints = new Endpoints(this.baseClient);
|
|
1182
1766
|
this.applications = new Applications(this.baseClient);
|
|
1183
|
-
this.playbacks = new Playbacks(this.baseClient);
|
|
1184
1767
|
this.sounds = new Sounds(this.baseClient);
|
|
1185
1768
|
this.asterisk = new Asterisk(this.baseClient);
|
|
1186
1769
|
this.bridges = new Bridges(this.baseClient);
|
|
@@ -1203,11 +1786,27 @@ var AriClient = class {
|
|
|
1203
1786
|
}
|
|
1204
1787
|
while (this.pendingListeners.length > 0) {
|
|
1205
1788
|
const { event, callback } = this.pendingListeners.shift();
|
|
1789
|
+
if (wsClient.listenerCount(event) > 0) {
|
|
1790
|
+
console.log(
|
|
1791
|
+
`Listener j\xE1 registrado para o evento '${event}' no app '${app}'. Ignorando duplicata.`
|
|
1792
|
+
);
|
|
1793
|
+
continue;
|
|
1794
|
+
}
|
|
1206
1795
|
console.log(`Registrando listener para '${app}' no evento: ${event}`);
|
|
1207
1796
|
wsClient.on(event, callback);
|
|
1208
1797
|
}
|
|
1209
1798
|
}
|
|
1210
1799
|
}
|
|
1800
|
+
async reconnectWebSocket(app) {
|
|
1801
|
+
console.log(`Tentando reconectar o WebSocket para o app '${app}'...`);
|
|
1802
|
+
try {
|
|
1803
|
+
await this.connectSingleWebSocket(app);
|
|
1804
|
+
this.processPendingListeners();
|
|
1805
|
+
console.log(`Reconex\xE3o bem-sucedida para o app '${app}'.`);
|
|
1806
|
+
} catch (error) {
|
|
1807
|
+
console.error(`Erro ao reconectar o WebSocket para '${app}':`, error);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1211
1810
|
channels;
|
|
1212
1811
|
endpoints;
|
|
1213
1812
|
applications;
|
|
@@ -1219,24 +1818,6 @@ var AriClient = class {
|
|
|
1219
1818
|
getWebSocketClients() {
|
|
1220
1819
|
return this.wsClients;
|
|
1221
1820
|
}
|
|
1222
|
-
/**
|
|
1223
|
-
* Registra um listener para eventos de WebSocket relacionados a canais.
|
|
1224
|
-
* @param eventType Tipo de evento.
|
|
1225
|
-
* @param callback Callback a ser executado quando o evento for recebido.
|
|
1226
|
-
*/
|
|
1227
|
-
onChannelEvent(eventType, callback) {
|
|
1228
|
-
if (this.wsClients.size === 0) {
|
|
1229
|
-
console.warn(
|
|
1230
|
-
"Nenhuma conex\xE3o WebSocket est\xE1 ativa. O listener ser\xE1 pendente."
|
|
1231
|
-
);
|
|
1232
|
-
this.pendingListeners.push({ event: eventType, callback });
|
|
1233
|
-
return;
|
|
1234
|
-
}
|
|
1235
|
-
for (const [app, wsClient] of this.wsClients.entries()) {
|
|
1236
|
-
console.log(`Registrando evento '${eventType}' no app '${app}'`);
|
|
1237
|
-
wsClient.on(eventType, callback);
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
1821
|
/**
|
|
1241
1822
|
* Registra listeners globais para eventos de WebSocket.
|
|
1242
1823
|
*/
|
|
@@ -1274,7 +1855,7 @@ var AriClient = class {
|
|
|
1274
1855
|
}
|
|
1275
1856
|
// Método para criar uma instância de ChannelInstance
|
|
1276
1857
|
createChannelInstance(channelId) {
|
|
1277
|
-
return this.channels.
|
|
1858
|
+
return this.channels.Channel(channelId);
|
|
1278
1859
|
}
|
|
1279
1860
|
handleWebSocketEvent(event) {
|
|
1280
1861
|
console.log("Evento recebido no WebSocket:", event.type, event);
|
|
@@ -1338,26 +1919,58 @@ var AriClient = class {
|
|
|
1338
1919
|
if (!app) {
|
|
1339
1920
|
throw new Error("O nome do aplicativo \xE9 obrigat\xF3rio.");
|
|
1340
1921
|
}
|
|
1341
|
-
if (this.
|
|
1342
|
-
console.log(`Conex\xE3o WebSocket para '${app}' j\xE1
|
|
1343
|
-
return;
|
|
1922
|
+
if (this.webSocketReady.get(app)) {
|
|
1923
|
+
console.log(`Conex\xE3o WebSocket para '${app}' j\xE1 est\xE1 ativa.`);
|
|
1924
|
+
return this.webSocketReady.get(app);
|
|
1344
1925
|
}
|
|
1345
1926
|
const protocol = this.config.secure ? "wss" : "ws";
|
|
1346
1927
|
const eventsParam = subscribedEvents && subscribedEvents.length > 0 ? `&event=${subscribedEvents.join(",")}` : "&subscribeAll=true";
|
|
1347
1928
|
const wsUrl = `${protocol}://${encodeURIComponent(
|
|
1348
1929
|
this.config.username
|
|
1349
1930
|
)}:${encodeURIComponent(this.config.password)}@${this.config.host}:${this.config.port}/ari/events?app=${app}${eventsParam}`;
|
|
1350
|
-
const
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1931
|
+
const backoffOptions = {
|
|
1932
|
+
delayFirstAttempt: false,
|
|
1933
|
+
startingDelay: 1e3,
|
|
1934
|
+
timeMultiple: 2,
|
|
1935
|
+
maxDelay: 3e4,
|
|
1936
|
+
numOfAttempts: 10,
|
|
1937
|
+
jitter: "full",
|
|
1938
|
+
retry: (error, attemptNumber) => {
|
|
1939
|
+
console.warn(
|
|
1940
|
+
`Tentativa ${attemptNumber} falhou para '${app}': ${error.message}`
|
|
1941
|
+
);
|
|
1942
|
+
return !this.wsClients.has(app) || !this.wsClients.get(app)?.isConnected();
|
|
1943
|
+
}
|
|
1944
|
+
};
|
|
1945
|
+
const webSocketPromise = new Promise(async (resolve, reject) => {
|
|
1946
|
+
try {
|
|
1947
|
+
if (this.isReconnecting.get(app)) {
|
|
1948
|
+
console.warn(`J\xE1 est\xE1 tentando reconectar para o app '${app}'.`);
|
|
1949
|
+
return;
|
|
1950
|
+
}
|
|
1951
|
+
this.isReconnecting.set(app, true);
|
|
1952
|
+
const wsClient = new WebSocketClient(wsUrl);
|
|
1953
|
+
await (0, import_exponential_backoff2.backOff)(async () => {
|
|
1954
|
+
if (!wsClient) {
|
|
1955
|
+
throw new Error("WebSocketClient instance is null.");
|
|
1956
|
+
}
|
|
1957
|
+
await wsClient.connect();
|
|
1958
|
+
console.log(`WebSocket conectado para o app: ${app}`);
|
|
1959
|
+
this.integrateWebSocketEvents(app, wsClient);
|
|
1960
|
+
await this.ensureAppRegistered(app);
|
|
1961
|
+
this.wsClients.set(app, wsClient);
|
|
1962
|
+
this.processPendingListeners();
|
|
1963
|
+
}, backoffOptions);
|
|
1964
|
+
resolve();
|
|
1965
|
+
} catch (error) {
|
|
1966
|
+
console.error(`Erro ao conectar WebSocket para '${app}':`, error);
|
|
1967
|
+
reject(error);
|
|
1968
|
+
} finally {
|
|
1969
|
+
this.isReconnecting.delete(app);
|
|
1970
|
+
}
|
|
1971
|
+
});
|
|
1972
|
+
this.webSocketReady.set(app, webSocketPromise);
|
|
1973
|
+
return webSocketPromise;
|
|
1361
1974
|
}
|
|
1362
1975
|
/**
|
|
1363
1976
|
* Integrates WebSocket events with playback listeners.
|
|
@@ -1470,465 +2083,6 @@ var AriClient = class {
|
|
|
1470
2083
|
this.wsClients.clear();
|
|
1471
2084
|
console.log("Todos os WebSockets foram fechados.");
|
|
1472
2085
|
}
|
|
1473
|
-
/**
|
|
1474
|
-
* Retrieves a list of active channels from the Asterisk ARI.
|
|
1475
|
-
*
|
|
1476
|
-
* @returns {Promise<Channel[]>} A promise resolving to the list of active channels.
|
|
1477
|
-
*/
|
|
1478
|
-
/**
|
|
1479
|
-
* Lists all active channels.
|
|
1480
|
-
*/
|
|
1481
|
-
async listChannels() {
|
|
1482
|
-
return this.channels.list();
|
|
1483
|
-
}
|
|
1484
|
-
async hangupChannel(channelId) {
|
|
1485
|
-
return this.channels.hangup(channelId);
|
|
1486
|
-
}
|
|
1487
|
-
/**
|
|
1488
|
-
* Creates a new channel.
|
|
1489
|
-
*/
|
|
1490
|
-
async originateChannel(data) {
|
|
1491
|
-
return this.channels.originate(data);
|
|
1492
|
-
}
|
|
1493
|
-
/**
|
|
1494
|
-
* Continues the dialplan for a specific channel.
|
|
1495
|
-
*/
|
|
1496
|
-
async continueChannelDialplan(channelId, context, extension, priority, label) {
|
|
1497
|
-
return this.channels.continueDialplan(
|
|
1498
|
-
channelId,
|
|
1499
|
-
context,
|
|
1500
|
-
extension,
|
|
1501
|
-
priority,
|
|
1502
|
-
label
|
|
1503
|
-
);
|
|
1504
|
-
}
|
|
1505
|
-
/**
|
|
1506
|
-
* Moves a channel to another Stasis application.
|
|
1507
|
-
*/
|
|
1508
|
-
async moveChannelToApplication(channelId, app, appArgs) {
|
|
1509
|
-
return this.channels.moveToApplication(channelId, app, appArgs);
|
|
1510
|
-
}
|
|
1511
|
-
/**
|
|
1512
|
-
* Sets a channel variable.
|
|
1513
|
-
*/
|
|
1514
|
-
async setChannelVariable(channelId, variable, value) {
|
|
1515
|
-
return this.channels.setChannelVariable(channelId, variable, value);
|
|
1516
|
-
}
|
|
1517
|
-
/**
|
|
1518
|
-
* Gets a channel variable.
|
|
1519
|
-
*/
|
|
1520
|
-
async getChannelVariable(channelId, variable) {
|
|
1521
|
-
return this.channels.getChannelVariable(channelId, variable);
|
|
1522
|
-
}
|
|
1523
|
-
/**
|
|
1524
|
-
* Starts music on hold for a channel.
|
|
1525
|
-
*/
|
|
1526
|
-
async startChannelMusicOnHold(channelId) {
|
|
1527
|
-
return this.channels.startMusicOnHold(channelId);
|
|
1528
|
-
}
|
|
1529
|
-
/**
|
|
1530
|
-
* Stops music on hold for a channel.
|
|
1531
|
-
*/
|
|
1532
|
-
async stopChannelMusicOnHold(channelId) {
|
|
1533
|
-
return this.channels.stopMusicOnHold(channelId);
|
|
1534
|
-
}
|
|
1535
|
-
/**
|
|
1536
|
-
* Records audio from a channel.
|
|
1537
|
-
*/
|
|
1538
|
-
async recordAudio(channelId, options) {
|
|
1539
|
-
return this.channels.record(channelId, options);
|
|
1540
|
-
}
|
|
1541
|
-
/**
|
|
1542
|
-
* Starts snooping on a channel.
|
|
1543
|
-
*/
|
|
1544
|
-
async snoopChannel(channelId, options) {
|
|
1545
|
-
return this.channels.snoopChannel(channelId, options);
|
|
1546
|
-
}
|
|
1547
|
-
/**
|
|
1548
|
-
* Starts snooping on a channel with a specific snoop ID.
|
|
1549
|
-
*/
|
|
1550
|
-
async snoopChannelWithId(channelId, snoopId, options) {
|
|
1551
|
-
return this.channels.snoopChannelWithId(channelId, snoopId, options);
|
|
1552
|
-
}
|
|
1553
|
-
/**
|
|
1554
|
-
* Initiates a dial operation on a previously created channel.
|
|
1555
|
-
* This function attempts to connect the specified channel to its configured destination.
|
|
1556
|
-
*
|
|
1557
|
-
* @param channelId - The unique identifier of the channel to dial.
|
|
1558
|
-
* @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.
|
|
1559
|
-
* @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.
|
|
1560
|
-
* @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.
|
|
1561
|
-
* @throws Will throw an error if the dial operation fails, e.g., if the channel doesn't exist or is in an invalid state.
|
|
1562
|
-
*/
|
|
1563
|
-
async dialChannel(channelId, caller, timeout) {
|
|
1564
|
-
return this.channels.dial(channelId, caller, timeout);
|
|
1565
|
-
}
|
|
1566
|
-
/**
|
|
1567
|
-
* Retrieves RTP statistics for a channel.
|
|
1568
|
-
*/
|
|
1569
|
-
async getRTPStatistics(channelId) {
|
|
1570
|
-
return this.channels.getRTPStatistics(channelId);
|
|
1571
|
-
}
|
|
1572
|
-
/**
|
|
1573
|
-
* Creates a channel to an external media source/sink.
|
|
1574
|
-
*/
|
|
1575
|
-
async createExternalMedia(options) {
|
|
1576
|
-
return this.channels.createExternalMedia(options);
|
|
1577
|
-
}
|
|
1578
|
-
/**
|
|
1579
|
-
* Redirects a channel to a different location.
|
|
1580
|
-
*/
|
|
1581
|
-
async redirectChannel(channelId, endpoint) {
|
|
1582
|
-
return this.channels.redirectChannel(channelId, endpoint);
|
|
1583
|
-
}
|
|
1584
|
-
/**
|
|
1585
|
-
* Sends a ringing indication to a channel.
|
|
1586
|
-
*/
|
|
1587
|
-
async ringChannel(channelId) {
|
|
1588
|
-
return this.channels.ringChannel(channelId);
|
|
1589
|
-
}
|
|
1590
|
-
/**
|
|
1591
|
-
* Stops the ringing indication on a specified channel in the Asterisk system.
|
|
1592
|
-
*
|
|
1593
|
-
* This function sends a request to the Asterisk server to cease the ringing
|
|
1594
|
-
* indication on a particular channel. This is typically used when you want to
|
|
1595
|
-
* stop the ringing sound on a channel without answering or hanging up the call.
|
|
1596
|
-
*
|
|
1597
|
-
* @param channelId - The unique identifier of the channel on which to stop the ringing.
|
|
1598
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1599
|
-
*
|
|
1600
|
-
* @returns A Promise that resolves when the ringing has been successfully stopped on the specified channel.
|
|
1601
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1602
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1603
|
-
*/
|
|
1604
|
-
async stopRingChannel(channelId) {
|
|
1605
|
-
return this.channels.stopRingChannel(channelId);
|
|
1606
|
-
}
|
|
1607
|
-
/**
|
|
1608
|
-
* Sends DTMF (Dual-Tone Multi-Frequency) tones to a specified channel.
|
|
1609
|
-
*
|
|
1610
|
-
* This function allows sending DTMF tones to a channel, which can be used for various purposes
|
|
1611
|
-
* such as interacting with IVR systems or sending signals during a call.
|
|
1612
|
-
*
|
|
1613
|
-
* @param channelId - The unique identifier of the channel to send DTMF tones to.
|
|
1614
|
-
* @param dtmf - A string representing the DTMF tones to send (e.g., "123#").
|
|
1615
|
-
* @param options - Optional parameters to control the timing of DTMF tones.
|
|
1616
|
-
* @param options.before - The time (in milliseconds) to wait before sending DTMF.
|
|
1617
|
-
* @param options.between - The time (in milliseconds) to wait between each DTMF tone.
|
|
1618
|
-
* @param options.duration - The duration (in milliseconds) of each DTMF tone.
|
|
1619
|
-
* @param options.after - The time (in milliseconds) to wait after sending all DTMF tones.
|
|
1620
|
-
* @returns A Promise that resolves when the DTMF tones have been successfully sent.
|
|
1621
|
-
*/
|
|
1622
|
-
async sendDTMF(channelId, dtmf, options) {
|
|
1623
|
-
return this.channels.sendDTMF(channelId, dtmf, options);
|
|
1624
|
-
}
|
|
1625
|
-
/**
|
|
1626
|
-
* Mutes a channel in the Asterisk system.
|
|
1627
|
-
*
|
|
1628
|
-
* This function initiates a mute operation on the specified channel, preventing
|
|
1629
|
-
* audio transmission in the specified direction(s).
|
|
1630
|
-
*
|
|
1631
|
-
* @param channelId - The unique identifier of the channel to be muted.
|
|
1632
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1633
|
-
* @param direction - The direction of audio to mute. Can be one of:
|
|
1634
|
-
* - "both": Mute both incoming and outgoing audio (default)
|
|
1635
|
-
* - "in": Mute only incoming audio
|
|
1636
|
-
* - "out": Mute only outgoing audio
|
|
1637
|
-
*
|
|
1638
|
-
* @returns A Promise that resolves when the mute operation has been successfully completed.
|
|
1639
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1640
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1641
|
-
*/
|
|
1642
|
-
async muteChannel(channelId, direction = "both") {
|
|
1643
|
-
return this.channels.muteChannel(channelId, direction);
|
|
1644
|
-
}
|
|
1645
|
-
/**
|
|
1646
|
-
* Unmutes a channel in the Asterisk system.
|
|
1647
|
-
*
|
|
1648
|
-
* This function removes the mute status from a specified channel, allowing audio
|
|
1649
|
-
* transmission to resume in the specified direction(s).
|
|
1650
|
-
*
|
|
1651
|
-
* @param channelId - The unique identifier of the channel to be unmuted.
|
|
1652
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1653
|
-
* @param direction - The direction of audio to unmute. Can be one of:
|
|
1654
|
-
* - "both": Unmute both incoming and outgoing audio (default)
|
|
1655
|
-
* - "in": Unmute only incoming audio
|
|
1656
|
-
* - "out": Unmute only outgoing audio
|
|
1657
|
-
*
|
|
1658
|
-
* @returns A Promise that resolves when the unmute operation has been successfully completed.
|
|
1659
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1660
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1661
|
-
*/
|
|
1662
|
-
async unmuteChannel(channelId, direction = "both") {
|
|
1663
|
-
return this.channels.unmuteChannel(channelId, direction);
|
|
1664
|
-
}
|
|
1665
|
-
/**
|
|
1666
|
-
* Puts a specified channel on hold.
|
|
1667
|
-
*
|
|
1668
|
-
* This function initiates a hold operation on the specified channel in the Asterisk system.
|
|
1669
|
-
* When a channel is put on hold, typically the audio is muted or replaced with hold music,
|
|
1670
|
-
* depending on the system configuration.
|
|
1671
|
-
*
|
|
1672
|
-
* @param channelId - The unique identifier of the channel to be put on hold.
|
|
1673
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1674
|
-
*
|
|
1675
|
-
* @returns A Promise that resolves when the hold operation has been successfully initiated.
|
|
1676
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1677
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1678
|
-
*/
|
|
1679
|
-
async holdChannel(channelId) {
|
|
1680
|
-
return this.channels.holdChannel(channelId);
|
|
1681
|
-
}
|
|
1682
|
-
/**
|
|
1683
|
-
* Removes a specified channel from hold.
|
|
1684
|
-
*
|
|
1685
|
-
* This function initiates an unhold operation on the specified channel in the Asterisk system.
|
|
1686
|
-
* When a channel is taken off hold, it typically resumes normal audio transmission,
|
|
1687
|
-
* allowing the parties to continue their conversation.
|
|
1688
|
-
*
|
|
1689
|
-
* @param channelId - The unique identifier of the channel to be taken off hold.
|
|
1690
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1691
|
-
*
|
|
1692
|
-
* @returns A Promise that resolves when the unhold operation has been successfully initiated.
|
|
1693
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1694
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1695
|
-
*/
|
|
1696
|
-
async unholdChannel(channelId) {
|
|
1697
|
-
return this.channels.unholdChannel(channelId);
|
|
1698
|
-
}
|
|
1699
|
-
/**
|
|
1700
|
-
* Creates a new channel in the Asterisk system using the provided originate request data.
|
|
1701
|
-
* This function initiates a new communication channel based on the specified parameters.
|
|
1702
|
-
*
|
|
1703
|
-
* @param data - An object containing the originate request data for channel creation.
|
|
1704
|
-
* This includes details such as the endpoint to call, the context to use,
|
|
1705
|
-
* and any variables to set on the new channel.
|
|
1706
|
-
* @param data.endpoint - The endpoint to call (e.g., "SIP/1234").
|
|
1707
|
-
* @param data.extension - The extension to dial after the channel is created.
|
|
1708
|
-
* @param data.context - The dialplan context to use for the new channel.
|
|
1709
|
-
* @param data.priority - The priority to start at in the dialplan.
|
|
1710
|
-
* @param data.app - The application to execute on the channel (alternative to extension/context/priority).
|
|
1711
|
-
* @param data.appArgs - The arguments to pass to the application, if 'app' is specified.
|
|
1712
|
-
* @param data.callerId - The caller ID to set on the new channel.
|
|
1713
|
-
* @param data.timeout - The timeout (in seconds) to wait for the channel to be answered.
|
|
1714
|
-
* @param data.variables - An object containing key-value pairs of channel variables to set.
|
|
1715
|
-
* @param data.channelId - An optional ID to assign to the new channel.
|
|
1716
|
-
* @param data.otherChannelId - The ID of another channel to bridge with after creation.
|
|
1717
|
-
*
|
|
1718
|
-
* @returns A Promise that resolves to the created Channel object.
|
|
1719
|
-
* The Channel object contains details about the newly created channel,
|
|
1720
|
-
* such as its unique identifier, state, and other relevant information.
|
|
1721
|
-
*
|
|
1722
|
-
* @throws Will throw an error if the channel creation fails for any reason,
|
|
1723
|
-
* such as invalid parameters or system issues.
|
|
1724
|
-
*/
|
|
1725
|
-
async createChannel(data) {
|
|
1726
|
-
return this.channels.createChannel(data);
|
|
1727
|
-
}
|
|
1728
|
-
/**
|
|
1729
|
-
* Originates a new channel with a specified ID using the provided originate request data.
|
|
1730
|
-
*
|
|
1731
|
-
* @param channelId - The desired unique identifier for the new channel.
|
|
1732
|
-
* @param data - The originate request data containing channel creation parameters.
|
|
1733
|
-
* @returns A promise that resolves to the created Channel object.
|
|
1734
|
-
*/
|
|
1735
|
-
async originateWithId(channelId, data) {
|
|
1736
|
-
return this.channels.originateWithId(channelId, data);
|
|
1737
|
-
}
|
|
1738
|
-
// Métodos relacionados a endpoints:
|
|
1739
|
-
/**
|
|
1740
|
-
* Lists all endpoints.
|
|
1741
|
-
*
|
|
1742
|
-
* @returns {Promise<Endpoint[]>} A promise resolving to the list of endpoints.
|
|
1743
|
-
*/
|
|
1744
|
-
async listEndpoints() {
|
|
1745
|
-
return this.endpoints.list();
|
|
1746
|
-
}
|
|
1747
|
-
/**
|
|
1748
|
-
* Retrieves details of a specific endpoint.
|
|
1749
|
-
*
|
|
1750
|
-
* @param technology - The technology of the endpoint.
|
|
1751
|
-
* @param resource - The resource name of the endpoint.
|
|
1752
|
-
* @returns {Promise<EndpointDetails>} A promise resolving to the details of the endpoint.
|
|
1753
|
-
*/
|
|
1754
|
-
async getEndpointDetails(technology, resource) {
|
|
1755
|
-
return this.endpoints.getDetails(technology, resource);
|
|
1756
|
-
}
|
|
1757
|
-
/**
|
|
1758
|
-
* Sends a message to an endpoint.
|
|
1759
|
-
*
|
|
1760
|
-
* @param technology - The technology of the endpoint.
|
|
1761
|
-
* @param resource - The resource name of the endpoint.
|
|
1762
|
-
* @param body - The message body to send.
|
|
1763
|
-
* @returns {Promise<void>} A promise resolving when the message is sent.
|
|
1764
|
-
*/
|
|
1765
|
-
async sendMessageToEndpoint(technology, resource, body) {
|
|
1766
|
-
return this.endpoints.sendMessage(technology, resource, body);
|
|
1767
|
-
}
|
|
1768
|
-
// Métodos relacionados a applications
|
|
1769
|
-
/**
|
|
1770
|
-
* Lists all applications.
|
|
1771
|
-
*
|
|
1772
|
-
* @returns {Promise<Application[]>} A promise resolving to the list of applications.
|
|
1773
|
-
*/
|
|
1774
|
-
async listApplications() {
|
|
1775
|
-
return this.applications.list();
|
|
1776
|
-
}
|
|
1777
|
-
/**
|
|
1778
|
-
* Retrieves details of a specific application.
|
|
1779
|
-
*
|
|
1780
|
-
* @param appName - The name of the application.
|
|
1781
|
-
* @returns {Promise<ApplicationDetails>} A promise resolving to the application details.
|
|
1782
|
-
*/
|
|
1783
|
-
async getApplicationDetails(appName) {
|
|
1784
|
-
return this.applications.getDetails(appName);
|
|
1785
|
-
}
|
|
1786
|
-
/**
|
|
1787
|
-
* Sends a message to a specific application.
|
|
1788
|
-
*
|
|
1789
|
-
* @param appName - The name of the application.
|
|
1790
|
-
* @param body - The message body to send.
|
|
1791
|
-
* @returns {Promise<void>} A promise resolving when the message is sent successfully.
|
|
1792
|
-
*/
|
|
1793
|
-
async sendMessageToApplication(appName, body) {
|
|
1794
|
-
return this.applications.sendMessage(appName, body);
|
|
1795
|
-
}
|
|
1796
|
-
// Métodos relacionados a playbacks
|
|
1797
|
-
/**
|
|
1798
|
-
* Retrieves details of a specific playback.
|
|
1799
|
-
*
|
|
1800
|
-
* @param playbackId - The unique identifier of the playback.
|
|
1801
|
-
* @returns {Promise<Playback>} A promise resolving to the playback details.
|
|
1802
|
-
*/
|
|
1803
|
-
async getPlaybackDetails(playbackId) {
|
|
1804
|
-
return this.playbacks.getDetails(playbackId);
|
|
1805
|
-
}
|
|
1806
|
-
/**
|
|
1807
|
-
* Controls a specific playback in the Asterisk server.
|
|
1808
|
-
* This function allows manipulation of an ongoing playback, such as pausing, resuming, or skipping.
|
|
1809
|
-
*
|
|
1810
|
-
* @param playbackId - The unique identifier of the playback to control.
|
|
1811
|
-
* This should be a string that uniquely identifies the playback in the Asterisk system.
|
|
1812
|
-
* @param controlRequest - An object containing the control operation details.
|
|
1813
|
-
* This object should conform to the PlaybackControlRequest interface,
|
|
1814
|
-
* which includes an 'operation' property specifying the control action to perform.
|
|
1815
|
-
* @returns A Promise that resolves when the control operation is successfully executed.
|
|
1816
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1817
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1818
|
-
* @throws Will throw an error if the playback control operation fails, e.g., if the playback doesn't exist
|
|
1819
|
-
* or the requested operation is invalid.
|
|
1820
|
-
*/
|
|
1821
|
-
async controlPlayback(playbackId, controlRequest) {
|
|
1822
|
-
const { operation } = controlRequest;
|
|
1823
|
-
return this.playbacks.control(playbackId, operation);
|
|
1824
|
-
}
|
|
1825
|
-
/**
|
|
1826
|
-
* Stops a specific playback in the Asterisk server.
|
|
1827
|
-
*
|
|
1828
|
-
* @param playbackId - The unique identifier of the playback to stop.
|
|
1829
|
-
* @returns A Promise that resolves when the playback is successfully stopped.
|
|
1830
|
-
*/
|
|
1831
|
-
async stopPlayback(playbackId) {
|
|
1832
|
-
return this.playbacks.stop(playbackId);
|
|
1833
|
-
}
|
|
1834
|
-
/**
|
|
1835
|
-
* Retrieves a list of all available sounds in the Asterisk server.
|
|
1836
|
-
*
|
|
1837
|
-
* @param params - Optional parameters to filter the list of sounds.
|
|
1838
|
-
* @returns A Promise that resolves to an array of Sound objects representing the available sounds.
|
|
1839
|
-
*/
|
|
1840
|
-
async listSounds(params) {
|
|
1841
|
-
return this.sounds.list(params);
|
|
1842
|
-
}
|
|
1843
|
-
/**
|
|
1844
|
-
* Retrieves detailed information about a specific sound in the Asterisk server.
|
|
1845
|
-
*
|
|
1846
|
-
* @param soundId - The unique identifier of the sound to retrieve details for.
|
|
1847
|
-
* @returns A Promise that resolves to a Sound object containing the details of the specified sound.
|
|
1848
|
-
*/
|
|
1849
|
-
async getSoundDetails(soundId) {
|
|
1850
|
-
return this.sounds.getDetails(soundId);
|
|
1851
|
-
}
|
|
1852
|
-
/**
|
|
1853
|
-
* Retrieves general information about the Asterisk server.
|
|
1854
|
-
*
|
|
1855
|
-
* @returns A Promise that resolves to an AsteriskInfo object containing server information.
|
|
1856
|
-
*/
|
|
1857
|
-
async getAsteriskInfo() {
|
|
1858
|
-
return this.asterisk.getInfo();
|
|
1859
|
-
}
|
|
1860
|
-
/**
|
|
1861
|
-
* Retrieves a list of all loaded modules in the Asterisk server.
|
|
1862
|
-
*
|
|
1863
|
-
* @returns A Promise that resolves to an array of Module objects representing the loaded modules.
|
|
1864
|
-
*/
|
|
1865
|
-
async listModules() {
|
|
1866
|
-
return this.asterisk.listModules();
|
|
1867
|
-
}
|
|
1868
|
-
/**
|
|
1869
|
-
* Manages a specific module in the Asterisk server by loading, unloading, or reloading it.
|
|
1870
|
-
*
|
|
1871
|
-
* @param moduleName - The name of the module to manage.
|
|
1872
|
-
* @param action - The action to perform on the module: "load", "unload", or "reload".
|
|
1873
|
-
* @returns A Promise that resolves when the module management action is completed successfully.
|
|
1874
|
-
*/
|
|
1875
|
-
async manageModule(moduleName, action) {
|
|
1876
|
-
return this.asterisk.manageModule(moduleName, action);
|
|
1877
|
-
}
|
|
1878
|
-
/**
|
|
1879
|
-
* Retrieves a list of all configured logging channels in the Asterisk server.
|
|
1880
|
-
*
|
|
1881
|
-
* @returns A Promise that resolves to an array of Logging objects representing the configured logging channels.
|
|
1882
|
-
*/
|
|
1883
|
-
async listLoggingChannels() {
|
|
1884
|
-
return this.asterisk.listLoggingChannels();
|
|
1885
|
-
}
|
|
1886
|
-
/**
|
|
1887
|
-
* Adds or removes a log channel in the Asterisk server.
|
|
1888
|
-
*
|
|
1889
|
-
* @param logChannelName - The name of the log channel to manage.
|
|
1890
|
-
* @param action - The action to perform: "add" to create a new log channel or "remove" to delete an existing one.
|
|
1891
|
-
* @param configuration - Optional configuration object for adding a log channel. Ignored when removing a channel.
|
|
1892
|
-
* @param configuration.type - The type of the log channel.
|
|
1893
|
-
* @param configuration.configuration - Additional configuration details for the log channel.
|
|
1894
|
-
* @returns A Promise that resolves when the log channel management action is completed successfully.
|
|
1895
|
-
*/
|
|
1896
|
-
async manageLogChannel(logChannelName, action, configuration) {
|
|
1897
|
-
return this.asterisk.manageLogChannel(
|
|
1898
|
-
logChannelName,
|
|
1899
|
-
action,
|
|
1900
|
-
configuration
|
|
1901
|
-
);
|
|
1902
|
-
}
|
|
1903
|
-
/**
|
|
1904
|
-
* Retrieves the value of a global variable from the Asterisk server.
|
|
1905
|
-
*
|
|
1906
|
-
* @param variableName - The name of the global variable to retrieve.
|
|
1907
|
-
* @returns A Promise that resolves to a Variable object containing the name and value of the global variable.
|
|
1908
|
-
*/
|
|
1909
|
-
async getGlobalVariable(variableName) {
|
|
1910
|
-
return this.asterisk.getGlobalVariable(variableName);
|
|
1911
|
-
}
|
|
1912
|
-
/**
|
|
1913
|
-
* Sets a global variable in the Asterisk server.
|
|
1914
|
-
*
|
|
1915
|
-
* This function allows you to set or update the value of a global variable
|
|
1916
|
-
* in the Asterisk server. Global variables are accessible throughout the
|
|
1917
|
-
* entire Asterisk system and can be used for various purposes such as
|
|
1918
|
-
* configuration settings or sharing data between different parts of the system.
|
|
1919
|
-
*
|
|
1920
|
-
* @param variableName - The name of the global variable to set or update.
|
|
1921
|
-
* This should be a string identifying the variable uniquely.
|
|
1922
|
-
* @param value - The value to assign to the global variable. This can be any
|
|
1923
|
-
* string value, including empty strings.
|
|
1924
|
-
* @returns A Promise that resolves when the global variable has been successfully
|
|
1925
|
-
* set. The promise resolves to void, indicating no specific return value.
|
|
1926
|
-
* If an error occurs during the operation, the promise will be rejected
|
|
1927
|
-
* with an error object.
|
|
1928
|
-
*/
|
|
1929
|
-
async setGlobalVariable(variableName, value) {
|
|
1930
|
-
return this.asterisk.setGlobalVariable(variableName, value);
|
|
1931
|
-
}
|
|
1932
2086
|
/**
|
|
1933
2087
|
* Inicializa uma nova instância de `ChannelInstance` para manipular canais localmente.
|
|
1934
2088
|
*
|
|
@@ -1936,7 +2090,7 @@ var AriClient = class {
|
|
|
1936
2090
|
* @returns Uma instância de `ChannelInstance` vinculada ao cliente atual.
|
|
1937
2091
|
*/
|
|
1938
2092
|
Channel(channelId) {
|
|
1939
|
-
return this.channels.
|
|
2093
|
+
return this.channels.Channel(channelId);
|
|
1940
2094
|
}
|
|
1941
2095
|
/**
|
|
1942
2096
|
* Inicializa uma nova instância de `PlaybackInstance` para manipular playbacks.
|