WebRTC via socket.io: My code only connects two people if they BOTH accept camera BEFORE clicking connect! Why?

This is really weird. So basically I am trying to connect two random users when they click connect.

Now, here's what happens.

It works fine if BOTH users accept camera BEFORE any of them click connect. So, I open tab 1, go to localhost, and click accept camera. I then go to open tab 2, go on localhost, and click accept camera. Then I click connect on both of them. Works fine, they get connected.

BUT if one of the users clicks accept camera AND connect BEFORE the other user accepts their camera, the users won't get connected! So, if I open tab 1, go to localhost, click accept camera, and right away click connect, and then I go to tab 2, to localhost, and only then accept camera and click connect, the users won't connect.

Why is this?

Here's my server code: http://hostcode.sourceforge.net/view/2917

Here's my client code: http://hostcode.sourceforge.net/view/2916

Please help, I am stumped.