UNPKG

@shopgate/engage

Version:
15 lines 2.15 kB
function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}import geolocationRequestBrowser from"./GeolocationRequestBrowser";import geolocationRequestApp from"./GeolocationRequestApp";import{GEOLOCATION_DEFAULT_TIMEOUT}from"../constants/geolocationRequest";/** * The GeolocationRequest class enables to retrieve the current geolocation of the device. */var GeolocationRequest=/*#__PURE__*/function(){/** * Constructor * @param {boolean} [useBrowserAPI=true] Wether the browser API or app commands a supposed to * be used to determine the geolocation. */function GeolocationRequest(){var useBrowserAPI=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;_classCallCheck(this,GeolocationRequest);this.useBrowserAPI=useBrowserAPI;this.options={timeout:GEOLOCATION_DEFAULT_TIMEOUT};}/** * Sets a timeout for the location request. * @param {number} [value=10000] The timeout in ms. * @returns {GeolocationRequest} */return _createClass(GeolocationRequest,[{key:"setTimeout",value:function setTimeout(){var value=arguments.length>0&&arguments[0]!==undefined?arguments[0]:GEOLOCATION_DEFAULT_TIMEOUT;this.options.timeout=value;return this;}/** * Dispatches the request. If no further provisions are made, it will trigger the geolocation * permission dialog if permissions are not already granted. * @returns {Promise} */},{key:"dispatch",value:function dispatch(){var instance=this.useBrowserAPI?geolocationRequestBrowser:geolocationRequestApp;return instance.dispatch(this.options.timeout);}}]);}();export default GeolocationRequest;