infobip-rtc
Version:
Infobip RTC JavaScript SDK - Infobip WebRTC API Implementation
41 lines • 1.19 kB
JavaScript
import { LoggerOptions } from "../log/LoggerOptions";
import { WsAction } from "../call/ws/WsAction";
export class WsErrorLogger {
constructor(errorSender, options = new LoggerOptions()) {
this.errorSender = errorSender;
this.options = options;
this.logs = [];
this.interval = this.createInterval(options.period);
}
error(log) {
this.logs.push(log);
if (this.logs.length > WsErrorLogger.MAX_LOGS) {
this.logs = this.logs.slice(-WsErrorLogger.MAX_LOGS);
}
}
stop() {
clearInterval(this.interval);
this.sendLogs();
}
sendLogs() {
if (this.logs.length > 0) {
try {
this.errorSender({
action: WsAction.ERROR,
errors: this.logs
});
this.logs = [];
}
catch (_) {
}
}
}
createInterval(period) {
return setInterval(() => {
this.sendLogs();
}, period || WsErrorLogger.DEFAULT_PERIOD);
}
}
WsErrorLogger.DEFAULT_PERIOD = 5000;
WsErrorLogger.MAX_LOGS = 50;
//# sourceMappingURL=WsErrorLogger.js.map