Skip to content

A simple notification dispatcher written in nodeJS using socket.io

Notifications You must be signed in to change notification settings

caruccio/socket.io-notify

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Socket.IO Notify

node >=4.1.1

A simple notification dispatcher written in nodeJS using socket.io

How to use

$ cd socket.io-notify
$ npm install
$ node .

Client side - Javascript

document.addEventListener("DOMContentLoaded", function(event) {
  var socket = io.connect('127.0.0.1:3000', {
    query: 'notificationKey=NOTIFICATION_KEY'
  });
  socket.on('NEW_NOTIFICATION', function (notification) {
    console.log(notification);
  });

  socket.emit('join', 'SOME_CHANNEL');
});

##Sending notifications

bash

$ curl --request POST 'http://localhost:3000/send' --header notification_secret:NOTIFICATION_SECRET --data 'notification=notificationexample&channel=SOME_CHANNEL'

Server side - PHP

<?php

use Guzzle\Http\Client;


$socketio_host = getenv('SOCKETIO_HOST');
$socketio_port = getenv('SOCKETIO_PORT');
$secret = getenv('NOTIFICATION_SECRET');
$channel = 'some_channel';
$client = new Client;
$request = $client->post($socketio_host.':'.$socketio_port. '/send', [], [
    'notification[description]' => $text,
    'channel' => $channel
]);
$request->setHeader('notification_secret', $secret);
$response = $request->send();

About

A simple notification dispatcher written in nodeJS using socket.io

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 47.8%
  • CSS 38.6%
  • HTML 13.6%