Sending and receiving realtime events in JavaScript