Disconnect Firebase Socket without refresh

117 views
Skip to first unread message

michael down

unread,
Feb 29, 2016, 2:29:47 PM2/29/16
to Firebase Google Group
Hi,

I hope you can help me, as im struggling to get this working.


I have multiple groups, each time a group is clicked, a new firebase socket is started:  

            var myDataRef = new Firebase('https://todofyp.firebaseio.com/');

however, the problem i have, is that when a user has clicked on a couple of groups, it creates a new instance of the firebase socket INSTEAD of overiding the current one. Any ideas how i can delete a firebase socket when a button is pressed?

Cheers

Kato Richardson

unread,
Feb 29, 2016, 2:42:11 PM2/29/16
to Firebase Google Group
Hi Michael,

Calling new Firebase(...) does not create a new web socket connection to the server. Internally, the SDK dose some great optimizations to help each client re-use the same connection. There are some ways you could be bypassing this, but by default this is true. Note that in web browsers, opening new browser tabs establishes a new socket connection (browser sandboxing won't allow tabs to share these resources).

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/c4b7ffe2-16d2-419d-858e-6bea0f0c3d4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

michael down

unread,
Mar 1, 2016, 2:27:22 AM3/1/16
to Firebase Google Group
Hey Kato, cheers for your reply. This is where the problem is coming from...

function updateGroupSelected()
{
    console.log(groupID + ' --lookie');
      userGroup = groupID.toString();
      var myDataRef = new Firebase('https://todofyp.firebaseio.com/');
      listRef = myDataRef.child("listItems");
      groupRef = listRef.child(userGroup);
      var defaultStatus = 'nrl';
      $('#messageInput').keypress(function (e) {
        if (e.keyCode == 13) {
          
          var name = userDisplayName;
          var text = $('#messageInput').val();
          if(text != '')
          {
          var currentTime = Firebase.ServerValue.TIMESTAMP;
          groupRef.push({name: name, text: text, groupID: userGroup, status: defaultStatus, time: currentTime});
          }
          $('#messageInput').val('');
          text = '';
          Firebase.goOffline();
        }
      });
      var onValueChange = groupRef.on('child_added', function(snapshot) {
        var message = snapshot.val();
        var key = snapshot.key();
        displayChatMessage(message.name, message.text, key);
        ItemsAddedByOthers(message.time, message.text, key);

      });
}


everytime i click on a group, it is calling this function and seems to be creating loads of new firebase connecitons? instead of overiding groupRef

Kato Richardson

unread,
Mar 1, 2016, 1:59:40 PM3/1/16
to Firebase Google Group
I'd be interested in hearing how you've verified it's that specific code. Based on what you have here, the connection would be severed after the first group is clicked, by Firebase.goOffline(), and never re-established. So it would be impossible for this to be creating multiple connections (it would have exactly zero connections). Of course, you may be using connection differently than we typically do, so again, defining exactly what you're seeing and how you've verified it may put us on the same page.

You may want to start out with some debug logging:

JS:  Firebase.enableLogging(true);
iOS:  [Firebase setLoggingEnabled:YES];
Android:  Firebase.getDefaultConfig().setLogLevel(Logger.Level.DEBUG);

And if you're still having issues, a minimal repro, with some steps to run it, will be necessary before I could take any other guesses as to the cause. Make sure you're on the latest versions.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages