Prevent multiple registrations of "message" event in API call
This happens in SwanShare. Example: if the SSO session expired, we keep registering the "message" events. If we renew the SSO session, then all the events will be fired at the same time, causing multiple API calls. We should remove this event before adding a new one. We also need to wait a few seconds to timeout and finish the pending calls.