Revamp Pusher server; Simplified broadcasts; Async pusher requests

This commit is contained in:
James Barnsley
2017-01-09 09:29:56 +13:00
parent deb1340141
commit 3b5babf52c
12 changed files with 374 additions and 324 deletions

View File

@ -14,21 +14,18 @@ frontend = {}
# Send a message to an individual connection # Send a message to an individual connection
# #
# @param recipient_connection_ids = array # @param recipient_connection_ids = array
# @param type = string (type of event, ie connection_opened)
# @param action = string (action method of this message) # @param action = string (action method of this message)
# @param message_id = string (used for callbacks) # @param request_id = string (used for callbacks)
# @param data = array (any data required to include in our message) # @param data = array (any data required to include in our message)
## ##
def send_message( recipient_connection_id, type, action, message_id, data ): def send_message( recipient_connection_id, action, request_id, data ):
message = { message = {
'type': type,
'action': action, 'action': action,
'message_id': message_id, 'request_id': request_id,
'data': data 'data': data
} }
connections[recipient_connection_id]['connection'].write_message( json_encode(message) ) connections[recipient_connection_id]['connection'].write_message( json_encode(message) )
## ##
# Broadcast a message to all recipients # Broadcast a message to all recipients
# #
@ -143,173 +140,158 @@ class PusherWebsocketHandler(tornado.websocket.WebSocketHandler):
} }
logger.debug('Pusher message received: '+message) logger.debug('Pusher message received: '+message)
# query-based message that is expecting a response # broadcast message to other connections (except for self)
if messageJson['type'] == 'query': if messageJson['action'] == 'broadcast':
# fetch our pusher connections # respond to request with status update
if messageJson['action'] == 'get_connections': send_message(
self.connectionid,
connectionsDetailsList = [] 'response',
for connection in connections.itervalues(): messageJson['request_id'],
connectionsDetailsList.append(connection['client']) { 'status': 'Ok' }
)
send_message(
self.connectionid, for connection in connections.itervalues():
'response', if connection['client']['connectionid'] != self.connectionid:
messageJson['action'], connection['connection'].write_message(messageJson)
messageJson['message_id'],
{ 'connections': connectionsDetailsList } # send authroization details
) elif messageJson['action'] == 'send_authorization':
# change connection's client username # make sure we actually have a connection matching the provided connectionid
elif messageJson['action'] == 'change_username': if messageJson['recipient_connectionid'] in connections:
# username is the only value we allow clients to change # send payload to recipient
connections[messageJson['origin']['connectionid']]['client']['username'] = messageJson['username'] authorization_message = {
'type': 'broadcast',
# respond to request 'action': 'received_authorization',
send_message( 'authorization': messageJson['authorization'],
self.connectionid, 'me': messageJson['me'],
'response', 'origin': messageJson['origin']
messageJson['action'],
messageJson['message_id'],
{ 'connection': connections[messageJson['origin']['connectionid']]['client'] }
)
# notify all clients of this change
broadcast( 'connection_updated', { 'connections': connections[messageJson['origin']['connectionid']]['client'] })
# start radio
elif messageJson['action'] == 'start_radio':
# pull out just the radio data (we don't want all the message_id guff)
radio = {
'enabled': 1,
'seed_artists': messageJson['seed_artists'],
'seed_genres': messageJson['seed_genres'],
'seed_tracks': messageJson['seed_tracks']
} }
radio = self.frontend.start_radio( radio ) connections[messageJson['recipient_connectionid']]['connection'].write_message(authorization_message)
send_message(
self.connectionid,
'response',
'radio',
messageJson['message_id'],
{ 'radio': radio }
)
# stop radio
elif messageJson['action'] == 'stop_radio':
radio = self.frontend.stop_radio()
send_message(
self.connectionid,
'response',
'radio',
messageJson['message_id'],
{ 'radio': self.frontend.radio }
)
# fetch our current radio state
elif messageJson['action'] == 'get_radio':
send_message(
self.connectionid,
'response',
'radio',
messageJson['message_id'],
{ 'radio': self.frontend.radio }
)
# MOVED TO HTTP ENDPOINT FOR SIMPLICITY IN REACT+REDUX # respond to request with status update
send_message(
# # get our spotify authentication token
# elif messageJson['action'] == 'get_spotify_token':
# send_message(
# self.connectionid,
# 'response',
# messageJson['action'],
# messageJson['message_id'],
# { 'token': self.frontend.spotify_token }
# )
# # refresh our spotify authentication token
# elif messageJson['action'] == 'refresh_spotify_token':
# token = self.frontend.refresh_spotify_token()
# send_message(
# self.connectionid,
# 'response',
# messageJson['action'],
# messageJson['message_id'],
# { 'token': token }
# )
# get system version and check for upgrade
elif messageJson['action'] == 'get_version':
version = self.frontend.get_version()
send_message(
self.connectionid, self.connectionid,
'response', 'response',
messageJson['action'], messageJson['request_id'],
messageJson['message_id'], { 'status': 'Ok' }
{ 'version': version }
) )
# get system version and check for upgrade
elif messageJson['action'] == 'perform_upgrade':
version = self.frontend.get_version()
version['upgrade_successful'] = self.frontend.perform_upgrade()
send_message(
self.connectionid,
'response',
messageJson['action'],
messageJson['message_id'],
{ 'version': version }
)
# notify all clients of this change
broadcast( 'upgraded', { 'version': version })
# restart mopidy
elif messageJson['action'] == 'restart':
self.frontend.restart()
# not an action we recognise!
else: else:
send_message( # respond to request with status update
send_message(
self.connectionid, self.connectionid,
'response', 'response',
messageJson['action'], messageJson['request_id'],
messageJson['message_id'], { 'error': 'Could not send to that connection, does not exist' }
{ 'error': 'Unhandled action' }
) )
# fetch our pusher connections
elif messageJson['action'] == 'get_connections':
# point-and-shoot one-way broadcast connectionsDetailsList = []
elif messageJson['type'] == 'broadcast': for connection in connections.itervalues():
connectionsDetailsList.append(connection['client'])
# recipients array has items, so only send to specific clients
if messageJson.has_key('recipients'):
for connectionid in messageJson['recipients']:
connectionid = connectionid.encode("utf-8")
# make sure we actually have a connection matching the provided connectionid
if connectionid in connections:
connections[connectionid]['connection'].write_message(messageJson)
else:
logger.warn('Pusher: Tried to broadcast to connectionid '+connectionid+' but it doesn\'t exist!');
# empty, so send to all clients
else:
for connection in connections.itervalues():
# if we've set ignore_self, then don't send message to originating connection send_message(
if messageJson.has_key('ignore_self'): self.connectionid,
if connection['client']['connectionid'] != messageJson['origin']['connectionid']: 'response',
connection['connection'].write_message(messageJson) messageJson['request_id'],
{ 'connections': connectionsDetailsList }
# send it to everyone )
else:
connection['connection'].write_message(messageJson) # change connection's client username
elif messageJson['action'] == 'set_username':
# username is the only value we allow clients to change
connections[messageJson['origin']['connectionid']]['client']['username'] = messageJson['username']
# respond to request
send_message(
self.connectionid,
'response',
messageJson['request_id'],
{ 'username': messageJson['username'] }
)
# notify all clients of this change
broadcast( 'connection_updated', { 'connections': connections[messageJson['origin']['connectionid']]['client'] })
# start radio
elif messageJson['action'] == 'start_radio':
# pull out just the radio data (we don't want all the request_id guff)
radio = {
'enabled': 1,
'seed_artists': messageJson['seed_artists'],
'seed_genres': messageJson['seed_genres'],
'seed_tracks': messageJson['seed_tracks']
}
radio = self.frontend.start_radio( radio )
send_message(
self.connectionid,
'response',
messageJson['request_id'],
{ 'radio': radio }
)
# stop radio
elif messageJson['action'] == 'stop_radio':
radio = self.frontend.stop_radio()
send_message(
self.connectionid,
'response',
messageJson['request_id'],
{ 'radio': self.frontend.radio }
)
# fetch our current radio state
elif messageJson['action'] == 'get_radio':
send_message(
self.connectionid,
'response',
messageJson['request_id'],
{ 'radio': self.frontend.radio }
)
# get system version and check for upgrade
elif messageJson['action'] == 'get_version':
version = self.frontend.get_version()
send_message(
self.connectionid,
'response',
messageJson['request_id'],
{ 'version': version }
)
# get system version and check for upgrade
elif messageJson['action'] == 'perform_upgrade':
version = self.frontend.get_version()
version['upgrade_successful'] = self.frontend.perform_upgrade()
send_message(
self.connectionid,
'response',
messageJson['request_id'],
{ 'version': version }
)
# notify all clients of this change
broadcast( 'upgraded', { 'version': version })
# restart mopidy
elif messageJson['action'] == 'restart':
self.frontend.restart()
# not an action we recognise!
else:
send_message(
self.connectionid,
'response',
messageJson['request_id'],
{ 'error': 'Unhandled action' }
)
logger.debug( 'Pusher: Message received from '+ self.connectionid ) logger.debug( 'Pusher: Message received from '+ self.connectionid )

View File

@ -17,15 +17,7 @@ class SendAuthorizationModal extends React.Component{
handleClick(e, connectionid){ handleClick(e, connectionid){
e.preventDefault() e.preventDefault()
var data = { this.props.pusherActions.sendAuthorization( connectionid, this.props.authorization, this.props.me )
recipients: [connectionid],
action: 'send_authorization',
data: {
authorization: this.props.authorization,
me: this.props.me
}
}
this.props.pusherActions.instruct( 'broadcast', data )
this.props.uiActions.closeModal() this.props.uiActions.closeModal()
return false; return false;
} }

View File

@ -16,13 +16,13 @@ class PusherConnectionList extends React.Component{
componentDidMount(){ componentDidMount(){
if( this.props.connected ){ if( this.props.connected ){
this.props.pusherActions.getConnectionList(); this.props.pusherActions.getConnections();
} }
} }
componentWillReceiveProps(newProps){ componentWillReceiveProps(newProps){
if( !this.props.connected && newProps.connected ){ if( !this.props.connected && newProps.connected ){
this.props.pusherActions.getConnectionList(); this.props.pusherActions.getConnections();
} }
} }

View File

@ -12,7 +12,7 @@ const localstorageMiddleware = (function(){
// append our state to a global variable. This gives us access to debug the store at any point // append our state to a global variable. This gives us access to debug the store at any point
window._store = store window._store = store
//console.log(action) console.log(action)
switch( action.type ){ switch( action.type ){
@ -35,9 +35,9 @@ const localstorageMiddleware = (function(){
localStorage.setItem('pusher', JSON.stringify(pusher)); localStorage.setItem('pusher', JSON.stringify(pusher));
break; break;
case 'PUSHER_CHANGE_USERNAME': case 'PUSHER_USERNAME':
var stored_pusher = JSON.parse( localStorage.getItem('pusher') ) var stored_pusher = JSON.parse( localStorage.getItem('pusher') )
var pusher = Object.assign({}, stored_pusher, { username: action.data.connection.username }) var pusher = Object.assign({}, stored_pusher, { username: action.data.username })
localStorage.setItem('pusher', JSON.stringify(pusher)) localStorage.setItem('pusher', JSON.stringify(pusher))
break; break;

View File

@ -10,6 +10,13 @@ export function setPort( port ){
} }
} }
export function setUsername( username ){
return {
type: 'PUSHER_SET_USERNAME',
username: username
}
}
export function connect(){ export function connect(){
return { return {
type: 'PUSHER_CONNECT' type: 'PUSHER_CONNECT'
@ -28,21 +35,28 @@ export function performUpgrade(){
} }
} }
export function getConnectionList(){ export function getConnections(){
return { return {
type: 'PUSHER_INSTRUCT', type: 'PUSHER_GET_CONNECTIONS'
action: 'get_connections'
} }
} }
export function instruct( message_type, data = null ){ export function instruct( data = null ){
return { return {
type: 'PUSHER_INSTRUCT', type: 'PUSHER_INSTRUCT',
message_type: message_type,
data: data data: data
} }
} }
export function sendAuthorization( recipient_connectionid, authorization, me ){
return {
type: 'PUSHER_SEND_AUTHORIZATION',
recipient_connectionid: recipient_connectionid,
authorization: authorization,
me: me
}
}
export function startRadio( uris ){ export function startRadio( uris ){
return { return {
type: 'PUSHER_START_RADIO', type: 'PUSHER_START_RADIO',
@ -56,10 +70,9 @@ export function stopRadio(){
} }
} }
export function debug( call, data = null ){ export function debug( data = null ){
return { return {
type: 'PUSHER_DEBUG', type: 'PUSHER_DEBUG',
call: call,
data: data data: data
} }
} }

View File

@ -7,27 +7,53 @@ const PusherMiddleware = (function(){
// container for the actual Mopidy socket // container for the actual Mopidy socket
var socket = null; var socket = null;
var deferredRequests = [];
const resolveRequest = (requestId, message ) => {
var response = JSON.parse( message );
deferredRequests[request_id].resolve( response );
delete deferredRequests[request_id];
}
const rejectRequest = (requestId, message) => {
deferredRequests[requestId].reject( message );
}
// handle all manner of socket messages // handle all manner of socket messages
const handleMessage = (ws, store, message) => { const handleMessage = (ws, store, message) => {
switch( message.action ){
default: console.log('handle', message)
var name = 'unspecified'
if( message.action ) name = message.action switch (message.action){
name = name.replace('get_','').toUpperCase() case 'response':
store.dispatch({ type: 'PUSHER_'+name, data: message.data }) if (typeof( deferredRequests[ message.request_id ]) !== 'undefined' ){
deferredRequests[ message.request_id ].resolve( message )
} else {
console.error('Pusher: Response with no matching request', message);
}
break
case 'broadcast':
var type = 'UNRECOGNISED_BROADCAST'
if( message.data.type ) type = message.data.type.toUpperCase()
store.dispatch({ type: type, data: message.data })
break
} }
} }
const makeRequest = (data) => { const request = (data) => {
data.type = 'query'; return new Promise( (resolve, reject) => {
data.message_id = helpers.generateGuid();
socket.send( JSON.stringify(data) );
}
const broadcast = (data) => { // send the payload
data.type = 'broadcast'; data.request_id = helpers.generateGuid()
socket.send( JSON.stringify(data) ); socket.send( JSON.stringify(data) )
// add query to our deferred responses
deferredRequests[ data.request_id ] = {
resolve: resolve,
reject: reject
}
})
} }
@ -42,6 +68,15 @@ const PusherMiddleware = (function(){
switch(action.type) { switch(action.type) {
case 'PUSHER_INSTRUCT':
request( action.data )
.then(
response => {
store.dispatch({ type: 'PUSHER_INSTRUCT', data: response.data })
}
)
break
case 'PUSHER_CONNECT': case 'PUSHER_CONNECT':
if(socket != null) socket.close(); if(socket != null) socket.close();
@ -63,7 +98,12 @@ const PusherMiddleware = (function(){
socket.onopen = () => { socket.onopen = () => {
store.dispatch({ type: 'PUSHER_CONNECTED', connection: connection }); store.dispatch({ type: 'PUSHER_CONNECTED', connection: connection });
store.dispatch({ type: 'PUSHER_SET_USERNAME', username: connection.username }); store.dispatch({ type: 'PUSHER_SET_USERNAME', username: connection.username });
makeRequest({ action: 'get_radio' }); request({ action: 'get_radio' })
.then(
response => {
store.dispatch({ type: 'PUSHER_RADIO', data: response.data })
}
)
}; };
socket.onmessage = (message) => { socket.onmessage = (message) => {
@ -74,84 +114,69 @@ const PusherMiddleware = (function(){
break; break;
case 'PUSHER_CONNECTED': case 'PUSHER_CONNECTED':
makeRequest({ action: 'get_version' }); request({ action: 'get_version' })
.then(
response => {
store.dispatch({ type: 'PUSHER_VERSION', data: response.data })
}
)
return next(action); return next(action);
break; break;
case 'PUSHER_UPGRADING': case 'PUSHER_UPGRADING':
makeRequest({ action: 'perform_upgrade' }); request({ action: 'perform_upgrade' })
.then(
response => {
store.dispatch({ type: 'PUSHER_UPGRADE', data: response.data })
}
)
return next(action); return next(action);
break; break;
case 'PUSHER_SET_USERNAME':
request({ action: 'set_username', username: action.username })
.then(
response => {
store.dispatch({ type: 'PUSHER_USERNAME', data: { username: response.data.username }})
}
)
return next(action);
break;
case 'PUSHER_GET_CONNECTIONS':
case 'PUSHER_CLIENT_CONNECTED': case 'PUSHER_CLIENT_CONNECTED':
makeRequest({ action: 'get_connections' }); request({ action: 'get_connections' })
.then(
response => {
store.dispatch({ type: 'PUSHER_CONNECTIONS', data: response.data })
}
)
return next(action); return next(action);
break; break
case 'PUSHER_INSTRUCT':
switch( action.message_type ){
case 'query':
makeRequest( action.data )
break
case 'broadcast':
broadcast( action.data )
break
}
break;
case 'PUSHER_DEBUG': case 'PUSHER_DEBUG':
switch( action.call ){ request( action.data )
case 'query': .then(
makeRequest( action.data ) response => {
// THIS DOES NOT RETURN A PROMISE SO CAN'T DETECT RELATED RESPONSES store.dispatch({ type: 'DEBUG', response: response.data })
/*.then( response => { }
store.dispatch({ type: 'DEBUG', response: response }) )
})*/
break
case 'broadcast':
broadcast( action.data )
/*.then( response => {
store.dispatch({ type: 'DEBUG', response: response })
})*/
break
default:
store.dispatch({ type: 'DEBUG', response: '{ "error": "Invalid call" }' })
break
}
break; break;
case 'PUSHER_SEND_BROADCAST': case 'PUSHER_SEND_AUTHORIZATION':
broadcast({ action: action.action, data: action.data }); request({
action: 'send_authorization',
recipient_connectionid: action.recipient_connectionid,
authorization: action.authorization,
me: action.me
})
.then(
response => {
uiActions.createNotification('Authorization sent')
}
)
break; 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
case 'PUSHER_SEND_AUTHORIZATION': case 'PUSHER_SEND_AUTHORIZATION':
if( window.confirm('Spotify authorization for user '+action.data.me.id+' received. Do you want to import?') ){ if( window.confirm('Spotify authorization for user '+action.data.me.id+' received. Do you want to import?') ){
@ -168,19 +193,20 @@ const PusherMiddleware = (function(){
case 'PUSHER_START_RADIO': case 'PUSHER_START_RADIO':
store.dispatch({ request({
type: 'PUSHER_SEND_BROADCAST',
action: 'broadcast', action: 'broadcast',
ignore_self: true,
data: { data: {
type: 'notification', type: 'browser_notification',
data: { title: 'Radio started',
title: 'Radio started', body: store.getState().pusher.username +' started radio mode',
body: store.getState().pusher.username +' started radio mode', icon: ''
icon: '' }
}
}
}) })
.then(
response => {
uiActions.createNotification('Starting radio...')
}
)
var data = { var data = {
action: 'start_radio', action: 'start_radio',
@ -200,24 +226,25 @@ const PusherMiddleware = (function(){
} }
} }
makeRequest( data ) request( data )
break break
case 'PUSHER_STOP_RADIO': case 'PUSHER_STOP_RADIO':
store.dispatch({ request({
type: 'PUSHER_SEND_BROADCAST',
action: 'broadcast', action: 'broadcast',
ignore_self: true,
data: { data: {
type: 'notification', type: 'browser_notification',
data: { title: 'Radio stopped',
title: 'Radio stopped', body: store.getState().pusher.username +' stopped radio mode',
body: store.getState().pusher.username +' stopped radio mode', icon: ''
icon: '' }
}
}
}) })
.then(
response => {
uiActions.createNotification('Stopping radio')
}
)
store.dispatch( uiActions.createNotification('Stopping radio') ) store.dispatch( uiActions.createNotification('Stopping radio') )
var data = { var data = {
@ -226,7 +253,7 @@ const PusherMiddleware = (function(){
seed_genres: [], seed_genres: [],
seed_tracks: [] seed_tracks: []
} }
makeRequest( data ) request( data )
break break
// This action is irrelevant to us, pass it on to the next middleware // This action is irrelevant to us, pass it on to the next middleware

View File

@ -20,8 +20,11 @@ export default function reducer(pusher = {}, action){
case 'PUSHER_SET_PORT': case 'PUSHER_SET_PORT':
return Object.assign({}, pusher, { port: action.port }); return Object.assign({}, pusher, { port: action.port });
case 'PUSHER_CHANGE_USERNAME': case 'PUSHER_USERNAME':
return Object.assign({}, pusher, { username: action.data.connection.username }); return Object.assign({}, pusher, { username: action.data.username });
case 'PUSHER_CONNECTIONS':
return Object.assign({}, pusher, { connections: action.data.connections });
case 'PUSHER_CONNECTION_UPDATED': case 'PUSHER_CONNECTION_UPDATED':
function byID(connection){ function byID(connection){
@ -34,9 +37,6 @@ export default function reducer(pusher = {}, action){
return Object.assign({}, pusher, { connections: connections }); return Object.assign({}, pusher, { connections: connections });
case 'PUSHER_CONNECTIONS':
return Object.assign({}, pusher, { connections: action.data.connections });
case 'PUSHER_VERSION': case 'PUSHER_VERSION':
return Object.assign({}, pusher, { return Object.assign({}, pusher, {
version: action.data.version, version: action.data.version,

View File

@ -429,19 +429,44 @@ export function resolveRadioSeeds( radio ){
seed_genres: [] seed_genres: []
} }
var artist_ids = ''; var requests = []
for (var i = 0; i < radio.seed_artists.length; i++){
if (i > 0) artist_ids += ','
artist_ids += helpers.getFromUri('artistid', radio.seed_artists[i])
}
$.when( if (radio.seed_artists.length > 0){
sendRequest( dispatch, getState, 'artists/'+ artist_ids ) var artist_ids = '';
for (var i = 0; i < radio.seed_artists.length; i++){
if (i > 0) artist_ids += ','
artist_ids += helpers.getFromUri('artistid', radio.seed_artists[i])
}
// add to our list of async requests
requests.push(
sendRequest( dispatch, getState, 'artists/'+ artist_ids )
.then( response => { .then( response => {
if (!(response instanceof Array)) response = [response] if (!(response instanceof Array)) response = [response]
Object.assign(resolved_seeds.seed_artists, response); Object.assign(resolved_seeds.seed_artists, response);
}) })
)
}
if (radio.seed_tracks.length > 0){
var track_ids = '';
for (var i = 0; i < radio.seed_tracks.length; i++){
if (i > 0) track_ids += ','
track_ids += helpers.getFromUri('trackid', radio.seed_tracks[i])
}
// add to our list of async requests
requests.push(
sendRequest( dispatch, getState, 'tracks/'+ track_ids )
.then( response => {
if (!(response instanceof Array)) response = [response]
Object.assign(resolved_seeds.seed_tracks, response);
})
)
}
$.when.apply(
$, requests
).then( () => { ).then( () => {
dispatch({ dispatch({
type: 'PUSHER_RADIO_SEEDS_RESOLVED', type: 'PUSHER_RADIO_SEEDS_RESOLVED',

View File

@ -130,6 +130,37 @@ const UIMiddleware = (function(){
next(action) next(action)
break break
case 'RESTART':
location.reload()
break
case 'BROWSER_NOTIFICATION':
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
case 'CREATE_NOTIFICATION': case 'CREATE_NOTIFICATION':
// start a timeout to remove this notification // start a timeout to remove this notification

View File

@ -61,6 +61,9 @@ class Artist extends React.Component{
}else if( source == 'local' && props.mopidy_connected ){ }else if( source == 'local' && props.mopidy_connected ){
this.props.mopidyActions.getArtist( props.params.uri ); this.props.mopidyActions.getArtist( props.params.uri );
} }
// go back to overview
this.setState({ sub_view: 'overview' })
} }
loadMore(){ loadMore(){

View File

@ -25,7 +25,6 @@ class Debug extends React.Component{
this.state = { this.state = {
mopidy_call: 'playlists.asList', mopidy_call: 'playlists.asList',
mopidy_data: '{}', mopidy_data: '{}',
pusher_call: 'broadcast',
pusher_data: '{}' pusher_data: '{}'
} }
} }
@ -33,9 +32,9 @@ class Debug extends React.Component{
componentDidMount(){ componentDidMount(){
if( this.props.connectionid ){ if( this.props.connectionid ){
var data = { var data = {
action: "notification", action: "broadcast",
recipients: [this.props.connectionid],
data: { data: {
type: 'browser_notification',
title: "Title", title: "Title",
body: "Test notification", body: "Test notification",
icon: "http://lorempixel.com/100/100/nature/" icon: "http://lorempixel.com/100/100/nature/"
@ -47,15 +46,12 @@ class Debug extends React.Component{
callMopidy(e){ callMopidy(e){
e.preventDefault() e.preventDefault()
console.info('Mopidy Debugger', this.state.mopidy_call, JSON.parse(this.state.mopidy_data) )
this.props.mopidyActions.debug( this.state.mopidy_call, JSON.parse(this.state.mopidy_data) ) this.props.mopidyActions.debug( this.state.mopidy_call, JSON.parse(this.state.mopidy_data) )
} }
callPusher(e){ callPusher(e){
e.preventDefault() e.preventDefault()
console.info('Pusher Debugger', this.state.pusher_call, JSON.parse(this.state.pusher_data) ) this.props.pusherActions.debug( JSON.parse(this.state.pusher_data) )
this.props.pusherActions.debug( this.state.pusher_call, JSON.parse(this.state.pusher_data) )
this.props.uiActions.debugResponse({ status: 1, message: 'Sent', call: this.state.pusher_call, data: this.state.pusher_data })
} }
render(){ render(){
@ -82,10 +78,6 @@ class Debug extends React.Component{
</div> </div>
</form> </form>
</section>
<section>
<h4 className="underline">Mopidy</h4> <h4 className="underline">Mopidy</h4>
<form onSubmit={(e) => this.callMopidy(e)}> <form onSubmit={(e) => this.callMopidy(e)}>
<div className="field"> <div className="field">
@ -114,21 +106,8 @@ class Debug extends React.Component{
</div> </div>
</form> </form>
</section>
<section>
<h4 className="underline">Pusher</h4> <h4 className="underline">Pusher</h4>
<form onSubmit={(e) => this.callPusher(e)}> <form onSubmit={(e) => this.callPusher(e)}>
<div className="field">
<div className="name">Call</div>
<div className="input">
<input
type="text"
onChange={ e => this.setState({ pusher_call: e.target.value })}
value={ this.state.pusher_call } />
</div>
</div>
<div className="field"> <div className="field">
<div className="name">Data</div> <div className="name">Data</div>
<div className="input"> <div className="input">
@ -146,13 +125,11 @@ class Debug extends React.Component{
</div> </div>
</form> </form>
</section>
<section>
<h4 className="underline">Response</h4> <h4 className="underline">Response</h4>
<pre> <pre>
{ this.props.debug_response ? JSON.stringify(this.props.debug_response, null, 2) : null } { this.props.debug_response ? JSON.stringify(this.props.debug_response, null, 2) : null }
</pre> </pre>
</section> </section>
</div> </div>
); );

View File

@ -168,7 +168,7 @@ class Settings extends React.Component{
<input <input
type="text" type="text"
onChange={ e => this.setState({ pusher_username: e.target.value }) } onChange={ e => this.setState({ pusher_username: e.target.value }) }
onBlur={ e => this.props.pusherActions.instruct( 'query', { action: 'change_username', username: this.state.pusher_username }) } onBlur={ e => this.props.pusherActions.setUsername(this.state.pusher_username) }
value={ this.state.pusher_username } /> value={ this.state.pusher_username } />
</div> </div>
</div> </div>
@ -178,7 +178,7 @@ class Settings extends React.Component{
<input <input
type="text" type="text"
onChange={ e => this.setState({ pusher_port: e.target.value })} onChange={ e => this.setState({ pusher_port: e.target.value })}
onBlur={ e => this.props.pusherActions.setPort( this.state.pusher_port ) } onBlur={ e => this.props.pusherActions.setPort(this.state.pusher_port) }
value={ this.state.pusher_port } /> value={ this.state.pusher_port } />
</div> </div>
</div> </div>