Electromagnetic Approach to Cavity Spintronics