Unable to send Stream message

Hello, I’m trying to use the streamUserSend API to send a notification to one user. I’ve tried this following:

      const l = nk.streamUserGet(ctx.userId, ctx.sessionId, globalStream);
      nk.streamSend(globalStream, JSON.stringify({ type: "bot_match", matchId }), [l]);

This gives me the following error:

{"level":"debug","ts":"2025-03-06T14:30:15.933+0400","caller":"server/message_router.go:66","msg":"No session to route to","sid":"00000000-0000-0000-0000-000000000000"}
      const l = nk.streamUserList(globalStream);
      nk.streamSend(globalStream, JSON.stringify({ type: "bot_match", matchId }), l);

This gives the error:

{"level":"error","ts":"2025-03-06T14:28:02.990+0400","caller":"server/runtime_javascript.go:586","msg":"JavaScript runtime function raised an uncaught exception","mode":"before","id":"*rtapi.envelope_matchmakerremove","error":"TypeError: expects an array of presence objects at github.com/heroiclabs/nakama/v3/server.(*RuntimeJavascriptNakamaModule).mappings.(*RuntimeJavascriptNakamaModule).streamSend.func75 (native)"}

Not sure why this isn’t working. I’m calling this from the beforeMatchmakerRemove hook if that helps.

PS: I’m using streamSend over the Notification API because of the reliable option. Does that matter?

Regards

Hello @MinatoTW,

The error should indicate that the socket connection to the target user is not available anymore.

Either way you should be using the Notification API, the streams APIs are lower level and only meant for things that can’t be achieved using the preferred standard ones.

The underlying socket connections use TCP so the reliable option won’t matter in this case, it’s meant for implementations of rUDP whose support we haven’t made publicly available.

Best.

Thank you. I’m still curious about streamSend though, because I’m the only user logged in and I see the account in the streamUserGet response. So there’s no chance it can’t find my session. Also, if I use streamSend without presences it works fine.

I had misread the error message, it’s possible there’s an input validation bug, but I’m not sure yet.

Could you log a JSON.stringify of const l and post it here please?