Leaning up the initial connection, will trigger post-connection messages instead
This commit is contained in:
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"python.pythonPath": "/usr/local/bin/python"
|
||||
}
|
||||
@ -306,23 +306,21 @@ class IrisCore(pykka.ThreadingActor):
|
||||
return response
|
||||
|
||||
def add_connection(self, *args, **kwargs):
|
||||
connection_id = kwargs.get('connection_id', None)
|
||||
connection = kwargs.get('connection', None)
|
||||
client = kwargs.get('client', None)
|
||||
|
||||
new_connection = {
|
||||
self.connections[client['connection_id']] = {
|
||||
'client': client,
|
||||
'connection_id': connection_id,
|
||||
'id': client['connection_id'],
|
||||
'connection': connection
|
||||
}
|
||||
self.connections[connection_id] = new_connection
|
||||
|
||||
self.send_message(data={
|
||||
'recipient': connection_id,
|
||||
'method': 'connection_added',
|
||||
'recipient': client['connection_id'],
|
||||
'method': 'connection_established',
|
||||
'params': {
|
||||
'connection': {
|
||||
'connection_id': connection_id,
|
||||
'connection_id': client['connection_id'],
|
||||
'client_id': client['client_id'],
|
||||
'username': client['username'],
|
||||
'ip': client['ip']
|
||||
|
||||
@ -33,32 +33,22 @@ class WebsocketHandler(tornado.websocket.WebSocketHandler):
|
||||
|
||||
def open(self):
|
||||
|
||||
# decode our connection protocol value (which is a payload of id/name from javascript)
|
||||
protocolElements = mem.iris.digest_protocol(self.request.headers.get('Sec-Websocket-Protocol', []))
|
||||
|
||||
connection_id = protocolElements['connection_id']
|
||||
client_id = protocolElements['client_id']
|
||||
self.connection_id = connection_id
|
||||
username = protocolElements['username']
|
||||
created = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')
|
||||
|
||||
# get our IP
|
||||
# if it's local, then check for proxy origin
|
||||
# Get the client's IP. If it's local, then use it's proxy origin
|
||||
ip = self.request.remote_ip
|
||||
if (ip == '127.0.0.1' and hasattr(self.request.headers,'X-Forwarded-For')):
|
||||
ip = self.request.headers['X-Forwarded-For']
|
||||
|
||||
# construct our client object, and add to our list of connections
|
||||
# Construct our initial client object, and add to our list of connections
|
||||
client = {
|
||||
'client_id': client_id,
|
||||
'connection_id': connection_id,
|
||||
'username': username,
|
||||
'connection_id': mem.iris.generateGuid(),
|
||||
'client_id': mem.iris.generateGuid(),
|
||||
'ip': ip,
|
||||
'created': created
|
||||
'created': datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')
|
||||
}
|
||||
|
||||
# add to connections
|
||||
mem.iris.add_connection(connection_id=connection_id, connection=self, client=client)
|
||||
self.connection_id = client['connection_id']
|
||||
|
||||
mem.iris.add_connection(connection=self, client=client)
|
||||
|
||||
|
||||
def on_message(self, message):
|
||||
|
||||
@ -72120,6 +72120,9 @@ var 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;
|
||||
@ -72274,24 +72277,12 @@ var PusherMiddleware = function () {
|
||||
store.dispatch({ type: 'PUSHER_CONNECTING' });
|
||||
|
||||
var state = store.getState();
|
||||
var connection = {
|
||||
client_id: helpers.generateGuid(),
|
||||
connection_id: helpers.generateGuid(),
|
||||
username: 'Anonymous'
|
||||
};
|
||||
if (state.pusher.username) {
|
||||
connection.username = state.pusher.username;
|
||||
}
|
||||
connection.username = connection.username.replace(/\W/g, '');
|
||||
|
||||
socket = new WebSocket('ws' + (window.location.protocol === 'https:' ? 's' : '') + '://' + state.mopidy.host + ':' + state.mopidy.port + '/iris/ws/', [connection.client_id, connection.connection_id, connection.username]);
|
||||
socket = new WebSocket('ws' + (window.location.protocol === 'https:' ? 's' : '') + '://' + state.mopidy.host + ':' + state.mopidy.port + '/iris/ws/');
|
||||
|
||||
socket.onopen = function () {
|
||||
store.dispatch({
|
||||
type: 'PUSHER_CONNECTED',
|
||||
connection_id: connection.connection_id,
|
||||
client_id: connection.client_id,
|
||||
username: connection.username
|
||||
type: 'PUSHER_CONNECTED'
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -100,7 +100,7 @@
|
||||
|
||||
// Release details
|
||||
// These are automatically injected to built HTML
|
||||
var build = "1555971818";
|
||||
var build = "1556157415";
|
||||
var version = "3.36.1";
|
||||
|
||||
// Construct the script tag
|
||||
|
||||
@ -75,6 +75,9 @@ 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;
|
||||
@ -228,27 +231,14 @@ const PusherMiddleware = (function(){
|
||||
store.dispatch({type: 'PUSHER_CONNECTING'});
|
||||
|
||||
var state = store.getState();
|
||||
var connection = {
|
||||
client_id: helpers.generateGuid(),
|
||||
connection_id: helpers.generateGuid(),
|
||||
username: 'Anonymous'
|
||||
}
|
||||
if (state.pusher.username){
|
||||
connection.username = state.pusher.username;
|
||||
}
|
||||
connection.username = connection.username.replace(/\W/g, '');
|
||||
|
||||
socket = new WebSocket(
|
||||
'ws'+(window.location.protocol === 'https:' ? 's' : '')+'://'+state.mopidy.host+':'+state.mopidy.port+'/iris/ws/',
|
||||
[ connection.client_id, connection.connection_id, connection.username ]
|
||||
'ws'+(window.location.protocol === 'https:' ? 's' : '')+'://'+state.mopidy.host+':'+state.mopidy.port+'/iris/ws/'
|
||||
);
|
||||
|
||||
socket.onopen = () => {
|
||||
store.dispatch({
|
||||
type: 'PUSHER_CONNECTED',
|
||||
connection_id: connection.connection_id,
|
||||
client_id: connection.client_id,
|
||||
username: connection.username
|
||||
type: 'PUSHER_CONNECTED'
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user