You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			33 lines
		
	
	
		
			798 B
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			33 lines
		
	
	
		
			798 B
		
	
	
	
		
			TypeScript
		
	
| import { processMessage, SwarmPolling } from './swarmPolling';
 | |
| import fetch from 'node-fetch';
 | |
| import { PubKey } from '../types';
 | |
| 
 | |
| export class SwarmPollingStub extends SwarmPolling {
 | |
|   private readonly baseUrl = 'http://localhost:3000';
 | |
| 
 | |
|   protected async pollOnceForKey(pubkey: PubKey, isGroup: boolean) {
 | |
|     const pubkeyStr = pubkey.key ? pubkey.key : pubkey;
 | |
| 
 | |
|     const get = {
 | |
|       method: 'GET',
 | |
|     };
 | |
| 
 | |
|     const res = await fetch(
 | |
|       `${this.baseUrl}/messages?pubkey=${pubkeyStr}`,
 | |
|       get
 | |
|     );
 | |
| 
 | |
|     try {
 | |
|       const json = await res.json();
 | |
| 
 | |
|       const options = isGroup ? { conversationId: pubkeyStr } : {};
 | |
| 
 | |
|       json.messages.forEach((m: any) => {
 | |
|         processMessage(m.data, options);
 | |
|       });
 | |
|     } catch (e) {
 | |
|       window.log.error('invalid json: ', e);
 | |
|     }
 | |
|   }
 | |
| }
 |