@exotel-npm-dev/webrtc-client-sdk 1.0.0
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/package.json +25 -0
- package/src/api/callAPI/Call.js +83 -0
- package/src/api/callAPI/CallDetails.js +74 -0
- package/src/api/omAPI/Diagnostics.js +644 -0
- package/src/api/omAPI/DiagnosticsFSM.js +142 -0
- package/src/api/omAPI/DiagnosticsFSM.ts +378 -0
- package/src/api/omAPI/DiagnosticsListener.js +95 -0
- package/src/api/omAPI/FSM.js +126 -0
- package/src/api/omAPI/WebrtcLogger.js +55 -0
- package/src/api/omAPI/js-finite-state-machine.js +126 -0
- package/src/api/omAPI/log/index.js +8 -0
- package/src/api/omAPI/log/index.ts +3 -0
- package/src/api/omAPI/log/levels.js +13 -0
- package/src/api/omAPI/log/levels.ts +10 -0
- package/src/api/omAPI/log/logger-factory.js +115 -0
- package/src/api/omAPI/log/logger-factory.ts +119 -0
- package/src/api/omAPI/log/logger.js +41 -0
- package/src/api/omAPI/log/logger.ts +42 -0
- package/src/api/registerAPI/RegisterListener.js +43 -0
- package/src/constants/ErrorConstants.js +6 -0
- package/src/constants/common.js +12 -0
- package/src/listeners/CallCtrlerDummy.js +8 -0
- package/src/listeners/CallListener.js +38 -0
- package/src/listeners/Callback.js +176 -0
- package/src/listeners/ExWebClient.js +468 -0
- package/src/listeners/ExotelVoiceClientListener.js +45 -0
- package/src/listeners/SessionListeners.js +123 -0
- package/src/phone.json +75 -0
- package/src/phoneDetailsAPI.js +43 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// JS Finite State Machine
|
|
2
|
+
//
|
|
3
|
+
// A simple finite state machine library for code flow and transition control.
|
|
4
|
+
//
|
|
5
|
+
// https://github.com/jhund/js-finite-state-machine
|
|
6
|
+
// Copyright (c)2011 Jo Hund, ClearCove Software Inc.
|
|
7
|
+
// Based originally on FSM by Anthony Blackshaw <ant@getme.co.uk> (www.getme.co.uk) Copyright (c)2008
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
// Initializes a new state machine.
|
|
11
|
+
// Usage: var fsm = new FSM("initial", { d1: "foo", d2: "bar" });
|
|
12
|
+
//
|
|
13
|
+
// param [String] initialState the initial state of the state machine
|
|
14
|
+
// param [Object, optional] data data specific to this state machine. Is available as this.data in
|
|
15
|
+
// callbacks
|
|
16
|
+
function FSM(initialState, data) {
|
|
17
|
+
this.stateTransitions = {};
|
|
18
|
+
this.stateTransitionsFromAnyState = {};
|
|
19
|
+
this.defaultTransition = null;
|
|
20
|
+
this.currentState = initialState;
|
|
21
|
+
this.data = data;
|
|
22
|
+
this.debug = true; // set to true to turn on console output for debugging (see function "sendEvent")
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// Specify a "specific" transition for given events and currentStates.
|
|
27
|
+
//
|
|
28
|
+
// param [String, Array<String>] events the event(s) that trigger the transition.
|
|
29
|
+
// param [String, Array<String>] currentStates the state(s) that respond to the given event
|
|
30
|
+
// param [Function, null] callback the callback will be called before the transition happens
|
|
31
|
+
// param [String] nextState the state after the transition
|
|
32
|
+
FSM.prototype.addTransition = function(events, currentStates, callback, nextState) {
|
|
33
|
+
if(typeof(events) === 'string') { events = [events]; }
|
|
34
|
+
if(typeof(currentStates) === 'string') { currentStates = [currentStates]; }
|
|
35
|
+
for (var i = 0; i < events.length; i++) {
|
|
36
|
+
for (var j = 0; j < currentStates.length; j++) {
|
|
37
|
+
if (!nextState) { nextState = currentStates[j]; } // stay in state if no nextState given
|
|
38
|
+
this.stateTransitions[ [events[i], currentStates[j]] ] = [callback, nextState];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// Specify a "from any state" transition. This is applied if no specific transition is
|
|
45
|
+
// found for the currentState and event given
|
|
46
|
+
//
|
|
47
|
+
// param [String, Array<String>] events the event(s) that trigger the transition.
|
|
48
|
+
// param [Function, null] callback the callback will be called before the transition happens
|
|
49
|
+
// param [String] nextState the state after the transition
|
|
50
|
+
FSM.prototype.addTransitionFromAnyState = function(events, callback, nextState) {
|
|
51
|
+
if(typeof(events) === 'string') { events = [events]; }
|
|
52
|
+
for (var i = 0; i < events.length; i++) {
|
|
53
|
+
this.stateTransitionsFromAnyState[ events[i] ] = [callback, nextState];
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// Specify a "default" transition. This is applied if no other matching transition is
|
|
59
|
+
// found for the currentState and given event
|
|
60
|
+
//
|
|
61
|
+
// param [Function, null] callback the callback(s) will be called before the transition happens
|
|
62
|
+
// param [String] nextState the state after the transition
|
|
63
|
+
FSM.prototype.setDefaultTransition = function(callback, nextState) {
|
|
64
|
+
this.defaultTransition = [callback, nextState];
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
// Get the transition for the currentState and event given.
|
|
69
|
+
// Based on the current state and the event given, the state machine applies the first matching
|
|
70
|
+
// transition in the following order:
|
|
71
|
+
// * "specific" (for given currentState and event)
|
|
72
|
+
// * "from any state" (for given event)
|
|
73
|
+
// * "default" (if no matching transitions are found by now)
|
|
74
|
+
//
|
|
75
|
+
// param [String] event the event
|
|
76
|
+
// param [String] state the state
|
|
77
|
+
// return [Transition] the matching transition. [Callback, NextState]
|
|
78
|
+
FSM.prototype.getTransition = function(event, state) {
|
|
79
|
+
var r;
|
|
80
|
+
r = this.stateTransitions[[event, state]] || // first try "specific"
|
|
81
|
+
this.stateTransitionsFromAnyState[event] || // then try "from any state"
|
|
82
|
+
this.defaultTransition // lastly try default transition
|
|
83
|
+
if (r) {
|
|
84
|
+
// return [callback, newState] tuple. Stay in currentState if no nextState given
|
|
85
|
+
return [r[0], r[1] || this.currentState]
|
|
86
|
+
} else {
|
|
87
|
+
throw Error("Transition is undefined: (" + event + ", " + state + ")");
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
// Send an event to the state machine to trigger a transition.
|
|
93
|
+
//
|
|
94
|
+
// param [String] event the event to send to the state machine
|
|
95
|
+
// param [Object, optional] eventData data specific for this event. Available as eventData in
|
|
96
|
+
// callback
|
|
97
|
+
FSM.prototype.sendEvent = function(event, eventData) {
|
|
98
|
+
var result = this.getTransition(event, this.currentState),
|
|
99
|
+
currentState = this.currentState,
|
|
100
|
+
newState,
|
|
101
|
+
callback,
|
|
102
|
+
debugMsg;
|
|
103
|
+
newState = result[1];
|
|
104
|
+
callback = result[0];
|
|
105
|
+
|
|
106
|
+
if (this.debug && window.console && window.console.log) {
|
|
107
|
+
debugMsg = [];
|
|
108
|
+
if (this.data.name) {
|
|
109
|
+
debugMsg.push(this.data.name + ': ');
|
|
110
|
+
} else {
|
|
111
|
+
debugMsg.push('FSM: ');
|
|
112
|
+
}
|
|
113
|
+
debugMsg.push(event + ': ');
|
|
114
|
+
debugMsg.push(currentState + ' -> ' + newState);
|
|
115
|
+
if (eventData) { debugMsg.push('; with event data'); }
|
|
116
|
+
if (callback) { debugMsg.push('; with callback'); }
|
|
117
|
+
window.console.log(debugMsg.join(''));
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
this.currentState = newState;
|
|
121
|
+
this.action = callback;
|
|
122
|
+
if (callback) {
|
|
123
|
+
callback.call(this, eventData); // call callback in state_machine context
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* ES6 LOGGER */
|
|
2
|
+
/*
|
|
3
|
+
import Logger from 'node-logger-es6'
|
|
4
|
+
|
|
5
|
+
var es6Logger = Logger.configure(
|
|
6
|
+
{
|
|
7
|
+
level: 'debug',
|
|
8
|
+
rotation: 'd',
|
|
9
|
+
size: 5,
|
|
10
|
+
json: true,
|
|
11
|
+
timestamp: true
|
|
12
|
+
}
|
|
13
|
+
);
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/* CUSTOM-LOGGER */
|
|
17
|
+
/* Note currently customLogger uses console only
|
|
18
|
+
we can replace it with any other logger for
|
|
19
|
+
instances: es6Logger or ameyoLogger or winstonLogger.
|
|
20
|
+
essentially the idea is not to duplicate the logic of
|
|
21
|
+
handling levels and output stream.
|
|
22
|
+
*/
|
|
23
|
+
export var customLogger = {
|
|
24
|
+
|
|
25
|
+
log : (arg1, ...args) => {
|
|
26
|
+
console.log(arg1, args)
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
info : (arg1, ...args) => {
|
|
30
|
+
console.log(arg1, args)
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
warn : (arg1, ...args) => {
|
|
34
|
+
console.log(arg1, args)
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
error : (arg1, ...args) => {
|
|
38
|
+
console.log(arg1, args)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/* CONSOLE LOGGER */
|
|
44
|
+
var consoleLogger = console;
|
|
45
|
+
|
|
46
|
+
/* FINAL LOGGER TO USE */
|
|
47
|
+
export function webrtcLogger() {
|
|
48
|
+
if (customLogger) {
|
|
49
|
+
return customLogger;
|
|
50
|
+
} else {
|
|
51
|
+
return consoleLogger;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// JS Finite State Machine
|
|
2
|
+
//
|
|
3
|
+
// A simple finite state machine library for code flow and transition control.
|
|
4
|
+
//
|
|
5
|
+
// https://github.com/jhund/js-finite-state-machine
|
|
6
|
+
// Copyright (c)2011 Jo Hund, ClearCove Software Inc.
|
|
7
|
+
// Based originally on FSM by Anthony Blackshaw <ant@getme.co.uk> (www.getme.co.uk) Copyright (c)2008
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
// Initializes a new state machine.
|
|
11
|
+
// Usage: var fsm = new FSM("initial", { d1: "foo", d2: "bar" });
|
|
12
|
+
//
|
|
13
|
+
// param [String] initialState the initial state of the state machine
|
|
14
|
+
// param [Object, optional] data data specific to this state machine. Is available as this.data in
|
|
15
|
+
// callbacks
|
|
16
|
+
function FSM(initialState, data) {
|
|
17
|
+
this.stateTransitions = {};
|
|
18
|
+
this.stateTransitionsFromAnyState = {};
|
|
19
|
+
this.defaultTransition = null;
|
|
20
|
+
this.currentState = initialState;
|
|
21
|
+
this.data = data;
|
|
22
|
+
this.debug = true; // set to true to turn on console output for debugging (see function "sendEvent")
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// Specify a "specific" transition for given events and currentStates.
|
|
27
|
+
//
|
|
28
|
+
// param [String, Array<String>] events the event(s) that trigger the transition.
|
|
29
|
+
// param [String, Array<String>] currentStates the state(s) that respond to the given event
|
|
30
|
+
// param [Function, null] callback the callback will be called before the transition happens
|
|
31
|
+
// param [String] nextState the state after the transition
|
|
32
|
+
FSM.prototype.addTransition = function(events, currentStates, callback, nextState) {
|
|
33
|
+
if(typeof(events) === 'string') { events = [events]; }
|
|
34
|
+
if(typeof(currentStates) === 'string') { currentStates = [currentStates]; }
|
|
35
|
+
for (var i = 0; i < events.length; i++) {
|
|
36
|
+
for (var j = 0; j < currentStates.length; j++) {
|
|
37
|
+
if (!nextState) { nextState = currentStates[j]; } // stay in state if no nextState given
|
|
38
|
+
this.stateTransitions[ [events[i], currentStates[j]] ] = [callback, nextState];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// Specify a "from any state" transition. This is applied if no specific transition is
|
|
45
|
+
// found for the currentState and event given
|
|
46
|
+
//
|
|
47
|
+
// param [String, Array<String>] events the event(s) that trigger the transition.
|
|
48
|
+
// param [Function, null] callback the callback will be called before the transition happens
|
|
49
|
+
// param [String] nextState the state after the transition
|
|
50
|
+
FSM.prototype.addTransitionFromAnyState = function(events, callback, nextState) {
|
|
51
|
+
if(typeof(events) === 'string') { events = [events]; }
|
|
52
|
+
for (var i = 0; i < events.length; i++) {
|
|
53
|
+
this.stateTransitionsFromAnyState[ events[i] ] = [callback, nextState];
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// Specify a "default" transition. This is applied if no other matching transition is
|
|
59
|
+
// found for the currentState and given event
|
|
60
|
+
//
|
|
61
|
+
// param [Function, null] callback the callback(s) will be called before the transition happens
|
|
62
|
+
// param [String] nextState the state after the transition
|
|
63
|
+
FSM.prototype.setDefaultTransition = function(callback, nextState) {
|
|
64
|
+
this.defaultTransition = [callback, nextState];
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
// Get the transition for the currentState and event given.
|
|
69
|
+
// Based on the current state and the event given, the state machine applies the first matching
|
|
70
|
+
// transition in the following order:
|
|
71
|
+
// * "specific" (for given currentState and event)
|
|
72
|
+
// * "from any state" (for given event)
|
|
73
|
+
// * "default" (if no matching transitions are found by now)
|
|
74
|
+
//
|
|
75
|
+
// param [String] event the event
|
|
76
|
+
// param [String] state the state
|
|
77
|
+
// return [Transition] the matching transition. [Callback, NextState]
|
|
78
|
+
FSM.prototype.getTransition = function(event, state) {
|
|
79
|
+
var r;
|
|
80
|
+
r = this.stateTransitions[[event, state]] || // first try "specific"
|
|
81
|
+
this.stateTransitionsFromAnyState[event] || // then try "from any state"
|
|
82
|
+
this.defaultTransition // lastly try default transition
|
|
83
|
+
if (r) {
|
|
84
|
+
// return [callback, newState] tuple. Stay in currentState if no nextState given
|
|
85
|
+
return [r[0], r[1] || this.currentState]
|
|
86
|
+
} else {
|
|
87
|
+
throw Error("Transition is undefined: (" + event + ", " + state + ")");
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
// Send an event to the state machine to trigger a transition.
|
|
93
|
+
//
|
|
94
|
+
// param [String] event the event to send to the state machine
|
|
95
|
+
// param [Object, optional] eventData data specific for this event. Available as eventData in
|
|
96
|
+
// callback
|
|
97
|
+
FSM.prototype.sendEvent = function(event, eventData) {
|
|
98
|
+
var result = this.getTransition(event, this.currentState),
|
|
99
|
+
currentState = this.currentState,
|
|
100
|
+
newState,
|
|
101
|
+
callback,
|
|
102
|
+
debugMsg;
|
|
103
|
+
newState = result[1];
|
|
104
|
+
callback = result[0];
|
|
105
|
+
|
|
106
|
+
if (this.debug && window.console && window.console.log) {
|
|
107
|
+
debugMsg = [];
|
|
108
|
+
if (this.data.name) {
|
|
109
|
+
debugMsg.push(this.data.name + ': ');
|
|
110
|
+
} else {
|
|
111
|
+
debugMsg.push('FSM: ');
|
|
112
|
+
}
|
|
113
|
+
debugMsg.push(event + ': ');
|
|
114
|
+
debugMsg.push(currentState + ' -> ' + newState);
|
|
115
|
+
if (eventData) { debugMsg.push('; with event data'); }
|
|
116
|
+
if (callback) { debugMsg.push('; with callback'); }
|
|
117
|
+
window.console.log(debugMsg.join(''));
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
this.currentState = newState;
|
|
121
|
+
this.action = callback;
|
|
122
|
+
if (callback) {
|
|
123
|
+
callback.call(this, eventData); // call callback in state_machine context
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function __export(m) {
|
|
3
|
+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
4
|
+
}
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
__export(require("./levels"));
|
|
7
|
+
__export(require("./logger-factory"));
|
|
8
|
+
__export(require("./logger"));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Log levels.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
var Levels;
|
|
8
|
+
(function (Levels) {
|
|
9
|
+
Levels[Levels["error"] = 0] = "error";
|
|
10
|
+
Levels[Levels["warn"] = 1] = "warn";
|
|
11
|
+
Levels[Levels["log"] = 2] = "log";
|
|
12
|
+
Levels[Levels["debug"] = 3] = "debug";
|
|
13
|
+
})(Levels = exports.Levels || (exports.Levels = {}));
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var levels_1 = require("./levels");
|
|
4
|
+
var logger_1 = require("./logger");
|
|
5
|
+
/**
|
|
6
|
+
* Logger.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
var LoggerFactory = /** @class */ (function () {
|
|
10
|
+
function LoggerFactory() {
|
|
11
|
+
this.builtinEnabled = true;
|
|
12
|
+
this._level = levels_1.Levels.log;
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
this.loggers = {};
|
|
15
|
+
this.logger = this.getLogger("Exotel.WebrtcLib");
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(LoggerFactory.prototype, "level", {
|
|
18
|
+
get: function () {
|
|
19
|
+
return this._level;
|
|
20
|
+
},
|
|
21
|
+
set: function (newLevel) {
|
|
22
|
+
if (newLevel >= 0 && newLevel <= 3) {
|
|
23
|
+
this._level = newLevel;
|
|
24
|
+
}
|
|
25
|
+
else if (newLevel > 3) {
|
|
26
|
+
this._level = 3;
|
|
27
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
28
|
+
}
|
|
29
|
+
else if (levels_1.Levels.hasOwnProperty(newLevel)) {
|
|
30
|
+
this._level = newLevel;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this.logger.error("invalid 'level' parameter value: " + JSON.stringify(newLevel));
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(LoggerFactory.prototype, "connector", {
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
get: function () {
|
|
42
|
+
return this._connector;
|
|
43
|
+
},
|
|
44
|
+
set: function (value) {
|
|
45
|
+
if (!value) {
|
|
46
|
+
this._connector = undefined;
|
|
47
|
+
}
|
|
48
|
+
else if (typeof value === "function") {
|
|
49
|
+
this._connector = value;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this.logger.error("invalid 'connector' parameter value: " + JSON.stringify(value));
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
enumerable: true,
|
|
56
|
+
configurable: true
|
|
57
|
+
});
|
|
58
|
+
LoggerFactory.prototype.getLogger = function (category, label) {
|
|
59
|
+
if (label && this.level === 3) {
|
|
60
|
+
return new logger_1.Logger(this, category, label);
|
|
61
|
+
}
|
|
62
|
+
else if (this.loggers[category]) {
|
|
63
|
+
return this.loggers[category];
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
var logger = new logger_1.Logger(this, category);
|
|
67
|
+
this.loggers[category] = logger;
|
|
68
|
+
return logger;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
|
+
LoggerFactory.prototype.genericLog = function (levelToLog, category, label, content) {
|
|
73
|
+
if (this.level >= levelToLog) {
|
|
74
|
+
if (this.builtinEnabled) {
|
|
75
|
+
this.print(levelToLog, category, label, content);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (this.connector) {
|
|
79
|
+
this.connector(levels_1.Levels[levelToLog], category, label, content);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
+
LoggerFactory.prototype.print = function (levelToLog, category, label, content) {
|
|
84
|
+
if (typeof content === "string") {
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
+
var prefix = [new Date(), category];
|
|
87
|
+
if (label) {
|
|
88
|
+
prefix.push(label);
|
|
89
|
+
}
|
|
90
|
+
content = prefix.concat(content).join(" | ");
|
|
91
|
+
}
|
|
92
|
+
switch (levelToLog) {
|
|
93
|
+
case levels_1.Levels.error:
|
|
94
|
+
// eslint-disable-next-line no-console
|
|
95
|
+
console.error(content);
|
|
96
|
+
break;
|
|
97
|
+
case levels_1.Levels.warn:
|
|
98
|
+
// eslint-disable-next-line no-console
|
|
99
|
+
console.warn(content);
|
|
100
|
+
break;
|
|
101
|
+
case levels_1.Levels.log:
|
|
102
|
+
// eslint-disable-next-line no-console
|
|
103
|
+
console.log(content);
|
|
104
|
+
break;
|
|
105
|
+
case levels_1.Levels.debug:
|
|
106
|
+
// eslint-disable-next-line no-console
|
|
107
|
+
console.debug(content);
|
|
108
|
+
break;
|
|
109
|
+
default:
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return LoggerFactory;
|
|
114
|
+
}());
|
|
115
|
+
exports.LoggerFactory = LoggerFactory;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Levels } from "./levels";
|
|
2
|
+
import { Logger } from "./logger";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Logger.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export class LoggerFactory {
|
|
9
|
+
public builtinEnabled = true;
|
|
10
|
+
|
|
11
|
+
private _level: Levels = Levels.log;
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
private _connector: ((level: string, category: string, label: string | undefined, content: any) => void) | undefined;
|
|
14
|
+
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
private loggers: any = {};
|
|
17
|
+
private logger: Logger;
|
|
18
|
+
|
|
19
|
+
constructor() {
|
|
20
|
+
this.logger = this.getLogger("Exotel.WebrtcLib");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get level(): Levels {
|
|
24
|
+
return this._level;
|
|
25
|
+
}
|
|
26
|
+
set level(newLevel: Levels) {
|
|
27
|
+
if (newLevel >= 0 && newLevel <= 3) {
|
|
28
|
+
this._level = newLevel;
|
|
29
|
+
} else if (newLevel > 3) {
|
|
30
|
+
this._level = 3;
|
|
31
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
32
|
+
} else if (Levels.hasOwnProperty(newLevel)) {
|
|
33
|
+
this._level = newLevel;
|
|
34
|
+
} else {
|
|
35
|
+
this.logger.error("invalid 'level' parameter value: " + JSON.stringify(newLevel));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
get connector(): ((level: string, category: string, label: string | undefined, content: any) => void) | undefined {
|
|
41
|
+
return this._connector;
|
|
42
|
+
}
|
|
43
|
+
set connector(
|
|
44
|
+
value:
|
|
45
|
+
| ((
|
|
46
|
+
level: string,
|
|
47
|
+
category: string,
|
|
48
|
+
label: string | undefined,
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
content: any
|
|
51
|
+
) => void)
|
|
52
|
+
| undefined
|
|
53
|
+
) {
|
|
54
|
+
if (!value) {
|
|
55
|
+
this._connector = undefined;
|
|
56
|
+
} else if (typeof value === "function") {
|
|
57
|
+
this._connector = value;
|
|
58
|
+
} else {
|
|
59
|
+
this.logger.error("invalid 'connector' parameter value: " + JSON.stringify(value));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public getLogger(category: string, label?: string): Logger {
|
|
64
|
+
if (label && this.level === 3) {
|
|
65
|
+
return new Logger(this, category, label);
|
|
66
|
+
} else if (this.loggers[category]) {
|
|
67
|
+
return this.loggers[category];
|
|
68
|
+
} else {
|
|
69
|
+
const logger = new Logger(this, category);
|
|
70
|
+
this.loggers[category] = logger;
|
|
71
|
+
return logger;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
+
public genericLog(levelToLog: Levels, category: string, label: string | undefined, content: any): void {
|
|
77
|
+
if (this.level >= levelToLog) {
|
|
78
|
+
if (this.builtinEnabled) {
|
|
79
|
+
this.print(levelToLog, category, label, content);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (this.connector) {
|
|
84
|
+
this.connector(Levels[levelToLog], category, label, content);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
|
+
private print(levelToLog: Levels, category: string, label: string | undefined, content: any): void {
|
|
90
|
+
if (typeof content === "string") {
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
+
const prefix: Array<any> = [new Date(), category];
|
|
93
|
+
if (label) {
|
|
94
|
+
prefix.push(label);
|
|
95
|
+
}
|
|
96
|
+
content = prefix.concat(content).join(" | ");
|
|
97
|
+
}
|
|
98
|
+
switch (levelToLog) {
|
|
99
|
+
case Levels.error:
|
|
100
|
+
// eslint-disable-next-line no-console
|
|
101
|
+
console.error(content);
|
|
102
|
+
break;
|
|
103
|
+
case Levels.warn:
|
|
104
|
+
// eslint-disable-next-line no-console
|
|
105
|
+
console.warn(content);
|
|
106
|
+
break;
|
|
107
|
+
case Levels.log:
|
|
108
|
+
// eslint-disable-next-line no-console
|
|
109
|
+
console.log(content);
|
|
110
|
+
break;
|
|
111
|
+
case Levels.debug:
|
|
112
|
+
// eslint-disable-next-line no-console
|
|
113
|
+
console.debug(content);
|
|
114
|
+
break;
|
|
115
|
+
default:
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var levels_1 = require("./levels");
|
|
4
|
+
/**
|
|
5
|
+
* Logger.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
var Logger = /** @class */ (function () {
|
|
9
|
+
function Logger(logger, category, label) {
|
|
10
|
+
this.logger = logger;
|
|
11
|
+
this.category = category;
|
|
12
|
+
this.label = label;
|
|
13
|
+
}
|
|
14
|
+
Logger.prototype.error = function (content) {
|
|
15
|
+
this.genericLog(levels_1.Levels.error, content);
|
|
16
|
+
};
|
|
17
|
+
Logger.prototype.warn = function (content) {
|
|
18
|
+
this.genericLog(levels_1.Levels.warn, content);
|
|
19
|
+
};
|
|
20
|
+
Logger.prototype.log = function (content) {
|
|
21
|
+
this.genericLog(levels_1.Levels.log, content);
|
|
22
|
+
};
|
|
23
|
+
Logger.prototype.debug = function (content) {
|
|
24
|
+
this.genericLog(levels_1.Levels.debug, content);
|
|
25
|
+
};
|
|
26
|
+
Logger.prototype.genericLog = function (level, content) {
|
|
27
|
+
this.logger.genericLog(level, this.category, this.label, content);
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(Logger.prototype, "level", {
|
|
30
|
+
get: function () {
|
|
31
|
+
return this.logger.level;
|
|
32
|
+
},
|
|
33
|
+
set: function (newLevel) {
|
|
34
|
+
this.logger.level = newLevel;
|
|
35
|
+
},
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true
|
|
38
|
+
});
|
|
39
|
+
return Logger;
|
|
40
|
+
}());
|
|
41
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Levels } from "./levels";
|
|
2
|
+
import { LoggerFactory } from "./logger-factory";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Logger.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export class Logger {
|
|
9
|
+
private logger: LoggerFactory;
|
|
10
|
+
private category: string;
|
|
11
|
+
private label: string | undefined;
|
|
12
|
+
|
|
13
|
+
constructor(logger: LoggerFactory, category: string, label?: string) {
|
|
14
|
+
this.logger = logger;
|
|
15
|
+
this.category = category;
|
|
16
|
+
this.label = label;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public error(content: string): void {
|
|
20
|
+
this.genericLog(Levels.error, content);
|
|
21
|
+
}
|
|
22
|
+
public warn(content: string): void {
|
|
23
|
+
this.genericLog(Levels.warn, content);
|
|
24
|
+
}
|
|
25
|
+
public log(content: string): void {
|
|
26
|
+
this.genericLog(Levels.log, content);
|
|
27
|
+
}
|
|
28
|
+
public debug(content: string): void {
|
|
29
|
+
this.genericLog(Levels.debug, content);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private genericLog(level: Levels, content: string): void {
|
|
33
|
+
this.logger.genericLog(level, this.category, this.label, content);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get level(): Levels {
|
|
37
|
+
return this.logger.level;
|
|
38
|
+
}
|
|
39
|
+
set level(newLevel: Levels) {
|
|
40
|
+
this.logger.level = newLevel;
|
|
41
|
+
}
|
|
42
|
+
}
|