From 5d0936d39c73c9ee2025baa149b7aa2d2e111d88 Mon Sep 17 00:00:00 2001
From: Dorian Goepp <dorian.goepp@gmail.com>
Date: Thu, 18 Apr 2019 15:34:07 +0200
Subject: [PATCH] handle case when the topic is not published

---
 src/VideoStream/index.js | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/VideoStream/index.js b/src/VideoStream/index.js
index e49e4f6..830b39a 100644
--- a/src/VideoStream/index.js
+++ b/src/VideoStream/index.js
@@ -6,9 +6,19 @@ class VideoStream extends Component {
         super(props)
 
         const hasUrl = ('url' in this.props && this.props.url);
+        this.topic = '/pepper/image_raw';
+        this.defaultImage = '';
+
         this.state = {
-            url: hasUrl ? this.props.url : 'http://localhost:8081/stream?topic=/pepper/image_raw'
-        }
+            url: hasUrl ? this.props.url : this.defaultImage
+        };
+
+        this.props.ros.getTopics(function(infos){
+            console.debug(infos.topics)
+            if (undefined !== infos.topics.find(elem => elem === this.topic)) {
+                this.setState({url: 'http://localhost:8081/stream?topic=' + this.topic});
+            }
+          }.bind(this))
     }
 
     handleSettingsChange(event) {
-- 
GitLab