Removing ws subprotocol; Creating new post-connection update hook

This commit is contained in:
James Barnsley
2019-04-26 15:21:29 +12:00
parent a9dad3e648
commit 202eedae74
20 changed files with 170 additions and 138 deletions

View File

@ -311,23 +311,10 @@ class IrisCore(pykka.ThreadingActor):
self.connections[client['connection_id']] = {
'client': client,
'id': client['connection_id'],
'connection_id': client['connection_id'],
'connection': connection
}
self.send_message(data={
'recipient': client['connection_id'],
'method': 'connection_established',
'params': {
'connection': {
'connection_id': client['connection_id'],
'client_id': client['client_id'],
'username': client['username'],
'ip': client['ip']
}
}
})
self.broadcast(data={
'method': 'connection_added',
'params': {
@ -335,6 +322,40 @@ class IrisCore(pykka.ThreadingActor):
}
})
def update_connection(self, *args, **kwargs):
callback = kwargs.get('callback', None)
data = kwargs.get('data', {})
connection_id = data['connection_id']
if connection_id in self.connections:
self.connections[connection_id]['client']['username'] = data['username']
self.connections[connection_id]['client']['client_id'] = data['client_id']
self.broadcast(data={
'method': "connection_changed",
'params': {
'connection': self.connections[connection_id]['client']
}
})
response = {
'connection': self.connections[connection_id]['client']
}
if (callback):
callback(response)
else:
return response
else:
error = 'Connection "'+data['connection_id']+'" not found'
logger.error(error)
error = {
'message': error
}
if (callback):
callback(False, error)
else:
return error
def remove_connection(self, connection_id):
if connection_id in self.connections:
try: