Skip to content

Commit

Permalink
Fixed race condition where _sessionId was null
Browse files Browse the repository at this point in the history
  • Loading branch information
jwngr committed Aug 30, 2016
1 parent eec01f2 commit 20820f7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/js/firechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@
}
}, this);

// Generate a unique session id for the visit.
var sessionRef = this._userRef.child('sessions').push();
this._sessionId = sessionRef.key;
this._queuePresenceOperation(sessionRef, true, null);
// Queue up a presence operation to remove the session when presence is lost
this._queuePresenceOperation(this._sessionRef, true, null);

// Register our username in the public user listing.
var usernameRef = this._usersOnlineRef.child(this._userName.toLowerCase());
Expand Down Expand Up @@ -256,6 +254,9 @@
self._userId = userId.toString();
self._userName = userName.toString();
self._userRef = self._firechatRef.child('users').child(self._userId);
self._sessionRef = self._userRef.child('sessions').push();
self._sessionId = self._sessionRef.key;

self._loadUserMetadata(function() {
root.setTimeout(function() {
callback(self._user);
Expand Down

0 comments on commit 20820f7

Please sign in to comment.