glennwedin / socket-mediator

Mediator for frontend socket handling

Home Page:https://www.wedinweb.no/blog/javascript-mediator-for-notifications-using-socket.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

socket-mediator

Mediator for frontend socket handling The mediator is the "Notifications"-object in index.html It lets you register modules to listen for and receive notifications when there is any. The module also lets you create notifications.

To run:

npm install -g browser-sync
npm install
npm start

Register listener

/*Callback*/
var handleData = function (data) {
//do stuff with the received data
}

/*Depends on a instance of socket.io*/
var notify = new Notifications(socket);
notify.listen(handleData);

Create notification

/*Depends on a instance of socket.io*/
var notify = new Notifications(socket);
notify.create({
    title: "Notification title",
    notification: "This is the actual notification";
});

About

Mediator for frontend socket handling

https://www.wedinweb.no/blog/javascript-mediator-for-notifications-using-socket.io

License:MIT License


Languages

Language:HTML 85.9%Language:JavaScript 14.1%