useSharedPresence() API Docs
Kitchen-sink Example
Here's an example of using the hook with all the options and returns displayed.
export function MaxedOut() {
const {
self, // this peer's data
setState, // set this client's dynamic state
others, // everyone else's data (but not this client's)
stats, // the number of peers who had connected at least once
connected, // if this peer is connected or not
started, // if the presence room has been initialized or not
error // any errors, if any
} = useSharedPresence<TOptionalTypeOfDynamicState>({
peerId: peerId, // replace this with any string that uniquely identifies the user; ideally keep stable
room: 'a-specific-room-key', // if you don't want airstate to infer from url
token: 'jwt-signed-by-your-server', // to maintain authentication & authorization
client: customClient, // if you don't use to use the default client with default config
initialState: {
x: 0,
y: 0,
},
validate: (rawState: any) => {
// return validated parsed data
// or throw error
return schema.parse(rawState);
}
});
return <>{/* ... */}</>
}
API
WIP.