Hi ,
i want to develop animation app.
All device's (which installed app) flashlight will do that animation at specific time.They must be start at same time.
i will give array about off-on.All device must be on at same time and then off at same time.
So i do ajax call for to get animation begin time.
animation start at sametime for all devices.if time does not ready all of them wait when time is ok all devices start at same time .i give same array(whic include on-off info) but same devices get off when other is still on...How can i handle this?this is my code and descripton
receivedEvent: function (id) {
var on = [true,false,true];
var todayDate = (new Date().getTime()/1000);
var dateGSF = new Date(2020,11,25);
$.ajax({url: "URL...",
async: false,
success: function(result){//
var on1=result.split("?")[1];
on=on1.split(",");//this is on-off information array like this var on = [true,false,true]
window.localStorage.setItem("tarih",result.split("?")[2]);//this is animation start time
window.localStorage.setItem("dizi",on);
var serverTime=result.split("?")[3];//i get server unix UTC time.Maybe device time is wrong.
window.localStorage.setItem("ileri_geri",(todayDate-(serverTime)));// ileri_geri is difference between server time and device time.So if device time
//was more or less i will calculate.So i want to start animation with same time
flashlightDemo1(on);
}});
},
function flashlightDemo1(on) {
var ileri_geri=window.localStorage.getItem("ileri_geri");//difference device time and server time for synchronise
var tarih=window.localStorage.getItem("tarih");//this is animation start time
var baladiMi=false;//if animation start then i set this to true
if (parseInt(new Date().getTime()/1000)>(parseInt(new Date(tarih).getTime()/1000)+parseInt(ileri_geri))) //if animation time is ok let animation begin
{
flashlightDemo(on);
baladiMi=true;
}
var Fsettimeout=setTimeout(flashlightDemo1,100,on);
if(baladiMi){
clearTimeout(Fsettimeout);//if animation start clear interval
}
}
and this is my plugin
var index = 0;
function flashlightDemo(on) {
if ( on[ index ]==='true') {//if true on else off
window.plugins.flashlight.switchOn();
} else {
window.plugins.flashlight.switchOff();
}
index++;
setTimeout( flashlightDemo,1000,on );
}