mirror of
				https://github.com/owncast/owncast.git
				synced 2025-10-31 18:18:06 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			29 lines
		
	
	
		
			377 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			377 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| const URL = '/api/ping';
 | |
| const INTERVAL = 4000;
 | |
| 
 | |
| function ping() {
 | |
|   try {
 | |
|     fetch(URL);
 | |
|   } catch (e) {
 | |
|     console.error(e);
 | |
|   }
 | |
| }
 | |
| 
 | |
| class ViewerPing {
 | |
|   timer: ReturnType<typeof setInterval>;
 | |
| 
 | |
|   start() {
 | |
|     this.stop();
 | |
| 
 | |
|     this.timer = setInterval(() => {
 | |
|       ping();
 | |
|     }, INTERVAL);
 | |
|   }
 | |
| 
 | |
|   stop() {
 | |
|     clearInterval(this.timer);
 | |
|   }
 | |
| }
 | |
| 
 | |
| export default ViewerPing;
 | 
