I\'m trying to make a \"FourConnect\"-game with javascript. I want, that there is a list from all online users. This list I\'ve made with the example on the firebase site. N
From what I understand. You want a chat window in the game so that users logged to communicate among themselves, okay?
Well, in its structure, you simply add something like:
-Games
-rooms
-charOfRoomSpecific
- users
+ InmydEpSe5oZcLZUhfU
-InrLM6uxAsoOayOgFce
name: "Barbara"
status "away"
- messages
+ InmyBlaBlae5oZcLPKSu
-InmyBlaBlae5oZcLPKSu2
user: "Barbara"
say: "Hello man, will gamer!"
+ charOfRoomSpecific2
+ charOfRoomSpecific3
...
So, for your users in the room can read the message simply:
FirebaseRef.child ("rooms/charOfYourRoomSpecific/messages");
And everyone who has access to this room will see in real time their conversations.
In order to send a message to another user, you need that user to be monitoring a known location in your Firebase. Then when you want to send them a message, you simply modify that location in some way and they'll get a callback. Here's some pseudo code:
var root = new Firebase(...);
//On initialization start listening for messages
root.child("users/inbound-messages").on("child_added",
function(newMessageSnapshot) {
displaySomethingToTheUser(newMessageSnapshot.val());
newMessageSnapshot.ref().remove();
}
);
//Send a message to another user
root.child(otherUserId).child("inbound-messages").push("Hi other user!");