Standardized status value on all pusher responses; deliver_message

This commit is contained in:
James Barnsley
2017-02-21 08:58:49 +13:00
parent ba5ef316f4
commit 148fe39cd4
4 changed files with 76 additions and 31 deletions

View File

@ -29,10 +29,6 @@ class IrisCore(object):
}
def on_start(self):
logger.info('--- Starting Iris core '+self.version)
##
# Generate a random string
#
@ -83,7 +79,7 @@ class IrisCore(object):
for connection in self.connections.itervalues():
connection['connection'].write_message( json_encode(data) )
return {
'status': 'ok',
'status': 1,
'message': 'Broadcast to '+str(len(self.connections))+' connections'
}
@ -101,6 +97,7 @@ class IrisCore(object):
connections.append(connection['client'])
return {
'status': 1,
'connections': connections
}
@ -145,7 +142,7 @@ class IrisCore(object):
'connection': self.connections[connection_id]['client']
})
return {
'type': 'username_changed',
'status': 1,
'username': data['username']
}
@ -153,8 +150,27 @@ class IrisCore(object):
error = 'Connection "'+data['connection_id']+'" not found'
logger.error(error)
return {
'error': error
}
'status': 0,
'message': error
}
def deliver_message(self, data):
to = data['to']
if to in self.connections:
self.send_message(to, data['message'])
return {
'status': 1
}
else:
error = 'Connection "'+data['connection_id']+'" not found'
logger.error(error)
return {
'status': 0,
'message': error
}
@ -194,6 +210,7 @@ class IrisCore(object):
upgrade_available = False
return {
'status': 1,
'version': {
'current': self.version,
'latest': latest_version,
@ -223,6 +240,7 @@ class IrisCore(object):
def get_radio(self, data):
return {
'status': 1,
'radio': self.radio
}
@ -235,7 +253,8 @@ class IrisCore(object):
# no uris means we can't play radio
if not uris:
return {
'error': 'No recommendations found'
'status': 0,
'message': 'No recommendations found'
}
# if we got recommendations
@ -268,7 +287,9 @@ class IrisCore(object):
'radio': self.radio
})
return {}
return {
'status': 1
}
def load_more_tracks( self ):
@ -327,6 +348,7 @@ class IrisCore(object):
def get_queue_metadata(self, data):
return {
'status': 1,
'queue_metadata': self.queue_metadata
}
@ -345,7 +367,9 @@ class IrisCore(object):
'queue_metadata': self.queue_metadata
})
return {}
return {
'status': 1
}
def clean_queue_metadata( self ):
cleaned_queue_metadata = {}
@ -363,7 +387,9 @@ class IrisCore(object):
'queue_metadata': self.queue_metadata
})
return {}
return {
'status': 1
}
##

View File

@ -15,27 +15,34 @@ class SendAuthorizationModal extends React.Component{
super(props)
}
handleClick(e, connectionid){
handleClick(e, connection_id){
e.preventDefault()
this.props.pusherActions.sendAuthorization( connectionid, this.props.authorization, this.props.me )
this.props.pusherActions.sendAuthorization( connection_id, this.props.authorization, this.props.me )
this.props.uiActions.closeModal()
return false;
}
render(){
var connections = []
for (var connection_id in this.props.connections){
if (this.props.connections.hasOwnProperty(connection_id)) {
connections.push(this.props.connections[connection_id])
}
}
return (
<div>
<h4 className="no-bottom-padding">Share Spotify authentication</h4>
<h3 className="grey-text">Send your authentication tokens to another client. When the recipient client imports this, their Iris will have full access to your Spotify account ({this.props.me.id}).</h3>
<div className="list small pusher-connection-list">
{
this.props.connections.map( (connection, index) => {
connections.map( (connection, index) => {
// don't list OUR connection
if (connection.connectionid == this.props.connectionid) return null
if (connection.connection_id == this.props.connection_id) return null
return (
<div className='list-item connection' key={connection.connectionid} onClick={ e => this.handleClick(e, connection.connectionid) }>
<div className='list-item connection' key={connection.connection_id} onClick={ e => this.handleClick(e, connection.connection_id) }>
{ connection.username }
&nbsp;
<span className="grey-text">({ connection.ip })</span>
@ -53,7 +60,7 @@ const mapStateToProps = (state, ownProps) => {
return {
me: state.spotify.me,
authorization: state.spotify.authorization,
connectionid: state.pusher.connectionid,
connection_id: state.pusher.connection_id,
connections: state.pusher.connections
}
}

View File

@ -50,10 +50,13 @@ export function instruct( data = null ){
export function sendAuthorization( recipient_connectionid, authorization, me ){
return {
type: 'PUSHER_SEND_AUTHORIZATION',
recipient_connectionid: recipient_connectionid,
authorization: authorization,
me: me
type: 'PUSHER_DELIVER_MESSAGE',
to: recipient_connectionid,
message: {
type: 'spotify_authorization',
authorization: authorization,
me: me
}
}
}

View File

@ -60,15 +60,6 @@ const PusherMiddleware = (function(){
return store => next => action => {
switch(action.type) {
case 'PUSHER_INSTRUCT':
request( action )
.then(
response => {
store.dispatch({ type: 'PUSHER_INSTRUCT', data: response.data })
}
)
break
case 'PUSHER_CONNECT':
if(socket != null) socket.close();
@ -144,6 +135,24 @@ const PusherMiddleware = (function(){
return next(action);
break;
case 'PUSHER_INSTRUCT':
request( action )
.then(
response => {
store.dispatch({ type: 'PUSHER_INSTRUCT', data: response.data })
}
)
break
case 'PUSHER_DELIVER_MESSAGE':
request('deliver_message', action)
.then(
response => {
store.dispatch( uiActions.createNotification(response.message) )
}
)
break
case 'PUSHER_GET_QUEUE_METADATA':
request('get_queue_metadata')
.then(