diff --git a/mopidy_iris/core.py b/mopidy_iris/core.py index d83e166c..15e3cdd3 100755 --- a/mopidy_iris/core.py +++ b/mopidy_iris/core.py @@ -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 + } ## diff --git a/src/js/components/Modal/SendAuthorizationModal.js b/src/js/components/Modal/SendAuthorizationModal.js index 7950f3ad..0031f864 100755 --- a/src/js/components/Modal/SendAuthorizationModal.js +++ b/src/js/components/Modal/SendAuthorizationModal.js @@ -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 (

Share Spotify authentication

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}).

{ - 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 ( -
this.handleClick(e, connection.connectionid) }> +
this.handleClick(e, connection.connection_id) }> { connection.username }   ({ connection.ip }) @@ -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 } } diff --git a/src/js/services/pusher/actions.js b/src/js/services/pusher/actions.js index c24e1aa4..eb5c78df 100755 --- a/src/js/services/pusher/actions.js +++ b/src/js/services/pusher/actions.js @@ -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 + } } } diff --git a/src/js/services/pusher/middleware.js b/src/js/services/pusher/middleware.js index 5dbf5a68..0cc5f6a0 100755 --- a/src/js/services/pusher/middleware.js +++ b/src/js/services/pusher/middleware.js @@ -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(