Skip to content

Commit

Permalink
fix: return UNKNOWN_VERSION_NUMBER when cannot parse
Browse files Browse the repository at this point in the history
  • Loading branch information
afgiel committed Oct 1, 2024
1 parent 7c29970 commit a6a8582
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ export const Permissions = Object.freeze({
ADMINISTRATOR: BigFlagUtils.getFlag(3),
});

export const UNKNOWN_VERSION_NUMBER = -1;
export const HANDSHAKE_SDK_VERSION_MINIUM_MOBILE_VERSION = 250;
18 changes: 10 additions & 8 deletions src/Discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import commands, {Commands} from './commands';
import {v4 as uuidv4} from 'uuid';
import {SDKError} from './error';
import {EventSchema, ERROR, Events as RPCEvents} from './schema/events';
import {Platform, RPCCloseCodes, HANDSHAKE_SDK_VERSION_MINIUM_MOBILE_VERSION} from './Constants';
import {
Platform,
RPCCloseCodes,
HANDSHAKE_SDK_VERSION_MINIUM_MOBILE_VERSION,
UNKNOWN_VERSION_NUMBER,
} from './Constants';
import getDefaultSdkConfiguration from './utils/getDefaultSdkConfiguration';
import {ConsoleLevel, consoleLevels, wrapConsoleMethod} from './utils/console';
import type {TSendCommand, TSendCommandPayload} from './schema/types';
Expand Down Expand Up @@ -208,15 +213,15 @@ export class DiscordSDK implements IDiscordSDK {
}
}

private parseMajorMobileVersion(): number | null {
private parseMajorMobileVersion(): number {
if (this.mobileAppVersion && this.mobileAppVersion.includes('.')) {
try {
return parseInt(this.mobileAppVersion.split('.')[0]);
} catch {
return null;
return UNKNOWN_VERSION_NUMBER;
}
}
return null;
return UNKNOWN_VERSION_NUMBER;
}

private handshake() {
Expand All @@ -227,10 +232,7 @@ export class DiscordSDK implements IDiscordSDK {
frame_id: this.frameId,
};
const majorMobileVersion = this.parseMajorMobileVersion();
if (
this.platform === Platform.DESKTOP ||
(majorMobileVersion != null && majorMobileVersion >= HANDSHAKE_SDK_VERSION_MINIUM_MOBILE_VERSION)
) {
if (this.platform === Platform.DESKTOP || majorMobileVersion >= HANDSHAKE_SDK_VERSION_MINIUM_MOBILE_VERSION) {
handshakePayload['sdk_version'] = this.sdkVersion;
}
this.source?.postMessage([Opcodes.HANDSHAKE, handshakePayload], this.sourceOrigin);
Expand Down

0 comments on commit a6a8582

Please sign in to comment.