From dbcb2f5558e1f82db9d0709336f44466301c6421 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Thu, 28 May 2020 15:09:56 +0300
Subject: [PATCH] Try to improve MSE stability

---
 web-service/public/js/bundle.js | 16 +++++++++++++---
 web-service/public/js/index.js  | 16 +++++++++++++---
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/web-service/public/js/bundle.js b/web-service/public/js/bundle.js
index b1fc70a39..312f7bc60 100644
--- a/web-service/public/js/bundle.js
+++ b/web-service/public/js/bundle.js
@@ -70815,7 +70815,12 @@ function FTLStream(peer, uri, element) {
 			this.queue.push(data);
 		} else {
 			//console.log("Direct append: ", data);
-			this.sourceBuffer.appendBuffer(data);
+
+			try {
+				this.sourceBuffer.appendBuffer(data);
+			} catch (e) {
+				console.error("Failed to append buffer");
+			}
 		}
 	}
 
@@ -70926,11 +70931,16 @@ function FTLStream(peer, uri, element) {
 		});
 
 		this.sourceBuffer.addEventListener('updateend', () => {
-			if (this.queue.length > 0) {
+			if (this.queue.length > 0 && !this.sourceBuffer.updating) {
 				let s = this.queue[0];
 				this.queue.shift();
 				//console.log("Append", s);
-				this.sourceBuffer.appendBuffer(s);
+
+				try {
+					this.sourceBuffer.appendBuffer(s);
+				} catch(e) {
+					console.error("Failed to append buffer");
+				}
 			}
 		});
 	});
diff --git a/web-service/public/js/index.js b/web-service/public/js/index.js
index d6242d5d4..3808bb630 100644
--- a/web-service/public/js/index.js
+++ b/web-service/public/js/index.js
@@ -404,7 +404,12 @@ function FTLStream(peer, uri, element) {
 			this.queue.push(data);
 		} else {
 			//console.log("Direct append: ", data);
-			this.sourceBuffer.appendBuffer(data);
+
+			try {
+				this.sourceBuffer.appendBuffer(data);
+			} catch (e) {
+				console.error("Failed to append buffer");
+			}
 		}
 	}
 
@@ -515,11 +520,16 @@ function FTLStream(peer, uri, element) {
 		});
 
 		this.sourceBuffer.addEventListener('updateend', () => {
-			if (this.queue.length > 0) {
+			if (this.queue.length > 0 && !this.sourceBuffer.updating) {
 				let s = this.queue[0];
 				this.queue.shift();
 				//console.log("Append", s);
-				this.sourceBuffer.appendBuffer(s);
+
+				try {
+					this.sourceBuffer.appendBuffer(s);
+				} catch(e) {
+					console.error("Failed to append buffer");
+				}
 			}
 		});
 	});
-- 
GitLab