Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications for duels #189

Draft
wants to merge 48 commits into
base: main
Choose a base branch
from
Draft

Notifications for duels #189

wants to merge 48 commits into from

Conversation

valentinperignon
Copy link
Member

@valentinperignon valentinperignon commented Feb 11, 2021

Changes

  • Require authorization (client)
  • Receive push notification (client / sw)
  • Send push notification to user when a new duel is available (server)
  • Redirect the user to the duel when the notification is clicked (sw)
  • Update tests

How it works

  • When the user logs in, we get a token that allows Firebase to identify the user's device
  • To be able to get this token, the user must agree to receive notifications (for the moment, firebase does this automatically, but we could ask for this ourselves and display an already coded information screen (see "Request for authorization for notifications" screenshot)
  • This token is saved in the localStorage and in the database in the user table through /api/v1/messaging/token/add
  • When a round of a duel is played, the server sends a notification to the user
  • If the application is in the background, the service-worker receives the notification (a message from the server to be precise) and displays it
  • If the application is in the foreground, the client receives the notification and displays it
  • When the user disconnects, the token is deleted from the localStorage and the database

Issue

The server can send notifications and the service-worker can receive them. On the other hand we encounter a bug when installing and activating firebase on the client.

Screenshots

Request for authorization for notifications:
Screen Shot 2021-02-16 at 11 07 07

Notification (here on macOS ❤️ ) when the app is in the background:
Screen Shot 2021-02-28 at 14 47 17

Notification when the app is in the foreground:
Screen Shot 2021-02-28 at 17 16 56

@valentinperignon valentinperignon self-assigned this Feb 11, 2021
@valentinperignon valentinperignon added the backend Server side issue label Feb 11, 2021
Copy link
Member

@nathanaelhoun nathanaelhoun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first thoughts on it, before testing 😄 Really excited!

client/src/components/FullScreenMessage.js Outdated Show resolved Hide resolved
Comment on lines +6 to +7
self.importScripts("https://www.gstatic.com/firebasejs/8.2.9/firebase-app.js");
self.importScripts("https://www.gstatic.com/firebasejs/8.2.9/firebase-messaging.js");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this possible to have these file in our bundle instead of downloading them from a third-party server?

@@ -65,16 +80,64 @@ self.addEventListener("fetch", (e) => {
const newResource = r.clone();
caches.open(cacheName).then((cache) => {
console.info(`[Service Worker] Caching new resource: ${e.request.url}`);
cache.put(e.request, newResource);
cache.put(e.request, newResource).catch(() => console.error("Can't cache new resource"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an error or a simple warning?

client/src/service-worker.js Outdated Show resolved Hide resolved
client/src/test/App.test.js Outdated Show resolved Hide resolved
client/src/test/App.test.js Show resolved Hide resolved
class MessagingHandler {
constructor() {
// Information available in the firebase console
this.app = firebase.initializeApp({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I will try

server/controllers/messaging.js Outdated Show resolved Hide resolved
@FrancoisPog
Copy link
Member

Would it be possible to change then/catch to await/async for consistency 😃

@valentinperignon
Copy link
Member Author

@FrancoisPog Yes, I am currently doing it on the best merge of my life :)

@valentinperignon valentinperignon added the on break Issue not closed but awaiting resources label Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Server side issue on break Issue not closed but awaiting resources
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants