问题描述:

In a previous post I was wondering where to implement the presence system. I tried putting the code in my LoginCtrl as such:

$rootScope.$on("$stateChangeStart", function (event, toState, toParams, fromState, fromParams) {

var myConnectionsRef = firebase.database().ref('users/joe/connections');

var lastOnlineRef = firebase.database().ref('users/joe/lastOnline');

var connectedRef = firebase.database().ref('.info/connected');

connectedRef.on('value', function(snap) {

if (snap.val() === true) {

var con = myConnectionsRef.push(true);

con.onDisconnect().remove();

// when I disconnect, update the last time I was seen online

lastOnlineRef.onDisconnect().set(firebase.database.ServerValue.TIMESTAMP);

}

});

I use the $stateChangeStart listener to make sure "the disconnect operations should be queued before a user is marked online" (Per Firebase Google Doc), since, from what I understand, $stateChangeStart (state/content) change precedes $locationChangeStart (url) change. Please let me know if I get it right.

Now the issue I have right now is that I'm getting message saying:

FIREBASE WARNING: Exception was thrown by user callback. TypeError: myConnectionsRef.push is not a function"

相关阅读:
Top