mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-11-14 19:05:01 -05:00
lib/client: send BOUNCER BIND and CAP END immediately
Don't wait for auth to finish. This reduces the number of roundtrips.
This commit is contained in:
parent
bc3abbec32
commit
adefc620de
1 changed files with 24 additions and 27 deletions
|
@ -293,15 +293,6 @@ export default class Client extends EventTarget {
|
|||
case irc.RPL_LOGGEDOUT:
|
||||
console.log("Logged out");
|
||||
break;
|
||||
case irc.RPL_SASLSUCCESS:
|
||||
console.log("SASL authentication success");
|
||||
if (this.status != Client.Status.REGISTERED) {
|
||||
if (this.enabledCaps["soju.im/bouncer-networks"] && this.params.bouncerNetwork) {
|
||||
this.send({ command: "BOUNCER", params: ["BIND", this.params.bouncerNetwork] });
|
||||
}
|
||||
this.send({ command: "CAP", params: ["END"] });
|
||||
}
|
||||
break;
|
||||
case irc.RPL_NAMREPLY:
|
||||
this.pushPendingList("NAMES " + msg.params[2], msg);
|
||||
break;
|
||||
|
@ -325,6 +316,9 @@ export default class Client extends EventTarget {
|
|||
case irc.RPL_ENDOFWHO:
|
||||
this.endPendingList("WHO", msg);
|
||||
break;
|
||||
case irc.RPL_SASLSUCCESS:
|
||||
console.log("SASL authentication success");
|
||||
break;
|
||||
case irc.ERR_NICKLOCKED:
|
||||
case irc.ERR_SASLFAIL:
|
||||
case irc.ERR_SASLTOOLONG:
|
||||
|
@ -398,6 +392,9 @@ export default class Client extends EventTarget {
|
|||
}
|
||||
|
||||
authenticate(mechanism, params) {
|
||||
if (!this.supportsSASL(mechanism)) {
|
||||
throw new Error(`${mechanism} authentication not supported by the server`);
|
||||
}
|
||||
console.log(`Starting SASL ${mechanism} authentication`);
|
||||
this.send({ command: "AUTHENTICATE", params: [mechanism] });
|
||||
switch (mechanism) {
|
||||
|
@ -576,20 +573,28 @@ export default class Client extends EventTarget {
|
|||
case "LS":
|
||||
this.supportsCap = true;
|
||||
this.addAvailableCaps(args[args.length - 1]);
|
||||
if (args[0] != "*") {
|
||||
console.log("Available server caps:", this.availableCaps);
|
||||
if (args[0] == "*") {
|
||||
break;
|
||||
}
|
||||
|
||||
let capEnd = true;
|
||||
if ((this.params.saslPlain && this.supportsSASL("PLAIN")) || (this.params.saslExternal && this.supportsSASL("EXTERNAL"))) {
|
||||
// CAP END is deferred after authentication finishes
|
||||
capEnd = false;
|
||||
console.log("Available server caps:", this.availableCaps);
|
||||
|
||||
this.requestCaps();
|
||||
|
||||
if (this.status !== Client.Status.REGISTERED) {
|
||||
if (this.availableCaps["sasl"] !== undefined) {
|
||||
if (this.params.saslPlain) {
|
||||
this.authenticate("PLAIN", this.params.saslPlain);
|
||||
} else if (this.params.saslExternal) {
|
||||
this.authenticate("EXTERNAL");
|
||||
}
|
||||
}
|
||||
|
||||
this.requestCaps();
|
||||
|
||||
if (this.status != Client.Status.REGISTERED && capEnd) {
|
||||
this.send({ command: "CAP", params: ["END"] });
|
||||
if (this.availableCaps["soju.im/bouncer-networks"] !== undefined && this.params.bouncerNetwork) {
|
||||
this.send({ command: "BOUNCER", params: ["BIND", this.params.bouncerNetwork] });
|
||||
}
|
||||
|
||||
this.send({ command: "CAP", params: ["END"] });
|
||||
}
|
||||
break;
|
||||
case "NEW":
|
||||
|
@ -610,14 +615,6 @@ export default class Client extends EventTarget {
|
|||
args[0].split(" ").forEach((cap) => {
|
||||
cap = cap.toLowerCase();
|
||||
this.enabledCaps[cap] = true;
|
||||
|
||||
if (cap === "sasl" && this.status !== Client.Status.REGISTERED) {
|
||||
if (this.params.saslPlain) {
|
||||
this.authenticate("PLAIN", this.params.saslPlain);
|
||||
} else if (this.params.saslExternal) {
|
||||
this.authenticate("EXTERNAL");
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "NAK":
|
||||
|
|
Loading…
Reference in a new issue