Renaming of pusher events
This commit is contained in:
@ -108,9 +108,17 @@ class IrisCore(object):
|
||||
}
|
||||
self.connections[connection_id] = new_connection
|
||||
|
||||
self.send_message(
|
||||
connection_id, {
|
||||
'type': 'connected',
|
||||
'connection_id': connection_id,
|
||||
'username': client['username']
|
||||
}
|
||||
)
|
||||
|
||||
self.broadcast({
|
||||
'type': 'client_connected',
|
||||
'client': client
|
||||
'type': 'connection_added',
|
||||
'connection': client
|
||||
})
|
||||
|
||||
def remove_connection(self, connection_id):
|
||||
@ -119,8 +127,8 @@ class IrisCore(object):
|
||||
client = self.connections[connection_id]['client']
|
||||
del self.connections[connection_id]
|
||||
self.broadcast({
|
||||
'type': 'client_disconnected',
|
||||
'client': client
|
||||
'type': 'connection_removed',
|
||||
'connection': client
|
||||
})
|
||||
except:
|
||||
logger.error('Failed to close connection to '+ connection_id)
|
||||
@ -133,7 +141,10 @@ class IrisCore(object):
|
||||
'type': 'connection_updated',
|
||||
'connection': self.connections[connection_id]['client']
|
||||
})
|
||||
return {}
|
||||
return {
|
||||
'type': 'username_changed',
|
||||
'username': data['username']
|
||||
}
|
||||
|
||||
else:
|
||||
error = 'Connection "'+data['connection_id']+'" not found'
|
||||
|
||||
2
src/js/bootstrap.js
vendored
2
src/js/bootstrap.js
vendored
@ -37,7 +37,7 @@ var initialState = {
|
||||
connected: false,
|
||||
port: 6681,
|
||||
username: 'Anonymous',
|
||||
connections: [],
|
||||
connections: {},
|
||||
version: {
|
||||
current: '0.0.0'
|
||||
}
|
||||
|
||||
@ -28,12 +28,20 @@ class PusherConnectionList extends React.Component{
|
||||
|
||||
render(){
|
||||
if( !this.props.connected ) return <div className="pusher-connection-list grey-text">Not connected</div>
|
||||
if( typeof(this.props.connections) == 'undefined' || this.props.connections.length <= 0 ) return <div className="pusher-connection-list grey-text">No connections</div>;
|
||||
|
||||
var connections = []
|
||||
for (var connection_id in this.props.connections){
|
||||
if (this.props.connections.hasOwnProperty(connection_id)) {
|
||||
connections.push(this.props.connections[connection_id])
|
||||
}
|
||||
}
|
||||
|
||||
if (connections.length <= 0) return <div className="pusher-connection-list grey-text">No connections</div>;
|
||||
|
||||
return (
|
||||
<div className="pusher-connection-list">
|
||||
{
|
||||
this.props.connections.map( (connection, index) => {
|
||||
connections.map( (connection, index) => {
|
||||
var is_me = false;
|
||||
if( connection.connection_id == this.props.connection_id ) is_me = true;
|
||||
return (
|
||||
|
||||
@ -23,8 +23,7 @@ const localstorageMiddleware = (function(){
|
||||
if( !pusher ) pusher = {};
|
||||
Object.assign(
|
||||
pusher,{
|
||||
username: action.connection.username,
|
||||
connectionid: action.connection.connectionid
|
||||
connection_id: action.connection_id
|
||||
}
|
||||
);
|
||||
localStorage.setItem('pusher', JSON.stringify(pusher));
|
||||
@ -37,9 +36,9 @@ const localstorageMiddleware = (function(){
|
||||
localStorage.setItem('pusher', JSON.stringify(pusher));
|
||||
break;
|
||||
|
||||
case 'PUSHER_USERNAME':
|
||||
case 'PUSHER_USERNAME_CHANGED':
|
||||
var stored_pusher = JSON.parse( localStorage.getItem('pusher') )
|
||||
var pusher = Object.assign({}, stored_pusher, { username: action.data.username })
|
||||
var pusher = Object.assign({}, stored_pusher, { username: action.username })
|
||||
localStorage.setItem('pusher', JSON.stringify(pusher))
|
||||
break;
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ export function startUpgrade(){
|
||||
|
||||
export function getConnections(){
|
||||
return {
|
||||
type: 'GET_CONNECTIONS'
|
||||
type: 'PUSHER_GET_CONNECTIONS'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ const PusherMiddleware = (function(){
|
||||
|
||||
// handle all manner of socket messages
|
||||
const handleMessage = (ws, store, message) => {
|
||||
console.log(message)
|
||||
|
||||
// response to a request [we] made
|
||||
if (typeof(message.request_id) !== 'undefined' && message.request_id){
|
||||
if (typeof( deferredRequests[ message.request_id ]) !== 'undefined' ){
|
||||
@ -34,7 +34,7 @@ const PusherMiddleware = (function(){
|
||||
// general message
|
||||
// this can be client-client, server-client or a broadcast to many clients
|
||||
} else {
|
||||
message.type = message.type.toUpperCase()
|
||||
message.type = 'PUSHER_'+message.type.toUpperCase()
|
||||
store.dispatch(message)
|
||||
}
|
||||
}
|
||||
@ -88,11 +88,6 @@ const PusherMiddleware = (function(){
|
||||
[ connection.clientid, connection.connection_id, connection.username ]
|
||||
);
|
||||
|
||||
socket.onopen = () => {
|
||||
store.dispatch({ type: 'PUSHER_CONNECTED', connection_id: connection.connection_id });
|
||||
store.dispatch({ type: 'PUSHER_SET_USERNAME', username: connection.username });
|
||||
};
|
||||
|
||||
socket.onmessage = (message) => {
|
||||
var message = JSON.parse(message.data);
|
||||
handleMessage( socket, store, message )
|
||||
@ -149,10 +144,6 @@ const PusherMiddleware = (function(){
|
||||
return next(action);
|
||||
break;
|
||||
|
||||
case 'ERROR':
|
||||
store.dispatch( uiActions.createNotification(action.source+': '+action.message,'bad') )
|
||||
break;
|
||||
|
||||
case 'PUSHER_GET_QUEUE_METADATA':
|
||||
request('get_queue_metadata')
|
||||
.then(
|
||||
@ -171,7 +162,7 @@ const PusherMiddleware = (function(){
|
||||
})
|
||||
break;
|
||||
|
||||
case 'START_UPGRADE':
|
||||
case 'PUSHER_START_UPGRADE':
|
||||
request('upgrade')
|
||||
.then(
|
||||
response => {
|
||||
@ -199,21 +190,18 @@ const PusherMiddleware = (function(){
|
||||
})
|
||||
.then(
|
||||
response => {
|
||||
console.log(response)
|
||||
if (response.error){
|
||||
console.error(response.error)
|
||||
return false
|
||||
}
|
||||
|
||||
//response.type = 'PUSHER_USERNAME'
|
||||
//store.dispatch(response)
|
||||
response.type = 'PUSHER_USERNAME_CHANGED'
|
||||
store.dispatch(response)
|
||||
}
|
||||
)
|
||||
return next(action);
|
||||
break;
|
||||
|
||||
case 'GET_CONNECTIONS':
|
||||
case 'NEW_CONNECTION':
|
||||
case 'PUSHER_GET_CONNECTIONS':
|
||||
request('get_connections')
|
||||
.then(
|
||||
response => {
|
||||
@ -221,8 +209,7 @@ const PusherMiddleware = (function(){
|
||||
console.error(response.error)
|
||||
return false
|
||||
}
|
||||
|
||||
response.type = 'CONNECTIONS'
|
||||
response.type = 'PUSHER_CONNECTIONS'
|
||||
store.dispatch(response)
|
||||
}
|
||||
)
|
||||
@ -237,7 +224,6 @@ const PusherMiddleware = (function(){
|
||||
console.error(response.error)
|
||||
return false
|
||||
}
|
||||
|
||||
response.type = 'DEBUG'
|
||||
store.dispatch(response)
|
||||
}
|
||||
|
||||
@ -8,7 +8,9 @@ export default function reducer(pusher = {}, action){
|
||||
|
||||
case 'PUSHER_CONNECTED':
|
||||
return Object.assign({}, pusher, {
|
||||
connection_id: action.connection_id
|
||||
connected: true,
|
||||
connection_id: action.connection_id,
|
||||
username: action.username
|
||||
});
|
||||
|
||||
case 'PUSHER_DISCONNECTED':
|
||||
@ -17,30 +19,34 @@ export default function reducer(pusher = {}, action){
|
||||
case 'PUSHER_SET_PORT':
|
||||
return Object.assign({}, pusher, { port: action.port });
|
||||
|
||||
case 'PUSHER_USERNAME':
|
||||
case 'PUSHER_USERNAME_CHANGED':
|
||||
return Object.assign({}, pusher, { username: action.username });
|
||||
|
||||
case 'CONNECTIONS':
|
||||
return Object.assign({}, pusher, { connections: action.connections });
|
||||
|
||||
case 'CONNECTION_UPDATED':
|
||||
function byID(connection){
|
||||
return connection.connection_id == action.connection.connection_id;
|
||||
case 'PUSHER_CONNECTIONS':
|
||||
var connections = {}
|
||||
for (var i = 0; i < action.connections.length; i++){
|
||||
connections[action.connections[i].connection_id] = action.connections[i]
|
||||
}
|
||||
var connection = pusher.connections.find(byID);
|
||||
var index = pusher.connections.indexOf(connection);
|
||||
var connections = Object.assign([], pusher.connections);
|
||||
connections[index] = action.connection;
|
||||
|
||||
return Object.assign({}, pusher, { connections: connections });
|
||||
|
||||
case 'VERSION':
|
||||
case 'PUSHER_CONNECTION_ADDED':
|
||||
case 'PUSHER_CONNECTION_UPDATED':
|
||||
var connections = Object.assign({}, pusher.connections)
|
||||
connections[action.connection.connection_id] = action.connection
|
||||
return Object.assign({}, pusher, { connections: connections });
|
||||
|
||||
case 'PUSHER_CONNECTION_REMOVED':
|
||||
var connections = Object.assign({}, pusher.connections)
|
||||
delete connections[action.connection.connection_id]
|
||||
return Object.assign({}, pusher, { connections: connections });
|
||||
|
||||
case 'PUSHER_VERSION':
|
||||
return Object.assign({}, pusher, {
|
||||
version: action.version,
|
||||
upgrading: false
|
||||
});
|
||||
|
||||
case 'START_UPGRADE':
|
||||
case 'PUSHER_START_UPGRADE':
|
||||
return Object.assign({}, pusher, { upgrading: true });
|
||||
|
||||
default:
|
||||
|
||||
@ -21,7 +21,7 @@ const UIMiddleware = (function(){
|
||||
break
|
||||
|
||||
case 'PUSHER_CONNECTED':
|
||||
ReactGA.event({ category: 'Pusher', action: 'Connected', label: action.connection.username })
|
||||
ReactGA.event({ category: 'Pusher', action: 'Connected', label: action.connection_id+'/'+action.username })
|
||||
next(action)
|
||||
break
|
||||
|
||||
|
||||
@ -181,7 +181,7 @@ class Settings extends React.Component{
|
||||
<div className="field">
|
||||
<div className="name"></div>
|
||||
<div className="input">
|
||||
<button type="submit" className="secondary">Apply</button>
|
||||
<button type="submit" className="secondary">Apply and reload</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user