@ipcom/asterisk-ari 0.0.76 → 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 +731 -530
- package/dist/cjs/index.cjs.map +4 -4
- package/dist/esm/index.js +754 -530
- 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/baseClient.d.ts +21 -3
- package/dist/types/ari-client/baseClient.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 -11
- 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,9 +1,586 @@
|
|
|
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";
|
|
4
579
|
var BaseClient = class {
|
|
5
580
|
client;
|
|
6
581
|
eventEmitter = new EventEmitter();
|
|
582
|
+
wsClients = /* @__PURE__ */ new Map();
|
|
583
|
+
// Gerencia os WebSocket clients
|
|
7
584
|
constructor(baseUrl, username, password) {
|
|
8
585
|
this.client = axios.create({
|
|
9
586
|
baseURL: baseUrl,
|
|
@@ -44,9 +621,46 @@ var BaseClient = class {
|
|
|
44
621
|
const response = await this.client.delete(path);
|
|
45
622
|
return response.data;
|
|
46
623
|
}
|
|
624
|
+
// Gerenciamento de WebSocket clients
|
|
625
|
+
/**
|
|
626
|
+
* Adiciona um WebSocket client ao gerenciador.
|
|
627
|
+
* @param app - Nome do aplicativo ou contexto associado.
|
|
628
|
+
* @param wsClient - Instância do WebSocketClient.
|
|
629
|
+
*/
|
|
630
|
+
addWebSocketClient(app, wsClient) {
|
|
631
|
+
if (this.wsClients.has(app)) {
|
|
632
|
+
throw new Error(`J\xE1 existe um WebSocket client registrado para '${app}'`);
|
|
633
|
+
}
|
|
634
|
+
this.wsClients.set(app, wsClient);
|
|
635
|
+
console.log(`WebSocket client adicionado para '${app}'`);
|
|
636
|
+
}
|
|
47
637
|
/**
|
|
48
|
-
*
|
|
638
|
+
* Remove um WebSocket client do gerenciador.
|
|
639
|
+
* @param app - Nome do aplicativo ou contexto associado.
|
|
49
640
|
*/
|
|
641
|
+
removeWebSocketClient(app) {
|
|
642
|
+
if (!this.wsClients.has(app)) {
|
|
643
|
+
throw new Error(`Nenhum WebSocket client encontrado para '${app}'`);
|
|
644
|
+
}
|
|
645
|
+
this.wsClients.delete(app);
|
|
646
|
+
console.log(`WebSocket client removido para '${app}'`);
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Obtém todos os WebSocket clients.
|
|
650
|
+
* @returns Um Map contendo todos os WebSocket clients registrados.
|
|
651
|
+
*/
|
|
652
|
+
getWebSocketClients() {
|
|
653
|
+
return this.wsClients;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Obtém um WebSocket client específico.
|
|
657
|
+
* @param app - Nome do aplicativo ou contexto associado.
|
|
658
|
+
* @returns O WebSocket client correspondente.
|
|
659
|
+
*/
|
|
660
|
+
getWebSocketClient(app) {
|
|
661
|
+
return this.wsClients.get(app);
|
|
662
|
+
}
|
|
663
|
+
// Gerenciamento de eventos WebSocket
|
|
50
664
|
onWebSocketEvent(callback) {
|
|
51
665
|
console.log("Registrando callback para eventos do WebSocket");
|
|
52
666
|
this.eventEmitter.on("websocketEvent", (event) => {
|
|
@@ -54,9 +668,6 @@ var BaseClient = class {
|
|
|
54
668
|
callback(event);
|
|
55
669
|
});
|
|
56
670
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Emite eventos do WebSocket.
|
|
59
|
-
*/
|
|
60
671
|
emitWebSocketEvent(event) {
|
|
61
672
|
console.log("Emitindo evento do WebSocket:", event);
|
|
62
673
|
this.eventEmitter.emit("websocketEvent", event);
|
|
@@ -287,6 +898,9 @@ function toQueryParams2(options) {
|
|
|
287
898
|
Object.entries(options).filter(([, value]) => value !== void 0).map(([key, value]) => [key, value])
|
|
288
899
|
).toString();
|
|
289
900
|
}
|
|
901
|
+
function isPlaybackEvent(event, playbackId) {
|
|
902
|
+
return event.type.startsWith("Playback") && "playbackId" in event && event.playbackId !== void 0 && (!playbackId || event.playbackId === playbackId);
|
|
903
|
+
}
|
|
290
904
|
function isChannelEvent(event, channelId) {
|
|
291
905
|
const hasChannel = "channel" in event && event.channel?.id !== void 0;
|
|
292
906
|
const matchesChannelId = hasChannel && (!channelId || event.channel?.id === channelId);
|
|
@@ -533,7 +1147,7 @@ var Channels = class extends EventEmitter2 {
|
|
|
533
1147
|
this.baseClient = baseClient;
|
|
534
1148
|
this.client = client;
|
|
535
1149
|
}
|
|
536
|
-
|
|
1150
|
+
Channel(channelId) {
|
|
537
1151
|
return new ChannelInstance(this.client, this.baseClient, channelId);
|
|
538
1152
|
}
|
|
539
1153
|
/**
|
|
@@ -764,25 +1378,30 @@ var Endpoints = class {
|
|
|
764
1378
|
import { EventEmitter as EventEmitter3 } from "events";
|
|
765
1379
|
var PlaybackInstance = class extends EventEmitter3 {
|
|
766
1380
|
// Garantimos que o ID esteja disponível
|
|
767
|
-
constructor(baseClient, playbackId) {
|
|
1381
|
+
constructor(client, baseClient, playbackId) {
|
|
768
1382
|
super();
|
|
1383
|
+
this.client = client;
|
|
769
1384
|
this.baseClient = baseClient;
|
|
770
1385
|
this.playbackId = playbackId;
|
|
771
1386
|
this.id = playbackId || `playback-${Date.now()}`;
|
|
772
|
-
this.
|
|
773
|
-
|
|
1387
|
+
const wsClients = this.client.getWebSocketClients();
|
|
1388
|
+
const wsClient = Array.from(wsClients.values()).find(
|
|
1389
|
+
(client2) => client2.isConnected()
|
|
1390
|
+
);
|
|
1391
|
+
if (!wsClient) {
|
|
1392
|
+
throw new Error(
|
|
1393
|
+
`Nenhum WebSocket conectado dispon\xEDvel para o playback: ${this.id}`
|
|
1394
|
+
);
|
|
1395
|
+
}
|
|
1396
|
+
wsClient.on("message", (event) => {
|
|
1397
|
+
if (isPlaybackEvent(event, this.id)) {
|
|
1398
|
+
console.log(`Evento recebido no ChannelInstance: ${event.type}`, event);
|
|
774
1399
|
this.emit(event.type, event);
|
|
775
1400
|
}
|
|
776
1401
|
});
|
|
777
1402
|
}
|
|
778
1403
|
playbackData = null;
|
|
779
1404
|
id;
|
|
780
|
-
/**
|
|
781
|
-
* Verifica se o evento é relacionado a um playback.
|
|
782
|
-
*/
|
|
783
|
-
isPlaybackEvent(event) {
|
|
784
|
-
return event && typeof event === "object" && "playbackId" in event;
|
|
785
|
-
}
|
|
786
1405
|
/**
|
|
787
1406
|
* Obtém os detalhes do playback.
|
|
788
1407
|
*/
|
|
@@ -837,32 +1456,23 @@ var PlaybackInstance = class extends EventEmitter3 {
|
|
|
837
1456
|
}
|
|
838
1457
|
};
|
|
839
1458
|
var Playbacks = class extends EventEmitter3 {
|
|
840
|
-
constructor(client) {
|
|
1459
|
+
constructor(baseClient, client) {
|
|
841
1460
|
super();
|
|
1461
|
+
this.baseClient = baseClient;
|
|
842
1462
|
this.client = client;
|
|
843
|
-
this.client.onWebSocketEvent((event) => {
|
|
844
|
-
if (this.isPlaybackEvent(event)) {
|
|
845
|
-
const playbackId = event.playbackId;
|
|
846
|
-
if (playbackId) {
|
|
847
|
-
this.emit(`${event.type}:${playbackId}`, event);
|
|
848
|
-
}
|
|
849
|
-
this.emit(event.type, event);
|
|
850
|
-
}
|
|
851
|
-
});
|
|
852
|
-
}
|
|
853
|
-
/**
|
|
854
|
-
* Verifica se o evento é relacionado a um playback.
|
|
855
|
-
*/
|
|
856
|
-
isPlaybackEvent(event) {
|
|
857
|
-
console.log({ eventAri: event });
|
|
858
|
-
return event && typeof event === "object" && "playbackId" in event;
|
|
859
1463
|
}
|
|
860
1464
|
/**
|
|
861
1465
|
* Inicializa uma nova instância de `PlaybackInstance`.
|
|
862
1466
|
*/
|
|
863
1467
|
Playback(playbackId) {
|
|
864
1468
|
const id = playbackId || `playback-${Date.now()}`;
|
|
865
|
-
return new PlaybackInstance(this.client, id);
|
|
1469
|
+
return new PlaybackInstance(this.client, this.baseClient, id);
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Obtém os clientes WebSocket disponíveis.
|
|
1473
|
+
*/
|
|
1474
|
+
getWebSocketClients() {
|
|
1475
|
+
return this.client.getWebSocketClients();
|
|
866
1476
|
}
|
|
867
1477
|
/**
|
|
868
1478
|
* Emite eventos de playback.
|
|
@@ -884,7 +1494,7 @@ var Playbacks = class extends EventEmitter3 {
|
|
|
884
1494
|
* @returns A promise that resolves to a Playback object containing the details of the specified playback.
|
|
885
1495
|
*/
|
|
886
1496
|
async getDetails(playbackId) {
|
|
887
|
-
return this.
|
|
1497
|
+
return this.baseClient.get(`/playbacks/${playbackId}`);
|
|
888
1498
|
}
|
|
889
1499
|
/**
|
|
890
1500
|
* Controls a specific playback by performing various operations such as pause, resume, restart, reverse, forward, or stop.
|
|
@@ -900,7 +1510,7 @@ var Playbacks = class extends EventEmitter3 {
|
|
|
900
1510
|
* @returns A promise that resolves when the control operation is successfully executed.
|
|
901
1511
|
*/
|
|
902
1512
|
async control(playbackId, operation) {
|
|
903
|
-
await this.
|
|
1513
|
+
await this.baseClient.post(
|
|
904
1514
|
`/playbacks/${playbackId}/control?operation=${operation}`
|
|
905
1515
|
);
|
|
906
1516
|
}
|
|
@@ -911,7 +1521,7 @@ var Playbacks = class extends EventEmitter3 {
|
|
|
911
1521
|
* @returns A promise that resolves when the playback is successfully stopped.
|
|
912
1522
|
*/
|
|
913
1523
|
async stop(playbackId) {
|
|
914
|
-
await this.
|
|
1524
|
+
await this.baseClient.delete(`/playbacks/${playbackId}`);
|
|
915
1525
|
}
|
|
916
1526
|
/**
|
|
917
1527
|
* Registers a listener for playback events.
|
|
@@ -978,9 +1588,11 @@ var Sounds = class {
|
|
|
978
1588
|
};
|
|
979
1589
|
|
|
980
1590
|
// src/ari-client/websocketClient.ts
|
|
1591
|
+
var import_exponential_backoff = __toESM(require_backoff(), 1);
|
|
981
1592
|
import { EventEmitter as EventEmitter4 } from "events";
|
|
982
1593
|
import WebSocket from "ws";
|
|
983
1594
|
var WebSocketClient = class extends EventEmitter4 {
|
|
1595
|
+
// Para gerenciar tentativas de reconexão
|
|
984
1596
|
/**
|
|
985
1597
|
* Creates a new WebSocketClient instance.
|
|
986
1598
|
* @param url - The WebSocket server URL to connect to.
|
|
@@ -993,6 +1605,44 @@ var WebSocketClient = class extends EventEmitter4 {
|
|
|
993
1605
|
isClosedManually = false;
|
|
994
1606
|
isReconnecting = false;
|
|
995
1607
|
messageListeners = [];
|
|
1608
|
+
maxReconnectAttempts = 30;
|
|
1609
|
+
reconnectAttempts = 0;
|
|
1610
|
+
async reconnect() {
|
|
1611
|
+
console.log("Iniciando processo de reconex\xE3o...");
|
|
1612
|
+
const backoffOptions = {
|
|
1613
|
+
delayFirstAttempt: false,
|
|
1614
|
+
startingDelay: 1e3,
|
|
1615
|
+
// 1 segundo inicial
|
|
1616
|
+
timeMultiple: 2,
|
|
1617
|
+
// Multiplicador exponencial
|
|
1618
|
+
maxDelay: 3e4,
|
|
1619
|
+
// 30 segundos de atraso máximo
|
|
1620
|
+
numOfAttempts: this.maxReconnectAttempts,
|
|
1621
|
+
// Limite de tentativas
|
|
1622
|
+
jitter: "full",
|
|
1623
|
+
retry: (error, attemptNumber) => {
|
|
1624
|
+
console.warn(
|
|
1625
|
+
`Tentativa ${attemptNumber} de reconex\xE3o falhou: ${error.message}`
|
|
1626
|
+
);
|
|
1627
|
+
return !this.isClosedManually;
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
try {
|
|
1631
|
+
await (0, import_exponential_backoff.backOff)(async () => {
|
|
1632
|
+
console.log(`Tentando reconectar (#${this.reconnectAttempts + 1})...`);
|
|
1633
|
+
await this.connect();
|
|
1634
|
+
console.log("Reconex\xE3o bem-sucedida.");
|
|
1635
|
+
}, backoffOptions);
|
|
1636
|
+
this.reconnectAttempts = 0;
|
|
1637
|
+
this.isReconnecting = false;
|
|
1638
|
+
} catch (error) {
|
|
1639
|
+
console.error(
|
|
1640
|
+
`Reconex\xE3o falhou ap\xF3s ${this.maxReconnectAttempts} tentativas.`,
|
|
1641
|
+
error
|
|
1642
|
+
);
|
|
1643
|
+
this.isReconnecting = false;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
996
1646
|
/**
|
|
997
1647
|
* Establishes a connection to the WebSocket server.
|
|
998
1648
|
* @returns A Promise that resolves when the connection is established, or rejects if an error occurs.
|
|
@@ -1006,6 +1656,7 @@ var WebSocketClient = class extends EventEmitter4 {
|
|
|
1006
1656
|
console.log("WebSocket conectado.");
|
|
1007
1657
|
this.isClosedManually = false;
|
|
1008
1658
|
this.isReconnecting = false;
|
|
1659
|
+
this.reconnectAttempts = 0;
|
|
1009
1660
|
resolve();
|
|
1010
1661
|
});
|
|
1011
1662
|
this.ws.on("error", (err) => {
|
|
@@ -1014,8 +1665,10 @@ var WebSocketClient = class extends EventEmitter4 {
|
|
|
1014
1665
|
});
|
|
1015
1666
|
this.ws.on("close", (code, reason) => {
|
|
1016
1667
|
console.warn(`WebSocket desconectado: ${code} - ${reason}`);
|
|
1017
|
-
this.isReconnecting = false;
|
|
1018
1668
|
this.emit("close", { code, reason });
|
|
1669
|
+
if (!this.isClosedManually) {
|
|
1670
|
+
this.reconnect();
|
|
1671
|
+
}
|
|
1019
1672
|
});
|
|
1020
1673
|
this.ws.on("message", (rawData) => {
|
|
1021
1674
|
this.handleMessage(rawData);
|
|
@@ -1115,9 +1768,9 @@ var AriClient = class {
|
|
|
1115
1768
|
const baseUrl = `${httpProtocol}://${normalizedHost}:${config.port}/ari`;
|
|
1116
1769
|
this.baseClient = new BaseClient(baseUrl, config.username, config.password);
|
|
1117
1770
|
this.channels = new Channels(this.baseClient, this);
|
|
1771
|
+
this.playbacks = new Playbacks(this.baseClient, this);
|
|
1118
1772
|
this.endpoints = new Endpoints(this.baseClient);
|
|
1119
1773
|
this.applications = new Applications(this.baseClient);
|
|
1120
|
-
this.playbacks = new Playbacks(this.baseClient);
|
|
1121
1774
|
this.sounds = new Sounds(this.baseClient);
|
|
1122
1775
|
this.asterisk = new Asterisk(this.baseClient);
|
|
1123
1776
|
this.bridges = new Bridges(this.baseClient);
|
|
@@ -1140,11 +1793,27 @@ var AriClient = class {
|
|
|
1140
1793
|
}
|
|
1141
1794
|
while (this.pendingListeners.length > 0) {
|
|
1142
1795
|
const { event, callback } = this.pendingListeners.shift();
|
|
1796
|
+
if (wsClient.listenerCount(event) > 0) {
|
|
1797
|
+
console.log(
|
|
1798
|
+
`Listener j\xE1 registrado para o evento '${event}' no app '${app}'. Ignorando duplicata.`
|
|
1799
|
+
);
|
|
1800
|
+
continue;
|
|
1801
|
+
}
|
|
1143
1802
|
console.log(`Registrando listener para '${app}' no evento: ${event}`);
|
|
1144
1803
|
wsClient.on(event, callback);
|
|
1145
1804
|
}
|
|
1146
1805
|
}
|
|
1147
1806
|
}
|
|
1807
|
+
async reconnectWebSocket(app) {
|
|
1808
|
+
console.log(`Tentando reconectar o WebSocket para o app '${app}'...`);
|
|
1809
|
+
try {
|
|
1810
|
+
await this.connectSingleWebSocket(app);
|
|
1811
|
+
this.processPendingListeners();
|
|
1812
|
+
console.log(`Reconex\xE3o bem-sucedida para o app '${app}'.`);
|
|
1813
|
+
} catch (error) {
|
|
1814
|
+
console.error(`Erro ao reconectar o WebSocket para '${app}':`, error);
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1148
1817
|
channels;
|
|
1149
1818
|
endpoints;
|
|
1150
1819
|
applications;
|
|
@@ -1156,24 +1825,6 @@ var AriClient = class {
|
|
|
1156
1825
|
getWebSocketClients() {
|
|
1157
1826
|
return this.wsClients;
|
|
1158
1827
|
}
|
|
1159
|
-
/**
|
|
1160
|
-
* Registra um listener para eventos de WebSocket relacionados a canais.
|
|
1161
|
-
* @param eventType Tipo de evento.
|
|
1162
|
-
* @param callback Callback a ser executado quando o evento for recebido.
|
|
1163
|
-
*/
|
|
1164
|
-
onChannelEvent(eventType, callback) {
|
|
1165
|
-
if (this.wsClients.size === 0) {
|
|
1166
|
-
console.warn(
|
|
1167
|
-
"Nenhuma conex\xE3o WebSocket est\xE1 ativa. O listener ser\xE1 pendente."
|
|
1168
|
-
);
|
|
1169
|
-
this.pendingListeners.push({ event: eventType, callback });
|
|
1170
|
-
return;
|
|
1171
|
-
}
|
|
1172
|
-
for (const [app, wsClient] of this.wsClients.entries()) {
|
|
1173
|
-
console.log(`Registrando evento '${eventType}' no app '${app}'`);
|
|
1174
|
-
wsClient.on(eventType, callback);
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
1828
|
/**
|
|
1178
1829
|
* Registra listeners globais para eventos de WebSocket.
|
|
1179
1830
|
*/
|
|
@@ -1211,7 +1862,7 @@ var AriClient = class {
|
|
|
1211
1862
|
}
|
|
1212
1863
|
// Método para criar uma instância de ChannelInstance
|
|
1213
1864
|
createChannelInstance(channelId) {
|
|
1214
|
-
return this.channels.
|
|
1865
|
+
return this.channels.Channel(channelId);
|
|
1215
1866
|
}
|
|
1216
1867
|
handleWebSocketEvent(event) {
|
|
1217
1868
|
console.log("Evento recebido no WebSocket:", event.type, event);
|
|
@@ -1275,26 +1926,58 @@ var AriClient = class {
|
|
|
1275
1926
|
if (!app) {
|
|
1276
1927
|
throw new Error("O nome do aplicativo \xE9 obrigat\xF3rio.");
|
|
1277
1928
|
}
|
|
1278
|
-
if (this.
|
|
1279
|
-
console.log(`Conex\xE3o WebSocket para '${app}' j\xE1
|
|
1280
|
-
return;
|
|
1929
|
+
if (this.webSocketReady.get(app)) {
|
|
1930
|
+
console.log(`Conex\xE3o WebSocket para '${app}' j\xE1 est\xE1 ativa.`);
|
|
1931
|
+
return this.webSocketReady.get(app);
|
|
1281
1932
|
}
|
|
1282
1933
|
const protocol = this.config.secure ? "wss" : "ws";
|
|
1283
1934
|
const eventsParam = subscribedEvents && subscribedEvents.length > 0 ? `&event=${subscribedEvents.join(",")}` : "&subscribeAll=true";
|
|
1284
1935
|
const wsUrl = `${protocol}://${encodeURIComponent(
|
|
1285
1936
|
this.config.username
|
|
1286
1937
|
)}:${encodeURIComponent(this.config.password)}@${this.config.host}:${this.config.port}/ari/events?app=${app}${eventsParam}`;
|
|
1287
|
-
const
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1938
|
+
const backoffOptions = {
|
|
1939
|
+
delayFirstAttempt: false,
|
|
1940
|
+
startingDelay: 1e3,
|
|
1941
|
+
timeMultiple: 2,
|
|
1942
|
+
maxDelay: 3e4,
|
|
1943
|
+
numOfAttempts: 10,
|
|
1944
|
+
jitter: "full",
|
|
1945
|
+
retry: (error, attemptNumber) => {
|
|
1946
|
+
console.warn(
|
|
1947
|
+
`Tentativa ${attemptNumber} falhou para '${app}': ${error.message}`
|
|
1948
|
+
);
|
|
1949
|
+
return !this.wsClients.has(app) || !this.wsClients.get(app)?.isConnected();
|
|
1950
|
+
}
|
|
1951
|
+
};
|
|
1952
|
+
const webSocketPromise = new Promise(async (resolve, reject) => {
|
|
1953
|
+
try {
|
|
1954
|
+
if (this.isReconnecting.get(app)) {
|
|
1955
|
+
console.warn(`J\xE1 est\xE1 tentando reconectar para o app '${app}'.`);
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
this.isReconnecting.set(app, true);
|
|
1959
|
+
const wsClient = new WebSocketClient(wsUrl);
|
|
1960
|
+
await (0, import_exponential_backoff2.backOff)(async () => {
|
|
1961
|
+
if (!wsClient) {
|
|
1962
|
+
throw new Error("WebSocketClient instance is null.");
|
|
1963
|
+
}
|
|
1964
|
+
await wsClient.connect();
|
|
1965
|
+
console.log(`WebSocket conectado para o app: ${app}`);
|
|
1966
|
+
this.integrateWebSocketEvents(app, wsClient);
|
|
1967
|
+
await this.ensureAppRegistered(app);
|
|
1968
|
+
this.wsClients.set(app, wsClient);
|
|
1969
|
+
this.processPendingListeners();
|
|
1970
|
+
}, backoffOptions);
|
|
1971
|
+
resolve();
|
|
1972
|
+
} catch (error) {
|
|
1973
|
+
console.error(`Erro ao conectar WebSocket para '${app}':`, error);
|
|
1974
|
+
reject(error);
|
|
1975
|
+
} finally {
|
|
1976
|
+
this.isReconnecting.delete(app);
|
|
1977
|
+
}
|
|
1978
|
+
});
|
|
1979
|
+
this.webSocketReady.set(app, webSocketPromise);
|
|
1980
|
+
return webSocketPromise;
|
|
1298
1981
|
}
|
|
1299
1982
|
/**
|
|
1300
1983
|
* Integrates WebSocket events with playback listeners.
|
|
@@ -1407,465 +2090,6 @@ var AriClient = class {
|
|
|
1407
2090
|
this.wsClients.clear();
|
|
1408
2091
|
console.log("Todos os WebSockets foram fechados.");
|
|
1409
2092
|
}
|
|
1410
|
-
/**
|
|
1411
|
-
* Retrieves a list of active channels from the Asterisk ARI.
|
|
1412
|
-
*
|
|
1413
|
-
* @returns {Promise<Channel[]>} A promise resolving to the list of active channels.
|
|
1414
|
-
*/
|
|
1415
|
-
/**
|
|
1416
|
-
* Lists all active channels.
|
|
1417
|
-
*/
|
|
1418
|
-
async listChannels() {
|
|
1419
|
-
return this.channels.list();
|
|
1420
|
-
}
|
|
1421
|
-
async hangupChannel(channelId) {
|
|
1422
|
-
return this.channels.hangup(channelId);
|
|
1423
|
-
}
|
|
1424
|
-
/**
|
|
1425
|
-
* Creates a new channel.
|
|
1426
|
-
*/
|
|
1427
|
-
async originateChannel(data) {
|
|
1428
|
-
return this.channels.originate(data);
|
|
1429
|
-
}
|
|
1430
|
-
/**
|
|
1431
|
-
* Continues the dialplan for a specific channel.
|
|
1432
|
-
*/
|
|
1433
|
-
async continueChannelDialplan(channelId, context, extension, priority, label) {
|
|
1434
|
-
return this.channels.continueDialplan(
|
|
1435
|
-
channelId,
|
|
1436
|
-
context,
|
|
1437
|
-
extension,
|
|
1438
|
-
priority,
|
|
1439
|
-
label
|
|
1440
|
-
);
|
|
1441
|
-
}
|
|
1442
|
-
/**
|
|
1443
|
-
* Moves a channel to another Stasis application.
|
|
1444
|
-
*/
|
|
1445
|
-
async moveChannelToApplication(channelId, app, appArgs) {
|
|
1446
|
-
return this.channels.moveToApplication(channelId, app, appArgs);
|
|
1447
|
-
}
|
|
1448
|
-
/**
|
|
1449
|
-
* Sets a channel variable.
|
|
1450
|
-
*/
|
|
1451
|
-
async setChannelVariable(channelId, variable, value) {
|
|
1452
|
-
return this.channels.setChannelVariable(channelId, variable, value);
|
|
1453
|
-
}
|
|
1454
|
-
/**
|
|
1455
|
-
* Gets a channel variable.
|
|
1456
|
-
*/
|
|
1457
|
-
async getChannelVariable(channelId, variable) {
|
|
1458
|
-
return this.channels.getChannelVariable(channelId, variable);
|
|
1459
|
-
}
|
|
1460
|
-
/**
|
|
1461
|
-
* Starts music on hold for a channel.
|
|
1462
|
-
*/
|
|
1463
|
-
async startChannelMusicOnHold(channelId) {
|
|
1464
|
-
return this.channels.startMusicOnHold(channelId);
|
|
1465
|
-
}
|
|
1466
|
-
/**
|
|
1467
|
-
* Stops music on hold for a channel.
|
|
1468
|
-
*/
|
|
1469
|
-
async stopChannelMusicOnHold(channelId) {
|
|
1470
|
-
return this.channels.stopMusicOnHold(channelId);
|
|
1471
|
-
}
|
|
1472
|
-
/**
|
|
1473
|
-
* Records audio from a channel.
|
|
1474
|
-
*/
|
|
1475
|
-
async recordAudio(channelId, options) {
|
|
1476
|
-
return this.channels.record(channelId, options);
|
|
1477
|
-
}
|
|
1478
|
-
/**
|
|
1479
|
-
* Starts snooping on a channel.
|
|
1480
|
-
*/
|
|
1481
|
-
async snoopChannel(channelId, options) {
|
|
1482
|
-
return this.channels.snoopChannel(channelId, options);
|
|
1483
|
-
}
|
|
1484
|
-
/**
|
|
1485
|
-
* Starts snooping on a channel with a specific snoop ID.
|
|
1486
|
-
*/
|
|
1487
|
-
async snoopChannelWithId(channelId, snoopId, options) {
|
|
1488
|
-
return this.channels.snoopChannelWithId(channelId, snoopId, options);
|
|
1489
|
-
}
|
|
1490
|
-
/**
|
|
1491
|
-
* Initiates a dial operation on a previously created channel.
|
|
1492
|
-
* This function attempts to connect the specified channel to its configured destination.
|
|
1493
|
-
*
|
|
1494
|
-
* @param channelId - The unique identifier of the channel to dial.
|
|
1495
|
-
* @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.
|
|
1496
|
-
* @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.
|
|
1497
|
-
* @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.
|
|
1498
|
-
* @throws Will throw an error if the dial operation fails, e.g., if the channel doesn't exist or is in an invalid state.
|
|
1499
|
-
*/
|
|
1500
|
-
async dialChannel(channelId, caller, timeout) {
|
|
1501
|
-
return this.channels.dial(channelId, caller, timeout);
|
|
1502
|
-
}
|
|
1503
|
-
/**
|
|
1504
|
-
* Retrieves RTP statistics for a channel.
|
|
1505
|
-
*/
|
|
1506
|
-
async getRTPStatistics(channelId) {
|
|
1507
|
-
return this.channels.getRTPStatistics(channelId);
|
|
1508
|
-
}
|
|
1509
|
-
/**
|
|
1510
|
-
* Creates a channel to an external media source/sink.
|
|
1511
|
-
*/
|
|
1512
|
-
async createExternalMedia(options) {
|
|
1513
|
-
return this.channels.createExternalMedia(options);
|
|
1514
|
-
}
|
|
1515
|
-
/**
|
|
1516
|
-
* Redirects a channel to a different location.
|
|
1517
|
-
*/
|
|
1518
|
-
async redirectChannel(channelId, endpoint) {
|
|
1519
|
-
return this.channels.redirectChannel(channelId, endpoint);
|
|
1520
|
-
}
|
|
1521
|
-
/**
|
|
1522
|
-
* Sends a ringing indication to a channel.
|
|
1523
|
-
*/
|
|
1524
|
-
async ringChannel(channelId) {
|
|
1525
|
-
return this.channels.ringChannel(channelId);
|
|
1526
|
-
}
|
|
1527
|
-
/**
|
|
1528
|
-
* Stops the ringing indication on a specified channel in the Asterisk system.
|
|
1529
|
-
*
|
|
1530
|
-
* This function sends a request to the Asterisk server to cease the ringing
|
|
1531
|
-
* indication on a particular channel. This is typically used when you want to
|
|
1532
|
-
* stop the ringing sound on a channel without answering or hanging up the call.
|
|
1533
|
-
*
|
|
1534
|
-
* @param channelId - The unique identifier of the channel on which to stop the ringing.
|
|
1535
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1536
|
-
*
|
|
1537
|
-
* @returns A Promise that resolves when the ringing has been successfully stopped on the specified channel.
|
|
1538
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1539
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1540
|
-
*/
|
|
1541
|
-
async stopRingChannel(channelId) {
|
|
1542
|
-
return this.channels.stopRingChannel(channelId);
|
|
1543
|
-
}
|
|
1544
|
-
/**
|
|
1545
|
-
* Sends DTMF (Dual-Tone Multi-Frequency) tones to a specified channel.
|
|
1546
|
-
*
|
|
1547
|
-
* This function allows sending DTMF tones to a channel, which can be used for various purposes
|
|
1548
|
-
* such as interacting with IVR systems or sending signals during a call.
|
|
1549
|
-
*
|
|
1550
|
-
* @param channelId - The unique identifier of the channel to send DTMF tones to.
|
|
1551
|
-
* @param dtmf - A string representing the DTMF tones to send (e.g., "123#").
|
|
1552
|
-
* @param options - Optional parameters to control the timing of DTMF tones.
|
|
1553
|
-
* @param options.before - The time (in milliseconds) to wait before sending DTMF.
|
|
1554
|
-
* @param options.between - The time (in milliseconds) to wait between each DTMF tone.
|
|
1555
|
-
* @param options.duration - The duration (in milliseconds) of each DTMF tone.
|
|
1556
|
-
* @param options.after - The time (in milliseconds) to wait after sending all DTMF tones.
|
|
1557
|
-
* @returns A Promise that resolves when the DTMF tones have been successfully sent.
|
|
1558
|
-
*/
|
|
1559
|
-
async sendDTMF(channelId, dtmf, options) {
|
|
1560
|
-
return this.channels.sendDTMF(channelId, dtmf, options);
|
|
1561
|
-
}
|
|
1562
|
-
/**
|
|
1563
|
-
* Mutes a channel in the Asterisk system.
|
|
1564
|
-
*
|
|
1565
|
-
* This function initiates a mute operation on the specified channel, preventing
|
|
1566
|
-
* audio transmission in the specified direction(s).
|
|
1567
|
-
*
|
|
1568
|
-
* @param channelId - The unique identifier of the channel to be muted.
|
|
1569
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1570
|
-
* @param direction - The direction of audio to mute. Can be one of:
|
|
1571
|
-
* - "both": Mute both incoming and outgoing audio (default)
|
|
1572
|
-
* - "in": Mute only incoming audio
|
|
1573
|
-
* - "out": Mute only outgoing audio
|
|
1574
|
-
*
|
|
1575
|
-
* @returns A Promise that resolves when the mute operation has been successfully completed.
|
|
1576
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1577
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1578
|
-
*/
|
|
1579
|
-
async muteChannel(channelId, direction = "both") {
|
|
1580
|
-
return this.channels.muteChannel(channelId, direction);
|
|
1581
|
-
}
|
|
1582
|
-
/**
|
|
1583
|
-
* Unmutes a channel in the Asterisk system.
|
|
1584
|
-
*
|
|
1585
|
-
* This function removes the mute status from a specified channel, allowing audio
|
|
1586
|
-
* transmission to resume in the specified direction(s).
|
|
1587
|
-
*
|
|
1588
|
-
* @param channelId - The unique identifier of the channel to be unmuted.
|
|
1589
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1590
|
-
* @param direction - The direction of audio to unmute. Can be one of:
|
|
1591
|
-
* - "both": Unmute both incoming and outgoing audio (default)
|
|
1592
|
-
* - "in": Unmute only incoming audio
|
|
1593
|
-
* - "out": Unmute only outgoing audio
|
|
1594
|
-
*
|
|
1595
|
-
* @returns A Promise that resolves when the unmute operation has been successfully completed.
|
|
1596
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1597
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1598
|
-
*/
|
|
1599
|
-
async unmuteChannel(channelId, direction = "both") {
|
|
1600
|
-
return this.channels.unmuteChannel(channelId, direction);
|
|
1601
|
-
}
|
|
1602
|
-
/**
|
|
1603
|
-
* Puts a specified channel on hold.
|
|
1604
|
-
*
|
|
1605
|
-
* This function initiates a hold operation on the specified channel in the Asterisk system.
|
|
1606
|
-
* When a channel is put on hold, typically the audio is muted or replaced with hold music,
|
|
1607
|
-
* depending on the system configuration.
|
|
1608
|
-
*
|
|
1609
|
-
* @param channelId - The unique identifier of the channel to be put on hold.
|
|
1610
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1611
|
-
*
|
|
1612
|
-
* @returns A Promise that resolves when the hold operation has been successfully initiated.
|
|
1613
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1614
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1615
|
-
*/
|
|
1616
|
-
async holdChannel(channelId) {
|
|
1617
|
-
return this.channels.holdChannel(channelId);
|
|
1618
|
-
}
|
|
1619
|
-
/**
|
|
1620
|
-
* Removes a specified channel from hold.
|
|
1621
|
-
*
|
|
1622
|
-
* This function initiates an unhold operation on the specified channel in the Asterisk system.
|
|
1623
|
-
* When a channel is taken off hold, it typically resumes normal audio transmission,
|
|
1624
|
-
* allowing the parties to continue their conversation.
|
|
1625
|
-
*
|
|
1626
|
-
* @param channelId - The unique identifier of the channel to be taken off hold.
|
|
1627
|
-
* This should be a string that uniquely identifies the channel in the Asterisk system.
|
|
1628
|
-
*
|
|
1629
|
-
* @returns A Promise that resolves when the unhold operation has been successfully initiated.
|
|
1630
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1631
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1632
|
-
*/
|
|
1633
|
-
async unholdChannel(channelId) {
|
|
1634
|
-
return this.channels.unholdChannel(channelId);
|
|
1635
|
-
}
|
|
1636
|
-
/**
|
|
1637
|
-
* Creates a new channel in the Asterisk system using the provided originate request data.
|
|
1638
|
-
* This function initiates a new communication channel based on the specified parameters.
|
|
1639
|
-
*
|
|
1640
|
-
* @param data - An object containing the originate request data for channel creation.
|
|
1641
|
-
* This includes details such as the endpoint to call, the context to use,
|
|
1642
|
-
* and any variables to set on the new channel.
|
|
1643
|
-
* @param data.endpoint - The endpoint to call (e.g., "SIP/1234").
|
|
1644
|
-
* @param data.extension - The extension to dial after the channel is created.
|
|
1645
|
-
* @param data.context - The dialplan context to use for the new channel.
|
|
1646
|
-
* @param data.priority - The priority to start at in the dialplan.
|
|
1647
|
-
* @param data.app - The application to execute on the channel (alternative to extension/context/priority).
|
|
1648
|
-
* @param data.appArgs - The arguments to pass to the application, if 'app' is specified.
|
|
1649
|
-
* @param data.callerId - The caller ID to set on the new channel.
|
|
1650
|
-
* @param data.timeout - The timeout (in seconds) to wait for the channel to be answered.
|
|
1651
|
-
* @param data.variables - An object containing key-value pairs of channel variables to set.
|
|
1652
|
-
* @param data.channelId - An optional ID to assign to the new channel.
|
|
1653
|
-
* @param data.otherChannelId - The ID of another channel to bridge with after creation.
|
|
1654
|
-
*
|
|
1655
|
-
* @returns A Promise that resolves to the created Channel object.
|
|
1656
|
-
* The Channel object contains details about the newly created channel,
|
|
1657
|
-
* such as its unique identifier, state, and other relevant information.
|
|
1658
|
-
*
|
|
1659
|
-
* @throws Will throw an error if the channel creation fails for any reason,
|
|
1660
|
-
* such as invalid parameters or system issues.
|
|
1661
|
-
*/
|
|
1662
|
-
async createChannel(data) {
|
|
1663
|
-
return this.channels.createChannel(data);
|
|
1664
|
-
}
|
|
1665
|
-
/**
|
|
1666
|
-
* Originates a new channel with a specified ID using the provided originate request data.
|
|
1667
|
-
*
|
|
1668
|
-
* @param channelId - The desired unique identifier for the new channel.
|
|
1669
|
-
* @param data - The originate request data containing channel creation parameters.
|
|
1670
|
-
* @returns A promise that resolves to the created Channel object.
|
|
1671
|
-
*/
|
|
1672
|
-
async originateWithId(channelId, data) {
|
|
1673
|
-
return this.channels.originateWithId(channelId, data);
|
|
1674
|
-
}
|
|
1675
|
-
// Métodos relacionados a endpoints:
|
|
1676
|
-
/**
|
|
1677
|
-
* Lists all endpoints.
|
|
1678
|
-
*
|
|
1679
|
-
* @returns {Promise<Endpoint[]>} A promise resolving to the list of endpoints.
|
|
1680
|
-
*/
|
|
1681
|
-
async listEndpoints() {
|
|
1682
|
-
return this.endpoints.list();
|
|
1683
|
-
}
|
|
1684
|
-
/**
|
|
1685
|
-
* Retrieves details of a specific endpoint.
|
|
1686
|
-
*
|
|
1687
|
-
* @param technology - The technology of the endpoint.
|
|
1688
|
-
* @param resource - The resource name of the endpoint.
|
|
1689
|
-
* @returns {Promise<EndpointDetails>} A promise resolving to the details of the endpoint.
|
|
1690
|
-
*/
|
|
1691
|
-
async getEndpointDetails(technology, resource) {
|
|
1692
|
-
return this.endpoints.getDetails(technology, resource);
|
|
1693
|
-
}
|
|
1694
|
-
/**
|
|
1695
|
-
* Sends a message to an endpoint.
|
|
1696
|
-
*
|
|
1697
|
-
* @param technology - The technology of the endpoint.
|
|
1698
|
-
* @param resource - The resource name of the endpoint.
|
|
1699
|
-
* @param body - The message body to send.
|
|
1700
|
-
* @returns {Promise<void>} A promise resolving when the message is sent.
|
|
1701
|
-
*/
|
|
1702
|
-
async sendMessageToEndpoint(technology, resource, body) {
|
|
1703
|
-
return this.endpoints.sendMessage(technology, resource, body);
|
|
1704
|
-
}
|
|
1705
|
-
// Métodos relacionados a applications
|
|
1706
|
-
/**
|
|
1707
|
-
* Lists all applications.
|
|
1708
|
-
*
|
|
1709
|
-
* @returns {Promise<Application[]>} A promise resolving to the list of applications.
|
|
1710
|
-
*/
|
|
1711
|
-
async listApplications() {
|
|
1712
|
-
return this.applications.list();
|
|
1713
|
-
}
|
|
1714
|
-
/**
|
|
1715
|
-
* Retrieves details of a specific application.
|
|
1716
|
-
*
|
|
1717
|
-
* @param appName - The name of the application.
|
|
1718
|
-
* @returns {Promise<ApplicationDetails>} A promise resolving to the application details.
|
|
1719
|
-
*/
|
|
1720
|
-
async getApplicationDetails(appName) {
|
|
1721
|
-
return this.applications.getDetails(appName);
|
|
1722
|
-
}
|
|
1723
|
-
/**
|
|
1724
|
-
* Sends a message to a specific application.
|
|
1725
|
-
*
|
|
1726
|
-
* @param appName - The name of the application.
|
|
1727
|
-
* @param body - The message body to send.
|
|
1728
|
-
* @returns {Promise<void>} A promise resolving when the message is sent successfully.
|
|
1729
|
-
*/
|
|
1730
|
-
async sendMessageToApplication(appName, body) {
|
|
1731
|
-
return this.applications.sendMessage(appName, body);
|
|
1732
|
-
}
|
|
1733
|
-
// Métodos relacionados a playbacks
|
|
1734
|
-
/**
|
|
1735
|
-
* Retrieves details of a specific playback.
|
|
1736
|
-
*
|
|
1737
|
-
* @param playbackId - The unique identifier of the playback.
|
|
1738
|
-
* @returns {Promise<Playback>} A promise resolving to the playback details.
|
|
1739
|
-
*/
|
|
1740
|
-
async getPlaybackDetails(playbackId) {
|
|
1741
|
-
return this.playbacks.getDetails(playbackId);
|
|
1742
|
-
}
|
|
1743
|
-
/**
|
|
1744
|
-
* Controls a specific playback in the Asterisk server.
|
|
1745
|
-
* This function allows manipulation of an ongoing playback, such as pausing, resuming, or skipping.
|
|
1746
|
-
*
|
|
1747
|
-
* @param playbackId - The unique identifier of the playback to control.
|
|
1748
|
-
* This should be a string that uniquely identifies the playback in the Asterisk system.
|
|
1749
|
-
* @param controlRequest - An object containing the control operation details.
|
|
1750
|
-
* This object should conform to the PlaybackControlRequest interface,
|
|
1751
|
-
* which includes an 'operation' property specifying the control action to perform.
|
|
1752
|
-
* @returns A Promise that resolves when the control operation is successfully executed.
|
|
1753
|
-
* The promise resolves to void, indicating no specific return value.
|
|
1754
|
-
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
1755
|
-
* @throws Will throw an error if the playback control operation fails, e.g., if the playback doesn't exist
|
|
1756
|
-
* or the requested operation is invalid.
|
|
1757
|
-
*/
|
|
1758
|
-
async controlPlayback(playbackId, controlRequest) {
|
|
1759
|
-
const { operation } = controlRequest;
|
|
1760
|
-
return this.playbacks.control(playbackId, operation);
|
|
1761
|
-
}
|
|
1762
|
-
/**
|
|
1763
|
-
* Stops a specific playback in the Asterisk server.
|
|
1764
|
-
*
|
|
1765
|
-
* @param playbackId - The unique identifier of the playback to stop.
|
|
1766
|
-
* @returns A Promise that resolves when the playback is successfully stopped.
|
|
1767
|
-
*/
|
|
1768
|
-
async stopPlayback(playbackId) {
|
|
1769
|
-
return this.playbacks.stop(playbackId);
|
|
1770
|
-
}
|
|
1771
|
-
/**
|
|
1772
|
-
* Retrieves a list of all available sounds in the Asterisk server.
|
|
1773
|
-
*
|
|
1774
|
-
* @param params - Optional parameters to filter the list of sounds.
|
|
1775
|
-
* @returns A Promise that resolves to an array of Sound objects representing the available sounds.
|
|
1776
|
-
*/
|
|
1777
|
-
async listSounds(params) {
|
|
1778
|
-
return this.sounds.list(params);
|
|
1779
|
-
}
|
|
1780
|
-
/**
|
|
1781
|
-
* Retrieves detailed information about a specific sound in the Asterisk server.
|
|
1782
|
-
*
|
|
1783
|
-
* @param soundId - The unique identifier of the sound to retrieve details for.
|
|
1784
|
-
* @returns A Promise that resolves to a Sound object containing the details of the specified sound.
|
|
1785
|
-
*/
|
|
1786
|
-
async getSoundDetails(soundId) {
|
|
1787
|
-
return this.sounds.getDetails(soundId);
|
|
1788
|
-
}
|
|
1789
|
-
/**
|
|
1790
|
-
* Retrieves general information about the Asterisk server.
|
|
1791
|
-
*
|
|
1792
|
-
* @returns A Promise that resolves to an AsteriskInfo object containing server information.
|
|
1793
|
-
*/
|
|
1794
|
-
async getAsteriskInfo() {
|
|
1795
|
-
return this.asterisk.getInfo();
|
|
1796
|
-
}
|
|
1797
|
-
/**
|
|
1798
|
-
* Retrieves a list of all loaded modules in the Asterisk server.
|
|
1799
|
-
*
|
|
1800
|
-
* @returns A Promise that resolves to an array of Module objects representing the loaded modules.
|
|
1801
|
-
*/
|
|
1802
|
-
async listModules() {
|
|
1803
|
-
return this.asterisk.listModules();
|
|
1804
|
-
}
|
|
1805
|
-
/**
|
|
1806
|
-
* Manages a specific module in the Asterisk server by loading, unloading, or reloading it.
|
|
1807
|
-
*
|
|
1808
|
-
* @param moduleName - The name of the module to manage.
|
|
1809
|
-
* @param action - The action to perform on the module: "load", "unload", or "reload".
|
|
1810
|
-
* @returns A Promise that resolves when the module management action is completed successfully.
|
|
1811
|
-
*/
|
|
1812
|
-
async manageModule(moduleName, action) {
|
|
1813
|
-
return this.asterisk.manageModule(moduleName, action);
|
|
1814
|
-
}
|
|
1815
|
-
/**
|
|
1816
|
-
* Retrieves a list of all configured logging channels in the Asterisk server.
|
|
1817
|
-
*
|
|
1818
|
-
* @returns A Promise that resolves to an array of Logging objects representing the configured logging channels.
|
|
1819
|
-
*/
|
|
1820
|
-
async listLoggingChannels() {
|
|
1821
|
-
return this.asterisk.listLoggingChannels();
|
|
1822
|
-
}
|
|
1823
|
-
/**
|
|
1824
|
-
* Adds or removes a log channel in the Asterisk server.
|
|
1825
|
-
*
|
|
1826
|
-
* @param logChannelName - The name of the log channel to manage.
|
|
1827
|
-
* @param action - The action to perform: "add" to create a new log channel or "remove" to delete an existing one.
|
|
1828
|
-
* @param configuration - Optional configuration object for adding a log channel. Ignored when removing a channel.
|
|
1829
|
-
* @param configuration.type - The type of the log channel.
|
|
1830
|
-
* @param configuration.configuration - Additional configuration details for the log channel.
|
|
1831
|
-
* @returns A Promise that resolves when the log channel management action is completed successfully.
|
|
1832
|
-
*/
|
|
1833
|
-
async manageLogChannel(logChannelName, action, configuration) {
|
|
1834
|
-
return this.asterisk.manageLogChannel(
|
|
1835
|
-
logChannelName,
|
|
1836
|
-
action,
|
|
1837
|
-
configuration
|
|
1838
|
-
);
|
|
1839
|
-
}
|
|
1840
|
-
/**
|
|
1841
|
-
* Retrieves the value of a global variable from the Asterisk server.
|
|
1842
|
-
*
|
|
1843
|
-
* @param variableName - The name of the global variable to retrieve.
|
|
1844
|
-
* @returns A Promise that resolves to a Variable object containing the name and value of the global variable.
|
|
1845
|
-
*/
|
|
1846
|
-
async getGlobalVariable(variableName) {
|
|
1847
|
-
return this.asterisk.getGlobalVariable(variableName);
|
|
1848
|
-
}
|
|
1849
|
-
/**
|
|
1850
|
-
* Sets a global variable in the Asterisk server.
|
|
1851
|
-
*
|
|
1852
|
-
* This function allows you to set or update the value of a global variable
|
|
1853
|
-
* in the Asterisk server. Global variables are accessible throughout the
|
|
1854
|
-
* entire Asterisk system and can be used for various purposes such as
|
|
1855
|
-
* configuration settings or sharing data between different parts of the system.
|
|
1856
|
-
*
|
|
1857
|
-
* @param variableName - The name of the global variable to set or update.
|
|
1858
|
-
* This should be a string identifying the variable uniquely.
|
|
1859
|
-
* @param value - The value to assign to the global variable. This can be any
|
|
1860
|
-
* string value, including empty strings.
|
|
1861
|
-
* @returns A Promise that resolves when the global variable has been successfully
|
|
1862
|
-
* set. The promise resolves to void, indicating no specific return value.
|
|
1863
|
-
* If an error occurs during the operation, the promise will be rejected
|
|
1864
|
-
* with an error object.
|
|
1865
|
-
*/
|
|
1866
|
-
async setGlobalVariable(variableName, value) {
|
|
1867
|
-
return this.asterisk.setGlobalVariable(variableName, value);
|
|
1868
|
-
}
|
|
1869
2093
|
/**
|
|
1870
2094
|
* Inicializa uma nova instância de `ChannelInstance` para manipular canais localmente.
|
|
1871
2095
|
*
|
|
@@ -1873,7 +2097,7 @@ var AriClient = class {
|
|
|
1873
2097
|
* @returns Uma instância de `ChannelInstance` vinculada ao cliente atual.
|
|
1874
2098
|
*/
|
|
1875
2099
|
Channel(channelId) {
|
|
1876
|
-
return this.channels.
|
|
2100
|
+
return this.channels.Channel(channelId);
|
|
1877
2101
|
}
|
|
1878
2102
|
/**
|
|
1879
2103
|
* Inicializa uma nova instância de `PlaybackInstance` para manipular playbacks.
|