Skip to content

Commit

Permalink
reduced verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
turtledreams committed Jan 10, 2025
1 parent b23bb98 commit f65e1b1
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 65 deletions.
89 changes: 55 additions & 34 deletions lib/countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -4386,8 +4386,22 @@
if (e) {
return;
}
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, received content: [" + resp + "]");
_classPrivateFieldGet2(_displayContent, _this).call(_this, resp);
if (!resp) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.VERBOSE, "sendContentRequest, no content to display");
return;
}
try {
var response = JSON.parse(resp);
} catch (error) {
// verbose log
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.VERBOSE, "sendContentRequest, No content to display or an error while parsing content: " + error);
return;
}
if (!response.html || !response.geo) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.VERBOSE, "sendContentRequest, no html content or orientation to display");
return;
}
_classPrivateFieldGet2(_displayContent, _this).call(_this, response);
clearInterval(_classPrivateFieldGet2(_contentZoneTimer, _this)); // prevent multiple content requests while one is on
window.addEventListener('message', function (event) {
_classPrivateFieldGet2(_interpretContentMessage, _this).call(_this, event);
Expand All @@ -4399,6 +4413,9 @@
var width = window.innerWidth;
var height = window.innerHeight;
var iframe = document.getElementById(_classPrivateFieldGet2(_contentIframeID, _this));
if (!iframe) {
return;
}
iframe.contentWindow.postMessage({
type: 'resize',
width: width,
Expand All @@ -4408,72 +4425,75 @@
});
}, true);
});
_classPrivateFieldInitSpec(this, _displayContent, function (content) {
if (!content) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "displayContent, no content to display");
return;
_classPrivateFieldInitSpec(this, _displayContent, function (response) {
try {
var iframe = document.createElement("iframe");
iframe.id = _classPrivateFieldGet2(_contentIframeID, _this);
iframe.src = response.html;
iframe.style.position = "absolute";
var dimensionToUse = response.geo.p;
var resInfo = _classPrivateFieldGet2(_getResolution, _this).call(_this, true);
if (resInfo.width >= resInfo.height) {
dimensionToUse = response.geo.l;
}
;
iframe.style.left = dimensionToUse.x + "px";
iframe.style.top = dimensionToUse.y + "px";
iframe.style.width = dimensionToUse.w + "px";
iframe.style.height = dimensionToUse.h + "px";
iframe.style.border = "none";
iframe.style.zIndex = "999999";
document.body.appendChild(iframe);
} catch (error) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.ERROR, "displayContent, Error while creating iframe for the content: " + error);
}
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "displayContent, displaying content");
var response = JSON.parse(content);
var iframe = document.createElement("iframe");
iframe.id = _classPrivateFieldGet2(_contentIframeID, _this);
iframe.src = response.html;
iframe.style.position = "absolute";
var dimensionToUse = response.geo.p;
var resInfo = _classPrivateFieldGet2(_getResolution, _this).call(_this, true);
if (resInfo.width >= resInfo.height) {
dimensionToUse = response.geo.l;
}
iframe.style.left = dimensionToUse.x + "px";
iframe.style.top = dimensionToUse.y + "px";
iframe.style.width = dimensionToUse.w + "px";
iframe.style.height = dimensionToUse.h + "px";
iframe.style.border = "none";
iframe.style.zIndex = "999999";
document.body.appendChild(iframe);
});
_classPrivateFieldInitSpec(this, _interpretContentMessage, function (messageEvent) {
if (messageEvent.origin !== _this.url) {
// this.#log(logLevelEnums.ERROR, "sendContentRequest, Received message from invalid origin");
// this.#log(logLevelEnums.ERROR, "interpretContentMessage, Received message from invalid origin");
// silent ignore
return;
}
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Received message from: [" + messageEvent.origin + "] with data: [" + JSON.stringify(messageEvent.data) + "]");
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, Received message from: [" + messageEvent.origin + "] with data: [" + JSON.stringify(messageEvent.data) + "]");
var _messageEvent$data = messageEvent.data,
close = _messageEvent$data.close,
link = _messageEvent$data.link,
event = _messageEvent$data.event,
resize_me = _messageEvent$data.resize_me;
if (event) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Received event");
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, Received event");
if (close === 1) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Closing content frame for event");
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, Closing content frame for event");
_classPrivateFieldGet2(_closeContentFrame, _this).call(_this);
}
if (!Array.isArray(event)) {
if (_typeof(event) === "object") {
_readOnlyError("event");
} else {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.ERROR, "sendContentRequest, Invalid event type: [" + _typeof(event) + "]");
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.ERROR, "interpretContentMessage, Invalid event type: [" + _typeof(event) + "]");
return;
}
}
// event is expected to be an array of events
for (var i = 0; i < event.length; i++) {
_classPrivateFieldGet2(_add_cly_events, _this).call(_this, event[i]);
_classPrivateFieldGet2(_add_cly_events, _this).call(_this, event[i]); // let this method handle the event
}
}
if (link) {
if (close === 1) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Closing content frame for link");
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, Closing content frame for link");
_classPrivateFieldGet2(_closeContentFrame, _this).call(_this);
}
window.open(link, "_blank");
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Opened link in new tab: [".concat(link, "]"));
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, Opened link in new tab: [".concat(link, "]"));
}
if (resize_me) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Resizing iframe");
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, Resizing iframe");
var resInfo = _classPrivateFieldGet2(_getResolution, _this).call(_this, true);
if (!resize_me.l || !resize_me.p || !resize_me.l.x || !resize_me.l.y || !resize_me.l.w || !resize_me.l.h || !resize_me.p.x || !resize_me.p.y || !resize_me.p.w || !resize_me.p.h) {
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.ERROR, "interpretContentMessage, Invalid resize object");
return;
}
var dimensionToUse = resize_me.p;
if (resInfo.width >= resInfo.height) {
dimensionToUse = resize_me.l;
Expand All @@ -4489,10 +4509,11 @@
}
});
_classPrivateFieldInitSpec(this, _closeContentFrame, function () {
// we might want to remove event listeners here too but with the current implementation, it seems unnecessary
var iframe = document.getElementById(_classPrivateFieldGet2(_contentIframeID, _this));
if (iframe) {
iframe.remove();
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, removed iframe");
_classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, removed iframe");
if (_classPrivateFieldGet2(_inContentZone, _this)) {
// if user did not exit content zone, re-enter
_classPrivateFieldGet2(_enterContentZoneInternal, _this).call(_this, true);
Expand Down
Loading

0 comments on commit f65e1b1

Please sign in to comment.