Hi Risa!
No worries, most dogs will poo out worms at least once in their life. Have you got your rascal on a worming treatment, like a pill or a liquid flea and worm combination? I strongly recommend having all your pets on worm and flea treatment, its easy to do, and usually only needs doing once every 1-3 months, and it keeps your furries much happier and healthier!
If your dog has recently pooed with worms in it, theres no reason you can't still play. You should treat the worms as soon as possible, but you can continue petting and rubbing and playing as always. Dog worms live mostly in the intestines, and get pooed out when they are mature. You cannot "catch" them through skin contact. The worst you can do is pick up a few eggs from the environment, but these are unlikely to be on your actual dog, and as long as you wash you hands after playtime, you should be all good to keep playing as much as you like.
You can get worm treatments at your local vet, or stores such as PetSmart carry them as well. Both locations will have more information on worms specific to your area, their lifecycle, and how to treat them.
Overall, no worries about you catching worms, just be clean, and have fun with your rascal!