@voicenter-team/opensips-js 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/README.md +75 -0
  2. package/build/enum/call.event.listener.type.d.ts +7 -0
  3. package/build/enum/call.event.listener.type.js +10 -0
  4. package/build/enum/metric.keys.to.include.d.ts +2 -0
  5. package/build/enum/metric.keys.to.include.js +4 -0
  6. package/build/helpers/UA/index.d.ts +6 -0
  7. package/build/helpers/UA/index.js +9 -0
  8. package/build/helpers/audio.helper.d.ts +9 -0
  9. package/build/helpers/audio.helper.js +60 -0
  10. package/build/helpers/filter.helper.d.ts +2 -0
  11. package/build/helpers/filter.helper.js +14 -0
  12. package/build/helpers/time.helper.d.ts +16 -0
  13. package/build/helpers/time.helper.js +28 -0
  14. package/build/helpers/volume.helper.d.ts +2 -0
  15. package/build/helpers/volume.helper.js +76 -0
  16. package/build/helpers/webrtcmetrics/collector.d.ts +32 -0
  17. package/build/helpers/webrtcmetrics/collector.js +282 -0
  18. package/build/helpers/webrtcmetrics/engine.d.ts +20 -0
  19. package/build/helpers/webrtcmetrics/engine.js +164 -0
  20. package/build/helpers/webrtcmetrics/exporter.d.ts +116 -0
  21. package/build/helpers/webrtcmetrics/exporter.js +528 -0
  22. package/build/helpers/webrtcmetrics/extractor.d.ts +1 -0
  23. package/build/helpers/webrtcmetrics/extractor.js +976 -0
  24. package/build/helpers/webrtcmetrics/index.d.ts +63 -0
  25. package/build/helpers/webrtcmetrics/index.js +93 -0
  26. package/build/helpers/webrtcmetrics/metrics.d.ts +2 -0
  27. package/build/helpers/webrtcmetrics/metrics.js +8 -0
  28. package/build/helpers/webrtcmetrics/probe.d.ts +76 -0
  29. package/build/helpers/webrtcmetrics/probe.js +153 -0
  30. package/build/helpers/webrtcmetrics/utils/config.d.ts +12 -0
  31. package/build/helpers/webrtcmetrics/utils/config.js +28 -0
  32. package/build/helpers/webrtcmetrics/utils/helper.d.ts +13 -0
  33. package/build/helpers/webrtcmetrics/utils/helper.js +134 -0
  34. package/build/helpers/webrtcmetrics/utils/log.d.ts +7 -0
  35. package/build/helpers/webrtcmetrics/utils/log.js +71 -0
  36. package/build/helpers/webrtcmetrics/utils/models.d.ts +309 -0
  37. package/build/helpers/webrtcmetrics/utils/models.js +298 -0
  38. package/build/helpers/webrtcmetrics/utils/score.d.ts +4 -0
  39. package/build/helpers/webrtcmetrics/utils/score.js +235 -0
  40. package/build/helpers/webrtcmetrics/utils/shortUUId.d.ts +1 -0
  41. package/build/helpers/webrtcmetrics/utils/shortUUId.js +7 -0
  42. package/build/index.d.ts +170 -0
  43. package/build/index.js +849 -0
  44. package/package.json +61 -0
  45. package/src/types/declarations.d.ts +6 -0
  46. package/src/types/generic.d.ts +1 -0
  47. package/src/types/listeners.d.ts +42 -0
  48. package/src/types/rtc.d.ts +133 -0
  49. package/src/types/webrtcmetrics.d.ts +64 -0
@@ -0,0 +1,20 @@
1
+ export default class ProbesEngine {
2
+ constructor(cfg: any);
3
+ _config: any;
4
+ _probes: any[];
5
+ _startedTime: number | null;
6
+ _callbacks: {
7
+ onresult: null;
8
+ };
9
+ get probes(): any[];
10
+ get isRunning(): boolean;
11
+ get isIdle(): boolean;
12
+ addNewProbe(peerConnection: any, options: any): Probe;
13
+ removeExistingProbe(probe: any): void;
14
+ start(): Promise<void>;
15
+ stop(forced: any): void;
16
+ registerCallback(name: any, callback: any, context: any): void;
17
+ unregisterCallback(name: any): void;
18
+ fireOnReports(report: any): void;
19
+ }
20
+ import Probe from "./probe";
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const log_1 = require("./utils/log");
16
+ const config_1 = require("./utils/config");
17
+ const probe_1 = __importDefault(require("./probe"));
18
+ const models_1 = require("./utils/models");
19
+ const helper_1 = require("./utils/helper");
20
+ const moduleName = "engine ";
21
+ class ProbesEngine {
22
+ constructor(cfg) {
23
+ this._config = cfg;
24
+ this._probes = [];
25
+ this._startedTime = null;
26
+ this._callbacks = {
27
+ onresult: null,
28
+ };
29
+ (0, log_1.info)(moduleName, `configured for probing every ${this._config.refreshEvery}ms`);
30
+ (0, log_1.info)(moduleName, `configured for starting after ${this._config.startAfter}ms`);
31
+ (0, log_1.info)(moduleName, `${(!this._config.stopAfter || this._config.stopAfter !== -1) ? `configured for stopped after ${this._config.stopAfter}ms` : "configured for never stopped"}`);
32
+ (0, log_1.debug)(moduleName, "engine initialized");
33
+ }
34
+ get probes() {
35
+ return this._probes;
36
+ }
37
+ get isRunning() {
38
+ return this._probes.some((probe) => (probe.isRunning));
39
+ }
40
+ get isIdle() {
41
+ return this._probes.every((probe) => (probe.isIdle));
42
+ }
43
+ addNewProbe(peerConnection, options) {
44
+ if (!peerConnection) {
45
+ throw new Error("undefined peer connection");
46
+ }
47
+ const probeConfig = (0, config_1.getConfig)(peerConnection, options, this._config);
48
+ const probe = new probe_1.default(probeConfig);
49
+ this._probes.push(probe);
50
+ (0, log_1.debug)(moduleName, `${this._probes.length} probes registered`);
51
+ return probe;
52
+ }
53
+ removeExistingProbe(probe) {
54
+ if (!probe) {
55
+ throw new Error("undefined probe");
56
+ }
57
+ if (probe.state === models_1.COLLECTOR_STATE.RUNNING) {
58
+ probe.stop();
59
+ }
60
+ this._probes = this._probes.filter((existingProbe) => (probe.id !== existingProbe.id));
61
+ }
62
+ start() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ const startProbes = () => {
65
+ this._probes.forEach((probe) => probe.start());
66
+ };
67
+ const takeReferenceStat = () => __awaiter(this, void 0, void 0, function* () {
68
+ return (Promise.all(this._probes.map((probe) => (probe.takeReferenceStats()))));
69
+ });
70
+ const shouldCollectStats = () => {
71
+ if (this.isIdle) {
72
+ // don't collect if there is no running probes
73
+ return false;
74
+ }
75
+ if (!this._config.stopAfter || this._config.stopAfter < 0) {
76
+ // always collect if stopAfter has not been set
77
+ return true;
78
+ }
79
+ // Else check expiration
80
+ return (Date.now() < this._startedTime + this._config.stopAfter);
81
+ };
82
+ const collectStats = () => __awaiter(this, void 0, void 0, function* () {
83
+ const globalReport = (0, models_1.getDefaultGlobalMetric)();
84
+ const runningProbes = this._probes.filter((probe) => (probe.isRunning));
85
+ for (const probe of runningProbes) {
86
+ const report = yield probe.collectStats();
87
+ if (report) {
88
+ globalReport.probes.push(report);
89
+ }
90
+ (0, log_1.debug)(moduleName, `got probe ${probe.id}`);
91
+ yield (0, helper_1.timeout)(0);
92
+ }
93
+ // Compute total measure time
94
+ globalReport.delta_time_to_measure_probes_ms = (0, helper_1.sumValuesOfReports)(globalReport.probes, "experimental", "time_to_measure_ms");
95
+ globalReport.delta_KBytes_in = (0, helper_1.sumValuesOfReports)(globalReport.probes, "data", "delta_KBytes_in");
96
+ globalReport.delta_KBytes_out = (0, helper_1.sumValuesOfReports)(globalReport.probes, "data", "delta_KBytes_out");
97
+ globalReport.delta_kbs_in = (0, helper_1.sumValuesOfReports)(globalReport.probes, "data", "delta_kbs_in");
98
+ globalReport.delta_kbs_out = (0, helper_1.sumValuesOfReports)(globalReport.probes, "data", "delta_kbs_out");
99
+ globalReport.total_time_decoded_in = (0, helper_1.sumValuesOfReports)(globalReport.probes, "video", "total_time_decoded_in");
100
+ globalReport.total_time_encoded_out = (0, helper_1.sumValuesOfReports)(globalReport.probes, "video", "total_time_encoded_out");
101
+ return globalReport;
102
+ });
103
+ (0, log_1.debug)(moduleName, "starting to collect");
104
+ startProbes();
105
+ (0, log_1.debug)(moduleName, "generating reference reports...");
106
+ yield takeReferenceStat();
107
+ (0, log_1.debug)(moduleName, "reference reports generated");
108
+ this._startedTime = Date.now();
109
+ while (shouldCollectStats()) {
110
+ (0, log_1.debug)(moduleName, `wait ${this._config.refreshEvery}ms before collecting`);
111
+ yield (0, helper_1.timeout)(this._config.refreshEvery);
112
+ if (shouldCollectStats()) {
113
+ (0, log_1.debug)(moduleName, "collecting...");
114
+ const preTime = Date.now();
115
+ const globalReport = yield collectStats();
116
+ const postTime = Date.now();
117
+ globalReport.delta_time_consumed_to_measure_ms = postTime - preTime;
118
+ this.fireOnReports(globalReport);
119
+ (0, log_1.debug)(moduleName, "collected");
120
+ }
121
+ }
122
+ (0, log_1.debug)(moduleName, "reaching end of the collecting period...");
123
+ if (this.isRunning) {
124
+ setTimeout(() => {
125
+ this.stop();
126
+ }, 0);
127
+ }
128
+ });
129
+ }
130
+ stop(forced) {
131
+ const stopProbes = (manual) => {
132
+ this._probes.forEach((probe) => {
133
+ probe.stop(manual);
134
+ });
135
+ };
136
+ (0, log_1.info)(moduleName, "stop collecting");
137
+ stopProbes(forced);
138
+ }
139
+ registerCallback(name, callback, context) {
140
+ if (name in this._callbacks) {
141
+ this._callbacks[name] = { callback, context };
142
+ (0, log_1.debug)(moduleName, `registered callback '${name}'`);
143
+ }
144
+ else {
145
+ (0, log_1.error)(moduleName, `can't register callback for '${name}' - not found`);
146
+ }
147
+ }
148
+ unregisterCallback(name) {
149
+ if (name in this._callbacks) {
150
+ this._callbacks[name] = null;
151
+ delete this._callbacks[name];
152
+ (0, log_1.debug)(this._moduleName, `unregistered callback '${name}'`);
153
+ }
154
+ else {
155
+ (0, log_1.error)(this._moduleName, `can't unregister callback for '${name}' - not found`);
156
+ }
157
+ }
158
+ fireOnReports(report) {
159
+ if (this._callbacks.onresult && report.probes.length > 0) {
160
+ (0, helper_1.call)(this._callbacks.onresult.callback, this._callbacks.onresult.context, report);
161
+ }
162
+ }
163
+ }
164
+ exports.default = ProbesEngine;
@@ -0,0 +1,116 @@
1
+ export default class Exporter {
2
+ constructor(cfg: any);
3
+ _start: string | null;
4
+ _end: string | null;
5
+ _cfg: any;
6
+ _referenceReport: any;
7
+ _reports: any[];
8
+ _events: any[];
9
+ start(): Date;
10
+ stop(): Date;
11
+ saveReferenceReport(report: any): void;
12
+ getReferenceReport(): any;
13
+ addReport(report: any): void;
14
+ addCustomEvent(event: any): void;
15
+ reset(): void;
16
+ get ticket(): {
17
+ version: string;
18
+ configuration: {
19
+ frequency: any;
20
+ };
21
+ started: string | null;
22
+ ended: string | null;
23
+ ua: {
24
+ agent: string;
25
+ pname: any;
26
+ user_id: any;
27
+ };
28
+ call: {
29
+ call_id: any;
30
+ events: any[];
31
+ };
32
+ details: {
33
+ count: number;
34
+ reports: any[];
35
+ reference: any;
36
+ };
37
+ ssrc: {};
38
+ data: {
39
+ rtt: {
40
+ avg: number | null;
41
+ min: number | null;
42
+ max: number | null;
43
+ volatility: number | null;
44
+ _unit: {
45
+ avg: string;
46
+ min: string;
47
+ max: string;
48
+ volatility: string;
49
+ };
50
+ };
51
+ packetsLost: {
52
+ audio: {
53
+ in: {
54
+ avg: number;
55
+ };
56
+ };
57
+ video: {
58
+ in: {
59
+ avg: number;
60
+ };
61
+ };
62
+ unit: {
63
+ avg: string;
64
+ };
65
+ };
66
+ bitrate: {
67
+ in: {
68
+ avg: number | null;
69
+ min: number | null;
70
+ max: number | null;
71
+ volatility: number | null;
72
+ };
73
+ out: {
74
+ avg: number | null;
75
+ min: number | null;
76
+ max: number | null;
77
+ volatility: number | null;
78
+ };
79
+ unit: {
80
+ avg: string;
81
+ min: string;
82
+ max: string;
83
+ volatility: string;
84
+ };
85
+ };
86
+ traffic: {
87
+ in: {
88
+ avg: number | null;
89
+ min: number | null;
90
+ max: number | null;
91
+ volatility: number | null;
92
+ };
93
+ out: {
94
+ avg: number | null;
95
+ min: number | null;
96
+ max: number | null;
97
+ volatility: number | null;
98
+ };
99
+ unit: {
100
+ avg: string;
101
+ min: string;
102
+ max: string;
103
+ volatility: string;
104
+ };
105
+ };
106
+ network: {
107
+ localConnection: string;
108
+ remoteConnection: string;
109
+ };
110
+ };
111
+ };
112
+ updateConfig(config: any): void;
113
+ getLastReport(): any;
114
+ getBeforeLastReport(): any;
115
+ getReportsNumber(): number;
116
+ }