2021-04-01 01:13:36 +08:00
|
|
|
import Bowser from 'bowser';
|
2018-05-03 02:55:46 +08:00
|
|
|
|
2022-02-17 08:51:39 +08:00
|
|
|
const userAgent = window.navigator.userAgent;
|
|
|
|
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
|
|
|
|
const isTablet = BOWSER_RESULTS.platform.type === 'tablet' || (BOWSER_RESULTS.os.name === 'macOS' && window.navigator.maxTouchPoints > 0);
|
|
|
|
const isMobile = isPhone || isTablet;
|
|
|
|
const hasMediaDevices = !!navigator.mediaDevices;
|
|
|
|
const osName = BOWSER_RESULTS.os.name;
|
2023-04-26 22:33:27 +08:00
|
|
|
const isIos = osName === 'iOS' || (isTablet && osName=="macOS");
|
2021-04-01 19:14:24 +08:00
|
|
|
const isMacos = osName === 'macOS';
|
2022-02-17 08:51:39 +08:00
|
|
|
const isIphone = !!(userAgent.match(/iPhone/i));
|
2021-04-01 19:14:24 +08:00
|
|
|
|
2021-04-01 01:13:36 +08:00
|
|
|
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;
|