# \[RPC\] Calling custom rpc fuction sessionId missing

**URL:** <https://forum.heroiclabs.com/t/rpc-calling-custom-rpc-fuction-sessionid-missing/2690>\
**Category:** Runtime Framework\
**Tags:** typescript\
**Created:** [June 1, 2022, 10:07am UTC](https://forum.heroiclabs.com/t/rpc-calling-custom-rpc-fuction-sessionid-missing/2690 "2022-06-01T10:07:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kennot](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@kennot](https://forum.heroiclabs.com/u/kennot)\
**Post date:** [June 1, 2022, 10:07am UTC](https://forum.heroiclabs.com/t/rpc-calling-custom-rpc-fuction-sessionid-missing/2690/1 "2022-06-01T10:07:48Z")

</div>

Hi pro,

I am back again. Got some issues during developing a custom RPC function.

It’s about the streaming service. While joining the stream, I use `ctx.sessionId` to get the session id but get `undefined`. And add user to stream requires attaching a session id (can be sent manually during request rpc function, but why?)

This is my code for joining stream:

```auto
function playerJoinStream(ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, payload: any) {
  try {
    let streamId: nkruntime.Stream = joinStreamId;
    logger.info("*+*+*+*+*+*+*+")
    logger.info("trigger player join stream");
    logger.info("ctx json:" + JSON.stringify(ctx));
    // logger.info("ctx.sessionId:" + ctx.sessionId);
    logger.info("trigger player join stream");

    logger.info("*+*+*+*+*+*+*+")
    nk.streamUserJoin(ctx.userId, ctx.sessionId, streamId);

  } catch (error) {
    logger.info(JSON.stringify(error))
  }
}

```

and this is the log

```auto
nakama_1 | {"level":"info","ts":"2022-06-01T09:12:31.201Z","caller":"server/runtime_javascript_logger.go:68","msg":"*+*+*+*+*+*+*+"}
nakama_1 | {"level":"info","ts":"2022-06-01T09:12:31.202Z","caller":"server/runtime_javascript_logger.go:68","msg":"trigger player join stream"}
nakama_1 | {"level":"info","ts":"2022-06-01T09:12:31.202Z","caller":"server/runtime_javascript_logger.go:68","msg":"ctx json:{\"node\":\"nakama1\",\"env\":{},\"executionMode\":2,\"queryParams\":{},\"userSessionExp\":1654081898,\"userId\":\"188d0185-b8f1-4df6-81c8-8af1d11c6321\",\"username\":\"testtest\",\"clientIp\":\"172.19.0.1\",\"clientPort\":\"63686\"}"}

```

As the log shows above, ctx not contain the `sessionId`.  
Is anything I missed out?

Add on details: client is able to join chat channel

---

<div class="post-metadata">

**Author:** ![ftkg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/ftkg/32/1180_2.png) [@ftkg](https://forum.heroiclabs.com/u/ftkg)\
**Post date:** [June 1, 2022, 4:23pm UTC](https://forum.heroiclabs.com/t/rpc-calling-custom-rpc-fuction-sessionid-missing/2690/2 "2022-06-01T16:23:24Z")

</div>

Hi @kennot,

Are you calling the RPC function over a socket?  
You will only receive a session ID if communicating though a socket connection, as the socket contains the session ID for the socket handle managed by the game server.

---

<div class="post-metadata">

**Author:** ![kennot](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@kennot](https://forum.heroiclabs.com/u/kennot)\
**Post date:** [June 2, 2022, 6:33am UTC](https://forum.heroiclabs.com/t/rpc-calling-custom-rpc-fuction-sessionid-missing/2690/3 "2022-06-02T06:33:28Z")

</div>

hi @ftkg,

Thanks your advice, I found out there is another example code from the documentation after `client.rpc()`. Which is `socket.rpc()`, now i can fetching `sessionId` without any issues.

---

<div class="post-metadata">

**Author:** ![kennot](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@kennot](https://forum.heroiclabs.com/u/kennot)\
**Post date:** [June 2, 2022, 7:48am UTC](https://forum.heroiclabs.com/t/rpc-calling-custom-rpc-fuction-sessionid-missing/2690/4 "2022-06-02T07:48:19Z")

</div>

Hi pro,  
I got some additional questions regarding the join/leave stream.

There is a method to make the client leave the stream by using `streamUserLeave` .  
How about when clients disconnect or close the game before triggering `streamUserLeave`?

---

<div class="post-metadata">

**Author:** ![ftkg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/ftkg/32/1180_2.png) [@ftkg](https://forum.heroiclabs.com/u/ftkg)\
**Post date:** [June 2, 2022, 2:25pm UTC](https://forum.heroiclabs.com/t/rpc-calling-custom-rpc-fuction-sessionid-missing/2690/5 "2022-06-02T14:25:40Z")

</div>

On disconnects, the user will be automatically removed from any streams it was part of, as described in the docs: [Nakama: Streams | Heroic Labs Documentation](https://heroiclabs.com/docs/nakama/server-framework/streams/#leave-a-stream)

Also please start a new topic if you have further unrelated questions.
