예제 #1
0
 private void GetMessages() // 방 생성자의 닉네임을 통해 해당 방을 찾아 채팅 내용을 불러옴
 {
     FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://project-6629124072636312930-default-rtdb.firebaseio.com/");
     reference = FirebaseDatabase.DefaultInstance.RootReference;
     reference.Child("chatRooms").GetValueAsync().ContinueWithOnMainThread(task =>
     {
         if (task.IsFaulted || task.IsCanceled)
         {
         }
         else if (task.IsCompleted)
         {
             DataSnapshot snapshot = task.Result;             // users의 쿼리 결과를 snapshot으로 받아옴
             foreach (DataSnapshot data in snapshot.Children) // snapshot의 각 하위 개체들에 적용
             {
                 IDictionary createdBy = (IDictionary)data.Child("createdBy").Value;
                 if (createdBy["name"].Equals(roommaster)) // Private 채팅방 생성
                 {
                     IDictionary chatRooms = (IDictionary)data.Value;
                     key = chatRooms["id"].ToString();
                     database.ListenForMessages(InstantiateMessage, Debug.Log, key);
                 }
                 else if (createdBy["name"].Equals("admin")) // Public 채팅방 생성
                 {
                     IDictionary chatRooms = (IDictionary)data.Value;
                     key = chatRooms["id"].ToString();
                     database.ListenForMessages(InstantiateMessagePublic, Debug.Log, key);
                 }
             }
         }
     });
 }