UNPKG

meta-client

Version:
56 lines (48 loc) 1.64 kB
import Desktop from './Device/Desktop'; import Touch from './Device/Touch'; import Reality from './Device/Reality'; import {log} from './Utilities'; let Mobile = { Android: function() { return navigator.userAgent.match(/Android/i); }, BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); }, iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i); }, Opera: function() { return navigator.userAgent.match(/Opera Mini/i); }, Windows: function() { return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i); }, any: function() { return (Mobile.Android() || Mobile.BlackBerry() || Mobile.iOS() || Mobile.Opera() || Mobile.Windows()); } }; class Device { constructor(WORLD, HUMAN){ WORLD.isFor(HUMAN); //TODO NOT SO SWEET... let that = this; this.id = "Device"; log(this.id); if( Mobile.any() ){ log(that.id, 'detected mobile/touch device'); return new Touch(WORLD, HUMAN); }else { if (navigator.getVRDisplays) { log(that.id, "WebVR Device found and function."); return new Reality(WORLD, HUMAN); } else if (navigator.getVRDevices) { log(that.id, "Your browser supports WebVR but not the latest version. See <a href='http://webvr.info'>webvr.info</a> for more info."); return new Desktop(WORLD, HUMAN); } else { log(that.id, "Your browser does not support WebVR. See <a href='http://webvr.info'>webvr.info</a> for assistance."); return new Desktop(WORLD, HUMAN); } } } } export default Device;