-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathshared.ts
More file actions
44 lines (39 loc) · 1.29 KB
/
shared.ts
File metadata and controls
44 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { EngineName } from "@/types/enums";
import { Stockfish11 } from "./stockfish11";
import { Stockfish16 } from "./stockfish16";
import { Stockfish16_1 } from "./stockfish16_1";
import { Stockfish17 } from "./stockfish17";
export const isWasmSupported = () =>
typeof WebAssembly === "object" &&
WebAssembly.validate(
Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)
);
export const isMultiThreadSupported = () => {
try {
return SharedArrayBuffer !== undefined && !isIosDevice();
} catch {
return false;
}
};
export const isIosDevice = () =>
typeof navigator !== "undefined" &&
/iPhone|iPad|iPod/i.test(navigator.userAgent);
export const isMobileDevice = () =>
isIosDevice() ||
(typeof navigator !== "undefined" &&
/Android|Opera Mini/i.test(navigator.userAgent));
export const isEngineSupported = (name: EngineName): boolean => {
switch (name) {
case EngineName.Stockfish17:
case EngineName.Stockfish17Lite:
return Stockfish17.isSupported();
case EngineName.Stockfish16_1:
case EngineName.Stockfish16_1Lite:
return Stockfish16_1.isSupported();
case EngineName.Stockfish16:
case EngineName.Stockfish16NNUE:
return Stockfish16.isSupported();
case EngineName.Stockfish11:
return Stockfish11.isSupported();
}
};