From ba3de927ed834adf5ddb19304b156e83411b13d5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simon=20D=C3=B6ring?= <simon.doering@stud.hs-bochum.de>
Date: Mon, 11 Jan 2021 16:16:25 +0100
Subject: [PATCH] Add if checks to prevent exceptions in odd cases

---
 novnc/app/camera-receiver.js | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/novnc/app/camera-receiver.js b/novnc/app/camera-receiver.js
index 823ad4d..e86026c 100644
--- a/novnc/app/camera-receiver.js
+++ b/novnc/app/camera-receiver.js
@@ -121,9 +121,17 @@ document.addEventListener('DOMContentLoaded', function() {
         delete videoGeometryParams[slot];
         delete source[slot];
         var videoContainer = getVideoContainer(slot);
-        videoContainer.remove();
-        janusPluginHandles[slot].detach();
-        delete janusPluginHandles[slot];
+        if (videoContainer) {
+            videoContainer.remove();
+        } else {
+            console.error(`Tried to remove video container for slot ${slot} that is not mounted`);
+        }
+        if (janusPluginHandles[slot]) {
+            janusPluginHandles[slot].detach();
+            delete janusPluginHandles[slot];
+        } else {
+            console.error(`Tried to remove janus plugin handle for slot ${slot}`);
+        }
     }
 
     function newRemoteFeed(slot, feedId, initialState) {
@@ -299,9 +307,9 @@ document.addEventListener('DOMContentLoaded', function() {
             var annotationEl = template.content.firstChild;
             if (annotationEl && annotationEl.classList) {
                 annotationEl.classList.add('annotation');
-                var prevAnnotation = videoContainer.querySelector('.annotation');
-                if (prevAnnotation) {
-                    prevAnnotation.remove();
+                var prevAnnotationEl = videoContainer.querySelector('.annotation');
+                if (prevAnnotationEl) {
+                    prevAnnotationEl.remove();
                 }
                 videoContainer.appendChild(annotationEl);
             } else {
-- 
GitLab