OverviewFilesCommitsIssuesDocsReleasesPeers

holepunchto-deps / @holepunchto / keet-core / lib / core / rooms / index.js

1 lines · javascript ref:
const e=require("ready-resource"),{Readable:t}=require("streamx"),r=require("@holepunchto/keet-room-registry");module.exports=class extends e{constructor(e,{key:t}){super(),this.keet=e,this.key=t,this.store=null,this.swarmWorker=null,this._keetRoomRegistry=null}async _open(){this.store=this.keet.store.session(),this.swarmWorker=this.keet.swarmWorker,this._keetRoomRegistry=new r(this.store,{key:this.key}),await this._keetRoomRegistry.ready()}async _close(){await(this._keetRoomRegistry?.close()),await(this.store?.close())}search(e){return t.from(this._search(e))}async*_search(e=[]){this.opened||await this.ready(),this.swarmWorker.startDiscoverySwarming(this._keetRoomRegistry.discoveryKey,{deferSwarming:!1,limit:1}),e=e.map(t).filter(e=>e);try{for await(const s of this._keetRoomRegistry.find()){const i=t(s.title);e.every(e=>i.includes(e))&&(yield{...s,avatar:r(s.avatar)})}}catch(e){this.keet.onerror(e)}function t(e){return e?e.replace(/\s/g,"").toLowerCase():""}function r(e){return e?e={small:{pointer:{inlined:e.inlined},hash:e.hash??null,metadata:{name:e.name??null,mimetype:e.mimetype??null,width:e.width??null,height:e.height??null}}}:null}}};