{"id":4411,"date":"2021-11-18T21:18:34","date_gmt":"2021-11-18T13:18:34","guid":{"rendered":"https:\/\/www.enablex.io\/developer\/?page_id=4411"},"modified":"2025-02-21T15:18:26","modified_gmt":"2025-02-21T07:18:26","slug":"room-connection","status":"publish","type":"page","link":"https:\/\/doc.smartflomeet.ttns.in\/developer\/video-api\/client-api\/ios-toolkit\/room-connection\/","title":{"rendered":"Room Connection: iOS SDK &#8211; Video API"},"content":{"rendered":"\n<h4>Table of Contents<\/h4>\n\n\n\n<ul><li><a href=\"#init-room\">Initiate a Room<\/a><\/li><li><a href=\"#connect-room\">Connect to Room<\/a><\/li><li><a href=\"#join-room\">Join a Room with Stream<\/a><\/li><li><a href=\"#disconnect-room\">Disconnect from a Room<\/a><\/li><li><a href=\"#handle-disconnect-reconnect\">Handle Network Disconnection &amp; Reconnection<\/a><\/li><\/ul>\n\n\n\n<a name=\"init-room\"><\/a>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2>Initiate a Room<\/h2>\n\n\n\n<p>An RTC session takes place in a Virtual Room hosted on the portal and the iOS SDK allows the Client endpoint application to connect to it. The process starts with initializing a Room Object using the\u00a0<code>EnxRoom<\/code>\u00a0Class.  <\/p>\n\n\n\n<p><strong>Class<\/strong>: <code>EnxRoom<\/code><\/p>\n\n\n\n<p><strong>Method<\/strong>: <code>-(instancetype)init;<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">EnxRoom *room = [[EnxRoom alloc] init];<\/pre>\n\n\n\n<a name=\"connect-room\"><\/a>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2>Connect to Room<\/h2>\n\n\n\n<p>The\u00a0<code>EnxRoom.connect()<\/code> method\u00a0connects the client application to the virtual Room\u00a0hosted on the\u00a0Video server where the RTC session takes place.\u00a0After initializing the room, the client endpoint must\u00a0connect\u00a0to the\u00a0room to establish a bi-directional communication channel over a\u00a0Web\u00a0Socket.\u00a0\u00a0<\/p>\n\n\n\n<p>As the communication takes place over the\u00a0Web\u00a0Sockets using Socket\u00a0Events, any network issue leading to the disconnection of the Web Sockets would cause the communication to fail. In such cases,\u00a0the platform offers the option\u00a0to Auto-Reconnect.<\/p>\n\n\n\n<p>Note that Auto-Reconnect is not applicable under the following circumstances:<\/p>\n\n\n\n<ul><li>The last participant disconnected from Adhoc Room.<\/li><li>The participant is dropped from the Room by the Moderator.<\/li><li>The user disconnects explicitly.<\/li><\/ul>\n\n\n\n<p><strong>Class<\/strong>: <code>EnxRoom<\/code><\/p>\n\n\n\n<p><strong>Method<\/strong>: <code>- (void)connect:(NSString *)token<\/code> <code>roomInfo:(NSDictionary *)roomInfo<\/code> <code>advanceOptions:(NSArray *)advanceOption;<\/code> <\/p>\n\n\n\n<p><strong>Parameters:<\/strong><\/p>\n\n\n\n<ul><li><code>token<\/code>: String. A JWT Token to connect to the Room as received using Server API Call via Application Server.<\/li><li><code>roomInfo<\/code>\u00a0\u2013 Optional. JSON Object with Reconnection Options. JSON keys are explained below:<ul><li><code>allow_reconnect<\/code>:\u00a0<code>Boolean<\/code>. Default:\u00a0<em>true<\/em>. Set to\u00a0<em>true<\/em>\u00a0to enable Auto-Reconnect feature. When set to\u00a0<em>false<\/em>, the Client endpoint does not try to reconnect to the portal.<\/li><li><code>number_of_attempts<\/code>:\u00a0<code>Numeric<\/code>. Min Value: 1. Max Value: Not specified, use any number. Default: 3. A maximum number of attempts made by the Client endpoint to reconnect to the portal.<\/li><li><code>timeout_interval<\/code>:\u00a0<code>Numeric<\/code>. Timeout Interval in Millisecond required by the Client endpoint to wait before attempting to reconnect.<\/li><li><code>activeviews<\/code>: <code>Enum<\/code>. Values:\u00a0<code>list<\/code>\u00a0or\u00a0<code>view<\/code>. Set to\u00a0<code>view<\/code>\u00a0to get a predefined view of all the video Streams in a session. Set to\u00a0<code>list<\/code>\u00a0to get individual streams to create your own view with the video streams.<\/li><li><code>forceTurn<\/code>: <code>Boolean<\/code>. Default: <em>false<\/em>. Set to <em>true<\/em> to force Video Streams through a TURN Server.<\/li><li><code>chat_only<\/code>: <code>Boolean<\/code>. Default: <em>false<\/em>. Set to <em>true<\/em> to enable only text-chat and disable audio-video communications.<\/li><li><code>playerConfiguration: <\/code>JSON Object with Video Player Configurations.<ul><li><code>audiomute: Boolean<\/code>. Default: <em>true<\/em>. Set to\u00a0<em>true<\/em>\u00a0to show and\u00a0<em>false<\/em>\u00a0to hide the Audio Mute\/Unmute button.<\/li><li><code>videomute:<\/code> <code>Boolean<\/code>. Default: <em>true<\/em>. Set to\u00a0<em>true<\/em>\u00a0to show and\u00a0<em>false<\/em>\u00a0to hide the Video Mute\/Unmute button.<\/li><li><code>bandwidth:<\/code> <code>Boolean<\/code>. Default: <em>true<\/em>. Set to\u00a0<em>true<\/em>\u00a0to show and\u00a0<em>false<\/em>\u00a0hide the Low-Bandwidth notification button.<\/li><li><code>screenshot:<\/code> <code>Boolean<\/code>. Default: <em>true<\/em>. Set to\u00a0<em>true<\/em>\u00a0to show and\u00a0<em>false<\/em>\u00a0to hide the Screenshot button.<\/li><li><code>avatar:<\/code> <code>Boolean<\/code>. Default: <em>true<\/em>. Set\u00a0<em>true<\/em>\u00a0to show and\u00a0<em>false<\/em>\u00a0to hide Avatar for No-Video Stream.<\/li><li><code>iconColor: String<\/code>. Default #FFFFFF. HEX color code for icons.<\/li><li><code>iconHeight: Number<\/code>. Default 30. Icon height in pixel.<\/li><li><code>iconWidth: Number<\/code>. Default 30. Icon width in pixel.<\/li><li><code>avatarHeight: Number<\/code>. Default 200. Avatar height in pixel.<\/li><li><code>avatarWidth: Number<\/code>. Default 200. Avatar width in pixel.<\/li><li><code>pinned: Boolean<\/code>. Default: <em>false<\/em>. Set to <em>true<\/em> to show pinned user icon.<\/li><\/ul><\/li><\/ul><\/li><li><code>advanceOptions<\/code>\u00a0\u2013 Optional. Array of Advanced Options. Each element of the array consists of a key-value pair as given below:<ul><li><code>battery_updates<\/code>:\u00a0<code>Boolean<\/code>. Set to\u00a0<em>true\u00a0<\/em>to enable Auto-Battery Updates feature.<\/li><li><code>notify-video-resolution-change<\/code>:\u00a0<code>Boolean<\/code>. Set\u00a0to\u00a0<em>true<\/em>\u00a0to enable Video Resolution Change Notification feature.<\/li><\/ul><\/li><\/ul>\n\n\n\n<p><strong>Delegate Methods<\/strong>:<\/p>\n\n\n\n<ul><li><code>- room:didConnect:<\/code>&nbsp; &#8211; Acknowledgment to the Client endpoint when it gets connected to the Room.<\/li><li><code>- room:didError:<\/code>&#8211; Acknowledgment to the Client endpoint when it fails to connect to the Room.<\/li><li><code>- room:userDidJoined:<\/code> &#8211; Notification to everyone in the Room when a new user is connected to the Room.<\/li><li>&#8211; <code>room:didRoomAwaited<\/code>\u2013 Notification to the Client endpoint when it awaits the Moderator\u2019s permission to enter a Knock-enabled Room or awaits the Moderator to enter the Room first in a Wait-for-Moderator enabled Room. The event\u2019s JSON structure provides information on whether the Room is Knock-enabled&nbsp;<code>{ \"event_type\": \"knock\" }<\/code>&nbsp;or Wait-for-Moderator enabled&nbsp;<code>{ \"event_type\": \"wait_for_moderator\" }<\/code>.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">NSString *token = \"XXX\";\nNSDictionary *roomInfo = { \/\/ Re-Connect Options\n @\"allow_reconnect\": true,\n @\"number_of_attempts\": 3,\n @\"timeout_interval\": 10000,\n @\"audio_only\": false\n}; \n\nNSDictionary *advanceDict= @{\n @\"id\":@\"battery_updates\",\n @\"enable\":@YES\n};\n\nNSMutableArray *advanceOptionArray = [[NSMutableArray alloc] init];\n\n[advanceOptionArray addObject:advanceDict];\n\nadvanceDict= @{\n @\"id\":@\"notify-video-resolution-change\",\n @\"enable\":@YES\n};\n\n[advanceOptionArray addObject:advanceDict]; \n\n\/\/ Initiates Room \nEnxRoom *room = [[EnxRoom alloc] init];\n\n\/\/ Connects with Re-Connection &amp; Advance Options\n[room connect:token roomInfo:roomInfo advanceOptions:advanveOptionArray ];\n \n\n\/\/Delegate methods\n-(void)room:(EnxRoom *)room didConnect:(NSDictionary *)roomMetadata{\n      \/\/ Connected. Delegate receives room instance and Room Meta JSON.\n}\n\n-(void)room:(EnxRoom *)room didError:(NSString *)reason{\n \/\/ Connection failed. Find error\n}\n\n-(void)room:(EnxRoom *)room userDidJoined:(NSArray *)Data{\n \/\/ A new user connected. user JSON has user information\n}\n\n-(void)room:(EnxRoom *)room didActiveTalkerList:(NSArray *)Data{\n      \/\/ List of talkers in the Room\n      \/\/ Received after room connected.\n}<\/pre>\n\n\n\n<p><strong>Error Codes \/ Exceptions:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Code <\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>5086<\/td><td>Unable to Connect to Room.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<a name=\"join-room\"><\/a>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2>Join a Room with Stream<\/h2>\n\n\n\n<p>A typical process to connect to a room is as&nbsp;follows:&nbsp;<\/p>\n\n\n\n<ol><li>Initiate a room and connect to it.&nbsp;<\/li><li>Initiate streaming after connecting which requires you to check media accessibility.<\/li><li>Publish local stream.<\/li><li>Check if&nbsp;the&nbsp;stream is successfully published.&nbsp;<\/li><\/ol>\n\n\n\n<p>To successfully join a Room, you need to ensure the success of each step before proceeding to the next thus making it a complex process. <\/p>\n\n\n\n<p>The <code>EnxRtc.joinRoom()<\/code> method allows you to quickly join a room and get started without having to follow the&nbsp;above&nbsp;procedure step by step. <\/p>\n\n\n\n<p><strong>Class<\/strong>: <code>EnxRtc<\/code><\/p>\n\n\n\n<p><strong>Method<\/strong>: <code>-(EnxStream *)joinRoom:(NSString *)token<\/code> <code>delegate:(id)delegate PublishStreamInfo:<\/code> <code>(NSDictionary *)publishStreamInfo; <\/code><\/p>\n\n\n\n<p><strong>Parameters<\/strong>: <\/p>\n\n\n\n<ul><li><code>token <\/code>&#8211; String. A JWT Token to connect to the Room as received using Server API Call via Application Server.<\/li><li><code>delegate<\/code>:  EnxRoomDelegate object is the delegate for the EnxRoom object.<\/li><li><code>publishStreamInfo<\/code>&#8211; Optional. <a href=\"..\/..\/appendix\/#stream-options\">Stream Initialization Meta Info<\/a>. <\/li><\/ul>\n\n\n\n<p><strong>Returns<\/strong>:  <code>EnxStream <\/code>&#8211; Published Local Stream JSON Object.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">NSDictionary* publishStreamInfo = {\n         video: true,\n         audio: true,\n         data: true,\n         attributes: { name: \"XX\" }\n}\n\nNSString* token = \"XXX\";\n\nEnxRtc *enxRtc = [[EnxRtc alloc] init];\nEnxStream *localStream = [enxRtc joinRoom:token delegate:self publishStreamInfo:publishStreamInfo];\n\n\/\/Delegate methods\n-(void)room:(EnxRoom *)room didConnect:(NSDictionary *)roomMetadata{\n\t\/\/ Connected. Delegate receives room instance and Room Meta JSON.\n}\n\n-(void)room:(EnxRoom *)room didError:(NSString *)reason{\n\t\/\/ Connection failed. Find error\n}\n<\/pre>\n\n\n\n<a name=\"disconnect-room\"><\/a>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2>Disconnect from a Room<\/h2>\n\n\n\n<p>The <code>EnxRoom.disconnect()<\/code> method&nbsp;is used to close the session and&nbsp;disconnect&nbsp;the client endpoint from the&nbsp;Room. The&nbsp;media and&nbsp;signaling&nbsp;sockets are also released in this process.&nbsp;&nbsp;<\/p>\n\n\n\n<p><strong>Class<\/strong>: <code>EnxRoom<\/code> <\/p>\n\n\n\n<p><strong>Method<\/strong>: <code>- (void)disconnect; <\/code><\/p>\n\n\n\n<p><strong>Delegate Methods<\/strong>:<\/p>\n\n\n\n<ul><li><code>\u2013room:didRoomDisconnect: <\/code>&#8211; Acknowledgment to the user when disconnected. The Callback allows you to update the UI of the user post disconnect.<\/li><li><code>\u2013room:userDidDisconnected: <\/code>&#8211; Notification to everyone in the Room when a user gets disconnected. The Callback allows you to update the UI of other connected users.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">[room disconnect];\n\n- (void)room:(EnxRoom *)room didRoomDisconnect:(NSArray * _Nullable)response {\n    \/\/ You are disconnected\n}\n-(void)room:(EnxRoom *)room userDidDisconnected:(NSArray *)Data{\n     \/\/ A user is disconnected\n     \/\/ Data - User Information of disconnected user\n}<\/pre>\n\n\n\n<p><strong>Error Codes \/ Exceptions<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Code<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>5031<\/td><td>Repeated disconnect() call made while previous disconnection request is in process.<\/td><\/tr><tr><td>5032<\/td><td>When the user tries to disconnect after getting disconnected from the Room.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<a name=\"handle-disconnect-reconnect\"><\/a>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2>Handle Disconnection &amp; Reconnection<\/h2>\n\n\n\n<p>A Client endpoint is connected with the portal over Secured Web Socket, which is susceptible to network failures. The Client endpoint is notified of the failure through the following Callbacks:<\/p>\n\n\n\n<p><strong>Delegate Methods:<\/strong><\/p>\n\n\n\n<ul><li><code>- room:didConnectionLost:<\/code> \u2013 Notification to the Client endpoint when the endpoint loses network connection.<\/li><li><code>- room:didConnectionInterrupted: <\/code>\u2013 Notification to the Client endpoint when the connection is interrupted e.g Switch from WiFi to 4G and vice versa.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">- (void)room:(EnxRoom*)room didConnectionLost:(NSArray*)data {\n\t\/\/ Disconnected. Handle UI \n} \n\n- (void)room:(EnxRoom*)room didConnectionInterrupted:(NSArray*)data{\n\t\/\/ Interrupted. Handle UI \n}<\/pre>\n\n\n\n<p>For disconnected endpoints, The portal provides\u00a0<strong>Auto-Reconnection<\/strong>\u00a0functionality to ensure a better user experience. To use the Auto-Reconnection feature, you must <a rel=\"noreferrer noopener\" href=\"#connect-room\" data-type=\"internal\" data-id=\"#connect-room\" target=\"_blank\">Connect to Room with Reconnection options.<\/a> Note that Auto-Reconnect is not applicable under the following circumstances:<\/p>\n\n\n\n<ol id=\"block-537a7084-cca4-4018-b007-3c9732f0cee5\"><li>The last participant disconnected from Adhoc Room.<\/li><li>The participant is dropped from the Room by the Moderator.<\/li><li>The user disconnects explicitly.<\/li><\/ol>\n\n\n\n<p><strong>Delegate Methods:<\/strong><\/p>\n\n\n\n<ul><li><code>- room:didUserReconnectSuccess:<\/code>\u2013 Notification to the user when the Client endpoint successfully gets reconnected with the portal.<\/li><li><code>- room:didReconnect: <\/code>\u2013 Notification to the user when the Client endpoint attempts to reconnect within the given time period. <\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/To receive and handle reconnection events, \n\/\/ you need to pass an argument called roomInfo (its is an optional parameter) while connecting to the room through the room api - joinRoom() or connect(). For example,\n\nNSDictionary *roomInfo = { \n\t@\"allow_reconnect\": true,\n\t@\"number_of_attempts\": 3,\n\t@\"timeout_interval\": 10000,\n\t@\"audio_only\": false\n}; \n\n\/\/This will helps the end-point user to auto-reconnect to the same room.\n\nNSDictionary *advanceDict= @{\n\t@\"id\":@\"battery_updates\",\n\t@\"enable\":@YES\n};\n\nNSMutableArray *advanceOptionArray = [[NSMutableArray alloc] init];\n\n[advanceOptionArray addObject:advanceDict];\n\nadvanceDict= @{\n\t@\"id\":@\"notify-video-resolution-change\",\n\t@\"enable\":@YES\n};\n\n[advanceOptionArray addObject:advanceDict]; \n\n\n-(void)room:(EnxRoom*)room didUserReconnectSuccess:(NSDictionary*)data{\n\t\/\/ Got reconnected\n}\n\n- (void)room:(EnxRoom *)room didReconnect:(NSString *)reason{\n\t\/\/ Reconnecting \n}<\/pre>\n\n\n\n<p><strong>Error Codes \/ Exceptions:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Code<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>5073<\/td><td>Connection is switched to the current network.<\/td><\/tr><tr><td>5074<\/td><td>Network disconnected.  Reconnection attempt timed-out.<\/td><\/tr><tr><td>5086<\/td><td>When any method is called while the Room is not connected.<\/td><\/tr><tr><td>5087<\/td><td>Reconnection failed.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<p>\u2190 <a href=\"..\/local-stream\/\"><\/a><a href=\"\/developer\/video-api\/client-api\/ios-toolkit\/local-stream\/\">Create Local Stream<\/a><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column\">\n<p class=\"has-text-align-center\"><a href=\"..\/\">Index<\/a><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column\">\n<p class=\"has-text-align-right\"><a href=\"..\/video-quality-adaption\/\"><\/a><a href=\"\/developer\/video-api\/client-api\/ios-toolkit\/video-quality-adaption\/\"><\/a><a href=\"\/developer\/video-api\/client-api\/ios-toolkit\/video-quality-adaption\/\">Quality Adjustment based on available Bandwidth<\/a> \u2192<a href=\"\/developer\/how-to-use\/\"><\/a><\/p>\n<\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Table of Contents Initiate a Room Connect to Room Join a Room with Stream Disconnect from a Room Handle Network Disconnection &amp; Reconnection Initiate a Room An RTC session takes place in a Virtual Room hosted on the portal and the iOS SDK allows the Client endpoint application to connect to it. The process starts with initializing a Room Object using the\u00a0EnxRoom\u00a0Class. Class: EnxRoom Method: -(instancetype)init; EnxRoom *room = [[EnxRoom&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3732,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"ub_ctt_via":""},"featured_image_src":null,"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"featured":false,"featured-large":false},"uagb_author_info":{"display_name":"vcxdevwpadmin","author_link":"https:\/\/doc.smartflomeet.ttns.in\/developer\/author\/vcxdevwpadmin\/"},"uagb_comment_info":0,"uagb_excerpt":"Table of Contents Initiate a Room Connect to Room Join a Room with Stream Disconnect from a Room Handle Network Disconnection &amp; Reconnection Initiate a Room An RTC session takes place in a Virtual Room hosted on the portal and the iOS SDK allows the Client endpoint application to connect to it. The process starts&hellip;","_links":{"self":[{"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages\/4411"}],"collection":[{"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/comments?post=4411"}],"version-history":[{"count":0,"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages\/4411\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages\/3732"}],"wp:attachment":[{"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/media?parent=4411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}