{"id":4219,"date":"2021-11-11T19:36:07","date_gmt":"2021-11-11T11:36:07","guid":{"rendered":"https:\/\/www.enablex.io\/developer\/?page_id=4219"},"modified":"2022-04-07T19:14:33","modified_gmt":"2022-04-07T11:14:33","slug":"canvas-streaming","status":"publish","type":"page","link":"https:\/\/doc.smartflomeet.ttns.in\/developer\/video-api\/client-api\/android-toolkit\/canvas-streaming\/","title":{"rendered":"Canvas Streaming: Android SDK &#8211; Video API"},"content":{"rendered":"\n<p>Canvas Streaming allows you to publish any view into the Room. To support Canvas Streaming in the Room, you need to enable canvas during <a rel=\"noreferrer noopener\" href=\"https:\/\/www.enablex.io\/developer\/video-api\/server-api\/rooms-route\/#create-room\" target=\"_blank\">Room Creation<\/a> by setting: <code>{ canvas: true; }}<\/code>&nbsp;in the JSON Payload.<\/p>\n\n\n\n<h4>Table of Contents<\/h4>\n\n\n\n<ul><li><a href=\"#start-canvas-streaming\">Start Canvas Streaming<\/a><\/li><li><a href=\"#stop-canvas-streaming\">Stop Canvas Streaming <\/a><\/li><li><a href=\"#play-canvas-streaming\">Receive &amp; Play Canvas Streams<\/a><\/li><li><a href=\"#force-stop-share\">Force Stop Canvas Streaming<\/a><\/li><\/ul>\n\n\n\n<a name=\"start-canvas-streaming\"><\/a>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3>Start Canvas Streaming<\/h3>\n\n\n\n<p>The&nbsp;<code>EnxRoom.startCanvas()<\/code>&nbsp;method is used to start canvas streaming.<\/p>\n\n\n\n<p><strong>Class:<\/strong> EnxRoom<\/p>\n\n\n\n<p><strong>Method<\/strong>:&nbsp;<code>public void startCanvas(View view)<\/code><\/p>\n\n\n\n<p><strong>Parameter:<\/strong><\/p>\n\n\n\n<p><code>View:<\/code>&nbsp;The View to be used for Canvas Streaming.<\/p>\n\n\n\n<p><strong>Callbacks<\/strong>:<\/p>\n\n\n\n<ul><li><code>onStartCanvasAck<\/code>&nbsp;\u2013 Acknowledgment to the publisher when Canvas Streaming starts.<\/li><li><code>onCanvasStarted&nbsp;<\/code>\u2013 Notification to everyone in the Room when Canvas Streaming starts.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">room.startCanvas(view); \n\n\/\/ Publisher receives acknowledgement\npublic void onStartCanvasAck(JSONObject jsonObject) {\n       \/\/ Handle JSON Object      \n}\n\n\/\/ Others in the Room are notified \npublic void onCanvasStarted(EnxStream enxStream) {\n \/\/ Get EnxPlayerView from ensStream\n \/\/ And add to View\n yourView.addView(enxStream.mEnxPlayerView);\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>5105<\/td><td>Repeated <code>startCanvas()<\/code> call when Canvas Streaming is already active.<\/td><\/tr><tr><td>5107<\/td><td>Repeated <code>startCanvas()<\/code> call when a previous request is in process.<\/td><\/tr><tr><td>5103<\/td><td>Canvas Streaming or Screen Share already active in the Room.<\/td><\/tr><tr><td>5110<\/td><td>Failed to publish Canvas Stream.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<a name=\"stop-canvas-streaming\"><\/a>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3>Stop Canvas Streaming<\/h3>\n\n\n\n<p>The <code>EnxRoom.stopCanvas()<\/code>&nbsp;method is used to stop Canvas Streaming. <\/p>\n\n\n\n<p><strong>Class:<\/strong> EnxRoom <\/p>\n\n\n\n<p><strong>Method<\/strong>:&nbsp;<code>public void stopCanvas()<\/code><\/p>\n\n\n\n<p><strong>Callbacks<\/strong>:&nbsp;<\/p>\n\n\n\n<ul><li><code>onStoppedCanvasAck<\/code>&nbsp;\u2013 Acknowledgment to the publisher when Canvas Streaming stops.<\/li><li><code>onCanvasStopped<\/code>\u2013 Notification to everyone in the Room when Canvas Streaming stops.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">room.stopCanvas(); \n\n\/\/ Publisher receives acknowledgement that Canvas Streaming stopped.\npublic void onStoppedCanvasAck(JSONObject jsonObject) {\n       \/\/ Handle JSON Object   \n}\n\n\/\/ Others in the Room are notified that Canvas Streaming stopped.\npublic void onCanvasStopped(EnxStream enxStream) {\n\t\/\/ And remove View from yourView\n\tyourView.removeAllViews();\n}<\/pre>\n\n\n\n<a name=\"play-canvas-streaming\"><\/a>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3>Receive &amp; Play Canvas Streams<\/h3>\n\n\n\n<p>A Client application developed using Android SDK cannot initiate HTML5 Canvas Streaming. However, it can receive Canvas Streaming initiated by a Client application developed using Web SDK that runs on Web Browsers. <\/p>\n\n\n\n<p>To receive Canvas Streaming, you need to subscribe to the Canvas Stream ID# 102. Once subscribed, you can play it like any other Video Stream using a Video Player.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ A new Canvas Streaming is available, receive Information\npublic void onCanvasStarted(JSONObject json) {\n\tString streamId\t\t= json.getString(\"streamId\");\n\tString canvasName\t= json.getString(\"name\");\n\t\n\t\/\/ Get Remote Streams in the Room\n\tMap&lt;String, EnxStream&gt; map = room.getRemoteStreams();\n\n\t\/\/ The Canvas Stream Object\n\tEnxStream CanvasStream = map.get(streamId); \n\t\n\t\/\/ Create playerView for Canvas Stream\n\tEnxPlayerView canvasPlayerView = new EnxPlayerView(\n\t\tCurrent-Class-Context, ScalingType, mediaOverlay);\n\n\t\/\/ Attach stream to playerView\n\tCanvasStream.attachRenderer(canvasPlayerView);\n\tyourLocalView.addView(canvasPlayerView);\n} \n\n\/\/ Canvas Streaming has stopped. Receive Information\npublic void onCanvasStopped(JSONObject json){\n\tString streamId\t\t= json.getString(\"streamId\");\n} <\/pre>\n\n\n\n<a name=\"force-stop-share\"><\/a>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3>Force Stop Canvas Streaming<\/h3>\n\n\n\n<p><strong>Availability:<\/strong> Android SDK 2.1.2+ <\/p>\n\n\n\n<p>If moderator wishes to force stop any ongoing Canvas Streaming by other user in the Room, he can do so by using <code>EnxRoom.stopAllSharing()<\/code> method. Note, this is Moderator exclusive feature, can&#8217;t be executed from Participant&#8217;s end point.<\/p>\n\n\n\n<p>This method also force stops any ongoing Screen Share.<\/p>\n\n\n\n<p><strong>Class:<\/strong> <code>EnxRoom<\/code><\/p>\n\n\n\n<p><strong>Observer<\/strong>: <code>ACK CallBack<\/code><\/p>\n\n\n\n<p><strong>Method:<\/strong> <code>public void stopAllSharing()<\/code> <\/p>\n\n\n\n<p><strong>Callbacks:<\/strong><\/p>\n\n\n\n<p><code>onStopAllSharingACK<\/code> &#8211; Notification to everyone in the Room when Screen-Sharing stops.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">EnxRoom.stopAllSharing()     \/\/ Force Stop Canvas Streaming\n\n \n\/\/ Notification to all when Canvas Streaming stops\npublic void onStopAllSharingACK(JSONObject jsonObject);     <\/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=\"..\/screen-share\/\">Screen Share<\/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=\"..\/annotation\/\"><\/a><a href=\"..\/annotation\/\">Annotation<\/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>Canvas Streaming allows you to publish any view into the Room. To support Canvas Streaming in the Room, you need to enable canvas during Room Creation by setting: { canvas: true; }}&nbsp;in the JSON Payload. Table of Contents Start Canvas Streaming Stop Canvas Streaming Receive &amp; Play Canvas Streams Force Stop Canvas Streaming Start Canvas Streaming The&nbsp;EnxRoom.startCanvas()&nbsp;method is used to start canvas streaming. Class: EnxRoom Method:&nbsp;public void startCanvas(View view) Parameter:&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3740,"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":"Canvas Streaming allows you to publish any view into the Room. To support Canvas Streaming in the Room, you need to enable canvas during Room Creation by setting: { canvas: true; }}&nbsp;in the JSON Payload. Table of Contents Start Canvas Streaming Stop Canvas Streaming Receive &amp; Play Canvas Streams Force Stop Canvas Streaming Start Canvas&hellip;","_links":{"self":[{"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages\/4219"}],"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=4219"}],"version-history":[{"count":0,"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages\/4219\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/pages\/3740"}],"wp:attachment":[{"href":"https:\/\/doc.smartflomeet.ttns.in\/developer\/wp-json\/wp\/v2\/media?parent=4219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}