@progressive-development/pd-spa-helper 0.3.44 → 0.3.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/PdSpaHelper.js +0 -1
- package/dist/src/PdSpaHelper.js.map +1 -1
- package/dist/src/service-provider/firebase/messagingFirebaseClient.d.ts +2 -6
- package/dist/src/service-provider/firebase/messagingFirebaseClient.js +31 -37
- package/dist/src/service-provider/firebase/messagingFirebaseClient.js.map +1 -1
- package/dist/src/service-provider/service-provider-impl.js +3 -3
- package/dist/src/service-provider/service-provider-impl.js.map +1 -1
- package/dist/src/store/mini-rx.store.js +2 -1
- package/dist/src/store/mini-rx.store.js.map +1 -1
- package/dist/src/store/spa-app-actions.d.ts +29 -0
- package/dist/src/store/spa-app-actions.js +3 -0
- package/dist/src/store/spa-app-actions.js.map +1 -1
- package/dist/src/store/spa-app-effects.d.ts +7 -0
- package/dist/src/store/spa-app-effects.js +7 -1
- package/dist/src/store/spa-app-effects.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/PdSpaHelper.ts +0 -3
- package/src/service-provider/firebase/messagingFirebaseClient.ts +31 -46
- package/src/service-provider/service-provider-impl.ts +4 -3
- package/src/store/mini-rx.store.ts +3 -2
- package/src/store/spa-app-actions.ts +10 -1
- package/src/store/spa-app-effects.ts +13 -1
package/package.json
CHANGED
package/src/PdSpaHelper.ts
CHANGED
|
@@ -4,8 +4,6 @@ import { property } from 'lit/decorators.js';
|
|
|
4
4
|
|
|
5
5
|
import { Subscription } from 'rxjs';
|
|
6
6
|
|
|
7
|
-
import { FirebaseApp } from 'firebase/app';
|
|
8
|
-
|
|
9
7
|
import '@progressive-development/pd-page/pd-menu.js';
|
|
10
8
|
import '@progressive-development/pd-page/pd-footer.js';
|
|
11
9
|
|
|
@@ -44,7 +42,6 @@ const TOAST_DURATION = 6000;
|
|
|
44
42
|
/**
|
|
45
43
|
* Transformed routes, generated during startInit.
|
|
46
44
|
*/
|
|
47
|
-
let app:FirebaseApp | undefined;
|
|
48
45
|
let transformedRoutes:Array<any>;
|
|
49
46
|
let navigationConfig:NavigationConfig;
|
|
50
47
|
|
|
@@ -1,57 +1,42 @@
|
|
|
1
1
|
import { FirebaseApp } from "firebase/app";
|
|
2
|
-
import { getMessaging, getToken
|
|
2
|
+
import { getMessaging, getToken } from "firebase/messaging";
|
|
3
3
|
|
|
4
4
|
import { MessagingConfig } from "../service-provider-model.js";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import { pdStore } from "../../store/mini-rx.store.js";
|
|
7
|
+
import { updateNewNotificationToken } from "../../store/spa-app-actions.js";
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
9
|
+
export const NOTIFICATION_TOKEN = "pd.spa.helper.notification.token";
|
|
10
|
+
|
|
11
|
+
// Funktion zur Anfrage der Berechtigung
|
|
12
|
+
async function ensureNotificationPermission(): Promise<"default" | "denied" | "granted"> {
|
|
13
|
+
if (Notification.permission === "default") {
|
|
14
|
+
return Notification.requestPermission();
|
|
15
|
+
}
|
|
16
|
+
return Notification.permission;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
* During start/load application, initialize Messaging.
|
|
19
|
-
*
|
|
20
|
-
* @param {*} app - initialized app.
|
|
21
|
-
*/
|
|
22
|
-
export const initFirebaseMessaging = (
|
|
19
|
+
export async function registerDevice(
|
|
23
20
|
app: FirebaseApp,
|
|
24
21
|
messageConfig: MessagingConfig
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
console.log("My current Token")
|
|
40
|
-
|
|
22
|
+
) {
|
|
23
|
+
try {
|
|
24
|
+
const messaging = getMessaging(app);
|
|
25
|
+
const permission = await ensureNotificationPermission();
|
|
26
|
+
if (permission === "granted") {
|
|
27
|
+
const currentToken = await getToken(messaging, { vapidKey: messageConfig.apidKey });
|
|
28
|
+
const storedToken = localStorage.getItem(NOTIFICATION_TOKEN);
|
|
29
|
+
if (currentToken && storedToken !== currentToken) {
|
|
30
|
+
pdStore().dispatch(updateNewNotificationToken({
|
|
31
|
+
messagingToken: currentToken
|
|
32
|
+
}));
|
|
33
|
+
} else {
|
|
34
|
+
console.warn("No token received - no new token was generated.");
|
|
35
|
+
}
|
|
41
36
|
} else {
|
|
42
|
-
|
|
43
|
-
console.log('No registration token available. Request permission to generate one.');
|
|
44
|
-
requestPermission();
|
|
37
|
+
console.warn("Notifications were either not allowed or permanently denied.");
|
|
45
38
|
}
|
|
46
|
-
}
|
|
47
|
-
console.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// TODO: Invalid if above code not successfully => refcator avoid call without permissions
|
|
52
|
-
onMessage(messagingRef, (payload) => {
|
|
53
|
-
console.log('Message received. ', payload);
|
|
54
|
-
// ...
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error("Error during device registration:", error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -12,7 +12,7 @@ import { callFunctionMock, initMockResponse } from "./mock/function-client.js";
|
|
|
12
12
|
import { ServiceCallController } from "../service-call-controller2.js";
|
|
13
13
|
import { deleteFirestorageDocument, downloadFileFirestorage, getFirestorageFile, getFirestorageFileList, initFirestorage, uploadFirestorageFile } from "./firebase/firestorage-client.js";
|
|
14
14
|
import { downloadFileMock, getMockFileList, initStorageMock, uploadStorageFileMock } from "./mock/storage-client.js";
|
|
15
|
-
import {
|
|
15
|
+
import { registerDevice } from "./firebase/messagingFirebaseClient.js";
|
|
16
16
|
|
|
17
17
|
let provider: ServiceProviderConfiguration | undefined;
|
|
18
18
|
let controller: ServiceCallController;
|
|
@@ -57,8 +57,9 @@ const initFirebaseApplicationServices = (
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
if (config.messagingConfig) {
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
registerDevice(firebaseApp, config.messagingConfig)
|
|
61
|
+
.then(() => console.debug(`complet registerDevice, right is ${Notification.permission}`));
|
|
62
|
+
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
console.debug("Firebase initialized");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { configureStore, Store, LoggerExtension, ReduxDevtoolsExtension, ImmutableStateExtension } from 'mini-rx-store';
|
|
2
2
|
import { StoreConfig } from '../service-provider/service-provider-model.js';
|
|
3
3
|
import { spaAppReducer } from '../store/spa-app-reducer.js';
|
|
4
|
-
import { appRouteEffect } from '../store/spa-app-effects.js';
|
|
4
|
+
import { appRouteEffect, registerNotificationTokenSuccessEffect } from '../store/spa-app-effects.js';
|
|
5
5
|
|
|
6
6
|
let store: Store;
|
|
7
7
|
|
|
@@ -9,7 +9,8 @@ const registerEffects = (effects: any[]) => {
|
|
|
9
9
|
if (store) {
|
|
10
10
|
// Register default app route effect
|
|
11
11
|
store.effect(appRouteEffect);
|
|
12
|
-
|
|
12
|
+
store.effect(registerNotificationTokenSuccessEffect);
|
|
13
|
+
|
|
13
14
|
// Register configured effects
|
|
14
15
|
effects.forEach(effect => store.effect(effect));
|
|
15
16
|
} else {
|
|
@@ -14,4 +14,13 @@ export const changeSubTask = action('SPA_APP_CHANGE_SUB_LOADING', payload<{
|
|
|
14
14
|
loadingActionId: string,
|
|
15
15
|
newTaskState: LoadingSubTask
|
|
16
16
|
}>());
|
|
17
|
-
export const removeLoadingState = action('SPA_APP_REMOVE_LOADING', payload<string>());
|
|
17
|
+
export const removeLoadingState = action('SPA_APP_REMOVE_LOADING', payload<string>());
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export const updateNewNotificationToken = action('UPDATE_NOTIFICATION_TOKEN', payload<{
|
|
21
|
+
messagingToken: string
|
|
22
|
+
}>());
|
|
23
|
+
export const updateNewNotificationTokenSuccess = action('UPDATE_NOTIFICATION_TOKEN_SUCCESS', payload<{
|
|
24
|
+
messagingToken: string
|
|
25
|
+
}>());
|
|
26
|
+
export const updateNewNotificationTokenFail = action('UPDATE_NOTIFICATION_TOKEN_FAIL', payload<Error>());
|
|
@@ -4,7 +4,8 @@ import { tap } from 'rxjs/operators';
|
|
|
4
4
|
|
|
5
5
|
import { ofType } from 'ts-action-operators';
|
|
6
6
|
|
|
7
|
-
import { routeAction } from './spa-app-actions.js';
|
|
7
|
+
import { routeAction, updateNewNotificationTokenSuccess } from './spa-app-actions.js';
|
|
8
|
+
import { NOTIFICATION_TOKEN } from '../service-provider/firebase/messagingFirebaseClient.js';
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
let routeElement: HTMLElement;
|
|
@@ -34,3 +35,14 @@ export const appRouteEffect = createEffect(
|
|
|
34
35
|
dispatch: false
|
|
35
36
|
}
|
|
36
37
|
);
|
|
38
|
+
|
|
39
|
+
export const registerNotificationTokenSuccessEffect = createEffect(
|
|
40
|
+
actions$.pipe(
|
|
41
|
+
ofType(updateNewNotificationTokenSuccess),
|
|
42
|
+
tap((action) => {
|
|
43
|
+
localStorage.setItem(NOTIFICATION_TOKEN, action.payload.messagingToken);
|
|
44
|
+
})
|
|
45
|
+
), {
|
|
46
|
+
dispatch: false
|
|
47
|
+
}
|
|
48
|
+
);
|