2021-04-01 01:13:36 +08:00
|
|
|
import Bowser from 'bowser';
|
2018-05-03 02:55:46 +08:00
|
|
|
|
2024-08-10 01:58:44 +08:00
|
|
|
export const userAgent = window.navigator.userAgent;
|
|
|
|
export const BOWSER_RESULTS = Bowser.parse(userAgent);
|
2018-05-03 02:55:46 +08:00
|
|
|
|
2021-04-01 01:13:36 +08:00
|
|
|
const isPhone = BOWSER_RESULTS.platform.type === 'mobile';
|
|
|
|
// we need a 'hack' to correctly detect ipads with ios > 13
|
2024-08-10 01:58:44 +08:00
|
|
|
export const isTablet = BOWSER_RESULTS.platform.type === 'tablet' || (BOWSER_RESULTS.os.name === 'macOS' && window.navigator.maxTouchPoints > 0);
|
|
|
|
export const isMobile = isPhone || isTablet;
|
|
|
|
export const hasMediaDevices = !!navigator.mediaDevices;
|
|
|
|
export const osName = BOWSER_RESULTS.os.name;
|
|
|
|
export const isIos = osName === 'iOS' || (isTablet && osName=="macOS");
|
|
|
|
export const isMacos = osName === 'macOS';
|
|
|
|
export const isIphone = !!(userAgent.match(/iPhone/i));
|
2021-04-01 19:14:24 +08:00
|
|
|
|
2024-08-10 01:58:44 +08:00
|
|
|
export const isPortrait = () => window.innerHeight > window.innerWidth;
|
2018-05-03 02:55:46 +08:00
|
|
|
|
2021-04-01 01:13:36 +08:00
|
|
|
const deviceInfo = {
|
|
|
|
isTablet,
|
|
|
|
isPhone,
|
|
|
|
isMobile,
|
|
|
|
hasMediaDevices,
|
|
|
|
osName,
|
|
|
|
isPortrait,
|
2021-04-01 19:14:24 +08:00
|
|
|
isIos,
|
|
|
|
isMacos,
|
|
|
|
isIphone,
|
2021-04-01 01:13:36 +08:00
|
|
|
};
|
2018-05-03 02:55:46 +08:00
|
|
|
|
|
|
|
export default deviceInfo;
|