forked from simonmartyr/MxPushNotifications
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from mendix/release/7.4.0
[UIA-15] Add support for web push
- Loading branch information
Showing
27 changed files
with
118 additions
and
3,565 deletions.
There are no files selected for viewing
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
Binary file not shown.
55 changes: 55 additions & 0 deletions
55
test/javascriptsource/pushnotifications/actions/RegisterForPushNotificationsWeb.js
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,55 @@ | ||
// This file was generated by Mendix Studio Pro. | ||
// | ||
// WARNING: Only the following code will be retained when actions are regenerated: | ||
// - the import list | ||
// - the code between BEGIN USER CODE and END USER CODE | ||
// - the code between BEGIN EXTRA CODE and END EXTRA CODE | ||
// Other code you write will be lost the next time you deploy the project. | ||
import "mx-global"; | ||
import { Big } from "big.js"; | ||
|
||
// BEGIN EXTRA CODE | ||
async function wait(timeout) { | ||
return new Promise(resolve => setTimeout(resolve, timeout)) | ||
} | ||
|
||
async function attemptWithRetries(retries, timeout, action) { | ||
for (let trial = 0; trial < retries; trial++) { | ||
try { | ||
return await action(); | ||
} catch (err) { | ||
await wait(timeout); | ||
} | ||
} | ||
return await action(); | ||
} | ||
// END EXTRA CODE | ||
|
||
/** | ||
* @param {string} vapidKey | ||
* @returns {Promise.<string>} | ||
*/ | ||
export async function RegisterForPushNotificationsWeb(vapidKey) { | ||
// BEGIN USER CODE | ||
if ("Notification" in window !== true) | ||
throw new Error("Notification API not available."); | ||
|
||
if ("firebase" in window !== true) | ||
throw new Error("Firebase API not available."); | ||
|
||
if (vapidKey === undefined || vapidKey === "") | ||
throw new Error("VAPID (Voluntary Application Server Identification) key not available.") | ||
|
||
// Request permission | ||
const permission = await Notification.requestPermission(); | ||
if (permission !== "granted") | ||
throw new Error("Permission to receive push notifications not granted.") | ||
|
||
// Get token | ||
const messaging = firebase.messaging(); | ||
const token = await attemptWithRetries(3, 1000, async () => await messaging.getToken({ vapidKey })); | ||
|
||
console.info("Registered for push notifications with token: " + token); | ||
return token; | ||
// END USER CODE | ||
} |
25 changes: 0 additions & 25 deletions
25
test/javasource/atlas_nativemobile_content/proxies/constants/Constants.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.