Reconnect when server complains about a username.

If a token does not specify a username, the server will request
one by failing the join message.  Disconnect from the WebSocket
in that case, and display the login dialog with the password
field invisible.
This commit is contained in:
Juliusz Chroboczek
2023-04-01 13:28:24 +02:00
parent 4c9e00d874
commit ac1dc77b30
3 changed files with 68 additions and 29 deletions
+6 -4
View File
@@ -179,7 +179,7 @@ function ServerConnection() {
*
* kind is one of 'join', 'fail', 'change' or 'leave'.
*
* @type{(this: ServerConnection, kind: string, group: string, permissions: Array<string>, status: Object<string,any>, data: Object<string,any>, message: string) => void}
* @type{(this: ServerConnection, kind: string, group: string, permissions: Array<string>, status: Object<string,any>, data: Object<string,any>, error: string, message: string) => void}
*/
this.onjoined = null;
/**
@@ -321,7 +321,7 @@ ServerConnection.prototype.connect = async function(url) {
sc.onuser.call(sc, id, 'delete');
}
if(sc.group && sc.onjoined)
sc.onjoined.call(sc, 'leave', sc.group, [], {}, {}, '');
sc.onjoined.call(sc, 'leave', sc.group, [], {}, {}, '', '');
sc.group = null;
sc.username = null;
if(sc.onclose)
@@ -393,7 +393,7 @@ ServerConnection.prototype.connect = async function(url) {
sc.onjoined.call(sc, m.kind, m.group,
m.permissions || [],
m.status, m.data,
m.value || null);
m.error || null, m.value || null);
break;
case 'user':
switch(m.kind) {
@@ -505,8 +505,10 @@ ServerConnection.prototype.join = async function(group, username, credentials, d
type: 'join',
kind: 'join',
group: group,
username: username,
};
if(typeof username !== 'undefined' && username !== null)
m.username = username;
if((typeof credentials) === 'string') {
m.password = credentials;
} else {