Skip to content

Commit 2ed3011

Browse files
committed
v12.1.3
1 parent 11aaf48 commit 2ed3011

File tree

8 files changed

+166
-18
lines changed

8 files changed

+166
-18
lines changed

build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/demoframe.html

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Message Listener Example</title>
8+
<script>
9+
// This function runs once the DOM is ready to be manipulated
10+
document.addEventListener('DOMContentLoaded', function () {
11+
// Access the iframe element
12+
var iframe = document.getElementById('example-iframe');
13+
14+
// This function handles received messages
15+
function receiveMessage(event) {
16+
// Check the origin to ensure the message is from a trusted source
17+
if (event.origin !== "http://0.0.0.0:4444") {
18+
console.error('Received message from unauthorized source');
19+
return; // Stop if the origin is not as expected
20+
}
21+
22+
// Log the message data for demonstration purposes
23+
const data = JSON.parse(event.data);
24+
25+
console.log(data);
26+
27+
// Respond with a 'pong' message
28+
if (data.type === 'admin' && data.name === 'init') {
29+
iframe.contentWindow.postMessage(JSON.stringify({
30+
type: "admin",
31+
name: "load"
32+
}), "*");
33+
34+
setTimeout(() => {
35+
iframe.contentWindow.postMessage(JSON.stringify({
36+
type: "admin",
37+
name: "pick"
38+
}), "*");
39+
}, 2500);
40+
}
41+
}
42+
43+
// Listen for message events
44+
window.addEventListener('message', receiveMessage, false);
45+
});
46+
</script>
47+
</head>
48+
49+
<body>
50+
<h1>Iframe Message Communication Example</h1>
51+
<!-- The iframe from where we will receive messages -->
52+
<iframe id="example-iframe" src="http://0.0.0.0:4444/" style="width: 600px; height: 400px;"></iframe>
53+
</body>
54+
55+
</html>

demo/main.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
const Gleap = window.Gleap;
22

3-
//Gleap.setFrameUrl("http://0.0.0.0:3001");
4-
//Gleap.setApiUrl("http://0.0.0.0:9000");
5-
//Gleap.setWSApiUrl("ws://0.0.0.0:8080");
3+
Gleap.setFrameUrl("http://0.0.0.0:3001");
4+
Gleap.setApiUrl("http://0.0.0.0:9000");
5+
Gleap.setWSApiUrl("ws://0.0.0.0:8080");
66

77
// Gleap.setLanguage("en");
88

9-
Gleap.setReplayOptions({
10-
recordCanvas: true,
11-
sampling: {
12-
canvas: 15,
13-
},
14-
dataURLOptions: {
15-
type: 'image/webp',
16-
quality: 0.6,
17-
},
18-
});
19-
20-
Gleap.initialize("U7alA97Vzu15arf4XFpPyxNOdNAv4u0H");
9+
Gleap.initialize("ogWhNhuiZcGWrva5nlDS8l7a78OfaLlV");
2110

2211
/*Gleap.setUrlHandler((url, newTab) => {
2312
alert("URL: " + url + " newTab: " + newTab);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gleap",
3-
"version": "12.1.2",
3+
"version": "12.1.3",
44
"main": "build/index.js",
55
"scripts": {
66
"start": "webpack serve",

published/12.1.3/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

published/latest/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Gleap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import GleapNotificationManager from "./GleapNotificationManager";
2222
import GleapBannerManager from "./GleapBannerManager";
2323
import GleapAudioManager from "./GleapAudioManager";
2424
import GleapTagManager from "./GleapTagManager";
25+
import GleapAdminManager from "./GleapAdminManager";
2526

2627
if (typeof HTMLCanvasElement !== "undefined" && HTMLCanvasElement.prototype && HTMLCanvasElement.prototype.__originalGetContext === undefined) {
2728
HTMLCanvasElement.prototype.__originalGetContext =
@@ -72,6 +73,7 @@ class Gleap {
7273
GleapMetaDataManager.getInstance();
7374
GleapConsoleLogManager.getInstance().start();
7475
GleapClickListener.getInstance().start();
76+
GleapAdminManager.getInstance().start();
7577
}
7678
}
7779

src/GleapAdminManager.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
2+
export default class GleapAdminManager {
3+
libraryInstance = null;
4+
5+
// GleapAdminManager singleton
6+
static instance;
7+
static getInstance() {
8+
if (!this.instance) {
9+
this.instance = new GleapAdminManager();
10+
}
11+
return this.instance;
12+
}
13+
14+
loadScript(url, callback) {
15+
var script = document.createElement('script');
16+
script.type = 'text/javascript';
17+
script.src = url;
18+
19+
script.onload = function () {
20+
if (typeof callback === 'function') {
21+
callback();
22+
}
23+
};
24+
25+
script.onreadystatechange = function () {
26+
if (this.readyState === 'complete' || this.readyState === 'loaded') {
27+
script.onload();
28+
}
29+
};
30+
31+
document.head.appendChild(script);
32+
}
33+
34+
loadAdminScript() {
35+
var self = this;
36+
console.log("LOAD SCRIPT!");
37+
this.loadScript('https://jsadminhelper.gleap.io/index.js', function () {
38+
if (window.GleapHelper) {
39+
self.libraryInstance = new window.GleapHelper.default();
40+
if (self.libraryInstance) {
41+
self.libraryInstance.onElementPicked = (selector) => {
42+
self.sendMessage({
43+
name: "element-picked",
44+
data: {
45+
selector
46+
}
47+
});
48+
};
49+
}
50+
}
51+
});
52+
}
53+
54+
start() {
55+
var self = this;
56+
57+
// Add window message listener.
58+
window.addEventListener("message", (event) => {
59+
if (!event.origin || !(event.origin === "https://app.gleap.io" || event.origin.startsWith("http://localhost"))) {
60+
return;
61+
}
62+
63+
try {
64+
const data = JSON.parse(event.data);
65+
if (data.type !== "admin") {
66+
return;
67+
}
68+
69+
if (data.name === "load") {
70+
self.loadAdminScript();
71+
}
72+
73+
if (data.name === "pick") {
74+
self.libraryInstance.startPicker();
75+
}
76+
77+
if (data.name === "navigate") {
78+
self.libraryInstance.stopPicker();
79+
}
80+
} catch (exp) {
81+
console.log(exp);
82+
}
83+
});
84+
85+
this.sendMessage({
86+
name: "init",
87+
});
88+
}
89+
90+
sendMessage(data) {
91+
try {
92+
if (window && window.parent) {
93+
window.parent.postMessage(JSON.stringify({
94+
...data,
95+
type: "admin"
96+
}), "*");
97+
}
98+
} catch (e) { }
99+
}
100+
101+
}

0 commit comments

Comments
 (0)