damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

primal.ts (861B)


      1 
      2 import * as nostr from './nostr'
      3 
      4 export function go(): i32 {
      5 	let subid = "sidebar_trending"
      6 	let relay = 'wss://cache0.primal.net/cache17'
      7 	var done: i32 = 0
      8 	var events: i32 = 0
      9 
     10 	nostr.pool_add_relay(relay)
     11 	nostr.pool_send_to(`["REQ","${subid}",{"cache":["explore_global_trending_24h"]}]`, relay)
     12 
     13 	while (!done) {
     14 		var ev = nostr.event_await(subid)
     15 		let type = nostr.event_get_type(ev)
     16 		switch (type) {
     17 		case nostr.EventType.OK:
     18 			nostr.log("ok")
     19 			break
     20 		case nostr.EventType.NOTE:
     21 			events++
     22 			let note = nostr.event_get_note(ev)
     23 			let kind = nostr.note_get_kind(note)
     24 			nostr.log(`type:${type} #${events} note, kind:${kind}`)
     25 			break
     26 		case nostr.EventType.EOSE:
     27 			nostr.log("eose, got " + events.toString() + " events")
     28 			done = true
     29 			break
     30 		default:
     31 			nostr.log("got event type " + type.toString())
     32 		}
     33 	}
     34 	
     35 	return events
     36 }
     37 
     38 go()