import { Component, OnInit } from '@angular/core'; import { Network } from '@ionic-native/network/ngx'; import { LoadAlertsService } from '../services/load-alerts.service'; import { OpenSettingsService } from '../services/open-settings.service'; //import { Hotspot, HotspotNetwork } from '@ionic-native/hotspot/ngx'; import { PopoverController, MenuController } from '@ionic/angular'; import { SpotGoproComponent } from './spot-gopro/spot-gopro.component'; import { switchMap, take, map } from 'rxjs/operators'; import { Plugins } from '@capacitor/core'; import { from } from 'rxjs'; import { UserService } from '../services/user.service'; import { StorageService } from '../services/storage.service'; import { tokenName } from '@angular/compiler'; //import { WifiWizard2 } from '@ionic-native/wifi-wizard-2/ngx'; declare var wifiinformation: any; //declare var WifiWizard2: any; @Component({ selector: 'app-spot', templateUrl: './spot.page.html', styleUrls: ['./spot.page.scss'], }) export class SpotPage implements OnInit { packages: any; planId: any; speed1: any; daily1: any; price1: any; speed2: any; daily2: any; price2: any; speed3: any; daily3: any; price3: any; speed4: any; daily4: any; price4: any; speed5: any; daily5: any; price5: any; speed6: any; daily6: any; price6: any; speed7: any; daily7: any; price7: any; speed8: any; daily8: any; price8: any; constructor(private network: Network, private loadalert: LoadAlertsService, private openNativeSettings: OpenSettingsService, public popoverController: PopoverController, // private hotspot: Hotspot, private menuCtrl: MenuController, private userService: UserService, private storage: StorageService, private authService: UserService //private wifiWizard2: WifiWizard2 ) { } lang; get Lang() { return this.lang; } ngOnInit() { this.storage.get("lang").then(data=>{console.log(data,'lang'); this.lang=data; this.loadPackages(); if(data==2) { document.dir='rtl' } else { document.dir='ltr' } }, error=>{console.log(error,'langError');}); } loadPackages() { this.loadalert.presentLoading(this.lang == 1 ? "Please Wait." : "Please Wait."); this.userService.getPackages(this.lang).subscribe(data => { this.planId = data.plan_id; this.packages = Object.keys(data.services_info).map(function(key) { return [Number(key), data.services_info[key]]; }); this.planId = data.plan_id; this.speed1 = this.packages[0][1].speed; this.daily1 = this.packages[0][1].daily_limit; this.price1 = this.packages[0][1].price; this.speed2 = this.packages[1][1].speed; this.daily2 = this.packages[1][1].daily_limit; this.price2 = this.packages[1][1].price; this.speed3 = this.packages[2][1].speed; this.daily3 = this.packages[2][1].daily_limit; this.price3 = this.packages[2][1].price; this.speed4 = this.packages[3][1].speed; this.daily4 = this.packages[3][1].daily_limit; this.price4 = this.packages[3][1].price; this.speed5 = this.packages[4][1].speed; this.daily5 = this.packages[4][1].daily_limit; this.price5 = this.packages[4][1].price; this.speed6 = this.packages[5][1].speed; this.daily6 = this.packages[5][1].daily_limit; this.price6 = this.packages[5][1].price; this.speed7 = this.packages[6][1].speed; this.daily7 = this.packages[6][1].daily_limit; this.price7 = this.packages[6][1].price; this.speed8 = this.packages[7][1].speed; this.daily8 = this.packages[7][1].daily_limit; this.price8 = this.packages[7][1].price; console.log(this.packages[0][1].speed); this.loadalert.dismissLoading(); }, error => { this.loadalert.PresentAlert("", "Attention", 'Error in connection.'); //this.loadalert.PresentAlert("","Attention",'This user does not have subscription yet.'); this.loadalert.dismissLoading(); console.log(error, "error"); }) } openwifi() { // console.log('wifi'); // from(Plugins.Storage.get({ key: 'authData' })).pipe( // map(storedData => { // if (!storedData || !storedData.value) { // return null; // } // const parsedData = JSON.parse(storedData.value) as { // oss_token: string; // oss_username: string; // }; // console.log(parsedData); // if (this.network.type != null && this.network.type != undefined) { // if (this.network.type.toLowerCase() === 'wifi') { // this.hotspot.connectToWifiAuthEncrypt('FREE G', parsedData.oss_token, '802.1x EAP', [parsedData.oss_username]).then(() => { // this.loadalert.PresentAlert('', 'Info', 'connect to wifi'); // //connection to the WiFi network was successfull // }).catch((error) => { // this.loadalert.PresentAlert('', 'Info', error); // //connection to the WiFi network failed // }); // this.loadalert.PresentAlert('', 'Info', 'Under Development'); // } else { // this.openNativeSettings.OpenWifi().then(data => { console.log(data, "Done"); }, // error => { console.log(error, 'error'); }); // } // } else { // this.openNativeSettings.OpenWifi().then(data => { console.log(data, "Done"); }, // error => { console.log(error, 'error'); }); // } // }) // ); // if (this.network.type.toLowerCase() === 'wifi') { // this.hotspot.connectToWifi('josettematta','kvyy4392').then(() => { // this.loadalert.PresentAlert('', 'Info', 'connect to wifi'); // //connection to the WiFi network was successfull // }).catch((error) => { // this.loadalert.PresentAlert('', 'Info', error); // //connection to the WiFi network failed // }); // } // else { // this.openNativeSettings.OpenWifi().then(data => { console.log(data, "Done"); }, // error => { console.log(error, 'error'); }); // }802.1x EAP // this.userService.getHotspot(this.lang).subscribe(data=>{ // console.log(data,"data"); // this.authService.usernametoken.subscribe(usernametoken => { // const password = usernametoken; // console.log(usernametoken); // this.hotspot.connectToWifi(data.connection_info.SSID, usernametoken).then( () => { // //connection to the WiFi network was successfull // this.loadalert.PresentAlert('', 'Info', 'connect to wifi'); // }).catch( (error) => { // //connection to the WiFi network failed // this.loadalert.PresentAlert('', 'error', error); // }); // }); // },error=>{ // console.log(error,"error"); // }) } getSampleInfo() { wifiinformation.getSampleInfo(wifi => { alert( 'SSID: ' + wifi.ssid + '\nMAC: ' + wifi.mac + '\nIP: ' + wifi.ip + '\nGateway: ' + wifi.gateway ); }, (err) => console.error(err)); } async presentPopover(ev: any) { const popover = await this.popoverController.create({ component: SpotGoproComponent, cssClass: 'my-custom-class', event: ev, translucent: true }); return await popover.present(); } onOpenMenu() { this.menuCtrl.toggle("first"); } }