WIP FCM push messaging.

This commit is contained in:
Patrick Fic
2020-05-01 09:21:30 -07:00
parent c98e0b33fd
commit a9a8c3b6aa
10 changed files with 1327 additions and 37 deletions

View File

@@ -11,10 +11,11 @@ import { WebSocketLink } from "apollo-link-ws";
import { getMainDefinition } from "apollo-utilities";
import React, { Component } from "react";
import GlobalLoadingBar from "../components/global-loading-bar/global-loading-bar.component";
import { auth } from "../firebase/firebase.utils";
import { auth, messaging } from "../firebase/firebase.utils";
import errorLink from "../graphql/apollo-error-handling";
import App from "./App";
import LogRocket from "logrocket";
import { notification } from "antd";
if (process.env.NODE_ENV === "production") LogRocket.init("gvfvfw/bodyshopapp");
@@ -116,6 +117,22 @@ export default class AppContainer extends Component {
this.state = { client };
}
async componentDidMount() {
messaging
.requestPermission()
.then(async function () {
const token = await messaging.getToken();
console.log("messaging -> token", token);
})
.catch(function (err) {
console.log("Unable to get permission to notify.", err);
});
navigator.serviceWorker.addEventListener("message", (message) => {
console.log("Comp Did Mount", message);
notification["info"]({ message: JSON.stringify(message.data) });
});
}
render() {
const { client } = this.state;