# Sessions

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

A **session** is the most fundamental building block of the Video SDK for Windows. A session is similar to, but not limited to, a virtual meeting where two or more users can communicate with each other over video and audio.

## Create and join a session

To create a session, you must provide a session name to uniquely identify it.

The process of creating and joining a session requires the developer's [SDK JWT](/docs/video-sdk/auth/). When you create and join a session through the Video SDK, you must provide a string value representing the session name. The name determines whether the SDK joins an existing session or creates a new one.

-   If you call `joinSession()` with a session name and there is no session currently active with that name, the SDK creates the session for you.
-   If a session with that name is currently active, the SDK lets you join the active session if you provide all the required parameters, for example, a password if one has been set for the session.

Sessions become inactive and available for reuse after you call `leaveSession()` to end a session or the backend closes the session when there are no longer any users in that session.

The session name only needs to be unique to your app at the developer account level. For instance, developers with separate developer accounts (separate SDK credentials) can use the same session name for their separate apps (for example, App A and App B). While the names are the same, Zoom creates different unique sessions for both of these apps. Two different apps built with the Video SDK cannot join sessions created by the other. Each app can only join a session that it created.

To create a session through the SDK, create an instance of `ZoomVideoSDKSessionContext` and provide the `userName`, `sessionName`,and **JWT** as shown below.

### Create a `ZoomVideoSDKSessionContext` object

```cpp
ZoomVideoSDKSessionContext sessionContext;
sessionContext.sessionName = L"Session name";
sessionContext.sessionPassword = L"Session password";
sessionContext.userName = L"User name";

// JWT for this session.
sessionContext.token = L"JWT";

// Video and audio options.
sessionContext.videoOption.localVideoOn = true;
sessionContext.audioOption.connect = true;
sessionContext.audioOption.mute = false;
```

### Properties of the `ZoomVideoSDKSessionContext` object

The following table describes all the properties of the `ZoomVideoSDKSessionContext` object.

| Name              | Required | Note                                                                                                                                                                                                                                                                                                                                                                                            |
| ----------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sessionName`     | Yes      | Name and unique identifier of the session. A user will be able to join the session by entering the session name. Should be alphanumeric with a max-length of 150 characters. It can include symbols and the space character. Session names are case insensitive (they are all converted to lowercase). This must match the `tpc` value in the [SDK JWT payload](/docs/video-sdk/auth/#payload). |
| `userName`        | Yes      | Display name of the user shown in the session. If empty, the name is displayed as the string "null". Max 200 characters. Values longer than 200 characters are truncated without error.                                                                                                                                                                                                         |
| `token`           | Yes      | JWT token generated from your SDK credentials. For details, see [Authorize](/docs/video-sdk/auth/).                                                                                                                                                                                                                                                                                             |
| `sessionPassword` | No       | Password for session. If set, the session will be private and can only be joined if the user provides a valid password. If not set, the session will be public for anyone in your account. To join, they must use `sessionName` only. The field has a max-length limit of 10 characters, printable ASCII characters only (ch >= 32 && ch < 127).                                                |
| `audioOption`     | No       | Configure audio settings by storing values in `ZoomVideoSDKAudioOption`.                                                                                                                                                                                                                                                                                                                        |
| `videoOption`     | No       | Configure video settings by storing values in `ZoomVideoSDKVideoOption`.                                                                                                                                                                                                                                                                                                                        |

## Leave a session

When you are ready to leave the session, call the `leaveSession` method. Leave session has a `bool` parameter that when set to true will end the session. Note, only the host can end the session.

```cpp
// A value of true will end the session, if you are the host.
m_pVideoSDK->leaveSession(false);
```

## Callbacks

Prior to joining a session, ensure that you have set up a delegate for callback events by conforming your class to the `IZoomVideoSDKDelegate` interface. For details, see [Implement a delegate](/docs/video-sdk/windows/integrate/#implement-a-delegate).

Once you have your context and delegate set up, call `joinSession()` to join a session.

```cpp
IZoomVideoSDKSession* pSession = m_pVideoSDK->joinSession(sessionContext);
if (!pSession)
{
    CString cstrInfo;
    cstrInfo.Format(_T("Failed to join session"));
}
else
{
    CString cstrInfo;
    cstrInfo.Format(_T("Joined session successfully."));
}
```

Note that the return value of `joinSession()` will return the session upon success, and NULL upon failure.

## Optimize join latency with pre-join

To reduce connection time in 1:1 calls or invite flows, prepare the session before the user accepts the call. When the user accepts, commit the join to connect immediately. This two-step flow minimizes the time between when a user answers a call and when they're in the call.

Before the user can use `prepareJoin()` and `commitJoin()`, the caller must already have the session up and running. The user then uses the pre-join flow to join the existing session more quickly.

Implement the surrounding incoming-call workflow, including push notification delivery and application-level call UI.

> **Note**
>
> The Video SDK provides support for joining a session and in-session capabilities after the session is joined, but it does not provide built-in support for push notification handling, system call UI, or incoming-call management.

### Prepare to join

First create your session context as described in [Create a ZoomVideoSDKSessionContext object](#create-a-zoomvideosdk-sessioncontext-object). Then call `prepareJoin()` to prepare the connection without joining the session. Configure the timeout interval using `ZoomVideoSDKPreJoinParam`.

```cpp
ZoomVideoSDKPreJoinParam preJoinParam;
preJoinParam.timeoutInterval = 30; // Timeout in seconds (1-60, or 0 for default 30s)

IZoomVideoSDKSession* pSession = m_pVideoSDK->prepareJoin(sessionContext, preJoinParam);
if (!pSession)
{
    CString cstrInfo;
    cstrInfo.Format(_T("Failed to prepare join"));
}
else
{
    CString cstrInfo;
    cstrInfo.Format(_T("Pre-join prepared successfully."));
}
```

| Name           | Required | Note                                                                                                                          |
| -------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `params`       | Yes      | `ZoomVideoSDKSessionContext` with session details. Same configuration as standard `joinSession()`.                            |
| `preJoinParam` | Yes      | `ZoomVideoSDKPreJoinParam` to configure timeout. Set `timeoutInterval` to 1-60 seconds, or 0 to use the default (30 seconds). |

### Commit the join

When the user accepts the call, finalize the connection by calling `commitJoin()`.

```cpp
ZoomVideoSDKErrors result = m_pVideoSDK->commitJoin();
```

The return value indicates success or error. Listen for `onSessionJoin()` to confirm you've successfully joined.

### Cancel pre-join

If the user declines the call after `prepareJoin()`, cancel the preparation.

```cpp
ZoomVideoSDKErrors result = m_pVideoSDK->cancelPrepareJoin();
```

## Hold participants until admitted

OnHold places participants in a holding state when they join a session. They stay on hold, outside the session, until a host or manager admits them.

The [`hold` JWT payload field](/docs/video-sdk/auth/#hold-participants-until-admitted) controls whether a session supports OnHold. Set it in the JWT of the first user to join, which starts the session.

-   `0` - (default) The session does not support OnHold.
-   `1` - The session supports OnHold, and OnHold is on when the session starts.
-   `2` - The session supports OnHold, but OnHold is off when the session starts. A host or manager can turn it on during the session.

When OnHold is on, participants who join receive `onHoldJoined()` instead of `onSessionJoin()` until a host or manager admits them.

> **Note**
>
> OnHold requires Video SDK 2.6.11 or later on Android, iOS, macOS, Windows, and Linux. The Video SDK for React Native, Flutter, Unity, and Electron supports OnHold in versions built on Video SDK 2.6.11 or later. The Video SDK for Web does not support OnHold yet.
>
> When `hold` is `1` or `2`, the session rejects join attempts from clients that do not support OnHold, including Web clients. Update every client that joins the session before you turn on OnHold.

### Check OnHold status

Get the `IZoomVideoSDKOnHoldHelper` by calling `getOnHoldHelper()`. Call `isSupportHold()` to check whether the current session supports OnHold, and `isOnHoldEnabled()` to check whether OnHold is on.

```cpp
IZoomVideoSDKOnHoldHelper* pOnHoldHelper = m_pVideoSDK->getOnHoldHelper();
if (pOnHoldHelper)
{
    bool isSupportHold = pOnHoldHelper->isSupportHold();
    bool isOnHoldEnabled = pOnHoldHelper->isOnHoldEnabled();
}
```

### Get notified when you are on hold

When the local user joins a session with OnHold on, the SDK calls `onHoldJoined()` instead of `onSessionJoin()`. Use this callback to show a holding screen until a host or manager admits the user.

```cpp
virtual void onHoldJoined()
{
    // The local user is on hold. Show a holding screen.
}
```

### Get notified when other users are on hold

The SDK calls `onHoldUserJoin()` when users are placed on hold, and `onHoldUserLeave()` when users leave the on-hold list. Use these callbacks to keep a list of users waiting for a host or manager to admit them.

Users leave the on-hold list in either of the following cases.

-   A host or manager admits them. Hosts and managers then also receive `onUserJoin()` for each admitted user who is not already in the session's user list.
-   They leave while still on hold. The SDK reports these users through `onHoldUserLeave()` only, not through `onUserLeave()`.

```cpp
virtual void onHoldUserJoin(IZoomVideoSDKOnHoldHelper* pOnHoldHelper, IVideoSDKVector<IZoomVideoSDKOnHoldUser*>* userList)
{
    if (!userList) return;
    for (int i = 0; i < userList->GetCount(); i++)
    {
        IZoomVideoSDKOnHoldUser* pUser = userList->GetItem(i);
        // Add pUser->getUserName() to your list of users on hold.
    }
}

virtual void onHoldUserLeave(IZoomVideoSDKOnHoldHelper* pOnHoldHelper, IVideoSDKVector<IZoomVideoSDKOnHoldUser*>* userList)
{
    // Remove these users from your list of users on hold.
}
```

### Admit users on hold

A host or manager can call `getOnHoldUserList()` to get the users currently on hold, then call `admit()` to admit one user or `admitAll()` to admit every user on hold.

```cpp
IZoomVideoSDKOnHoldHelper* pOnHoldHelper = m_pVideoSDK->getOnHoldHelper();
IVideoSDKVector<IZoomVideoSDKOnHoldUser*>* pOnHoldUsers = pOnHoldHelper->getOnHoldUserList();

// Admit one user.
if (pOnHoldUsers && pOnHoldUsers->GetCount() > 0)
{
    ZoomVideoSDKErrors result = pOnHoldHelper->admit(pOnHoldUsers->GetItem(0));
}

// Admit all users on hold.
ZoomVideoSDKErrors result = pOnHoldHelper->admitAll();
```

### Turn OnHold on or off during a session

A host or manager can call `enableHold()` to turn OnHold on or off in a session that supports OnHold. This change only affects future join attempts. It does not admit users who are already on hold.

```cpp
// Pass true to turn OnHold on, or false to turn it off.
ZoomVideoSDKErrors result = m_pVideoSDK->getOnHoldHelper()->enableHold(true);
```

## Important Callbacks

All of these callbacks can be found within your `IZoomVideoSDKDelegate` implementation. For information on implementation, see [Integrate](/docs/video-sdk/windows/integrate/).

-   `onSessionJoin()`: Called when current user has joined the session.
-   `onSessionLeave()`: Called when current user has left the session.
-   `onError(ZoomVideoSDKErrors errorCode, int detailErrorCode)`: Called when the SDK raises an error. For example, failure to join a session, network timeouts, etc. `ZoomVideoSDKErrors_Success` represents a successful callback without errors.
-   `onUserJoin(IZoomVideoSDKUserHelper\* pUserHelper, IVideoSDKVector\<IZoomVideoSDKUser\*\>\* userList)`: Called when any user joins the session. Helper is provided to provide user-related functionality. userList represents the updated list of users who just joined the session.
-   `onUserLeave(IZoomVideoSDKUserHelper\* pUserHelper,  IVideoSDKVector\<IZoomVideoSDKUser\*\>\* userList)`: Called when any user leaves the session. Helper is provided to provide user-related functionality. UserList represents the updated list of users who just left the session.
-   `onHoldJoined()`: Called when the current user joins a session with OnHold on and is placed on hold. See [Hold participants until admitted](#hold-participants-until-admitted).
-   `onHoldUserJoin(IZoomVideoSDKOnHoldHelper\* pOnHoldHelper, IVideoSDKVector\<IZoomVideoSDKOnHoldUser\*\>\* userList)`: Called when users are placed on hold. userList represents the users who were just placed on hold.
-   `onHoldUserLeave(IZoomVideoSDKOnHoldHelper\* pOnHoldHelper, IVideoSDKVector\<IZoomVideoSDKOnHoldUser\*\>\* userList)`: Called when users leave the on-hold list, either because a host or manager admitted them or because they left while on hold. userList represents the users who just left the on-hold list.
-   `onSessionNeedPassword(IZoomVideoSDKPasswordHandler\* handler)`: Called when attempting to join a session that requires a password, but no password was provided. A `handler` parameter is provided to retry the join. Use `handler` when you would like to retry joining the session. Through the `IZoomVideoSDKPasswordHandler` interface, call `inputSessionPassword` to pass in the password. Call `leaveSessionIgnorePassword` to not provide a password and leave the session instead.
-   `onSessionPasswordWrong(IZoomVideoSDKPasswordHandler\* handler)`: Called when attempting to join a session that requires a password, but the provided password was incorrect. A `handler` parameter is provided to retry the join. Use `handler` when you would like to retry joining the session. Through the `IZoomVideoSDKPasswordHandler` interface, call `inputSessionPassword` to pass in the password. Call `leaveSessionIgnorePassword` to not provide a password and leave the session instead.

## Session callback examples

### Get notified when the local user successfully joins or leaves a session

```cpp
void CExampleListener::onSessionJoin()
{
    // You have successfully joined the session.
}

void CExampleListener::onSessionLeave()
{
    // You have successfully left the session.
}
```

### Get notified when a user other than the local user successfully joins or leaves ### a session

```cpp
void CExampleListener::onUserJoin(IZoomVideoSDKUserHelper* pUserHelper, IVideoSDKVector<IZoomVideoSDKUser*>* userList)
{
    CString strInfo;
    IZoomVideoSDKUser* pUser;
    int count = userList->GetCount();

    for (int i = 0; i < count; i++)
    {
        pUser = userList->GetItem(i);
        if (!pUser) continue;

        strInfo.Format(_T("A user joined the session: name=%s"), pUser->getUserName());
    }
}

void CExampleListener::onUserLeave(IZoomVideoSDKUserHelper* pUserHelper, IVideoSDKVector<IZoomVideoSDKUser*>* userList)
{
    CString strInfo;
    IZoomVideoSDKUser* pUser;
    int count = userList->GetCount();

    for (int i = 0; i < count; i++)
    {
        pUser = userList->GetItem(i);
        if (!pUser) continue;

        strInfo.Format(_T("A user left the session: name=%s"), pUser->getUserName());
    }
}
```

### Get notified when the host of the session is changed

```cpp
void CExampleListener::onUserHostChanged(IZoomVideoSDKUserHelper* pUserHelper, IZoomVideoSDKUser* pUser)
{
    CString strInfo;
    strInfo.Format(_T("The host of the session is now: name=%s"), pUser->getUserName());
}
```

### Get notified when a password is required to join a session

```cpp
void CExampleListener::onSessionNeedPassword(IZoomVideoSDKPasswordHandler* handler)
{
    // Store password handler.
    m_pPasswordHandler = handler;

    // When ready, call inputSesstionPassword on the handler.
    if (m_pPasswordHandler)
    {
        CString strPassword;
        m_pPswHandler->inputSessionPassword(strPassword.GetBuffer());
    }

    // Or ignore the password request and leave the session with leaveSessionIgnorePassword.
   /* if (m_pPasswordHandler)
    {
        m_pPasswordHandler->leaveSessionIgnorePassword();
    }*/
}
```

### Get notified when a password is wrong when joining a session

```cpp
void CExampleListener::onSessionPasswordWrong(IZoomVideoSDKPasswordHandler* handler)
    // Store password handler.
    m_pPasswordHandler = handler;

    // When ready, call inputSesstionPassword on the handler.
    if (m_pPasswordHandler)
    {
        CString strPassword;
        m_pPswHandler->inputSessionPassword(strPassword.GetBuffer());
    }

    // Or ignore the password request and leave the session with leaveSessionIgnorePassword.
   /* if (m_pPasswordHandler)
    {
        m_pPasswordHandler->leaveSessionIgnorePassword();
    }*/
```

## Get user information

Each user joining a session is assigned an `IZoomVideoSDKUser` to provide access to various user information. This section gives you an overview of user information that you can view and manage.

While in a session, you can retrieve the following information of a user:

-   CustomID
-   Display name (UserName)
-   Video status
-   Audio status
-   Share status
-   Host status
-   Manager status
-   Video Statistics
-   Share Statistics
-   Custom Identity (set on JWT payload)

### Retrieve user

To obtain the `IZoomVideoSDKUser` of the current user, use `getMyself` through `IZoomVideoSDKSession`.

```cpp
// Get local user.
m_pVideoSDK->getSessionInfo()->getMyself();
```

To obtain all of the users in the session, use `getAllUsers`.

```cpp
// Get all users.
m_pVideoSDK->getSessionInfo()->getAllUsers();
```

### Get all users who are not the current user

The user who is currently using this instance of the SDK is referred to as **the local user**. To get a list of all users who are not the local user use this method:

```cpp
// Get all users who are not this user.
IVideoSDKVector<IZoomVideoSDKUser*>* remote_users = session->getRemoteUsers();
```

### Get user's video pipe

A user is tied to an `IZoomVideoSDKRawDataPipe` to render that user's video stream within a session. To obtain the video pipe of a user, use `GetVideoPipe` within `IZoomVideoSDKUser`. To obtain a user's share pipe, get the user's share actions with `getShareActionList`, then call `getSharePipe` on the `IZoomVideoSDKShareAction` you want.

```cpp
// Get the user's video pipe.
m_pUser->GetVideoPipe();

// Get a user's share pipe from their share action list.
IVideoSDKVector<IZoomVideoSDKShareAction*>* pShareActions = m_pUser->getShareActionList();
if (pShareActions && pShareActions->GetCount() > 0) {
    IZoomVideoSDKRawDataPipe* pSharePipe = pShareActions->GetItem(0)->getSharePipe();
}
```

## User roles and actions

People in a session can hold one of the following roles: host, manager, or participant.

### Host

The user with the host [`role_type`](/docs/video-sdk/auth/#payload) is the host of the session.

A **host** of the session has the following **privileges**.

-   View information of users in the session.
-   Change the display name of a user in the session.
-   Mute or unmute a user's audio.
-   Transfer the host role to someone else in the session.
-   Promote another user to be a manager of the session.
-   Remove participants from the session.
-   Revoke manager privilege from a user.
-   Start a live stream.
-   Prevent other users from sharing their screen (lock screen).
-   End the session.

### Manager

The manager or co-host role can be assigned to a participant by the host to help the host to manage the session participants.

A **manager** of the session is assigned the following subset of the **host privileges**.

-   Remove participants from a session.
-   Change the display name of a user in the session.
-   Mute or unmute a user's audio.
-   Prevent other users from sharing their screen (lock screen).

### Participant

A regular user who joins the session without host or manager permission. A participant has **privileges** to view their own information as well as the information of other users.

## Manage users

See below for details on how to manage users.

### Change display name

If you are the host, you can change your display name while in the session using `changeName` within `IZoomVideoSDKUserHelper`. If you are the host or a manager, you may also change the display name of other users:

```cpp
// Change name of user.
IZoomVideoSDKUserHelper* pUserHelper = m_pVideoSDK->getUserHelper();
pUserHelper->changeName(strNewDisplayName, pUser);
```

### Transfer host privilege to another user

The host of a session can transfer the host role to another user by calling `makeHost` within `IZoomVideoSDKUserHelper`.

```cpp
// Check if the current user is the host.
IZoomVideoSDKUser* pLocalUser = m_pVideoSDK->getSessionInfo()->getMyself();
bool localUserIsHost = pLocalUser->isHost();

if (localUserIsHost) {
    // Transfer host privileges to User.
    m_pVideoSDK->getUserHelper()->makeHost(pUser);
}
```

### Assign manager role

Managers can help manage users while in a session. The host can promote a user to be a manager by calling `makeManager` within `IZoomVideoSDKUserHelper`.

```cpp
// Check if the current User is the host.
IZoomVideoSDKUser* pLocalUser = m_pVideoSDK->getSessionInfo()->getMyself();
bool localUserIsHost = pLocalUser->isHost();

if (localUserIsHost) {
    // Make user a manager.
    m_pVideoSDK->getUserHelper()->makeManager(pUser);
}
```

### Revoke manager role

The host can revoke the manager role from a user by calling `revokeManager` within `IZoomVideoSDKUserHelper`.

```cpp
// Check if the current User is the host.
IZoomVideoSDKUser* pLocalUser = m_pVideoSDK->getSessionInfo()->getMyself();
bool localUserIsHost = pLocalUser->isHost();

if (localUserIsHost) {
    // Revoke manager privileges from User.
    m_pVideoSDK->getUserHelper()->revokeManager(pUser);
}
```

### Remove user from a session

Users with either host or manager privilege can remove users from a session using `removeUser` within `IZoomVideoSDKUserHelper`.

```cpp
// Get current user.
IZoomVideoSDKUser* pLocalUser = m_pVideoSDK->getSessionInfo()->getMyself();

// Check if the current User is the host.
bool localUserIsHost = pLocalUser->isHost();
// Check if the current User is a manager.
bool localUserIsAManager = pLocalUser->isManager();

if (localUserIsHost == true || localUserIsAManager == true) {
    // Remove User from session.
    m_pVideoSDK->getUserHelper()->removeUser(pUser);
}
```
