Webrtc peer => yjs clientId

I’m using the underlying webrtc provider to also share media streams (audio chat, in my case). I also use the awareness protocol to share mouse locations

For my purpose, I need to be able to correlate a peer (or peerId, or anything that happens during the provider setup/peer connections, etc.) with the eventual clientId that will be used/shared for the awareness protocol.

Is the information surfaced somewhere to go from peerId/connectionId/etc. => awareness-clientId?

I’m curious to hear if there is a better way, but here’s what I’m doing in relm.us:

  • create a document that contains a Y.Map
  • each peer creates its own UUID as a globally unique, permanent identifier
  • whenever a client comes online, add or update itself in the Y.Map, e.g. map.set(ydoc.clientID, permanentId)
  • every peer now has a shared “lookup” that can map from current clientID to permanent identifier (note that when reconnecting, it’s possible the clientID can change).

Can’t you just set the peer-id on the awareness instance?

I don’t recommend setting an entry for every peer on a Y.Map. That might lead to a huge data-trace because the key-string can never be garbage-collected by Yjs.

Indeed, this is what I ended up doing. I means that the field is nullable since I don’t know the peer id until the provider has done some work (connected? I’m not sure), and provider["room"] (and therefore provider["room"]["peer-id"]) will be undefined. But as long as the rest of my code treats it as nullable, it works out well.

I also use the awareness state to broadcast local volume animation at a throttled rate, so you get a nice animation of the speaker sound for everyone connected.