Skip to content

Commit

Permalink
📱 Future-proof version check
Browse files Browse the repository at this point in the history
  • Loading branch information
molenzwiebel committed Jan 13, 2018
1 parent 0d937b4 commit 247b808
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
1 change: 0 additions & 1 deletion web/src/components/champ-select/champ-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export default class ChampSelect extends Vue {

// Observe runes
this.$root.observe("/lol-perks/v1/pages", response => {
console.log("Got perks update.");
response.status === 200 && (this.runePages = response.content);
response.status === 200 && (this.runePages.sort((a, b) => a.order - b.order));
});
Expand Down
9 changes: 4 additions & 5 deletions web/src/components/invites/invites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ export default class Invites extends Vue {
// Start observing invitation changes.
this.$root.observe("/lol-lobby/v2/received-invitations", handleInvitationUpdate);

// 1.1.0 does not support observing endpoints that don't return objects (invitations returns an array)
// gracefully fall back and periodically poll instead. Anything above 1.1.0 supports it, and since 1.1.0
// was the first public version, a simple comparison is fine.
if (this.$root.peerVersion === "1.1.0") {
// Anything below 1.2.0 does not support observing anything that does not return an object.
// Opt for polling instead.
if (!this.$root.peerVersion.greaterThan(1, 1, 0)) {
console.log("Using polling to watch invites.");
setInterval(handleInvitationUpdate, 5000);
setInterval(handleInvitationUpdate, 3000);
}

// Check for initial pending invites.
Expand Down
5 changes: 3 additions & 2 deletions web/src/components/root/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Queue from "../queue/queue.vue";
import ReadyCheck from "../ready-check/ready-check.vue";
import ChampSelect from "../champ-select/champ-select.vue";
import Invites from "../invites/invites.vue";
import Version from "../../util/version";

// Represents a result from the LCU api.
export interface Result {
Expand All @@ -32,7 +33,7 @@ type WebsocketMessage = [1, string, number, any] | [2, number, number, any] | [3
export default class Root extends Vue {
connected = false;
socket: WebSocket;
peerVersion: string = "";
peerVersion: Version = <any>null; // null is required to allow vue to observe
notifications: string[] = [];

discoveryButtonType = "normal";
Expand Down Expand Up @@ -127,7 +128,7 @@ export default class Root extends Vue {
* haywire. This works fine though, so we use this instead.
*/
private setPeerVersion(version: string) {
this.peerVersion = version;
this.peerVersion = new Version(version);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions web/src/util/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Very simple semver-ish implementation of the Conduit version
* so we can perform some checks based on its version.
*/
export default class Version {
public readonly major: number;
public readonly minor: number;
public readonly patch: number;

constructor(version: string) {
const [major, minor, patch] = version.split(".");

this.major = +major;
this.minor = +minor;
this.patch = +patch;
}

greaterThan(major: number, minor: number, patch: number): boolean {
return this.major > major || this.minor > minor || this.patch > patch;
}
}

0 comments on commit 247b808

Please sign in to comment.