Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I implement the concept of channels in Firebase?

Tags:

firebase

The Firebase chat application seems to suggest that all clients will receive the messages sent to a given FireBase url.

Now, one way of ensuring that users only receive messages sent to a specific channel is to filter messages at the client, but this would mean that all messages will be propagated to all clients and the client would do the filtering.

Is there any way to establish channels at the Firebase server - or does this mean that one would need to create separate firebases for separate channels, which would mean that if one wanted user-specific push-messages, it might require creating one channel/firebase for each user.

So, what is the suggested solution?

like image 250
molicule Avatar asked Feb 13 '13 21:02

molicule


1 Answers

The Firebase Data Structure makes this quite easy, actually! The demo app puts the chat messages in the root of the Firebase (i.e. https://samplechat.firebaseio.com/), but you could just as easily use separate locations within your Firebase for separate chats, e.g. /chat1, /chat2, etc. Or better yet, you could have a /chats/ location with an arbitrary number of chats underneath, each named uniquely (possibly using push()).

Then a user could receive and push messages to a particular chat by referencing it directly (e.g. https://samplechat.firebaseio.com/chats/chat-id/) and then they won't get any data for any other chats.

like image 67
Michael Lehenbauer Avatar answered Sep 30 '22 02:09

Michael Lehenbauer