mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser: log JSNLog messages in dev mode. Better initPublisher log
parent
7e739bc2d4
commit
3f0756984a
|
@ -389,6 +389,7 @@ export class Publisher extends StreamManager {
|
||||||
const errorCallback = (openViduError: OpenViduError) => {
|
const errorCallback = (openViduError: OpenViduError) => {
|
||||||
this.accessDenied = true;
|
this.accessDenied = true;
|
||||||
this.accessAllowed = false;
|
this.accessAllowed = false;
|
||||||
|
logger.error(`Publisher initialization failed. ${openViduError.name}: ${openViduError.message}`)
|
||||||
reject(openViduError);
|
reject(openViduError);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -496,7 +497,7 @@ export class Publisher extends StreamManager {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getMediaError = error => {
|
const getMediaError = error => {
|
||||||
logger.error(`getMediaError: ${JSON.stringify(error)}`);
|
logger.error(`getMediaError: ${error.toString()}`);
|
||||||
this.clearPermissionDialogTimer(startTime, timeForDialogEvent);
|
this.clearPermissionDialogTimer(startTime, timeForDialogEvent);
|
||||||
if (error.name === 'Error') {
|
if (error.name === 'Error') {
|
||||||
// Safari OverConstrainedError has as name property 'Error' instead of 'OverConstrainedError'
|
// Safari OverConstrainedError has as name property 'Error' instead of 'OverConstrainedError'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {JL} from 'jsnlog'
|
import { JL } from 'jsnlog'
|
||||||
import {OpenVidu} from "../../OpenVidu/OpenVidu";
|
import { OpenVidu } from "../../OpenVidu/OpenVidu";
|
||||||
import {OpenViduLoggerConfiguration} from "./OpenViduLoggerConfiguration";
|
import { OpenViduLoggerConfiguration } from "./OpenViduLoggerConfiguration";
|
||||||
import JSNLogAjaxAppender = JL.JSNLogAjaxAppender;
|
import JSNLogAjaxAppender = JL.JSNLogAjaxAppender;
|
||||||
|
|
||||||
export class OpenViduLogger {
|
export class OpenViduLogger {
|
||||||
|
@ -25,16 +25,18 @@ export class OpenViduLogger {
|
||||||
private loggingFinalUserId: string | undefined;
|
private loggingFinalUserId: string | undefined;
|
||||||
|
|
||||||
|
|
||||||
private constructor() {}
|
private constructor() { }
|
||||||
|
|
||||||
static configureJSNLog(openVidu: OpenVidu, token: string) {
|
static configureJSNLog(openVidu: OpenVidu, token: string) {
|
||||||
try {
|
try {
|
||||||
// If instance is created and it is OpenVidu Pro
|
// If dev mode
|
||||||
if (this.instance && openVidu.webrtcStatsInterval > -1
|
if ((window['LOG_JSNLOG_RESULTS']) ||
|
||||||
// If logs are enabled
|
// If instance is created and it is OpenVidu Pro
|
||||||
&& openVidu.sendBrowserLogs === OpenViduLoggerConfiguration.debug
|
(this.instance && openVidu.webrtcStatsInterval > -1
|
||||||
// Only reconfigure it if session or finalUserId has changed
|
// If logs are enabled
|
||||||
&& this.instance.canConfigureJSNLog(openVidu, this.instance)) {
|
&& openVidu.sendBrowserLogs === OpenViduLoggerConfiguration.debug
|
||||||
|
// Only reconfigure it if session or finalUserId has changed
|
||||||
|
&& this.instance.canConfigureJSNLog(openVidu, this.instance))) {
|
||||||
// isJSNLogSetup will not be true until completed setup
|
// isJSNLogSetup will not be true until completed setup
|
||||||
this.instance.isJSNLogSetup = false;
|
this.instance.isJSNLogSetup = false;
|
||||||
this.instance.info("Configuring JSNLogs.");
|
this.instance.info("Configuring JSNLogs.");
|
||||||
|
@ -48,8 +50,8 @@ export class OpenViduLogger {
|
||||||
const parentReadyStateFunction = xhr.onreadystatechange;
|
const parentReadyStateFunction = xhr.onreadystatechange;
|
||||||
xhr.onreadystatechange = () => {
|
xhr.onreadystatechange = () => {
|
||||||
if ((xhr.status == 401) || (xhr.status == 403) || (xhr.status == 404)) {
|
if ((xhr.status == 401) || (xhr.status == 403) || (xhr.status == 404)) {
|
||||||
Object.defineProperty( xhr, "readyState", {value: 4});
|
Object.defineProperty(xhr, "readyState", { value: 4 });
|
||||||
Object.defineProperty( xhr, "status", {value: 200});
|
Object.defineProperty(xhr, "status", { value: 200 });
|
||||||
}
|
}
|
||||||
parentReadyStateFunction();
|
parentReadyStateFunction();
|
||||||
}
|
}
|
||||||
|
@ -88,10 +90,15 @@ export class OpenViduLogger {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Cut long messages
|
// Cut long messages
|
||||||
const stringifyJson = JSON.stringify(obj, getCircularReplacer());
|
let stringifyJson = JSON.stringify(obj, getCircularReplacer());
|
||||||
if (stringifyJson.length > this.instance.MAX_LENGTH_STRING_JSON) {
|
if (stringifyJson.length > this.instance.MAX_LENGTH_STRING_JSON) {
|
||||||
return `${stringifyJson.substring(0, this.instance.MAX_LENGTH_STRING_JSON)}...`;
|
stringifyJson = `${stringifyJson.substring(0, this.instance.MAX_LENGTH_STRING_JSON)}...`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (window['LOG_JSNLOG_RESULTS']) {
|
||||||
|
console.log(stringifyJson);
|
||||||
|
}
|
||||||
|
|
||||||
return stringifyJson;
|
return stringifyJson;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -121,7 +128,7 @@ export class OpenViduLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
static getInstance(): OpenViduLogger {
|
static getInstance(): OpenViduLogger {
|
||||||
if(!OpenViduLogger.instance){
|
if (!OpenViduLogger.instance) {
|
||||||
OpenViduLogger.instance = new OpenViduLogger();
|
OpenViduLogger.instance = new OpenViduLogger();
|
||||||
}
|
}
|
||||||
return OpenViduLogger.instance;
|
return OpenViduLogger.instance;
|
||||||
|
@ -135,7 +142,7 @@ export class OpenViduLogger {
|
||||||
return openVidu.session.sessionId != logger.loggingSessionId
|
return openVidu.session.sessionId != logger.loggingSessionId
|
||||||
}
|
}
|
||||||
|
|
||||||
log(...args: any[]){
|
log(...args: any[]) {
|
||||||
if (!this.isProdMode) {
|
if (!this.isProdMode) {
|
||||||
this.LOG_FNS[0].apply(this.logger, arguments);
|
this.LOG_FNS[0].apply(this.logger, arguments);
|
||||||
}
|
}
|
||||||
|
@ -176,12 +183,12 @@ export class OpenViduLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
flush() {
|
flush() {
|
||||||
if(this.isDebugLogEnabled() && this.currentAppender != null) {
|
if (this.isDebugLogEnabled() && this.currentAppender != null) {
|
||||||
this.currentAppender.sendBatch();
|
this.currentAppender.sendBatch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enableProdMode(){
|
enableProdMode() {
|
||||||
this.isProdMode = true;
|
this.isProdMode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue