UNPKG

@cause-911/core

Version:

Run `npm install @cause-911/core --save` to add this library to your project

1,373 lines (1,357 loc) 77.9 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@ngx-translate/core'), require('@angular/core'), require('rxjs'), require('@angular/common/http'), require('rxjs/operators'), require('@angular/material')) : typeof define === 'function' && define.amd ? define('@cause-911/core', ['exports', '@ngx-translate/core', '@angular/core', 'rxjs', '@angular/common/http', 'rxjs/operators', '@angular/material'], factory) : (global = global || self, factory((global['cause-911'] = global['cause-911'] || {}, global['cause-911'].core = {}), global.core, global.ng.core, global.rxjs, global.ng.common.http, global.rxjs.operators, global.ng.material)); }(this, function (exports, core, core$1, rxjs, http, operators, material) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var CoreModuleOptions = /** @class */ (function () { function CoreModuleOptions() { this.apiUrl = ''; this.languages = ['fr', 'en']; this.loginURL = '/login/'; this.refreshLoginURL = ''; this.allowRefreshToken = false; this.libraries = []; this.locale = ''; this.nbRetryOnNetworkError = 0; this.contentSecurityPolicyActivated = false; } return CoreModuleOptions; }()); /** @type {?} */ var CAUSE_CORE_MODULE_OPTIONS = new core$1.InjectionToken('cause-core-module-options', { providedIn: 'root', factory: CAUSE_CORE_MODULE_OPTIONS_FACTORY, }); /** * @return {?} */ function CAUSE_CORE_MODULE_OPTIONS_FACTORY() { return new CoreModuleOptions(); } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Configuration = /** @class */ (function () { function Configuration(options) { this.libraries = []; this.loginURL = ''; this.refreshLoginURL = ''; this.allowRefreshToken = true; this.apiUrl = ''; this.nbRetryOnNetworkError = 0; this.contentSecurityPolicyActivated = false; this.useCharset = 'UTF-8'; this.useAuthorizationType = 'Bearer'; this.useAccessToken = ''; this.useRefreshToken = ''; this.useCSRFToken = ''; this.useLocale = options.locale || 'fr'; this.useLanguages = options.languages || ['fr']; this.libraries = options.libraries || []; this.apiUrl = options.apiUrl || '/api/'; this.allowRefreshToken = options.allowRefreshToken || true; this.loginURL = options.loginURL || '/login/'; this.refreshLoginURL = options.refreshLoginURL || ''; this.nbRetryOnNetworkError = options.nbRetryOnNetworkError || 0; this.contentSecurityPolicyActivated = options.contentSecurityPolicyActivated || false; } Object.defineProperty(Configuration.prototype, "locale", { get: /** * @return {?} */ function () { return this.useLocale; }, set: /** * @param {?} value * @return {?} */ function (value) { this.useLocale = value; }, enumerable: true, configurable: true }); Object.defineProperty(Configuration.prototype, "languages", { get: /** * @return {?} */ function () { return this.useLanguages; }, set: /** * @param {?} value * @return {?} */ function (value) { this.useLanguages = value; this.setDefaultLocale(); }, enumerable: true, configurable: true }); Object.defineProperty(Configuration.prototype, "charset", { get: /** * @return {?} */ function () { return this.useCharset; }, set: /** * @param {?} value * @return {?} */ function (value) { this.useCharset = value; }, enumerable: true, configurable: true }); Object.defineProperty(Configuration.prototype, "authorizationType", { get: /** * @return {?} */ function () { return this.useAuthorizationType; }, set: /** * @param {?} value * @return {?} */ function (value) { this.useAuthorizationType = value; }, enumerable: true, configurable: true }); Object.defineProperty(Configuration.prototype, "refreshToken", { get: /** * @return {?} */ function () { if (this.contentSecurityPolicyActivated && !this.useRefreshToken) { this.useRefreshToken = localStorage.getItem('refreshToken'); } else if (!this.useRefreshToken) { this.useRefreshToken = sessionStorage.getItem('refreshToken'); } return this.useRefreshToken; }, set: /** * @param {?} value * @return {?} */ function (value) { if (this.contentSecurityPolicyActivated) { localStorage.setItem('refreshToken', value); } else { sessionStorage.setItem('refreshToken', value); } this.useRefreshToken = value; }, enumerable: true, configurable: true }); Object.defineProperty(Configuration.prototype, "accessToken", { get: /** * @return {?} */ function () { if (this.contentSecurityPolicyActivated && !this.useAccessToken) { this.useAccessToken = localStorage.getItem('accessToken'); } else if (!this.useAccessToken) { this.useAccessToken = sessionStorage.getItem('accessToken'); } return this.useAccessToken; }, set: /** * @param {?} value * @return {?} */ function (value) { if (this.contentSecurityPolicyActivated) { localStorage.setItem('accessToken', value); } else { sessionStorage.setItem('accessToken', value); } this.useAccessToken = value; }, enumerable: true, configurable: true }); Object.defineProperty(Configuration.prototype, "CSRFToken", { get: /** * @return {?} */ function () { if (this.contentSecurityPolicyActivated && !this.useAccessToken) { this.useCSRFToken = localStorage.getItem('CSRFToken'); } else if (!this.useCSRFToken) { this.useCSRFToken = sessionStorage.getItem('CSRFToken'); } return this.useCSRFToken; }, set: /** * @param {?} value * @return {?} */ function (value) { if (this.contentSecurityPolicyActivated) { localStorage.setItem('CSRFToken', value); } else { sessionStorage.setItem('CSRFToken', value); } this.useCSRFToken = value; }, enumerable: true, configurable: true }); /** * @private * @return {?} */ Configuration.prototype.setDefaultLocale = /** * @private * @return {?} */ function () { if (this.useLocale) { return; } if (navigator && navigator.language.indexOf('-') > -1) { if (this.languages.indexOf(navigator.language) > -1) { this.locale = navigator.language; return; } var _a = __read(navigator.language.split('-'), 2), langue = _a[0], country = _a[1]; if (this.languages.indexOf(langue) > -1) { this.locale = langue; return; } } else if (navigator && navigator.languages.length > 0) { for (var i in navigator.languages) { if (this.languages.indexOf(navigator.languages[i]) > -1) { this.locale = navigator.languages[i]; return; } } } }; return Configuration; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var CoreService = /** @class */ (function () { function CoreService(options, translateService) { this.translateService = translateService; this.config = new Configuration(options); this.config.locale = localStorage.getItem('locale') || this.config.locale || 'fr'; this.config.languages = this.config.languages || ['fr', 'en']; this.translateService.addLangs(this.config.languages); this.translateService.setDefaultLang(this.config.locale); this.translateService.use(this.config.locale); } /** * @return {?} */ CoreService.prototype.getConfig = /** * @return {?} */ function () { return this.config; }; /** * @return {?} */ CoreService.prototype.toggleLanguage = /** * @return {?} */ function () { if (this.config.languages.length < 2) { throw new Error('You need to configure at least two languages.'); } else if (this.config.languages.length === 2) { localStorage.setItem('locale', this.config.locale === 'fr' ? 'en' : 'fr'); } }; CoreService.decorators = [ { type: core$1.Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ CoreService.ctorParameters = function () { return [ { type: CoreModuleOptions, decorators: [{ type: core$1.Inject, args: [CAUSE_CORE_MODULE_OPTIONS,] }] }, { type: core.TranslateService } ]; }; /** @nocollapse */ CoreService.ngInjectableDef = core$1.ɵɵdefineInjectable({ factory: function CoreService_Factory() { return new CoreService(core$1.ɵɵinject(CAUSE_CORE_MODULE_OPTIONS), core$1.ɵɵinject(core.TranslateService)); }, token: CoreService, providedIn: "root" }); return CoreService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var ApiLookupService = /** @class */ (function () { function ApiLookupService(http) { this.http = http; this.http = http; } /** * @return {?} */ ApiLookupService.prototype.getIpInformation = /** * @return {?} */ function () { var _this = this; return new rxjs.Observable((/** * @param {?} observer * @return {?} */ function (observer) { _this.lookupIpWith_IpApi().subscribe((/** * @param {?} result * @return {?} */ function (result) { observer.next(result); observer.complete(); }), (/** * @return {?} */ function () { _this.lookupIpWith_GeoIpDb().subscribe((/** * @param {?} result * @return {?} */ function (result) { observer.next(result); observer.complete(); }), (/** * @return {?} */ function () { observer.error('Can\'t lookup the IP address'); })); })); })); }; /** * @private * @return {?} */ ApiLookupService.prototype.lookupIpWith_GeoIpDb = /** * @private * @return {?} */ function () { var _this = this; return new rxjs.Observable((/** * @param {?} observer * @return {?} */ function (observer) { _this.http.get('http://geoip-db.com/json').subscribe((/** * @param {?} response * @return {?} */ function (response) { observer.next((/** @type {?} */ ({ country: response['country_code'], countryName: response['country_name'], stateName: response['state'], cityName: response['city'], longitude: response['longitude'], latitude: response['latitude'] }))); observer.complete(); }), (/** * @param {?} error * @return {?} */ function (error) { observer.error(error); })); })); }; /** * @private * @return {?} */ ApiLookupService.prototype.lookupIpWith_IpApi = /** * @private * @return {?} */ function () { var _this = this; return new rxjs.Observable((/** * @param {?} observer * @return {?} */ function (observer) { _this.http.get('http://ip-api.com/json').subscribe(((/** * @param {?} response * @return {?} */ function (response) { observer.next((/** @type {?} */ ({ country: response['countryCode'], countryName: response['country'], state: response['region'], stateName: response['regionName'], cityName: response['city'], isp: response['isp'], longitude: response['lon'], latitude: response['lat'] }))); observer.complete(); })), (/** * @param {?} error * @return {?} */ function (error) { observer.error(error); })); })); }; ApiLookupService.decorators = [ { type: core$1.Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ ApiLookupService.ctorParameters = function () { return [ { type: http.HttpClient } ]; }; /** @nocollapse */ ApiLookupService.ngInjectableDef = core$1.ɵɵdefineInjectable({ factory: function ApiLookupService_Factory() { return new ApiLookupService(core$1.ɵɵinject(http.HttpClient)); }, token: ApiLookupService, providedIn: "root" }); return ApiLookupService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Browser = /** @class */ (function () { function Browser() { this.browserName = 'unknown'; this.browserVersion = 'unknown'; this.engineName = 'unknown'; this.engineVersion = 'unknown'; this.agent = (typeof (navigator) === 'object' ? navigator.userAgent.toLowerCase() : ''); this.detectBrowser(); this.detectVersion(); } /** * @return {?} */ Browser.prototype.toString = /** * @return {?} */ function () { return "Browser: " + this.browserName + " (" + this.browserVersion + "), Engine: " + this.engineName + " (" + this.engineVersion + ")"; }; /** * @private * @return {?} */ Browser.prototype.detectVersion = /** * @private * @return {?} */ function () { if (this.browserVersion === 'unknown') { /** @type {?} */ var browserVersion = this.agent.match(this.pattern.browser); this.browserVersion = (browserVersion ? (browserVersion[2] ? browserVersion[2] : browserVersion[1]) : 'unknown'); } if (this.engineVersion === 'unknown') { /** @type {?} */ var engineVersion = this.agent.match(this.pattern.engine); this.engineVersion = (engineVersion ? engineVersion[1] : 'unknown'); } }; /** * @private * @return {?} */ Browser.prototype.detectBrowser = /** * @private * @return {?} */ function () { if (this.agent.match(/webkit/)) { this.detectWebkitBrowser(); } else if (this.agent.match(/trident|msie/)) { this.detectTridentBrowser(); } else if (this.agent.match(/gecko/)) { this.detectGeckoBrowser(); } else if (this.agent.match(/presto/)) { this.pattern = { browser: /version\/([0-9\.]+)/, engine: /presto\/([0-9\.]+)/, }; this.engineName = 'presto'; this.browserName = 'opera'; } }; /** * @private * @return {?} */ Browser.prototype.detectGeckoBrowser = /** * @private * @return {?} */ function () { this.pattern = { browser: /gecko\/([0-9\.]+)/, engine: /rv:([0-9\.]+)/, }; this.engineName = 'gecko'; if (this.agent.match(/firefox/)) { this.pattern.browser = /firefox\/([0-9\.]+)/; this.browserName = 'firefox'; } }; /** * @private * @return {?} */ Browser.prototype.detectTridentBrowser = /** * @private * @return {?} */ function () { this.pattern = { browser: /msie ([0-9\.]+)/, engine: /trident\/([0-9\.]+)/, }; this.engineName = 'trident'; this.browserName = 'msie'; if (this.agent.match(/rv:/)) { // Internet Explorer 11 et + this.pattern.browser = /rv:([0-9\.]+)/; } else if (!this.agent.match(/msie/)) { // No "rv:" and no "msie", we assume that it's IE 11 this.browserVersion = '11.0'; } }; /** * @private * @return {?} */ Browser.prototype.detectWebkitBrowser = /** * @private * @return {?} */ function () { this.pattern = { browser: /webkit\/([0-9\.]+)/, engine: /applewebkit\/([0-9\.]+)/, }; this.engineName = 'webkit'; if (this.agent.match(/edge/)) { // Microsoft Edge this.pattern.browser = /edge\/([0-9\.]+)/; this.engineName = 'edgeHTML'; this.browserName = 'edge'; } else if (this.agent.match(/chrome/)) { // The web engine "blink" is used on many browser (Chrome, Opera, Vivaldi) this.engineName = 'blink'; if (this.agent.match(/vivaldi/)) { // Vivaldi this.pattern.browser = /vivaldi\/([0-9\.]+)/; this.browserName = 'vivaldi'; } else if (this.agent.match(/opr/)) { // Opera this.pattern.browser = /opr\/([0-9\.]+)/; this.browserName = 'opera'; } else if (this.agent.match(/crios/)) { // Chrome on iOS this.pattern.browser = /crios\/([0-9\.]+)/; this.browserName = 'chrome'; } else { // Chrome this.pattern.browser = /chrom(e|ium)\/([0-9\.]+)/; this.browserName = 'chrome'; } } else if (this.agent.match(/safari/)) { // Safari this.pattern.browser = /version\/([0-9\.]+)/; this.browserName = 'safari'; } }; return Browser; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var OperatingSystem = /** @class */ (function () { function OperatingSystem() { this.name = 'unknown'; this.version = 'unknown'; this.agent = (typeof (navigator) === 'object' ? navigator.userAgent.toLowerCase() : ''); this.detect(); } /** * @return {?} */ OperatingSystem.prototype.toString = /** * @return {?} */ function () { return "OS: " + this.name + " (" + this.version + ")"; }; /** * @private * @return {?} */ OperatingSystem.prototype.detect = /** * @private * @return {?} */ function () { /** @type {?} */ var os = [ { name: 'iOS', pattern: /iphone|ipad|ipod/ }, { name: 'Android', pattern: /android/ }, { name: 'Blackberry', pattern: /blackberry/ }, { name: 'Windows', pattern: /win/ }, { name: 'Chrome OS', pattern: /cros/ }, { name: 'Mac OS', pattern: /mac/ }, { name: 'Linux', pattern: /linux|x11/ }, { name: 'Open BSD', pattern: /openbsd/ }, { name: 'Unix', pattern: /unix/ }, { name: 'Sun OS', pattern: /sunos/ }, { name: 'beOS', pattern: /beos/ }, { name: 'QNX', pattern: /qnx/ }, { name: 'os2', pattern: /os\/2/ } ]; for (var i = 0, j = os.length; i < j; i++) { if (this.agent.match(os[i].pattern)) { this.name = os[i].name; break; } } this.detectVersion(); }; /** * @private * @return {?} */ OperatingSystem.prototype.detectVersion = /** * @private * @return {?} */ function () { if (this.name === 'Windows') { if (this.agent.match(/phone/)) { this.detectVersionWindowsPhone(); } else { this.detectVersionWindows(); } } else if (this.name === 'Mac OS') { this.detectVersionMac(); } else if (this.name === 'Android') { /** @type {?} */ var androidVersion = this.agent.match(/android ([0-9\.]+)/); this.version = (androidVersion ? ' ' + androidVersion[1] : ''); } else if (this.name === 'iOS') { /** @type {?} */ var iOSVersion = this.agent.match(/os ([0-9\_]+)/); this.version = (iOSVersion ? ' ' + iOSVersion[1].replace('_', '.') : ''); } }; /** * @private * @return {?} */ OperatingSystem.prototype.detectVersionWindows = /** * @private * @return {?} */ function () { this.name = 'Windows'; /** @type {?} */ var windows = [ { name: '10', pattern: /windows nt 10.0|windows 10.0/ }, { name: '10 Technical Preview', pattern: /windows nt 6.4/ }, { name: '8.1', pattern: /windows nt 6.3|windows 8.1/ }, { name: '8', pattern: /windows nt 6.2|windows 8.0|wow64/ }, { name: '7 / Server 2008 RC2', pattern: /windows nt 6.1|windows 7/ }, { name: 'Vista', pattern: /windows nt 6.0/ }, { name: 'Server 2003', pattern: /windows nt 5.2/ }, { name: 'XP', pattern: /windows nt 5.1|windows xp/ }, { name: '2000', pattern: /windows nt 5.0|windows 2000/ }, { name: 'NT 4.0', pattern: /windows nt 4.0|winnt4.0|winnt|windows nt/ }, { name: 'CE', pattern: /windows ce/ }, { name: 'ME', pattern: /windows me/ }, { name: '98', pattern: /windows 98|win98/ }, { name: '95', pattern: /windows 95|win95|windows_95/ }, { name: '3.11', pattern: /win16/ } ]; for (var i = 0, j = windows.length; i < j; i++) { if (this.agent.match(windows[i].pattern)) { this.version = windows[i].name; break; } } }; /** * @private * @return {?} */ OperatingSystem.prototype.detectVersionWindowsPhone = /** * @private * @return {?} */ function () { this.name = 'Windows Phone'; /** @type {?} */ var windows = [ { name: '10', pattern: /windows phone 10/ }, { name: '8.1', pattern: /windows phone 8.1/ }, { name: '8', pattern: /windows phone 8/ }, { name: '7.5', pattern: /windows phone os 7.5/ }, { name: '7', pattern: /windows phone os 7/ }, ]; for (var i = 0, j = windows.length; i < j; i++) { if (this.agent.match(windows[i].pattern)) { this.version = windows[i].name; break; } } }; /** * @private * @return {?} */ OperatingSystem.prototype.detectVersionMac = /** * @private * @return {?} */ function () { if (this.agent.match(/mac os x/)) { /** @type {?} */ var macVersion = this.agent.match(/mac os x ([0-9\_]+)/); this.name = 'Mac OS X'; this.version = (macVersion ? ' ' + macVersion[1].replace('_', '.') : ''); } else if (this.agent.match(/macppc|macintel|mac_powerpc|macintosh/)) { this.name = 'Mac OS'; } }; return OperatingSystem; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var ClientInformationService = /** @class */ (function () { function ClientInformationService(coreService, apiLookup) { var _this = this; this.apiLookup = apiLookup; this.visibilityChange = new core$1.EventEmitter(); this.config = coreService.getConfig(); document.addEventListener('visibilitychange webkitvisibilitychange mozvisibilitychange msvisibilitychange', (/** * @return {?} */ function () { return _this.onVisibilityChange(document.visibilityState === 'visible'); })); } /** * @return {?} */ ClientInformationService.prototype.getCoordinates = /** * @return {?} */ function () { var _this = this; return new rxjs.Observable((/** * @param {?} observer * @return {?} */ function (observer) { if (navigator && 'geolocation' in navigator) { navigator.geolocation.getCurrentPosition((/** * @param {?} position * @return {?} */ function (position) { observer.next([ position.coords.longitude, position.coords.latitude, ]); observer.complete(); }), (/** * @return {?} */ function () { return _this.getCoordinatesWithClientIP(observer); })); } else { _this.getCoordinatesWithClientIP(observer); } })); }; /** * @return {?} */ ClientInformationService.prototype.getLanguage = /** * @return {?} */ function () { var _this = this; return new rxjs.Observable((/** * @param {?} observer * @return {?} */ function (observer) { /** @type {?} */ var lang = [_this.config.locale]; if (navigator && 'languages' in navigator) { lang = (/** @type {?} */ (navigator.languages)); } else if (navigator && 'language' in navigator) { lang = [navigator.language]; } else if (navigator && 'userLanguage' in navigator) { lang = [navigator['userLanguage']]; } observer.next(lang); observer.complete(); })); }; /** * @return {?} */ ClientInformationService.prototype.getBrowser = /** * @return {?} */ function () { return new rxjs.Observable((/** * @param {?} observer * @return {?} */ function (observer) { /** @type {?} */ var browser = new Browser(); observer.next(browser); observer.complete(); })); }; /** * @return {?} */ ClientInformationService.prototype.getOperatingSystem = /** * @return {?} */ function () { return new rxjs.Observable((/** * @param {?} observer * @return {?} */ function (observer) { /** @type {?} */ var os = new OperatingSystem(); observer.next(os); observer.complete(); })); }; /** * @private * @param {?} observer * @return {?} */ ClientInformationService.prototype.getCoordinatesWithClientIP = /** * @private * @param {?} observer * @return {?} */ function (observer) { this.apiLookup.getIpInformation().subscribe((/** * @param {?} info * @return {?} */ function (info) { observer.next([ info.longitude, info.latitude, ]); observer.complete(); }), (/** * @return {?} */ function () { observer.next([-71.00, 48.00]); observer.error('Can\'t find the client location'); })); }; /** * @private * @param {?} visible * @return {?} */ ClientInformationService.prototype.onVisibilityChange = /** * @private * @param {?} visible * @return {?} */ function (visible) { this.visibilityChange.emit(visible); }; ClientInformationService.decorators = [ { type: core$1.Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ ClientInformationService.ctorParameters = function () { return [ { type: CoreService }, { type: ApiLookupService } ]; }; ClientInformationService.propDecorators = { visibilityChange: [{ type: core$1.Output }] }; /** @nocollapse */ ClientInformationService.ngInjectableDef = core$1.ɵɵdefineInjectable({ factory: function ClientInformationService_Factory() { return new ClientInformationService(core$1.ɵɵinject(CoreService), core$1.ɵɵinject(ApiLookupService)); }, token: ClientInformationService, providedIn: "root" }); return ClientInformationService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var FullscreenService = /** @class */ (function () { function FullscreenService() { var _this = this; this.statusChange = new core$1.EventEmitter(); document.addEventListener('fullscreenchange webkitfullscreenchange mozfullscreenchange msfullscreenchange', (/** * @return {?} */ function () { return _this.onChange(); })); } /** * @param {?} element * @return {?} */ FullscreenService.prototype.show = /** * @param {?} element * @return {?} */ function (element) { if (!element) { element = document.querySelector('body'); } if (element.requestFullscreen) { element.requestFullscreen(); } else if (element.webkitRequestFullscreen) { element.webkitRequestFullscreen(); } else if (element.mozRequestFullScreen) { element.mozRequestFullScreen(); } else if (element.msRequestFullscreen) { element.msRequestFullscreen(); } }; /** * @return {?} */ FullscreenService.prototype.exit = /** * @return {?} */ function () { document.querySelector('body').classList.remove('is-fullscreen'); if (document.exitFullscreen) { document.exitFullscreen(); } else if (document['webkitExitFullscreen']) { document['webkitExitFullscreen'](); } else if (document['mozCancelFullScreen']) { document['mozCancelFullScreen'](); } else if (document['msRequestFullscreen']) { document['msRequestFullscreen'](); } }; /** * @return {?} */ FullscreenService.prototype.isActived = /** * @return {?} */ function () { if ((screen.availHeight || screen.height - 30) <= window.innerHeight) { return true; } return false; }; /** * @private * @return {?} */ FullscreenService.prototype.onChange = /** * @private * @return {?} */ function () { if (this.isActived()) { document.querySelector('body').classList.add('is-fullscreen'); } else { document.querySelector('body').classList.remove('is-fullscreen'); } this.statusChange.emit(this.isActived()); }; FullscreenService.decorators = [ { type: core$1.Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ FullscreenService.ctorParameters = function () { return []; }; FullscreenService.propDecorators = { statusChange: [{ type: core$1.Output }] }; /** @nocollapse */ FullscreenService.ngInjectableDef = core$1.ɵɵdefineInjectable({ factory: function FullscreenService_Factory() { return new FullscreenService(); }, token: FullscreenService, providedIn: "root" }); return FullscreenService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var ImageService = /** @class */ (function () { function ImageService() { } /** * @param {?} file * @param {?=} maxWidth * @param {?=} maxHeight * @return {?} */ ImageService.prototype.compress = /** * @param {?} file * @param {?=} maxWidth * @param {?=} maxHeight * @return {?} */ function (file, maxWidth, maxHeight) { var _this = this; if (maxWidth === void 0) { maxWidth = 0; } if (maxHeight === void 0) { maxHeight = 0; } /** @type {?} */ var fileName = file.name; /** @type {?} */ var reader = new FileReader(); return new rxjs.Observable((/** * @param {?} observer * @return {?} */ function (observer) { reader.readAsDataURL(file); reader.onload = (/** * @param {?} e * @return {?} */ function (e) { /** @type {?} */ var image = new Image(); image.src = e.target['result'].toString(); image.onload = (/** * @return {?} */ function () { /** @type {?} */ var ratio = _this.findRatio(image, maxWidth, maxHeight); if (ratio !== null) { /** @type {?} */ var elem = document.createElement('canvas'); elem.width = ratio.width; elem.height = ratio.height; /** @type {?} */ var ctx = elem.getContext('2d'); ctx.drawImage(image, 0, 0, ratio.width, ratio.height); ctx.canvas.toBlob((/** * @param {?} blob * @return {?} */ function (blob) { /** @type {?} */ var resizeFile = new File([blob], fileName, { type: file.type, lastModified: Date.now() }); observer.next(resizeFile); }), file.type, 1); } else { observer.next(file); } }); }); })); }; /** * @private * @param {?} image * @param {?=} maxWidth * @param {?=} maxHeight * @return {?} */ ImageService.prototype.findRatio = /** * @private * @param {?} image * @param {?=} maxWidth * @param {?=} maxHeight * @return {?} */ function (image, maxWidth, maxHeight) { if (maxWidth === void 0) { maxWidth = 0; } if (maxHeight === void 0) { maxHeight = 0; } if (maxWidth === 0 && maxHeight === 0) { return null; } /** @type {?} */ var aspectRatio = (image.width / image.height); /** @type {?} */ var aspect = aspectRatio > 1 ? 'horizontal' : 'vertical'; maxWidth = maxWidth || image.width; maxHeight = maxHeight || image.height; if (image.width < maxWidth && image.height < maxHeight) { return null; } if (aspect === 'horizontal' && maxWidth < image.width) { return { width: maxWidth, height: (maxWidth / aspectRatio) }; } else { return { width: (maxHeight * aspectRatio), height: maxHeight }; } }; ImageService.decorators = [ { type: core$1.Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ ImageService.ctorParameters = function () { return []; }; /** @nocollapse */ ImageService.ngInjectableDef = core$1.ɵɵdefineInjectable({ factory: function ImageService_Factory() { return new ImageService(); }, token: ImageService, providedIn: "root" }); return ImageService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NetworkEstimates = /** @class */ (function () { function NetworkEstimates() { this.qualities = [{ type: 'GPRS', minimum: (20 * 1024), estimate: '50 Kb/s (max estimate)', }, { type: 'Regular2G', minimum: (50 * 1024), estimate: '250 Kb/s (max estimate)', }, { type: 'Good2G', minimum: (250 * 1024), estimate: '450 Kb/s (max estimate)', }, { type: 'Regular3G', minimum: (450 * 1024), estimate: '750 Kb/s (max estimate)', }, { type: 'Good3G', minimum: (750 * 1024), estimate: '1.5 Mb/s (max estimate)', }, { type: 'DSL', minimum: (1.5 * 1024 * 1024), estimate: '', }, { type: 'Regular4G', minimum: (3 * 1024 * 1024), estimate: '4 Mb/s (max estimate)', }, { type: 'WIFI', minimum: (15 * 1024 * 1024), estimate: '30 Mb/s (min estimate)', }, { type: 'Fiber', minimum: (30 * 1024 * 1024), estimate: '30 Mb/s (max estimate)', }, { type: 'LAN', minimum: (0.5 * 1024 * 1024 * 1024), estimate: '500 Mb/s (min estimate)', }]; } /** * @param {?} speedBps * @return {?} */ NetworkEstimates.prototype.estimate = /** * @param {?} speedBps * @return {?} */ function (speedBps) { /** @type {?} */ var estimate = ''; this.qualities.forEach((/** * @param {?} quality * @return {?} */ function (quality) { if (speedBps > quality.minimum) { estimate = quality.estimate; } })); return estimate; }; return NetworkEstimates; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NetworkInformationService = /** @class */ (function () { function NetworkInformationService() { var _this = this; this.estimates = new NetworkEstimates(); this.statusChange = new core$1.EventEmitter(); window.addEventListener('online', (/** * @return {?} */ function () { return _this.onStatusChange(true); })); window.addEventListener('offline', (/** * @return {?} */ function () { return _this.onStatusChange(false); })); } /** * @return {?} */ NetworkInformationService.prototype.getConnectionSpeed = /** * @return {?} */ function () { var _this = this; return new rxjs.Observable((/** * @param {?} observer * @return {?} */ function (observer) { if (navigator && 'connection' in navigator) { observer.next(navigator['connection']['downlink'] + " Mb/s"); observer.complete(); } else { _this.estimateDownlink(observer); } })); }; /** * @private * @param {?} observer * @return {?} */ NetworkInformationService.prototype.estimateDownlink = /** * @private * @param {?} observer * @return {?} */ function (observer) { var _this = this; /** @type {?} */ var startTime = (new Date()).getTime(); /** @type {?} */ var download = new Image(); download.onload = (/** * @return {?} */ function () { /** @type {?} */ var duration = ((new Date()).getTime() - startTime) / 1000; /** @type {?} */ var downloadSize = 104857600; /** @type {?} */ var bitsLoaded = downloadSize * 8; /** @type {?} */ var speedBps = (bitsLoaded / duration); observer.next(_this.estimates.estimate(speedBps)); observer.complete(); }); download.onerror = (/** * @param {?} error * @return {?} */ function (error) { observer.error(error); }); download.src = 'https://speed.hetzner.de/100MB.bin?_=' + startTime; }; /** * @private * @param {?} online * @return {?} */ NetworkInformationService.prototype.onStatusChange = /** * @private * @param {?} online * @return {?} */ function (online) { this.statusChange.emit(online); }; NetworkInformationService.decorators = [ { type: core$1.Injectable, args: [{