![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/keeview_app/html/ |
Upload File : |
(function (global) { /*** * @typedef GPSLocation * @property {number} latitude * @property {number} longitude * @property {number} accuracy * @property {number} altitude * @property {Date} time */ /**** * * @param props * @constructor */ function MobileNative(props) { Object.assign(this, props); this.parameters = {}; if (global['mobile_native_pending_received_notification']) { Object.assign(this.parameters, this._makeNotificationData(global['mobile_native_pending_received_notification'])) global['mobile_native_pending_received_notification'] = null; } Object.defineProperties(this, { systemFont: { get: function () { return global['mobile_native_system_font']; }, enumerable: true, configurable: false }, _listeners: { value: {}, enumerable: false, writable: true, configurable: true }, _hooks: { value: {}, enumerable: false, writable: true, configurable: true }, _localNotifyCallback: { value: {}, enumerable: false, writable: true, configurable: true }, parameters: { get: function () { global["mobile_native_parameters"] = global["mobile_native_parameters"] || {}; return global["mobile_native_parameters"]; } }, /*** * @type {"NOT_DETECT"|"NOT_DETERMINED"|"RESTRICT"|"DENIED"|"AUTHORIZED"|"AUTHORIZED_WHEN_IN_USE"} */ locationStatus: { get: function () { return global["mobile_native_location_status"] || "NOT_DETECT"; }, configurable: true, enumerable: true }, /*** * @type {"active"|"inactive"} */ appStatus: { get: function () { return global["mobile_native_app_status"]; }, configurable: true, enumerable: true }, /*** * @type {GPSLocation|null} */ lastReceivedLocation: { get: function () { return global["mobile_native_last_received_location"] || null; }, configurable: true, enumerable: true }, notificationStatus: { get: function () { return global["mobile_native_notification_status"] || null; }, configurable: true, enumerable: true }, /*** * @type {GPSLocation|null} */ lastReceivedLocationNotification: { get: function () { return global["mobile_native_last_received_notification"] || null; }, configurable: true, enumerable: true }, /** * @type {String} */ deviceId: { get: function () { return global["mobile_native_device_id"]; }, configurable: true, enumerable: true }, ANPsToken: { get: function () { var token = global["mobile_native_anps_token"] return token === 'null' ? null : token; }, configurable: true, enumerable: true }, FCMToken: { get: function () { var token = global["mobile_native_fcm_token"] return token === 'null' ? null : token; }, configurable: true, enumerable: true } }); this.on(this.EV_USER_OPEN_NOTIFICATION, this.ev_useOpenNotification.bind(this)); this.on(this.EV_RECEIVED_REMOTE_NOTIFICATION, this.ev_receivedRemoteNotification.bind(this)); this.on(this.EV_DOWNLOADED, function (event) { if (event.status === 'OK') absol.require('snackbar').show("Download complete: " + event.fileName); else { absol.require('snackbar').show("Download fail: " + event.fileName); } }); } MobileNative.prototype.EV_USER_OPEN_NOTIFICATION = 'user_open_notification'; MobileNative.prototype.EV_LOCATION_STATUS_CHANGE = 'location_status_change'; MobileNative.prototype.EV_APP_STATUS_CHANGE = 'app_status_change'; MobileNative.prototype.EV_RECEIVED_REMOTE_NOTIFICATION = 'received_remote_notification'; MobileNative.prototype.EV_LOCATION_FAIL = 'location_fail'; MobileNative.prototype.EV_LOCATION = 'location'; MobileNative.prototype.EV_APNS_TOKEN = 'apns_token'; MobileNative.prototype.EV_FCM_TOKEN = 'fcm_token'; MobileNative.prototype.EV_DOWNLOADED = 'downloaded'; MobileNative.prototype.HK_TASK = 'task'; MobileNative.prototype.HK_ClOUD_MESSAGE = 'cloud_message'; MobileNative.prototype.on = function (name, listener) { return this.onWithTimes(name, listener, Infinity); }; MobileNative.prototype.off = function (name, listener) { var idx; if (name in this._listeners) { idx = this._listeners[name].findIndex(function (it) { return it.listener === listener; }); if (idx >= 0) { this._listeners[name].splice(idx, 1); } } return this; }; MobileNative.prototype.once = function (name, listener) { return this.onWithTimes(name, listener, 1); }; MobileNative.prototype.onWithTimes = function (name, listener, times) { times = times || 1; if (this.isListening(name, listener)) return this; if (!(name in this._listeners)) { this._listeners[name] = []; } this._listeners[name].push({ listener: listener, times: times }); return this; }; MobileNative.prototype.fire = function (name) { var args = Array.prototype.slice.call(arguments, 1); if (name in this._listeners) { this._listeners[name].slice().forEach(function (it) { try { it.listener.apply(this, args); } catch (e) { console.error(e); this.print(e.message) } it.times--; }.bind(this)); this._listeners[name] = this._listeners[name].filter(function (it) { return it.times > 0; }) } return this; } MobileNative.prototype.isListening = function (name, callback) { if (name in this._listeners) { return !!this._listeners[name].find(function (it) { return it.listener === callback; }); } return false; }; MobileNative.prototype.postMessage = function (data) { if (global.webkit && global.webkit.messageHandlers && global.webkit.messageHandlers.nativeProcess) { global.webkit.messageHandlers.nativeProcess.postMessage(data); } }; MobileNative.prototype.onReceiveMessage = function (data) { if (data.cmd) { this.fire('cmd_' + data.cmd, data); } else if (data.type) { this.fire(data.type, data); this.fire("message", data); } }; MobileNative.prototype.addHook = function (name, callback) { if (this._hooks[name] && this._hooks[name].indexOf(callback) >= 0) return false; if (this._hooks[name] === undefined) this._hooks[name] = []; this._hooks[name].push(callback); return true; }; MobileNative.prototype.removeHook = function (name, callback) { var idx = -1; if (this._hooks[name]) { idx = this._hooks[name].indexOf(callback); if (idx >= 0) { this._hooks[name].splice(idx); return true; } } return false; }; MobileNative.prototype.fireHook = function (name) { var arr = this._hooks[name]; var args = Array.prototype.slice.call(arguments, 1); if (arr) { arr = arr.slice(); for (var i = 0; i < arr.length; ++i) { try { arr[i].apply(this, args); } catch (err) { console.err(err); } } } }; MobileNative.prototype._makeNotificationData = function (userInfo) { return Object.keys(userInfo).reduce(function (ac, key) { var value = userInfo[key]; if (key === 'aps') { if ('alert' in value) { ac.type = 'alert'; Object.assign(ac, value.alert); } } else if ((typeof value) === 'string' && value.match(/^\s*{/) && value.match(/}\s*$/)) { try { ac[key] = JSON.parse(userInfo[key]); } catch (err) { } } else { ac[key] = userInfo[key]; } return ac; }, {}); }; MobileNative.prototype.backToHome = function () { }; MobileNative.prototype.exit = function () { }; MobileNative.prototype.getAppStatus = function () { return this.appStatus; }; MobileNative.prototype.getDeviceToken = function () { return this.FCMToken || this.deviceId; }; //parameters /** * * @type {"debug"|"release"} */ MobileNative.prototype.mode = "debug"; MobileNative.prototype.setStatusHook = function (callback) { return { result: this.addHook('app_status', callback), message: '' }; }; MobileNative.prototype.unhookStatusHook = function (callback) { return this.removeHook('app_status', callback); }; MobileNative.prototype.setCloudMessageHook = function (callback) { return { result: this.addHook('cloud_message', callback), message: '' }; }; MobileNative.prototype.unHookCloudMessageHook = function (callback) { return this.removeHook('cloud_message', callback); }; MobileNative.prototype.setTaskHook = function (callback) { return { result: this.addHook(this.HK_TASK, callback), message: '' }; }; MobileNative.prototype.unhookTaskHook = function (callback) { return this.removeHook(this.HK_TASK, callback); }; MobileNative.prototype.setButtonHook = function (callback) { return { result: this.addHook('button', callback), message: 'iOS not support Button' }; }; MobileNative.prototype.unHookButtonHook = function (callback) { return this.removeHook('button', callback); }; MobileNative.prototype.localNotify = function (title, content, callback) { var ident = new Date().getTime() + '' + Math.random(); this.postMessage({ cmd: 'local_notify', ident: ident, content: content, title: title }); this._localNotifyCallback[ident] = callback; }; MobileNative.prototype.requestLocationPermissionAsync = function () { var self = this; return new Promise(function (resolve) { if (self.locationStatus === "RESTRICT" || self.locationStatus === 'DENIED') { resolve(false); } else if (self.locationStatus === 'AUTHORIZED_WHEN_IN_USE' || self.locationStatus === 'AUTHORIZED') { resolve(true); } else { function finish(result) { self.off(self.EV_LOCATION_STATUS_CHANGE, onLocationStatusChange); resolve(result); } function onLocationStatusChange(event) { var value = event.value; if (value === 'AUTHORIZED' || value === 'AUTHORIZED_WHEN_IN_USE') { finish(true); } else { finish(false); } } self.on(self.EV_LOCATION_STATUS_CHANGE, onLocationStatusChange); self.postMessage({ cmd: 'request_location_permission' }); } }); } MobileNative.prototype.getLocationAsync = function () { var self = this; return this.requestLocationPermissionAsync().then(function (isSuccess) { if (isSuccess) { return new Promise(function (resolve) { self.postMessage({ cmd: 'get_location' }); var timeoutOutIdx; function finish(result) { if (timeoutOutIdx > 0) clearTimeout(timeoutOutIdx); self.off('location', onLocation); resolve(result); } function onLocation(event) { finish(event.coordinate || null); } self.on('location', onLocation); timeoutOutIdx = setTimeout(function () { timeoutOutIdx = -1; finish(self.lastReceivedLocation); }, self.lastReceivedLocation ? 3000 : 15000); }); } else { return null; } }.bind(this)); }; MobileNative.prototype.getLocation = function (callback) { if (this.locationStatus.indexOf('AUTHORIZED') >= 0 || this.locationStatus === "NOT_DETERMINED") { if (typeof callback === "function") this.getLocationAsync().then(callback); return true; } else return false; }; MobileNative.prototype.checkLocationPermission = function () { return this.locationStatus === "AUTHORIZED" || this.locationStatus === "AUTHORIZED_WHEN_IN_USE"; }; MobileNative.prototype.requestLocationPermission = function (callback) { var res = this.locationStatus === 'NOT_DETERMINED'; if (typeof callback === "function") { this.requestLocationPermissionAsync().then(callback); } return res; }; MobileNative.prototype.reload = function () { location.reload(); setTimeout(function () { this.postMessage({ cmd: 'reload' }); }.bind(this), 300); }; MobileNative.prototype.print = function (text) { this.postMessage({ cmd: 'print', text: text }); }; MobileNative.prototype.saveAs = function (url, fileName) { if (url.indexOf(' ') >= 0 || absol.string.nonAccentVietnamese(url) !== url) url = encodeURI(url); console.log(url); this.postMessage({ cmd: 'saveAs', url: url, fileName: fileName }); } MobileNative.prototype.ev_useOpenNotification = function (event) { var userInfo = this._makeNotificationData(event.userInfo); var parameters = this.parameters; var ident = event.ident; if ("google.c.fid" in userInfo) { Object.keys(parameters).forEach(function (key) { delete parameters[key]; }); Object.assign(parameters, userInfo); this.fireHook(this.HK_TASK, parameters); } else if (this._localNotifyCallback[ident]) { try { this._localNotifyCallback[ident].call(this); } catch (error) { console.error(error); } delete this._localNotifyCallback[ident]; } }; MobileNative.prototype.ev_receivedRemoteNotification = function (event) { var userInfo = this._makeNotificationData(event.userInfo); this.fireHook(this.HK_ClOUD_MESSAGE, userInfo); }; var mobileHost = new MobileNative(); global.mobileHost = mobileHost; global.mobile_native_on_receive_message = mobileHost.onReceiveMessage.bind(mobileHost); //polyfill if (!navigator.geolocation) navigator.geolocation = {}; navigator.geolocation.getCurrentPosition = function (successCallback, errorCallback, options) { global.mobileHost.getLocationAsync().then(function (result) { successCallback({ coords: result }) }).catch(function (err) { errorCallback && errorCallback(err || new Error("Fail to get location")); }); }; var locationWatchCallbacks = {}; var locationWatchCallbackId = 0; navigator.geolocation.watchPosition = function (callback) { var id = locationWatchCallbackId++; locationWatchCallbacks[id] = function (event) { callback({ coords: event.coordinate }); } mobileHost.on('location', locationWatchCallbacks[id]); return id; }; navigator.geolocation.clearWatch = function (id) { if (!locationWatchCallbacks[id]) return; mobileHost.on('location', locationWatchCallbacks[id]); delete locationWatchCallbacks[id]; }; navigator.wkSaveAs = function (url, fileName) { mobileHost.saveAs(url, fileName); } })(window);