-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e78e0a
commit 7190352
Showing
15 changed files
with
312 additions
and
76 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class IFrameError extends Error {} | ||
module.exports = IFrameError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const IFrameError = require('../errors/IFrameError'); | ||
|
||
class IFrameController { | ||
constructor({w = window} = {}) { | ||
this.window = w; | ||
} | ||
|
||
open(url) { | ||
this.iFrame = this.window.document.createElement('iframe'); | ||
this.iFrame.src = url; | ||
this.iFrame.width = 0; | ||
this.iFrame.height = 0; | ||
this.window.document.body.appendChild(this.iFrame); | ||
} | ||
|
||
remove() { | ||
window.document.body.removeChild(this.iFrame); | ||
} | ||
|
||
async waitForMessage({messageType}) { | ||
return new Promise((resolve, reject) => { | ||
const timer = setInterval(() => { | ||
reject(new IFrameError('Silent sign-in timed out')); | ||
}, 5 * 1000); | ||
window.addEventListener('message', (message) => { | ||
if (!message.data || message.data.type !== messageType) { | ||
return; | ||
} | ||
clearInterval(timer); | ||
resolve(message); | ||
}); | ||
}); | ||
} | ||
} | ||
module.exports = IFrameController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.