@shopgate/engage
Version:
Shopgate's ENGAGE library.
43 lines (40 loc) • 1.48 kB
JavaScript
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.
*/
let 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(useBrowserAPI = true) {
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}
*/
var _proto = GeolocationRequest.prototype;
_proto.setTimeout = function setTimeout(value = 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}
*/;
_proto.dispatch = function dispatch() {
const instance = this.useBrowserAPI ? geolocationRequestBrowser : geolocationRequestApp;
return instance.dispatch(this.options.timeout);
};
return GeolocationRequest;
}();
export default GeolocationRequest;