# Reopening Created Subsessions not Working

**URL:** <https://devforum.zoom.us/t/reopening-created-subsessions-not-working/101202>\
**Category:** Web\
**Created:** [January 4, 2024, 1:27pm UTC](https://devforum.zoom.us/t/reopening-created-subsessions-not-working/101202 "2024-01-04T13:27:32Z")\
**Posts on this page:** 6\
**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:** [January 4, 2024, 1:27pm UTC](https://devforum.zoom.us/t/reopening-created-subsessions-not-working/101202/1 "2024-01-04T13:27:32Z")

</div>

**Description**  
Today while testing I decided to run my old script that did three simple things, create one subsession, open the subsession, close the subsession, and then open it again. While testing, I had the issue that after closing the subsession the first time, it wouldn’t open again, but instead it made the browser tabs to freeze. When I closed the frozen tabs and tried the same sequence again, the same thing happened.

**Browser Console Error**  
No errors.

**Which Web Video SDK version?**  
1.9.5

**Video SDK Code Snippets**  
Function to create subsessions

```auto
const createSubsessions = useCallback(
    async (subsessionNumber: number, pattern: SubsessionAllocationPattern) => {
      const totalParticipants = zmClient.getAllUser().filter(
        p => !p.displayName.endsWith('(Dozent:in)') &&
          !p.displayName.endsWith('(Moderator:in)')
      );

      if (totalParticipants.length < 1) {
        console.log('generated rooms', 0);
        message.info('Bitte versuchen Sie es erneut, wenn Teilnehmer verfügbar sind.');
        return;
      }
      message.info('Breakout-Räume werden erstellt. Bitte haben Sie etwas Geduld, da dies bis zu 10 Sekunden dauern kann. Wenn der Button nach 10 Sekunden nicht rot wird, klicken Sie bitte erneut.', 10);

      if (ssClient) {
        try {
          setRetryOpeningSubsessions(true);
          setIsRetryingOpenSubSessions(true);
          // const subsessions = await ssClient.createSubsessions(subsessionNumber, pattern);
          await ssClient.createSubsessions(subsessionNumber, pattern).then((subsessions) => {
            setSubsessions(subsessions as unknown as Subsession[]);
            openSubsessions();
          }).catch((err) => {
            if (err.reason === 'only host can do the operation') {
              message.error('Nur der Host kann den Vorgang ausführen');
            } else {
              message.error(err.reason)
            }
          });
        } catch (e) {
          console.warn(e);
        }
      }
    },
    [ssClient, setIsRetryingOpenSubSessions, openSubsessions, zmClient]
  );

```

Function to open subsessions

```auto

  const openSubsessions = useCallback(async () => {
    if (ssClient) {
      const guests = zmClient.getAllUser().filter(
        p => !p.displayName.endsWith('(Dozent:in)') &&
          !p.displayName.endsWith('(Moderator:in)')
      );

      if (guests.length < 1) {
        message.info(
          'Bitte versuchen Sie es erneut, wenn Teilnehmer verfügbar sind.'
        );
        return 0;
      }

      console.log('stored expected open room count', roomsToOpen)
      console.log('subsessions to open', subsessions);

      setRetryOpeningSubsessions(true);
      setIsRetryingOpenSubSessions(true);

      if (!subsessions.length || !ssClient.getSubsessionList().length) {
        return;
      }

      try {
        await ssClient.openSubsessions(subsessions, options).then(() => {
          setSubsessionStatus(() => SubsessionStatus.InProgress);

          if (ssClient.getSubsessionStatus() === SubsessionStatus.InProgress) {

            if (unassignedUserList.length) {
              const randomSubSession = subsessions[Math.floor(Math.random() * subsessions.length)];
              let participant: Participant | null;
              unassignedUserList.forEach(async (user) => {
                participant = user;
                ssClient.assignUserToSubsession(
                  user.userId,
                  randomSubSession.subsessionId
                ).then(() => {
                  setSubsessions(
                    produce((subsessions: Subsession[]) => {
                      const subsession = subsessions.find((r: Subsession) => r.subsessionId === randomSubSession.subsessionId);
                      if (subsession && participant) {
                        subsession.userList.push({
                          userId: participant.userId,
                          displayName: participant.displayName,
                          avatar: participant.avatar,
                          isInSubsession: true
                        });
                      }
                    })
                  );
                });
              });
            }

            if (chatClient && chatClient.getPrivilege() === ChatPrivilege.NoOne) {
              chatClient?.setPrivilege(ChatPrivilege.EveryonePublicly).then(() => {
                message.info('Die Chat-Berechtigung "Alle dürfen sprechen" wurde wieder aktiviert, um sicherzustellen, dass die Nutzer in den Breakout-Räumen schreiben können.');

                setAllowChatting(true);
              });
            }

            if (guests.length) {
              guests.forEach(async (g) => {
                await mediaStream?.unmuteAudio(g.userId);
                console.log('muted', g);
              });

              setUnmuteAllParticipants(true);
              setCurrentQueue((currentQueue: HandQueue[]) => []);
            }

            setDoNotDisturb(false);
            const moderator = zmClient.getAllUser().filter((u) => u.displayName.endsWith('(Moderator:in)'));
            if (moderator.length) {
              let command = {
                action: 'sent-moderation-update',
                dnd: false,
              }

              cmdClient?.send(JSON.stringify(command), moderator[0].userId);
            }
          }

        }).catch((err) => {
          if (err.reason === 'only host can do the operation') {
            message.error('Nur der Host kann den Vorgang ausführen');
          } else {
            message.error(err.reason)
          }
        });

      } catch (err) {
        console.log(err);
      }

      setRetryOpeningSubsessions(false);
      setIsRetryingOpenSubSessions(false);
      // await assignUnassignedUsersToAnyRunningSubsessions();
      console.log('sub open status', subsessionStatus);
      console.log('ssclient stat', ssClient.getSubsessionStatus());
    }
  }, [
    ssClient,
    zmClient,
    setIsRetryingOpenSubSessions,
    subsessionStatus,
    subsessions,
    unassignedUserList,
    roomsToOpen,
    options,
    chatClient,
    setDoNotDisturb,
    setAllowChatting,
    setUnmuteAllParticipants,
    setCurrentQueue,
    mediaStream,
    cmdClient
  ]);

```

Function to close subsessions

```auto

  const closeAllSubSessions = useCallback(async () => {
    if (ssClient) {
      setRetryOpeningSubsessions(false);
      await ssClient.closeAllSubsessions()
        .then(async () => {
          if (ssClient.getSubsessionStatus() === SubsessionStatus.Closed) {

            const guests = zmClient.getAllUser().filter(
              p => !p.displayName.endsWith('(Dozent:in)') &&
                !p.displayName.endsWith('(Moderator:in)')
            );

            if (guests.length) {
              guests.forEach(async (g) => {
                await mediaStream?.muteAudio(g.userId);
                console.log('muted', g);

                let command = {
                  action: 'host-ask-mute',
                  sender: zmClient.getSessionHost()?.userId
                }

                cmdClient?.send(JSON.stringify(command), g.userId);
              });
            }

            setUnmuteAllParticipants(false);

            await chatClient?.setPrivilege(ChatPrivilege.NoOne);
            setAllowChatting(false);

            setDoNotDisturb(true);
          }
        })
        .catch((err) => {
          if (err.reason === 'only host can do the operation') {
            message.error('Nur der Host kann den Vorgang ausführen');
          } else {
            message.error(err.reason)
          }
        });

      console.log('Done');
      console.log('retry-subs', retryOpeningSubsessions);
    }
  }, [
    ssClient,
    retryOpeningSubsessions,
    zmClient,
    setUnmuteAllParticipants,
    chatClient,
    setAllowChatting,
    setDoNotDisturb,
    mediaStream,
    cmdClient
  ]);

```

**To Reproduce(If applicable)**  
Steps to reproduce the behavior:

1. Create subsession and open subsessions
2. Close subsessions
3. Try to open subsessions again.
4. See error

---

<div class="post-metadata">

**Author:** ![ekaansh.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ekaansh.zoom/32/55004_2.png) [@ekaansh.zoom](https://devforum.zoom.us/u/ekaansh.zoom)\
**Post date:** [January 9, 2024, 4:57pm UTC](https://devforum.zoom.us/t/reopening-created-subsessions-not-working/101202/2 "2024-01-09T16:57:24Z")

</div>

Hey @godwin.owonam,  
I can double check but I believe if you’ve closed all subsessions, you’ll first have to create them again and then open them after. Have you tried that?

---

<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:** [January 11, 2024, 4:56am UTC](https://devforum.zoom.us/t/reopening-created-subsessions-not-working/101202/3 "2024-01-11T04:56:02Z")

</div>

Thanks @ekaansh.zoom

Well, closing subsessions does not “remove” the subsessions. It just returns the participants to the main room and marks the subsession as closed. You can reopen the same subsessions.

The main issue here is that the ssClient.closeAllSubsessions() method resolves and does not put the subsessions in “Closed” state, but in “Closing” state. So when I fire another event when this is resolved, it puts the subsessions in an unknown state. So when I try to reopen the subsessions or create new ones, my browser just freezes.

In the snippet below

```auto
ssClient.closeAllSubsessions().then(async() => {
    await chatClient?.setPrivilege(ChatPrivilege.NoOne);
     setAllowChatting(false);
});

```

would cause the subsessions to freeze my browser after closing if I try to reopen or recreate the subsessions.

If I put a check to ensure that the subsessions are closed before executing the code above,

```auto
ssClient.closeAllSubsessions().then(async() => {
    if (ssClient.getSubsessionStatus() === SubsessionStatus.Closed) {
        await chatClient?.setPrivilege(ChatPrivilege.NoOne);
        setAllowChatting(false);
     }
});

```

then the code between the ‘if’ clause does not run.

---

<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:** [January 12, 2024, 6:47am UTC](https://devforum.zoom.us/t/reopening-created-subsessions-not-working/101202/4 "2024-01-12T06:47:05Z")

</div>

Hey @godwin.owonam

I apologize for the documentation not clearly explaining the changes in subsession status.

After calling `ssClient.closeAllSubsessions()`, the subsession’s status becomes `SubsessionStatus.Closing`.

This is because if there is a `waitSeconds` option in `ssClient.openSubsessions`, it is intended to wait for users still in the subsession to leave. So, when `ssClient.closeAllSubsessions()` is called, the subsession’s status changes from `SubsessionStatus.InProgress` to `SubsessionStatus.Closing` and finally to `SubsessionStatus.Closed` .

You can monitor this state change by listening to the `subsession-state-change` event.

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:** [January 12, 2024, 9:50am UTC](https://devforum.zoom.us/t/reopening-created-subsessions-not-working/101202/5 "2024-01-12T09:50:59Z")

</div>

> [@vic.yang](#):
>
> `subsession-state-change`

I guess you mean `event_bo_room_state_change` on the event-callbacks.

Thanks. I will let you know when I try this solution.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [February 11, 2024, 7:51pm UTC](https://devforum.zoom.us/t/reopening-created-subsessions-not-working/101202/6 "2024-02-11T19:51:27Z")

</div>

Closed on February 11, 2024, 7:51pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
