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?