Skip to content

Commit a91ea24

Browse files
authored
Merge pull request DuendeArchive#304 from pawepaw/dev
fixes DuendeArchive#303. start monitoring session after session iframe is fully loaded
2 parents 1a14362 + 69dd350 commit a91ea24

File tree

6 files changed

+70
-38
lines changed

6 files changed

+70
-38
lines changed

dist/oidc-client.js

Lines changed: 20 additions & 8 deletions
Large diffs are not rendered by default.

dist/oidc-client.min.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.

lib/oidc-client.js

Lines changed: 20 additions & 8 deletions
Large diffs are not rendered by default.

lib/oidc-client.min.js

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

src/CheckSessionIFrame.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,28 @@ export default class CheckSessionIFrame {
1818
this._frame = window.document.createElement("iframe");
1919
this._frame.style.display = "none";
2020
this._frame.src = url;
21-
window.document.body.appendChild(this._frame);
2221

23-
this._boundMessageEvent = this._message.bind(this);
24-
window.addEventListener("message", this._boundMessageEvent, false);
2522
}
23+
load() {
24+
return new Promise((resolve) => {
25+
this._frame.onload = () => {
26+
resolve();
27+
}
2628

29+
window.document.body.appendChild(this._frame);
30+
this._boundMessageEvent = this._message.bind(this);
31+
window.addEventListener("message", this._boundMessageEvent, false);
32+
});
33+
}
2734
_message(e) {
2835
if (e.origin === this._frame_origin &&
2936
e.source === this._frame.contentWindow
3037
) {
31-
if (e.data === "error"){
38+
if (e.data === "error") {
3239
Log.error("error message from check session op iframe");
3340
this.stop();
3441
}
35-
else if (e.data === "changed"){
42+
else if (e.data === "changed") {
3643
Log.debug("changed message from check session op iframe");
3744
this.stop();
3845
this._callback();
@@ -42,13 +49,12 @@ export default class CheckSessionIFrame {
4249
}
4350
}
4451
}
45-
4652
start(session_state) {
4753
if (this._session_state !== session_state) {
4854
Log.debug("CheckSessionIFrame.start");
4955

5056
this.stop();
51-
57+
5258
this._session_state = session_state;
5359

5460
this._timer = window.setInterval(() => {

src/SessionMonitor.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export default class SessionMonitor {
5858
let interval = this._checkSessionInterval;
5959

6060
this._checkSessionIFrame = new this._CheckSessionIFrameCtor(this._callback.bind(this), client_id, url, interval);
61-
this._checkSessionIFrame.start(session_state);
61+
this._checkSessionIFrame.load().then(() => {
62+
this._checkSessionIFrame.start(session_state);
63+
});
6264
}
6365
else {
6466
Log.warn("No check session iframe found in the metadata");
@@ -98,7 +100,7 @@ export default class SessionMonitor {
98100

99101
if (session.sid === this._sid) {
100102
Log.debug("Same sub still logged in at OP, restarting check session iframe; session_state:", session.session_state);
101-
}
103+
}
102104
else {
103105
Log.debug("Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:", session.session_state);
104106
this._userManager.events._raiseUserSessionChanged();

0 commit comments

Comments
 (0)