From 83041b0ce277c95afaf1824f525ea0bec516f03f Mon Sep 17 00:00:00 2001
From: Wim Taymans <wtaymans@redhat.com>
Date: Thu, 18 Nov 2021 15:23:23 +0100
Subject: [PATCH 2/3] policy-node: wait for nodes when we become unlinked

If we were linked before but our node is removed, wait until a new node
becomes available instead of failing.

This fixes an issue where there is only 1 sink available and the card
profile is toggeled between pro and stereo. After the profile is
toggled, the sink is removed and the node would be killed with an error
because there is no fallback sink. The fix is similar to the
pipewire-media-session logic.
---
 src/scripts/policy-node.lua | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/scripts/policy-node.lua b/src/scripts/policy-node.lua
index 5029d1b..445b1a7 100644
--- a/src/scripts/policy-node.lua
+++ b/src/scripts/policy-node.lua
@@ -493,6 +493,9 @@ function handleLinkable (si)
     if not reconnect then
       Log.info (si, "... destroy node")
       node:request_destroy()
+    elseif si_flags[si.id].was_handled then
+      Log.info (si, "... waiting reconnect")
+      return
     end
 
     local client_id = node.properties["client.id"]
-- 
2.34.0

