# Chats lost when I switch from main session to subsession or from subsession to main session

**URL:** <https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081>\
**Category:** Video SDK\
**Created:** [November 8, 2023, 4:56pm UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081 "2023-11-08T16:56:40Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![godwin.owonam](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/godwin.owonam/32/53602_2.png) [@godwin.owonam](https://devforum.zoom.us/u/godwin.owonam)\
**Post date:** [November 8, 2023, 4:56pm UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/1 "2023-11-08T16:56:40Z")

</div>

**Video SDK Type and Version**  
_Web Video SDK version: 1.5.5_

**Description**  
_When I switch from main session to subsession or from subsession to main session the chat records are lost._

---

<div class="post-metadata">

**Author:** ![rehema.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/rehema.zoom/32/40323_2.png) [@rehema.zoom](https://devforum.zoom.us/u/rehema.zoom)\
**Post date:** [November 8, 2023, 6:07pm UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/2 "2023-11-08T18:07:55Z")

</div>

Hi @godwin.owonam ,

How are you storing and displaying chat messages in your application?

Thanks,  
Rehema

---

<div class="post-metadata">

**Author:** ![godwin.owonam](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/godwin.owonam/32/53602_2.png) [@godwin.owonam](https://devforum.zoom.us/u/godwin.owonam)\
**Post date:** [November 8, 2023, 6:27pm UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/3 "2023-11-08T18:27:38Z")

</div>

Hello @rehema.zoom,  
Thanks for responding. Currently on the Zoom Video SDK, (being that I have not changed the functionality), the chats are stored in the chat records which are stately preserved (in react useState hook) as an array.

The issue here is that these chat records are lost because the parent component (component which the Chat component is rendered) is re-rendered when I switch between main session and sub-session.

Like I said, I haven’t changed this functionality, so I’m wondering if there’s a way the SDK can be made to preserve the messages.

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [November 9, 2023, 8:13am UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/4 "2023-11-09T08:13:00Z")

</div>

Hey @godwin.owonam

The chat records will not be preserved when you are in and out of the subsession. The reason for this is that the `userId` will be changed after returning back to the main session from the subsession, which may cause the chat records to be inconsistent.

For your case, a workaround is to use an independent store (such as Redux, Mobx, or React Context, etc) to preserve the records within your application.

Thanks  
Vic

---

<div class="post-metadata">

**Author:** ![godwin.owonam](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/godwin.owonam/32/53602_2.png) [@godwin.owonam](https://devforum.zoom.us/u/godwin.owonam)\
**Post date:** [November 9, 2023, 10:37am UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/5 "2023-11-09T10:37:42Z")

</div>

Thanks @vic.yang

I will try the options you listed, but is the fact that the userId changes when retaining to the main session, the intended behaviour? Is there no way that the Devs can work around to keep this fixed?

I will keep you updated if any of the options you gave solved the issues.  
Best regards.  
@godwin.owonam

---

<div class="post-metadata">

**Author:** ![godwin.owonam](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/godwin.owonam/32/53602_2.png) [@godwin.owonam](https://devforum.zoom.us/u/godwin.owonam)\
**Post date:** [November 9, 2023, 11:52am UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/6 "2023-11-09T11:52:26Z")

</div>

@vic.yang

I used React Context and it did preserve the messages from the main room to the sub-sessions.

`In my current implementation` I used the React context to store the chat records, but it seems this record is not maintained between the main and sub-sessions. Feels like a temporary disconnect between the two instances. I have attached code snippets of the implementation below.

And this is a bigger issue for us when messages sent from the main room cannot be seen by participants in the sub-sessions.

That is, if the participants are in the sub sessions, and the host is in the main session, the chat message sent by the host in the main session is not visible to the participants in the sub sessions.

I would really appreciate your help.

**In chat-record-context.ts**

```auto
import React from 'react';
export default React.createContext<any | null>([]);

```

**In App.tsx**

```auto
 const [chatRecords, setChatRecords] = useState<ChatRecord[]>([]);

<ChatRecordContext.Provider value={{chatRecords, setChatRecords}}>
   // ... router logic with all components within
</ChatRecordContext.Provider>

```

**In chat.tsx:**

```auto
const {chatRecords, setChatRecords} = useContext(ChatRecordContext);
  // const [chatRecords, setChatRecords] = useState<ChatRecord[]>([]); (Previous storage)

```

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [November 10, 2023, 2:25am UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/7 "2023-11-10T02:25:51Z")

</div>

Hey @godwin.owonam

It seems there are two concerns regarding the chat function:

- In order to ensure seamless connectivity between users in the main session and subsession, we have implemented the `userGuid` attribute in the participant payload. This attribute remains unchanged throughout the entire session, regardless of how many times a user enters or leaves the subsession.  
[Participant | Zoom Video SDK for Web - 1.9.5](https://marketplacefront.zoom.us/sdk/custom/web/interfaces/Participant.html#userGuid)

- To send messages to the subsession, you can use the `subsession.broadcast` method. However, please keep in mind that only the host role can use this method, and the message will be broadcasted to all subsessions and the main session.  
[SubsessionClient | Zoom Video SDK for Web - 1.9.5](https://marketplacefront.zoom.us/sdk/custom/web/modules/SubsessionClient.html#broadcast)

Thanks  
Vic

---

<div class="post-metadata">

**Author:** ![godwin.owonam](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/godwin.owonam/32/53602_2.png) [@godwin.owonam](https://devforum.zoom.us/u/godwin.owonam)\
**Post date:** [November 10, 2023, 9:49am UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/8 "2023-11-10T09:49:52Z")

</div>

Thanks @vic.yang

So you’re saying I should upgrade the SDK? Would this be all I need to do?

Because I stated that I am using 1.5.5 in my first post.

---

<div class="post-metadata">

**Author:** ![godwin.owonam](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/godwin.owonam/32/53602_2.png) [@godwin.owonam](https://devforum.zoom.us/u/godwin.owonam)\
**Post date:** [November 10, 2023, 10:08am UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/9 "2023-11-10T10:08:54Z")

</div>

In order to ensure seamless connectivity between users in the main session and subsession, we have implemented the `userGuid` attribute in the participant payload. This attribute remains unchanged throughout the entire session, regardless of how many times a user enters or leaves the subsession.  
[Participant | Zoom Video SDK for Web - 1.9.5](https://marketplacefront.zoom.us/sdk/custom/web/interfaces/Participant.html#userGuid)

Does this mean that messages in the main session chat will be seen in the subsession chat. Because that is what we want ATM. @vic.yang

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [November 10, 2023, 10:13am UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/10 "2023-11-10T10:13:51Z")

</div>

Hey @godwin.owonam

It’s better to upgrade to the latest Video SDK Web version(1.9.5).

The `userGuid` attribute has been available since Video SDK 1.6.0.

If you need to send the message from the main session, use `subsession.broadcast` method. Please see the second point of the above comment.

> To send messages to the subsession, you can use the `subsession.broadcast` method. However, please keep in mind that only the host role can use this method, and the message will be broadcasted to all subsessions and the main session.

Thanks  
Vic

---

<div class="post-metadata">

**Author:** ![godwin.owonam](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/godwin.owonam/32/53602_2.png) [@godwin.owonam](https://devforum.zoom.us/u/godwin.owonam)\
**Post date:** [November 14, 2023, 11:41am UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/11 "2023-11-14T11:41:18Z")

</div>

> [@vic.yang](#):
>
> The `userGuid` attribute has been available since Video SDK 1.6.0.

Hi @vic.yang

So I upgraded the SDK as you said, but that doesn’t solve the problem because even though the userGuid is currently in the latest SDK, it is not used for the chats functionality, hence the problem was not solved even when userGuid was introduced in the SDK.

Unless I am supposed to do any extra work with the userGuid to solve this, upgrading did not solve this issue.

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [November 15, 2023, 3:45am UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/12 "2023-11-15T03:45:57Z")

</div>

Hey @godwin.owonam

That’s correct. Currently, `userId` is still used in the API of Video SDK Web.

In order to associate the chat records of the main session with the user, we need to first use the `userId` to identify the user and then retrieve the corresponding `userGuid`. As I mentioned before, the `userGuid` remains unchanged throughout the session, allowing us to establish a connection between the chat records from the main session and other subsessions.

Thanks  
Vic

---

<div class="post-metadata">

**Author:** ![godwin.owonam](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/godwin.owonam/32/53602_2.png) [@godwin.owonam](https://devforum.zoom.us/u/godwin.owonam)\
**Post date:** [November 21, 2023, 10:01am UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/13 "2023-11-21T10:01:47Z")

</div>

Hi @vic.yang

Do you mean this is something I have to do or is already done?

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [November 21, 2023, 10:24am UTC](https://devforum.zoom.us/t/chats-lost-when-i-switch-from-main-session-to-subsession-or-from-subsession-to-main-session/98081/14 "2023-11-21T10:24:26Z")

</div>

Hey @godwin.owonam

> In order to associate the chat records of the main session with the user, we need to first use the `userId` to identify the user and then retrieve the corresponding `userGuid` . As I mentioned before, the `userGuid` remains unchanged throughout the session, allowing us to establish a connection between the chat records from the main session and other subsessions.

That’s what you need to do in your application.

Thanks  
Vic
