Parallax refinement; Album responsive; Pusher browser notifications
This commit is contained in:
@ -13,7 +13,7 @@ const PusherMiddleware = (function(){
|
||||
default:
|
||||
var name = 'unspecified'
|
||||
if( message.action ) name = message.action
|
||||
name = name.replace('GET_','').toUpperCase()
|
||||
name = name.replace('get_','').toUpperCase()
|
||||
store.dispatch({ type: 'PUSHER_'+name, data: message.data })
|
||||
}
|
||||
}
|
||||
@ -24,6 +24,12 @@ const PusherMiddleware = (function(){
|
||||
socket.send( JSON.stringify(data) );
|
||||
}
|
||||
|
||||
const broadcast = (data) => {
|
||||
data.type = 'broadcast';
|
||||
socket.send( JSON.stringify(data) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Middleware
|
||||
*
|
||||
@ -84,6 +90,38 @@ const PusherMiddleware = (function(){
|
||||
makeRequest({ action: action.action, data: action.data });
|
||||
break;
|
||||
|
||||
case 'PUSHER_SEND_BROADCAST':
|
||||
broadcast({ action: action.action, data: action.data });
|
||||
break;
|
||||
|
||||
case 'PUSHER_NOTIFICATION':
|
||||
case 'PUSHER_BROADCAST':
|
||||
|
||||
var notification = window.Notification || window.mozNotification || window.webkitNotification;
|
||||
if ('undefined' === typeof notification) return false;
|
||||
if ('undefined' !== typeof notification) notification.requestPermission(function(permission){});
|
||||
|
||||
// handle nested data objects
|
||||
var data = {}
|
||||
if( typeof(action.data) ) data = action.data
|
||||
if( typeof(data.data) ) data = Object.assign({}, data, data.data)
|
||||
|
||||
// construct our browser notification
|
||||
var title = '';
|
||||
var options = {
|
||||
body: '',
|
||||
dir: 'auto',
|
||||
lang: 'EN',
|
||||
tag: 'iris'
|
||||
};
|
||||
if( data.title ) title = data.title;
|
||||
if( data.body ) options.body = data.body;
|
||||
if( data.icon ) options.icon = data.icon;
|
||||
|
||||
// make it so
|
||||
var notification = new notification( title, options );
|
||||
break;
|
||||
|
||||
// This action is irrelevant to us, pass it on to the next middleware
|
||||
default:
|
||||
return next(action);
|
||||
|
||||
Reference in New Issue
Block a user