Add basic Desktop notifications for game start + new move + game over
[vchess.git] / client / src / utils / notifications.js
diff --git a/client/src/utils/notifications.js b/client/src/utils/notifications.js
new file mode 100644 (file)
index 0000000..f849be7
--- /dev/null
@@ -0,0 +1,13 @@
+// https://developer.mozilla.org/en-US/docs/Web/API/notification
+export function notify(title, options) {
+  if (Notification.permission === "granted")
+    new Notification(title, options);
+  else if (Notification.permission !== 'denied') {
+    Notification.requestPermission(function (permission) {
+      if(!('permission' in Notification))
+        Notification.permission = permission;
+      if (permission === "granted")
+        var notification = new Notification(title, options);
+    });
+  }
+}