{"id":4094,"date":"2021-11-08T17:41:08","date_gmt":"2021-11-08T09:41:08","guid":{"rendered":"https:\/\/www.enablex.io\/developer\/?page_id=4094"},"modified":"2022-02-01T13:43:54","modified_gmt":"2022-02-01T05:43:54","slug":"publishing-local-stream","status":"publish","type":"page","link":"https:\/\/doc.smartflomeet.ttns.in\/developer\/video-api\/client-api\/web-toolkit\/publishing-local-stream\/","title":{"rendered":"Publishing Local Stream: Web SDK &#8211; Video API"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\"><p>Its important to publish your Media Stream into the Room for all others connected users to see and communicate with you. You may have a choice to continue publishing your stream until you exit or you  may unpublish and re-publish your Media Stream multiple times within the same session if so desired.<\/p><\/blockquote>\n\n\n\n<p>After initializing the stream, you&nbsp;need to&nbsp;publish it in the room&nbsp;so that the other users&nbsp;in the room&nbsp;can see and hear the user.&nbsp; The methods to publish, unpublish, and close a local stream are explained in this section.<\/p>\n\n\n\n<a name=\"toc\"><\/a>\n\n\n\n<h4>Table of Contents<\/h4>\n\n\n\n<ul id=\"block-a83baf6c-c8cf-4e0d-b11c-e003e75bf799\"><li><a href=\"#publish-stream\">Publish Stream<\/a><\/li><li><a href=\"#unpublish-stream\">Unpublish Stream<\/a><\/li><li><a href=\"#close-stream\">Close Stream<\/a><\/li><\/ul>\n\n\n\n<a name=\"publish-stream\"><\/a>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3>Publish Local Stream<\/h3>\n\n\n\n<p>The<code>&nbsp;EnxRoom.publish()<\/code> method&nbsp;publishes&nbsp;a local stream&nbsp;in&nbsp;the connected room.&nbsp;<\/p>\n\n\n\n<p><strong>Method<\/strong>: <code>EnxRoom.publish(LocalStream, PublishOpt, Callback)<\/code><\/p>\n\n\n\n<p><strong>Parameters<\/strong>: <\/p>\n\n\n\n<ul><li><code>LocalStream <\/code>&#8211; Initiated Stream Object.<\/li><li><code>PublishOpt <\/code>&#8211; Configurable options for publishing.<\/li><\/ul>\n\n\n\n<p><strong>Notification Events:<\/strong><\/p>\n\n\n\n<ul><li><code>stream-added<\/code> &#8211; Notification to everyone in the Room when a new stream is published in the Room.<\/li><li><code>stream-failed<\/code> &#8211; Notification to the Stream publisher when stream publishing fails.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ Configure Optional Publishing Options\nvar PublishOpt = {\n     \"minVideoBW\":\"Number\",  \n     \"maxVideoBW\": \"Number\" \n};\n\nroom.publish(localStream, PublishOpt, function(StreamId) {\n});\n\n\/\/ New Stream in Room Notification\nroom.addEventListener(\"stream-added\", function(event) {\n     if (localStream.getID() === event.stream.getID()) {\n         \/\/ Your stream published\n     } else {\n         \/\/ Someone else has published\n     }\n});\n\nroom.addEventListener(\"stream-failed\", function(event) {\n     \/\/ Failed to publish\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>1170<\/td><td>The feature is not enabled because of room configuration or lack of license.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<a name=\"unpublish-stream\"><\/a>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3>Unpublish Local Stream<\/h3>\n\n\n\n<p>The&nbsp;<code>EnxRoom.unpublish()<\/code>&nbsp;method&nbsp;disconnects the local stream from the room.&nbsp;Unpublishing a stream does not release the device access&nbsp;so that subsequent republishing does not require device-access-permission.&nbsp;&nbsp;<\/p>\n\n\n\n<p><strong>Method<\/strong>: <code>EnxRoom.unpublish(localStream, Callback) <\/code><\/p>\n\n\n\n<p><strong>Parameters<\/strong>: <\/p>\n\n\n\n<p><code>localStream<\/code> &#8211; Local Stream Object to be unpublished. <\/p>\n\n\n\n<p><strong>Notification:<\/strong> <\/p>\n\n\n\n<p><code>stream-removed<\/code> &#8211; Notification to everyone in the Room when a Stream is removed from the Room.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">room.unpublish(localStream, function(result, error) {\n    if (result === undefined) {\n        \/\/ Failed       \n     } else {\n        \/\/ Unpublished      \n     }  \n});  <\/pre>\n\n\n\n<a name=\"close-stream\"><\/a>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3>Close Local Stream<\/h3>\n\n\n\n<p>The <code>EnxStream.close()<\/code> method allows you to disconnect the local Stream from the Room similar to the&nbsp;unpublishing process. Closing the Stream leads to the following:<\/p>\n\n\n\n<ul><li>If stream has audio and video tracks, it stops capturing media stream from camera &amp; microphone.<\/li><li>If the stream is published into the room, it unpublishes the stream.<\/li><li>If the stream is being played in Player, it stops playing.<\/li><\/ul>\n\n\n\n<p><strong>Class:<\/strong> <code>EnxStream<\/code><\/p>\n\n\n\n<p><strong>Method:<\/strong> <code>EnxStream.close()<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">localStream.close();<\/pre>\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=\"..\/video-quality-adaption\/\">Quality Adaption with Bandwidth<\/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=\"..\/switch-camera-mic-speaker\/\">Switch Camera, Mic, Speaker<\/a>  \u2192 <\/p>\n<\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Its important to publish your Media Stream into the Room for all others connected users to see and communicate with you. You may have a choice to continue publishing your stream until you exit or you may unpublish and re-publish your Media Stream multiple times within the same session if so desired. After initializing the stream, you&nbsp;need to&nbsp;publish it in the room&nbsp;so that the other users&nbsp;in the room&nbsp;can see and&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3724,"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":"Its important to publish your Media Stream into the Room for all others connected users to see and communicate with you. You may have a choice to continue publishing your stream until you exit or you may unpublish and re-publish your Media Stream multiple times within the same session if so desired. After initializing the&hellip;","_links":{"self":[{"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages\/4094"}],"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=4094"}],"version-history":[{"count":0,"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages\/4094\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages\/3724"}],"wp:attachment":[{"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/media?parent=4094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}