P2P Rooms
Peer-to-peer rooms with no dedicated server: a player hosts a Crossplay server inside the game (the same kernel and pieces), friends join by room code over WebRTC through the rendezvous relay Crossplay runs for every project, and the host plays in-process. Rooms service (host / join / browse / leave), Unity-side WebRTC server transport, optional uGUI panel; the game adds its pieces via IInAppServerComposition. Turn P2P on for the project in the Hub to get its relay credentials. Requires com.unity.webrtc. Client-only.
Unity seams you implement 1
The client half's sockets. Bind your implementation in the client context and Crossplay's client calls it — this is where your models, animators, UI and controls plug in.
IP2pRooms unity SPI
Peer-to-peer rooms for a project that turned P2P on in the Hub: no dedicated server anywhere. HostAsync starts a Crossplay server INSIDE this game (the kernel plus whatever the game's IInAppServerComposition adds), claims a room code at the rendezvous relay and, by default, attaches this player to it in-process; JoinAsync dials a room code over WebRTC through the same relay; ListRoomsAsync browses open rooms when the project's tier allows it. Everything above the transport — pieces, messages, the game — is unchanged: a room is a Crossplay server like any other, it just lives in a player's game. Invite = share the code.
-
P2pRoomState StateCurrent state.
-
string RoomCodeThe room code hosted or joined, or null.
-
int PeerCountRemote peers connected to the room this player hosts (0 when not hosting).
-
UniTask<string> HostAsync(string roomCode = null, CancellationToken cancellationToken = default)Hosts a room. roomCode null = a generated code. Returns the code.
-
UniTask JoinAsync(string roomCode, CancellationToken cancellationToken = default)Joins the room with this code (typed or pasted: it is normalized first).
-
UniTask<IReadOnlyList<P2pRoomInfo>> ListRoomsAsync(CancellationToken cancellationToken = default)The project's open rooms, when its tier allows browsing; an empty list otherwise.
-
void Leave()Leaves the room: disconnects, stops the in-app server if hosting, releases the code.
-
event Action<string> HostedThe room is up and claimed at the relay (argument: the code to share).
-
event Action<string> JoinedConnected to a room someone else hosts (argument: the code).
-
event Action<int> PeerJoinedA remote peer connected to the room this player hosts (argument: the peer's connection id).
-
event Action<int> PeerLeftA remote peer left the room this player hosts.
-
event Action LeftThe room was left, by choice or because the host went away.
-
event Action<string> FailedHosting, joining or browsing failed (argument: a short reason).
Unity services you inject 1
Crossplay binds these in the client context. Inject and call them from your own MonoBehaviours and presenters.
IInAppServerComposition
The game's half of an in-app server: which pieces the server hosted inside a player's game runs. Crossplay registers the kernel and the transports; the game adds exactly the AddCrossplay* calls its dedicated build makes — the same pieces, the same options — so a room hosted by a player IS the game's server, not a different one. Implement it once and mark it [SingletonClass]; the default (kernel only) is bound when no game implementation is present.
-
void Compose(IServiceCollection services)Adds the game's pieces to the in-app server's service collection.
UI views you can replace 1
Each ships a working uGUI panel you can drag into a scene. Substitute your own view to keep the logic and change the look — the presenter never knows.
ICrossplayP2pView
Narrow contract the presenter drives: final strings in, user intents out. No room state here.