Sessions
A session is the most fundamental building block of the Video SDK. 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. Optionally, you can also include features such as chat and screen sharing in a session.
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. 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 SDK JWT as shown below.
Create a SessionContext object
let sessionContext = ZoomVideoSDKSessionContext()
// Ensure that you do not hard code JWT or any other confidential credentials in your production app.
sessionContext.token = "Your jwt"
sessionContext.sessionName = "Your session name"
sessionContext.userName = "Your name"
sessionContext.sessionPassword = "Your session password"
if let session = ZoomVideoSDK.shareInstance()?.joinSession(sessionContext) {
// Session joined successfully.
}
ZoomVideoSDKSessionContext *sessionContext = [[ZoomVideoSDKSessionContext alloc] init];
// Ensure that you do not hard code JWT or any other confidential credentials in your production app.
sessionContext.token = @"Your jwt";
sessionContext.sessionName = @"Your session name";
sessionContext.userName = @"Your name";
sessionContext.sessionPassword = @"Your session password";
ZoomVideoSDKSession *session = [[ZoomVideoSDK shareInstance] joinSession:sessionContext];
if (session) {
// Session joined successfully.
}
The following table describes all the properties of the sessionContext 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. |
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. See Authorize for details. |
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 ZoomVideoSDKAudioOptions. |
videoOption | No | Configure video settings by storing values in ZoomVideoSDKVideoOptions. |
Prior to joining a session, ensure that you have set up a delegate for callback events by conforming your class to the ZoomVideoSDKDelegate protocol and using ZoomVideoSDK.shareInstance()?.delegate = self or [ZoomVideoSDK shareInstance].delegate = self. To successfully monitor events related to a session, you will need to use some important callback functions.
Once you have your context and delegate set up, call the joinSession() method to join a session.
if let session = ZoomVideoSDK.shareInstance()?.joinSession(sessionContext) {
// Session joined successfully.
}
ZoomVideoSDKSession *session = [[ZoomVideoSDK shareInstance] joinSession:sessionContext];
if (session) {
// Session joined successfully.
}
Note that the return value of the joinSession() method will return the session upon success, and nil upon failure.
To retrieve further information about the joinSession attempt, you must listen for specific callbacks, some of which may require user interaction.
Leave a Session
When you are ready to leave the session, you must call the leaveSession() method and indicate whether or not you would like to end the session for everyone if you are the host of the session.
// A value of true will end the session if you are the host
ZoomVideoSDK.shareInstance()?.leaveSession(shouldEndSession)
// A value of true will end the session if you are the host
[[ZoomVideoSDK shareInstance] leaveSession:shouldEndSession];
Get user information
Each user joining a session is represented by an instance of the ZoomVideoSDKUser object. While in a session, you can retrieve the following information for a user:
- User ID
- Display name
- Custom User ID (set on JWT payload)
- Host and manager status
- Video, audio, and screen sharing status
- Video and screen sharing statistics, raw data, and canvas
See the ZoomVideoSDKUser class reference for details.
Get the current user
The user who is currently using this instance of the SDK is referred to as the local user. Use the getMySelf method to get the local user.
// Get local User.
ZoomVideoSDK.shareInstance()?.getSession()?.getMySelf()
// Get local User.
[[[ZoomVideoSDK shareInstance] getSession] getMySelf];
Get all users except the current user
Use the getRemoteUsers method to get a list of all users who are not the local user.
// Get all users who are not this user.
let remoteUsers = ZoomVideoSDK.shareInstance()?.getSession()?.getRemoteUsers()
// Get all users who are not this user.
NSArray *remoteUsers = [[[ZoomVideoSDK shareInstance] getSession] getRemoteUsers];
Get user's video canvas
A user's ZoomVideoSDKVideoCanvas is used to render the user's video stream within a session. To obtain the video canvas of a user, use getVideoCanvas within ZoomVideoSDKUser.
// Get user's video canvas.
user.getVideoCanvas()
// Get user's video canvas.
[user getVideoCanvas];
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 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, use the the changeName method to change your display name while in the session. If you are the host or manager, you may also change the display name of other users. See the examples below for details.
// Change name of User.
ZoomVideoSDK.shareInstance()?.getUserHelper().changeName(newName, with: user)
// Change name of User.
[[[ZoomVideoSDK shareInstance] getUserHelper] changeName:newName withUser:user];
Transfer host privilege to another user
When needed, the host of a session can call the makeHost function to transfer the host role to another user.
// Check if the current User is the host.
if let localUser = ZoomVideoSDK.shareInstance()?.getSession()?.getMySelf(),
localUser.isHost() {
// Transfer host privileges to User.
ZoomVideoSDK.shareInstance()?.getUserHelper().makeHost(user)
}
// Check if the current User is the host.
BOOL localUserIsHost = [[[[ZoomVideoSDK shareInstance] getSession] getMySelf] isHost];
if (localUserIsHost) {
// Transfer host privileges to User.
[[[ZoomVideoSDK shareInstance] getUserHelper] makeHost:user];
}
Assign manager role
Managers can help manage users while in a session. The host can call the makeManager method to promote a user to a manager.
// Check if the current User is the host.
if let localUser = ZoomVideoSDK.shareInstance()?.getSession()?.getMySelf(),
localUser.isHost() {
// Make User a manager.
ZoomVideoSDK.shareInstance()?.getUserHelper().makeManager(user)
}
// Check if the current User is the host.
BOOL localUserIsHost = [[[[ZoomVideoSDK shareInstance] getSession] getMySelf] isHost];
if (localUserIsHost) {
// Make User a manager.
[[[ZoomVideoSDK shareInstance] getUserHelper] makeManager:user];
}
Revoke manager role
The host can call revokeManager method to revoke the manager role from a user.
// Check if the current User is the host.
if let localUser = ZoomVideoSDK.shareInstance()?.getSession()?.getMySelf(),
localUser.isHost() {
// Revoke manager privileges from User.
ZoomVideoSDK.shareInstance()?.getUserHelper().revokeManager(user)
}
// Check if the current User is the host.
BOOL localUserIsHost = [[[[ZoomVideoSDK shareInstance] getSession] getMySelf] isHost];
if (localUserIsHost) {
// Revoke manager privileges from User.
[[[ZoomVideoSDK shareInstance] getUserHelper] revokeManager:user];
}
Remove user from a session
Users with either host or manager privilege can use the removeUser method within ZoomVideoSDKUserHelper to remove users from a session.
// Get current User.
if let localUser = ZoomVideoSDK.shareInstance()?.getSession()?.getMySelf() {
// Check if the current User is the host or a manager.
if localUser.isHost() || localUser.isManager() {
// Remove User from session.
ZoomVideoSDK.shareInstance()?.getUserHelper().remove(user)
}
}
// Get current User.
ZoomVideoSDKUser *localUser = [[[ZoomVideoSDK shareInstance] getSession] getMySelf];
// Check if the current User is the host.
BOOL localUserIsHost = [localUser isHost];
// Check if the current User is a manager.
BOOL localUserIsAManager = [localUser isManager];
if (localUserIsHost || localUserIsAManager) {
// Remove User from session.
[[[ZoomVideoSDK shareInstance] getUserHelper] removeUser:user];
}
Callbacks
All of these callbacks can be found within your ZoomVideoSDKDelegate implementation.
onSessionJoin: Called when current user has joined the session.onSessionLeave: Called when current user has left the session.onError: Called when the ZoomVideoSDK raises an error. For example, failure to join a session, network timeouts, etc. The error: Errors_Success (rawValue: 0) represents a successful callback without errors.onUserJoin: Called when any user joins the session. Helper is provided to provide user-related functionality.UserArrayrepresents the updated array of user IDs of users who have joined the session.onUserLeave: Called when any user joins the session.UserArrayrepresents the updated array of user IDs of users who have left the session.onSessionNeedPassword: Called when attempting to join a session that requires a password, but no password was provided. A completion parameter is provided to retry the join. Use completion when you would like to retry joining the session. Inside of the completion parameter, there is a field for the password and a Bool which when set to true will cancel the attempt to join the session and will ignore the password.onSessionPasswordWrongCalled when attempting to join a session that requires a password, but the provided password was incorrect. completion is provided to retry the join. Call completion when you would like to retry joining the session. Inside of the completion parameters is a field for the updated password and a Bool that when set to true will cancel the attempt to join the session and will ignore the password.
See Integrate for more details on how to add a listener delegate. See the following sections for examples.
Retrieve user information
The ZoomVideoSDKUserHelper helps with retrieval of user information associated with users as they join a session. To be notified when users join a session, use the onUserJoin callback within ZoomVideoSDKDelegate:
func onUserJoin(_ helper: ZoomVideoSDKUserHelper?, users userArray: [ZoomVideoSDKUser]?) {
// UserArray contains the new users.
// Use helper to perform actions on a user.
if let userArray = userArray {
for user in userArray {
print(user)
}
}
}
- (void)onUserJoin:(ZoomVideoSDKUserHelper *)helper users:(NSArray<ZoomVideoSDKUser *> *)userArray {
// UserArray contains the new users.
// Use helper to perform actions on a user.
for (int i = 0; i < userArray.count; i++) {
NSLog(@"%@", userArray[i]);
}
}
If you have not already implemented a listener for the callback events, see Integrate for details.
Get notified when a local user successfully joins or leaves a session
func onSessionJoin() {
// You have successfully joined the session.
return
}
func onSessionLeave() {
// You have successfully left the session.
return
}
- (void)onSessionJoin {
// You have successfully joined the session
}
- (void)onSessionLeave {
// You have successfully left the session
}
Get notified when other users successfully join or leave a session
func onUserJoin(_ helper: ZoomVideoSDKUserHelper?, users userArray: [ZoomVideoSDKUser]?) {
// UserArray contains the new users.
// Use helper to perform actions on a user.
if let userArray = userArray {
for user in userArray {
print(user)
}
}
}
func onUserLeave(_ helper: ZoomVideoSDKUserHelper?, users userArray: [ZoomVideoSDKUser]?) {
// UserArray contains the users that recently left.
// Use helper to perform actions on a user.
if let userArray = userArray {
for user in userArray {
print(user)
}
}
}
- (void)onUserJoin:(ZoomVideoSDKUserHelper *)helper users:(NSArray<ZoomVideoSDKUser *> *)userArray {
// UserArray contains the new users.
// Use helper to perform actions on a user.
for (int i = 0; i < userArray.count; i++) {
NSLog(@"%@", userArray[i]);
}
}
- (void)onUserLeave:(ZoomVideoSDKUserHelper *)helper users:(NSArray<ZoomVideoSDKUser *> *)userArray {
// UserArray contains the users that recently left.
// Use helper to perform actions on a user.
for (int i = 0; i < userArray.count; i++) {
NSLog(@"%@", userArray[i]);
}
}
Get notified when the host of the session changes
func onUserHostChanged(_ helper: ZoomVideoSDKUserHelper?, users user: ZoomVideoSDKUser?) {
// User is the new host of the session.
// Use helper to perform actions on a user.
if let userName = user?.getName() {
print("\\(userName): is the new host.")
}
}
- (void)onUserHostChanged:(ZoomVideoSDKUserHelper *)helper users:(ZoomVideoSDKUser *)user {
// User is the new host of the session.
// Use helper to perform actions on a user.
if (user.getUserName)
NSLog(@"%@: is the new host.", user.getUserName);
}
Get notified when a session requires password to join
func onSessionNeedPassword(_ completion: ((String?, Bool) -> ZoomVideoSDKERROR)? = nil) {
// Recommended action: prompt user to enter password again and pass user input into completion
if let completion = completion {
let userInput = "Password"
let cancelJoinSession = false
let completionReturnValue = completion(userInput, cancelJoinSession)
}
// Alternatively, you may abandon the attempt to join the session
// let userInput = nil
// let cancelJoinSession = true
// let completionReturnValue = completion(userInput, cancelJoinSession)
// print("Completion return value code: \(completionReturnValue)")
}
- (void)onSessionNeedPassword:(ZoomVideoSDKERROR (^)(NSString *, BOOL))completion {
// Recommended action: prompt user to enter password again and pass user input into completion
NSString *userInput = @"Password";
Boolean cancelJoinSession = NO;
if (completion) {
completion(userInput, cancelJoinSession);
}
// Alternatively, you may abandon the attempt to join the session
NSString *userInput = NULL;
Boolean cancelJoinSession = YES;
if (completion) {
completion(userInput, cancelJoinSession);
}
}
Get notified when a wrong password is entered while joining a session
func onSessionPasswordWrong(_ completion: ((String?, Bool) -> ZoomVideoSDKERROR)? = nil) {
// Recommended action: prompt user to enter password again and pass user input into completion
if let completion = completion {
let userInput = "Password"
let cancelJoinSession = false
let completionReturnValue = completion(userInput, cancelJoinSession)
}
// Alternatively, you may abandon the attempt to join the session
// let userInput = nil
// let cancelJoinSession = true
// let completionReturnValue = completion(userInput, cancelJoinSession)
// print("Completion return value code: \(completionReturnValue)")
}
- (void)onSessionPasswordWrong:(ZoomVideoSDKERROR (^)(NSString *, BOOL))completion {
// Recommended action: prompt user to enter password again and pass user input into completion
NSString *userInput = @"Password";
Boolean cancelJoinSession = NO;
if (completion) {
completion(userInput, cancelJoinSession);
}
// Alternatively, you may abandon the attempt to join the session
NSString *userInput = NULL;
Boolean cancelJoinSession = YES;
if (completion) {
completion(userInput, cancelJoinSession);
}
}