import { Component } from '@angular/core';
import { NavController, NavParams ,Platform} from 'ionic-angular';
import { LocalNotifications,Toast} from 'ionic-native';
import { FirebaseAuth, AuthProviders, AuthMethods} from 'angularfire2';
import { Authservice } from '../../providers/authservice';
import { AlbumPage } from '../../pages/album/album';
import { MycomplaintsPage } from '../../pages/mycomplaints/mycomplaints';
import { NeighboursPage } from '../../pages/neighbours/neighbours';
import { NotificationsPage } from '../../pages/notifications/notifications';
import { ChatlistPage } from '../../pages/chatlist/chatlist';
import { TabsPage } from '../../pages/tabs/tabs';
import { CircularPage } from '../../pages/circular/circular';
import { EventPage } from '../../pages/event/event';
import { SettingsPage } from '../../pages/settings/settings';
import { VisitorsPage } from '../../pages/visitors/visitors';
import { AlarmPage } from '../../pages/alarm/alarm';
import { AlarmdetailsPage } from '.././alarmdetails/alarmdetails';
import { PropertyPage } from '../../pages/property/property';
import { FormBuilder } from '@angular/forms';
import { AngularFire } from 'angularfire2';
declare var Media:any;
declare var window: any;
/*
Generated class for the Dashboard page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
@Component({
selector: 'page-dashboard',
templateUrl: 'dashboard.html'
})
export class DashboardPage {
EMERGENCY=[];
ApartID;
USERID;
audio;
audioplaying;
constructor(public af:AngularFire,public fb:FormBuilder,public platform: Platform,public authservice:Authservice,public navCtrl: NavController, public navParams: NavParams, public auth: FirebaseAuth) {
this.platform.ready().then(() => {
var url='https://firebasestorage.googleapis.com/v0/b/apartments-ea9e5.appspot.com/o/Loud-Ringtone-11-Emergency-Alert.mp3?alt=media&token=7d67b437-e96b-484e-bd97-008106a06dcb';
this.audio = new Media(url,
// success callback
function () { console.log("playAudio():Audio Success"); },
// error callback
function (err) { console.log("playAudio():Audio Error: " + err); },
function(statusCallback){console.log("Status"+statusCallback)
this.audioplaying = statusCallback;
localStorage.setItem("audioplaying",this.audioplaying);
}
);
schedule(a)
{
console.log("receive Notification")
var val=a;
var t:any=a.MSG;
var time:any=a.SEND_TIME;
LocalNotifications.schedule({
title: "Smart Premises",
text: t,
at: time,
sound:this.playSelectedTrack(),
});
called this Backroundnotifications() in constructor.It's work properly at first time.again goto another page after click dashboardpage .this function called many times.
I mean consoled the value of this.EMERGENCY many times.
any other user push firebase collections.I need get updated value only.
I am using ionic2 with firebase.
Here is my Component..
import { Component } from '@angular/core'; import { NavController, NavParams ,Platform} from 'ionic-angular'; import { LocalNotifications,Toast} from 'ionic-native'; import { FirebaseAuth, AuthProviders, AuthMethods} from 'angularfire2'; import { Authservice } from '../../providers/authservice'; import { AlbumPage } from '../../pages/album/album'; import { MycomplaintsPage } from '../../pages/mycomplaints/mycomplaints'; import { NeighboursPage } from '../../pages/neighbours/neighbours'; import { NotificationsPage } from '../../pages/notifications/notifications'; import { ChatlistPage } from '../../pages/chatlist/chatlist'; import { TabsPage } from '../../pages/tabs/tabs'; import { CircularPage } from '../../pages/circular/circular'; import { EventPage } from '../../pages/event/event'; import { SettingsPage } from '../../pages/settings/settings'; import { VisitorsPage } from '../../pages/visitors/visitors'; import { AlarmPage } from '../../pages/alarm/alarm'; import { AlarmdetailsPage } from '.././alarmdetails/alarmdetails'; import { PropertyPage } from '../../pages/property/property';
import { FormBuilder } from '@angular/forms'; import { AngularFire } from 'angularfire2'; declare var Media:any; declare var window: any; /* Generated class for the Dashboard page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on Ionic pages and navigation. */ @Component({ selector: 'page-dashboard', templateUrl: 'dashboard.html' }) export class DashboardPage { EMERGENCY=[]; ApartID; USERID; audio; audioplaying;
constructor(public af:AngularFire,public fb:FormBuilder,public platform: Platform,public authservice:Authservice,public navCtrl: NavController, public navParams: NavParams, public auth: FirebaseAuth) {
})
}
ionViewDidLoad() { console.log('ionViewDidLoad DashboardPage'); this.Backroundnotifications(); }
albums() { this.navCtrl.push(AlbumPage); } complaints() { this.navCtrl.push(MycomplaintsPage); } myNeighbours() { this.navCtrl.push(NeighboursPage); } notification() { this.navCtrl.push(NotificationsPage); } chats() { this.navCtrl.push(ChatlistPage); } directory() { this.navCtrl.push(TabsPage);
} circular() { this.navCtrl.push(CircularPage); } eventbooking() { this.navCtrl.push(EventPage); } settings() { this.navCtrl.push(SettingsPage); } visitors() { this.navCtrl.push(VisitorsPage); } propertyPage() { this.navCtrl.push(PropertyPage); } alarmPage() { this.navCtrl.push(AlarmPage); }
//receive notifications
schedule(a) { console.log("receive Notification") var val=a; var t:any=a.MSG; var time:any=a.SEND_TIME; LocalNotifications.schedule({ title: "Smart Premises", text: t, at: time, sound:this.playSelectedTrack(), });
}
playSelectedTrack():any{ console.log("audio play"); this.audio.play();
}
Backroundnotifications() { //Get Current UserID
}
}
called this Backroundnotifications() in constructor.It's work properly at first time.again goto another page after click dashboardpage .this function called many times.
I mean consoled the value of this.EMERGENCY many times.
any other user push firebase collections.I need get updated value only.
How i am able to do this.
Kindly help me,