F1 opt is expiring

I am currently working on F1 STEM OPT extension which is expiring on 5th June, 2020 and my husband is on H1-B. My employer filled for H1B this year and I got selected in lottery. Could you please help me with following questions:

  1. When should I apply for cap-gap ( to continue my work) as my F-1 Stem OPT is expiring on 5thJune 2020?
  2. In worst case if my H1B is denied, when should I file for H4?
  3. Do I have to go back to India before I apply for H4? Or is it possible I can change my status from F-1 to H-4 without going back to India?

Please advice. Thanks in advance.
Mahesh R