Managing matches you have not joined (Do not have a presence in)

I’m trying to set up a host/client room invite pattern for a quiz game. My design so far has assumed that a host cliet/session/socket can create and maintain matches without necessarily having to be present in them.

i.e.
As a host I would like to be able to:

  • Initialise a room and generate a room code (already implemented - easy enough)

  • Provide this room code to clients and have them join those specific rooms (already implemented - easy enough)

  • Be able to update the match state and send messages to clients without needing to be a presence in the room itself.

The last part has been a little sticky for me. The framework seems to not want to register messages from sockets that aren’t part of the presences of the room.

Here is my current match loop that is very simple, and can manage data flow easily when the host is actually connected to the room.

const matchLoop = (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, dispatcher: nkruntime.MatchDispatcher, tick: number, state: nkruntime.MatchState, messages: nkruntime.MatchMessage) : { state: nkruntime.MatchState} | null => {
logger.debug(“Lobby match loop executed”);
logger.debug(“Match loop was bundled with " + messages.length + " messages.”);
//This messages array returns as empty when the sender is not joined to the match.
return {
state
};
}

Is what I am trying to achieve possible?

I think you should think about designing your matches differently - there is no downside for having the host join the match.

In your match state (on the server) you can store presence that has the user ID of the host; and ensure you broadcast messages to only the presences that are interested (non-host users).

Thanks for the response.

You know, after typing out my post I kind of came to that conclusion naturally, and I’m already going forward with host-present matches.

Thanks again.