Skip to content

Commit 864d813

Browse files
committed
Added push notification support. v8.5.7
1 parent 576338e commit 864d813

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

demo/main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ Gleap.log("Test log err", "ERROR");
3131

3232
Gleap.trackEvent("Master Event");
3333

34+
Gleap.on("unregister-pushmessage-group", (data) => {
35+
console.log("unreg", data);
36+
});
37+
38+
Gleap.on("register-pushmessage-group", (data) => {
39+
console.log("reg", data);
40+
});
41+
3442
// Register custom action.
3543
Gleap.registerCustomAction((customAction) => {
3644
console.log("Custom action called:");
@@ -53,4 +61,4 @@ setTimeout(() => {
5361
xmlhttp.setRequestHeader("asdfasdf1", "wertwertwert1");
5462
xmlhttp.setRequestHeader("asdfasdf2", "wertwertwert2");
5563
xmlhttp.send();
56-
}, 1000);
64+
}, 1000);

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": "8.5.6",
3+
"version": "8.5.7",
44
"main": "build/index.js",
55
"scripts": {
66
"start": "webpack serve",

src/GleapSession.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GleapFrameManager, GleapNotificationManager } from "./Gleap";
1+
import { GleapEventManager, GleapFrameManager, GleapNotificationManager } from "./Gleap";
22
import { eraseGleapCookie, getGleapCookie, loadFromGleapCache, saveToGleapCache, setGleapCookie } from "./GleapHelper";
33

44
export default class GleapSession {
@@ -91,6 +91,10 @@ export default class GleapSession {
9191
};
9292

9393
clearSession = (attemp = 0, retry = true) => {
94+
if (this.session && this.session.gleapHash) {
95+
GleapEventManager.notifyEvent("unregister-pushmessage-group", `gleapuser-${this.session.gleapHash}`);
96+
}
97+
9498
try {
9599
saveToGleapCache(`session-${this.sdkKey}`, null);
96100
} catch (exp) { }
@@ -103,13 +107,13 @@ export default class GleapSession {
103107

104108
this.ready = false;
105109
this.session = {
106-
id: null,
107-
hash: null,
108-
type: null,
110+
gleapId: null,
111+
gleapHash: null,
109112
name: "",
110113
email: "",
114+
userId: "",
111115
phone: "",
112-
value: 0,
116+
value: 0
113117
};
114118

115119
GleapFrameManager.getInstance().sendMessage({
@@ -134,6 +138,16 @@ export default class GleapSession {
134138
return;
135139
}
136140

141+
var sessionChanged = true;
142+
if (this.session && this.session.gleapHash && this.session.gleapHash === session.gleapHash) {
143+
sessionChanged = false;
144+
}
145+
146+
// Unregister previous group.
147+
if (this.session && this.session.gleapHash && sessionChanged) {
148+
GleapEventManager.notifyEvent("unregister-pushmessage-group", `gleapuser-${this.session.gleapHash}`);
149+
}
150+
137151
saveToGleapCache(`session-${this.sdkKey}`, session);
138152
if (this.useCookies) {
139153
setGleapCookie(`session-${this.sdkKey}`, encodeURIComponent(JSON.stringify(session)), 365);
@@ -142,6 +156,11 @@ export default class GleapSession {
142156
this.session = session;
143157
this.ready = true;
144158

159+
// Register new push group.
160+
if (this.session && this.session.gleapHash && sessionChanged) {
161+
GleapEventManager.notifyEvent("register-pushmessage-group", `gleapuser-${this.session.gleapHash}`);
162+
}
163+
145164
this.notifySessionReady();
146165
};
147166

@@ -285,7 +304,7 @@ export default class GleapSession {
285304
...userData.customData,
286305
}
287306
}
288-
307+
289308
http.send(
290309
JSON.stringify({
291310
...dataToSend,

0 commit comments

Comments
 (0)