GithubHelp home page GithubHelp logo

Comments (5)

andersevenrud avatar andersevenrud commented on June 10, 2024 2

Yes, you can open a Pull Request to add a feature to support both "OS.js notifications" and "Native notifications" at the same time.

But just to make sure we're talking about the same thing here; this needs to be implemented in the actual client module.

I.e.: https://github.com/os-js/osjs-client/blob/master/src/notification.js where existing functionality exists.

from os.js.

andersevenrud avatar andersevenrud commented on June 10, 2024 1

I'm not really sure if there's a use-case for this to be provided by default.

But if you create a service provider package (npm compatible) and provide the full source I will gladly add it to the documentation.

from os.js.

andersevenrud avatar andersevenrud commented on June 10, 2024 1

Looks like this is actually creating native notifications. I thought by "synchronize" that it was the other way around.

Creating native notifications is actually already supported globally with configuration notifications.native or the native option in the service API.

If you want the option to do both, simply publish a PR for the client with changes to the Notification to allow that :)

from os.js.

mahdi00021 avatar mahdi00021 commented on June 10, 2024

There is no need for a service provider, here you only need a file for notification that is written with JavaScript and called in the index.js
Also, a listener is used in the index file to listen to create notifications

from os.js.

mahdi00021 avatar mahdi00021 commented on June 10, 2024

this file called in index.js and in

osjs.on('osjs/notification:create', (notification) => {
		   let message = notification.options.message;
		   
		   sendNotification(notification.options.title,message,'#'); 
		   console.log('notificationnotificationnotification',message);
		  
	});

this is Notification.js:

export default function sendNotification(title, message, url) {
    //First, check notification is supported or not in your browser!
    if (!Notification) {
      console.log('Push notifications are not supported in your browser..');
      return;
    }

    //Ask for permission from user 
    if (Notification.permission !== "granted") {
      Notification.requestPermission();
    } else {
      var notification = new Notification(title, {
        icon: 'favicon.png',
        body: message,
      });

      // Remove the notification when clicked and open the URL.
      notification.onclick = function() {
      
      };

      // Callback function when the notification is closed.
      notification.onclose = function() {
        console.log('Notification closed');
      };
    }
}

from os.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.