dmotz / trystero

✨🤝✨ Build instant multiplayer webapps, no server required — Magic WebRTC matchmaking over BitTorrent, Nostr, MQTT, IPFS, Supabase, and Firebase
https://oxism.com/trystero
MIT License
1.14k stars 85 forks source link

accessing your own peerId #72

Closed hchiam closed 1 month ago

hchiam commented 3 months ago

Hi! I'm new to trystero - From the current README, it didn't seem immediately obvious that for the js of a user to access their own peer ID selfId, you need to do an import like import {selfId} from './nostr.js'

I get that it's technically at the same level of indentation in the README as the other things listed under API (like joinRoom), but any thoughts on adding a code snippet here?

selfId_mentioned_inREADME

Maybe we could add something like this?

import {selfId} from 'trystero'
coderofsalvation commented 1 month ago

I also remember struggling with this, eventually I discovered I could access selfId as a global var (via variable hoisting?) : https://codeberg.org/coderofsalvation/xrfragment/src/branch/main/src/3rd/js/plugin/p2p/trystero.js#L54

however this example uses trystero-torrent.min.js, not the module version.

dmotz commented 1 month ago

Thanks for the suggestion, I added a section early in the readme mentioning how to do this.