bigbluebutton-Github/bigbluebutton-html5/imports/utils/deviceInfo.js

31 lines
889 B
JavaScript
Raw Normal View History

2021-04-01 01:13:36 +08:00
import Bowser from 'bowser';
2022-02-17 08:51:39 +08:00
const userAgent = window.navigator.userAgent;
const BOWSER_RESULTS = Bowser.parse(userAgent);
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;
const isIos = osName === 'iOS' || (isTablet && osName=="macOS");
const isMacos = osName === 'macOS';
2022-02-17 08:51:39 +08:00
const isIphone = !!(userAgent.match(/iPhone/i));
2021-04-01 01:13:36 +08:00
const isPortrait = () => window.innerHeight > window.innerWidth;
2021-04-01 01:13:36 +08:00
const deviceInfo = {
isTablet,
isPhone,
isMobile,
hasMediaDevices,
osName,
isPortrait,
isIos,
isMacos,
isIphone,
2021-04-01 01:13:36 +08:00
};
export default deviceInfo;