I suggest that you use a third wheel.

You will not need to write complex coding and save a lot of coding space and parts.