jamClient proxy

jamClient proxy acts as a wrapper which intercept methods
been passed to JK.jamClient and logs them
This commit is contained in:
Nuwan 2022-06-04 19:14:44 +05:30
parent ee54464cfc
commit 7721a9fa39
6 changed files with 35 additions and 0 deletions

View File

@ -2,6 +2,7 @@
// !!!! Keep white space after last require !!!!
//
//= require fakeJamClient
//= require jamClientProxy
//= require fakeJamClientMessages
//= require fakeJamClientRecordings
//= require backend_alerts

View File

@ -0,0 +1,28 @@
(function (context, $) {
"use strict";
context.JK = context.JK || {};
context.JK.jamClientProxy = function (obj) {
const logger = context.JK.logger;
//logger.info("*** JamClient Proxy instance initialized. ***");
return new Proxy(obj, {
get(target, prop) {
if (typeof target[prop] === 'function') {
return new Proxy(target[prop], {
apply: (target, thisArg, argumentsList) => {
logger.info('*** calling JK.jamClient.', prop, argumentsList);
return Reflect.apply(target, thisArg, argumentsList);
}
});
} else {
return Reflect.get(target, prop);
}
}
});
}
})(window, jQuery);

View File

@ -85,6 +85,7 @@
//= require ../web/affiliate_program
//= require ../web/affiliate_links
//= require fakeJamClient
//= require jamClientProxy
//= require fakeJamClientMessages
//= require fakeJamClientRecordings
//= require JamServer

View File

@ -18,6 +18,7 @@
//= require modern/JamServer_copy
//= require fakeJamClient
//= require jamClientProxy
//= require fakeJamClientMessages
//= require fakeJamClientRecordings

View File

@ -1163,6 +1163,9 @@
window.jamClient = interceptedJamClient;
}
//wrap jamClient in a proxy wrapper
window.jamClient = new JK.jamClientProxy(window.jamClient);
}
// pass in 'arguments' in a fail callback of a $.ajax

View File

@ -81,6 +81,7 @@
//= require web/affiliate_program
//= require web/affiliate_links
//= require fakeJamClient
//= require jamClientProxy
//= require fakeJamClientMessages
//= require fakeJamClientRecordings
//= require JamServer