Is there a way to programmatically check if there are other connected peers?

I believe the connected peers are on the Awareness object, provider.awareness. So maybe provider.awareness.getStates() (untested).

Keep in mind that clients can always be offline, or connecting at the same time, so it’s entirely possible that two clients will insert initialContent. See a larger discussion of setting initial content here: Initial offline value of a shared document - #25 by joshuafontany.