From 2942233c9c319d644485ec1f6d89d2118061e77a Mon Sep 17 00:00:00 2001
From: Jonas Jenwald <jonas.jenwald@gmail.com>
Date: Fri, 10 Jan 2020 14:35:12 +0100
Subject: [PATCH] Add support for `Promise.allSettled`

Please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled
---
 src/shared/compatibility.js   | 6 +-----
 src/shared/message_handler.js | 4 ++--
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/src/shared/compatibility.js b/src/shared/compatibility.js
index a44a2e7e2..fa7d6ad17 100644
--- a/src/shared/compatibility.js
+++ b/src/shared/compatibility.js
@@ -230,11 +230,7 @@ if (
       // need to be polyfilled for the IMAGE_DECODERS build target.
       return;
     }
-    if (
-      globalThis.Promise &&
-      globalThis.Promise.prototype &&
-      globalThis.Promise.prototype.finally
-    ) {
+    if (globalThis.Promise && globalThis.Promise.allSettled) {
       return;
     }
     globalThis.Promise = require("core-js/es/promise/index.js");
diff --git a/src/shared/message_handler.js b/src/shared/message_handler.js
index 58d6fbf86..ee3d56556 100644
--- a/src/shared/message_handler.js
+++ b/src/shared/message_handler.js
@@ -551,13 +551,13 @@ class MessageHandler {
   async _deleteStreamController(streamId) {
     // Delete the `streamController` only when the start, pull, and cancel
     // capabilities have settled, to prevent `TypeError`s.
-    await Promise.all(
+    await Promise.allSettled(
       [
         this.streamControllers[streamId].startCall,
         this.streamControllers[streamId].pullCall,
         this.streamControllers[streamId].cancelCall,
       ].map(function(capability) {
-        return capability && capability.promise.catch(function() {});
+        return capability && capability.promise;
       })
     );
     delete this.streamControllers[streamId];