Removing ws subprotocol; Creating new post-connection update hook
This commit is contained in:
@ -49,7 +49,7 @@ const localstorageMiddleware = (function(){
|
||||
);
|
||||
break;
|
||||
|
||||
case 'PUSHER_USERNAME_CHANGED':
|
||||
case 'PUSHER_SET_USERNAME':
|
||||
helpers.setStorage(
|
||||
'pusher',
|
||||
{
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
|
||||
/**
|
||||
* Actions and Action Creators
|
||||
**/
|
||||
|
||||
export function setPort(port){
|
||||
return {
|
||||
type: 'PUSHER_SET_PORT',
|
||||
@ -67,6 +63,13 @@ export function connectionAdded(connection){
|
||||
}
|
||||
}
|
||||
|
||||
export function updateConnection(connection){
|
||||
return {
|
||||
type: 'PUSHER_UPDATE_CONNECTION',
|
||||
connection: connection
|
||||
}
|
||||
}
|
||||
|
||||
export function connectionChanged(connection){
|
||||
return {
|
||||
type: 'PUSHER_CONNECTION_CHANGED',
|
||||
|
||||
@ -75,9 +75,6 @@ const PusherMiddleware = (function(){
|
||||
} else {
|
||||
|
||||
switch (message.method){
|
||||
case 'connection_extablished':
|
||||
store.dispatch(pusherActions.setUsername(store.getState().pusher.username));
|
||||
break;
|
||||
case 'connection_added':
|
||||
store.dispatch(pusherActions.connectionAdded(message.params.connection));
|
||||
break;
|
||||
@ -275,6 +272,7 @@ const PusherMiddleware = (function(){
|
||||
ReactGA.event({ category: 'Pusher', action: 'Connected', label: action.username});
|
||||
}
|
||||
|
||||
store.dispatch(pusherActions.updateConnection());
|
||||
store.dispatch(pusherActions.getConfig());
|
||||
store.dispatch(pusherActions.getRadio());
|
||||
store.dispatch(pusherActions.getCommands());
|
||||
@ -334,6 +332,37 @@ const PusherMiddleware = (function(){
|
||||
request(store, 'broadcast', action.data)
|
||||
break
|
||||
|
||||
case 'PUSHER_SET_USERNAME':
|
||||
store.dispatch(pusherActions.updateConnection({username: action.username}));
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'PUSHER_UPDATE_CONNECTION':
|
||||
|
||||
// Our action can provide new values during a state update (eg the field was just changed)
|
||||
// but by default we refer to our existing state
|
||||
let connection = {
|
||||
username: store.getState().pusher.username,
|
||||
client_id: store.getState().pusher.client_id,
|
||||
...(action.connection ? action.connection : {})
|
||||
}
|
||||
|
||||
request(store, 'update_connection', connection)
|
||||
.then(
|
||||
response => {
|
||||
response.type = 'PUSHER_CONNECTION_UPDATED'
|
||||
store.dispatch(response)
|
||||
},
|
||||
error => {
|
||||
store.dispatch(coreActions.handleException(
|
||||
'Could not update connection',
|
||||
error
|
||||
));
|
||||
}
|
||||
);
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'PUSHER_GET_QUEUE_METADATA':
|
||||
request(store, 'get_queue_metadata')
|
||||
.then(
|
||||
@ -358,31 +387,6 @@ const PusherMiddleware = (function(){
|
||||
})
|
||||
break;
|
||||
|
||||
case 'PUSHER_SET_USERNAME':
|
||||
request(store, 'set_username', {username: action.username})
|
||||
.then(
|
||||
response => {
|
||||
response.type = 'PUSHER_USERNAME_CHANGED'
|
||||
store.dispatch(response)
|
||||
},
|
||||
error => {
|
||||
store.dispatch(coreActions.handleException(
|
||||
'Could not set username',
|
||||
error
|
||||
));
|
||||
|
||||
// Forced change to local state, even if server-end failed
|
||||
// Useful for changing when not yet connected (ie Initial setup on
|
||||
// non-standard ports, etc)
|
||||
if (action.force){
|
||||
response.type = 'PUSHER_USERNAME_CHANGED'
|
||||
store.dispatch(response)
|
||||
}
|
||||
}
|
||||
);
|
||||
return next(action);
|
||||
break;
|
||||
|
||||
case 'PUSHER_GET_VERSION':
|
||||
request(store, 'get_version')
|
||||
.then(
|
||||
|
||||
@ -21,7 +21,7 @@ export default function reducer(pusher = {}, action){
|
||||
case 'PUSHER_SET_PORT':
|
||||
return Object.assign({}, pusher, { port: action.port });
|
||||
|
||||
case 'PUSHER_USERNAME_CHANGED':
|
||||
case 'PUSHER_SET_USERNAME':
|
||||
return Object.assign({}, pusher, { username: action.username });
|
||||
|
||||
case 'PUSHER_CONNECTIONS':
|
||||
@ -37,6 +37,13 @@ export default function reducer(pusher = {}, action){
|
||||
connections[action.connection.connection_id] = action.connection;
|
||||
return Object.assign({}, pusher, { connections: connections });
|
||||
|
||||
case 'PUSHER_CONNECTION_UPDATED':
|
||||
return Object.assign({}, pusher, {
|
||||
username: action.connection.username,
|
||||
client_id: action.connection.client_id,
|
||||
connection_id: action.connection.connection_id
|
||||
});
|
||||
|
||||
case 'PUSHER_CONNECTION_REMOVED':
|
||||
var connections = Object.assign({}, pusher.connections)
|
||||
delete connections[action.connection.connection_id]
|
||||
|
||||
Reference in New Issue
Block a user