mirror of https://github.com/OpenVidu/openvidu.git
openvidu-pro: Index browser logs based on finalUserId
parent
7c494b0476
commit
a8917c17ac
|
@ -1323,12 +1323,12 @@ export class Session extends EventDispatcher {
|
|||
reject(error);
|
||||
} else {
|
||||
|
||||
// Configure JSNLogs
|
||||
OpenViduLogger.configureJSNLog(this.openvidu, this.sessionId, response.id, token);
|
||||
|
||||
// Process join room response
|
||||
this.processJoinRoomResponse(response);
|
||||
|
||||
// Configure JSNLogs
|
||||
OpenViduLogger.configureJSNLog(this.openvidu, token);
|
||||
|
||||
// Initialize local Connection object with values returned by openvidu-server
|
||||
this.connection = new Connection(this, response);
|
||||
|
||||
|
|
|
@ -12,29 +12,36 @@ export class OpenViduLogger {
|
|||
private MAX_MSECONDS_BATCH_MESSAGES: number = 5000;
|
||||
|
||||
private logger: Console = window.console;
|
||||
private loggingSessionId: string;
|
||||
private LOG_FNS = [this.logger.log, this.logger.debug, this.logger.info, this.logger.warn, this.logger.error];
|
||||
private currentAppender: any;
|
||||
|
||||
private isProdMode = false;
|
||||
private isJSNLogSetup = false;
|
||||
|
||||
// This two variables are used to restart JSNLog
|
||||
// on different sessions and different userIds
|
||||
private loggingSessionId: string | undefined;
|
||||
private loggingFinalUserId: string | undefined;
|
||||
|
||||
|
||||
private constructor() {}
|
||||
|
||||
static configureJSNLog(openVidu: OpenVidu, sessionId: string, connectionId: string, token: string) {
|
||||
static configureJSNLog(openVidu: OpenVidu, token: string) {
|
||||
// If instance is created is OpenVidu Pro
|
||||
if (this.instance && openVidu.webrtcStatsInterval > -1
|
||||
// If logs are enabled
|
||||
&& openVidu.sendBrowserLogs === OpenViduLoggerConfiguration.debug
|
||||
// If diferent session or first session
|
||||
&& sessionId !== this.instance.loggingSessionId) {
|
||||
// Only reconfigure it if session or finalUserId has changed
|
||||
&& this.instance.canConfigureJSNLog(openVidu, this.instance)) {
|
||||
|
||||
try {
|
||||
// isJSNLogSetup will not be true until completed setup
|
||||
this.instance.isJSNLogSetup = false;
|
||||
this.instance.info("Configuring JSNLogs.");
|
||||
|
||||
const finalUserId = openVidu.finalUserId;
|
||||
const sessionId = openVidu.session.sessionId;
|
||||
|
||||
const beforeSendCallback = (xhr) => {
|
||||
// If 401 or 403 or 404 modify ready and status so JSNLog don't retry to send logs
|
||||
// https://github.com/mperdeck/jsnlog.js/blob/v2.30.0/jsnlog.ts#L805-L818
|
||||
|
@ -48,16 +55,16 @@ export class OpenViduLogger {
|
|||
}
|
||||
|
||||
// Headers to identify and authenticate logs
|
||||
xhr.setRequestHeader('Authorization', "Basic " + btoa(`${connectionId}%/%${sessionId}` + ":" + token));
|
||||
xhr.setRequestHeader('Authorization', "Basic " + btoa(`${finalUserId}%/%${sessionId}` + ":" + token));
|
||||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
|
||||
// Additional headers for OpenVidu
|
||||
xhr.setRequestHeader('OV-Connection-Id', connectionId);
|
||||
xhr.setRequestHeader('OV-Final-User-Id', finalUserId);
|
||||
xhr.setRequestHeader('OV-Session-Id', sessionId);
|
||||
xhr.setRequestHeader('OV-Token', token);
|
||||
}
|
||||
|
||||
// Creation of the appender.
|
||||
this.instance.currentAppender = JL.createAjaxAppender("appender-" + connectionId);
|
||||
this.instance.currentAppender = JL.createAjaxAppender(`appender-${finalUserId}-${sessionId}`);
|
||||
this.instance.currentAppender.setOptions({
|
||||
beforeSend: beforeSendCallback,
|
||||
maxBatchSize: 1000,
|
||||
|
@ -70,7 +77,7 @@ export class OpenViduLogger {
|
|||
const getCircularReplacer = () => {
|
||||
const seen = new WeakSet();
|
||||
return (key, value) => {
|
||||
if (typeof value === "object" && value !== null) {
|
||||
if (typeof value === "object" && value != null) {
|
||||
if (seen.has(value)) {
|
||||
return;
|
||||
}
|
||||
|
@ -93,11 +100,15 @@ export class OpenViduLogger {
|
|||
|
||||
this.instance.isJSNLogSetup = true;
|
||||
this.instance.loggingSessionId = sessionId;
|
||||
this.instance.loggingFinalUserId = finalUserId;
|
||||
this.instance.info("JSNLog configured.");
|
||||
} catch (e) {
|
||||
console.error("Error configuring JSNLog: ");
|
||||
console.error(e);
|
||||
this.instance.isJSNLogSetup = false;
|
||||
this.instance.loggingSessionId = undefined;
|
||||
this.instance.loggingFinalUserId = undefined;
|
||||
this.instance.currentAppender = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -166,4 +177,8 @@ export class OpenViduLogger {
|
|||
return this.isJSNLogSetup;
|
||||
}
|
||||
|
||||
private canConfigureJSNLog(openVidu: OpenVidu, logger: OpenViduLogger): boolean {
|
||||
return openVidu.session.sessionId != logger.loggingSessionId || openVidu.finalUserId != logger.loggingFinalUserId
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,11 +50,11 @@ public class TokenRegister {
|
|||
* O(1)
|
||||
* Check if the current token string was registered in an active session
|
||||
* @param token Token string to check if it is registered
|
||||
* @param connectionId Id of the connection to check
|
||||
* @param finalUserId userId of browser to check
|
||||
* @param sessionId Id of session to check
|
||||
* @return <code>true</code> if token was registered. <code>false</code> otherwise
|
||||
*/
|
||||
public boolean isTokenRegistered(String token, String connectionId, String sessionId) {
|
||||
public boolean isTokenRegistered(String token, String finalUserId, String sessionId) {
|
||||
if (!this.tokensRegistered.containsKey(token)) {
|
||||
// False because token is not registered
|
||||
return false;
|
||||
|
@ -77,23 +77,9 @@ public class TokenRegister {
|
|||
|
||||
// In this final state, if connectionId is equal to participant public id and session Id is the same,
|
||||
// the token is registered correctly in the specific connectionId and sessionId
|
||||
return participantsByTokens.get(token).getParticipantPublicId().equals(connectionId)
|
||||
return participantsByTokens.get(token).getFinalUserId().equals(finalUserId)
|
||||
&& participantsByTokens.get(token).getSessionId().equals(sessionId);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* O(1)
|
||||
* Get registered token from token string
|
||||
* @param tokenKey string key which represents the token
|
||||
* @return
|
||||
*/
|
||||
public Token getRegisteredToken(String tokenKey) {
|
||||
Token token = this.tokensRegistered.get(tokenKey);
|
||||
if (token != null) {
|
||||
return token;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue