Switch camera when Facetime camera on macbook is being used

I have a strange issue on my macbook, i usually have the lid closed with an external monitor and i use a usb webcam.

Sometimes when publishing video it is trying to use the facetime camera even though the lid is closed, the camera isn’t even publishing the stream. I know this because when i try to switch camera by unpublishing it vidu gives this error:

ERROR:Participant ‘con_IFSUWNqMcw’ is not streaming media. Code: 105 in Request: method:unpublishVideo params:{} request:undefined

So what actually ends up happening is the external camera is then activated but it’s leaving the original black video on the page because it thinks it’s not publishing to it.

Is there a way for me to detect if a camera is actually publishing on a stream before the unpublish() function is called and somehow remove the original video element?

I’m not sure if this is a bug or if it’s just confused, because it creates the video element for the facetime camera initially but because the lid is closed the camera isn’t actually active