2021-06-15 14:39:42 +00:00
|
|
|
import store from '../store';
|
2021-05-17 16:08:35 +00:00
|
|
|
class CampaignTimer {
|
|
|
|
constructor() {
|
|
|
|
this.campaignTimers = [];
|
|
|
|
}
|
|
|
|
|
2021-10-11 12:48:11 +00:00
|
|
|
initTimers = ({ campaigns }, websiteToken) => {
|
2021-05-17 16:08:35 +00:00
|
|
|
this.clearTimers();
|
2021-05-18 06:45:23 +00:00
|
|
|
campaigns.forEach(campaign => {
|
2021-05-17 16:08:35 +00:00
|
|
|
const { timeOnPage, id: campaignId } = campaign;
|
|
|
|
this.campaignTimers[campaignId] = setTimeout(() => {
|
2021-10-11 12:48:11 +00:00
|
|
|
store.dispatch('campaign/startCampaign', { campaignId, websiteToken });
|
2021-05-17 16:08:35 +00:00
|
|
|
}, timeOnPage * 1000);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
clearTimers = () => {
|
|
|
|
this.campaignTimers.forEach(timerId => {
|
|
|
|
clearTimeout(timerId);
|
|
|
|
this.campaignTimers[timerId] = null;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
export default new CampaignTimer();
|