Pusher username setting fully working
This commit is contained in:
@ -10,11 +10,11 @@ export function setConfig( config ){
|
||||
}
|
||||
}
|
||||
|
||||
export function setUsername( username ){
|
||||
export function changeUsername( username ){
|
||||
return {
|
||||
type: 'PUSHER_INSTRUCT',
|
||||
action: 'set_username',
|
||||
data: { username: username }
|
||||
action: 'change_username',
|
||||
data: username
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ const PusherMiddleware = (function(){
|
||||
connectionid: helpers.generateGuid(),
|
||||
username: Math.random().toString(36).substr(2, 9)
|
||||
}
|
||||
//if( state.pusher.username ) connection.username = state.pusher.username;
|
||||
if( state.pusher.username ) connection.username = state.pusher.username;
|
||||
|
||||
socket = new WebSocket(
|
||||
'ws://'+state.mopidy.host+':'+state.pusher.port+'/pusher',
|
||||
@ -54,6 +54,7 @@ const PusherMiddleware = (function(){
|
||||
|
||||
socket.onopen = () => {
|
||||
store.dispatch({ type: 'PUSHER_CONNECTED', connection: connection });
|
||||
store.dispatch({ type: 'PUSHER_SET_USERNAME', username: connection.username });
|
||||
};
|
||||
|
||||
socket.onmessage = (message) => {
|
||||
|
||||
@ -3,17 +3,24 @@ export default function reducer(pusher = {}, action){
|
||||
switch (action.type) {
|
||||
|
||||
case 'PUSHER_CONNECTED':
|
||||
return Object.assign({}, pusher, { connected: true, connecting: false, connectionid: action.connection.connectionid });
|
||||
return Object.assign({}, pusher, {
|
||||
connected: true,
|
||||
connecting: false,
|
||||
connectionid: action.connection.connectionid,
|
||||
username: action.connection.username
|
||||
});
|
||||
|
||||
case 'PUSHER_DISCONNECTED':
|
||||
return Object.assign({}, pusher, { connected: false, connecting: false });
|
||||
|
||||
case 'PUSHER_SET_CONFIG':
|
||||
return Object.assign({}, pusher, {
|
||||
username: action.username,
|
||||
port: action.port
|
||||
});
|
||||
|
||||
case 'PUSHER_CHANGE_USERNAME':
|
||||
return Object.assign({}, pusher, { username: action.data.connection.username });
|
||||
|
||||
case 'PUSHER_CONNECTION_UPDATED':
|
||||
function byID(connection){
|
||||
return connection.connectionid == action.data.connections.connectionid;
|
||||
|
||||
Reference in New Issue
Block a user