| 
									
										
										
										
											2017-11-27 22:50:46 +00:00
										 |  |  | class AlarmServiceDriverNode { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 00:22:38 +00:00
										 |  |  | 	constructor() { | 
					
						
							|  |  |  | 		this.notifications_ = {}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	hasPersistentNotifications() { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	notificationIsSet(id) { | 
					
						
							|  |  |  | 		return id in this.notifications_; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:50:46 +00:00
										 |  |  | 	async clearNotification(id) { | 
					
						
							| 
									
										
										
										
											2017-11-28 00:22:38 +00:00
										 |  |  | 		if (!this.notificationIsSet(id)) return; | 
					
						
							|  |  |  | 		clearTimeout(this.notifications_[id].timeoutId); | 
					
						
							|  |  |  | 		delete this.notifications_[id]; | 
					
						
							| 
									
										
										
										
											2017-11-27 22:50:46 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	async scheduleNotification(notification) { | 
					
						
							| 
									
										
										
										
											2017-11-28 00:22:38 +00:00
										 |  |  | 		const now = Date.now(); | 
					
						
							|  |  |  | 		const interval = notification.date.getTime() - now; | 
					
						
							|  |  |  | 		if (interval < 0) return; | 
					
						
							| 
									
										
										
										
											2017-11-27 22:50:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 00:22:38 +00:00
										 |  |  | 		const timeoutId = setTimeout(() => { | 
					
						
							|  |  |  | 			console.info('NOTIFICATION: ', notification); | 
					
						
							|  |  |  | 			this.clearNotification(notification.id); | 
					
						
							|  |  |  | 		}, interval); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:50:46 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = AlarmServiceDriverNode; |