Esempio n. 1
0
        static public void Loop(Lobby page)
        {
            if (client.socket == null || client.socket.Connected == false)
            {
                return;
            }

            CompletePacket data;

            if (client.PacketQueue.TryDequeue(out data) == true)
            {
                try
                {
                    switch (data.Protocol)
                    {
                    case (int)PROTOCOL.IdPktVersionRes:
                    {
                        VERSION_RES res = new VERSION_RES();
                        res = VERSION_RES.Parser.ParseFrom(data.Data);

                        var currentVersion = VersionTracking.CurrentVersion;

                        float        myversion = float.Parse(currentVersion);
                        const Double Eps       = 0.000000000000001;

                        if (Math.Abs(res.VarVersion - myversion) > Eps)
                        {
                            //첫 검수라 임시 주석 2번째 패치 부터는 활성화
                            //   Xamarin.Essentials.Browser.OpenAsync("https://play.google.com/store/apps/details?id=com.companyname.OMOK");

                            //    return;
                        }

                        NetProcess.SendLogin(User.Uid, User.Token);
                    }
                    break;

                    case (int)PROTOCOL.IdPktLoginRes:
                    {
                        LOGIN_RES res = new LOGIN_RES();
                        res = LOGIN_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                page.ClosePopup();
                            });

                        if (res.VarCode == ErrorCode.Success)
                        {
                            User.IsLogin = true;

                            User.Id              = res.VarIndex;
                            User.myInfo.win      = res.VarWin;
                            User.myInfo.lose     = res.VarLose;
                            User.myInfo.draw     = res.VarDraw;
                            User.myInfo.score    = res.VarScore;
                            User.myInfo.rank     = res.VarRank;
                            User.myInfo.level    = res.VarLevel;
                            User.myInfo.NickName = Helper.ToStr(res.VarName.ToByteArray());;
                            User.Locale          = Helper.ToStr(res.VarLocale.ToByteArray());

                            User.state = PlayerState.Lobby;

                            SendNoticeReq();

                            Device.BeginInvokeOnMainThread(() =>
                                {
                                    page.UpdatePlayerInfo();
                                    page.UpdateLocalMenu();

                                    if (User.myInfo.NickName == "")
                                    {
                                        page.NickNamePopup();
                                    }
                                    else
                                    {
                                        if (User.Auto == true)
                                        {
                                            page.MatchAuto();
                                        }
                                    }
                                });
                        }
                        else
                        {
                            //강제 exception 발생후 종료 후 재 실행
                            //System.Diagnostics.Process.GetCurrentProcess().Close();
                            //page.LoginInformation("Failed Login.");
                            throw new NullReferenceException();
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktNoticeRes:
                    {
                        NOTICE_RES res = new NOTICE_RES();
                        res = NOTICE_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                page.SetNotice(Helper.ToStr(res.VarMessage.ToByteArray()));
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktCheckNicknameRes:
                    {
                        CHECK_NICKNAME_RES res = new CHECK_NICKNAME_RES();
                        res = CHECK_NICKNAME_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                if (res.VarCode != ErrorCode.Success)
                                {
                                    page.SendNickNamePopupMessage();
                                }
                                else
                                {
                                    User.myInfo.NickName = Helper.ToStr(res.VarName.ToByteArray());

                                    page.CloseAllPopup();

                                    page.UpdatePlayerInfo();
                                }
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktCreateRoomRes:
                    {
                        CREATE_ROOM_RES res = new CREATE_ROOM_RES();
                        res = CREATE_ROOM_RES.Parser.ParseFrom(data.Data);

                        if (res.VarCode == ErrorCode.Success)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                                {
                                    page.ClosePopup();

                                    User.Color    = eTeam.Black;
                                    User.IsMyTurn = true;

                                    User.state = PlayerState.Room;

                                    pRoom = new Room();
                                    page.PushRoomPopup(pRoom);
                                });
                        }
                        else
                        {
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktNewUserInRoomNty:
                    {
                        NEW_USER_IN_ROOM_NTY res = new NEW_USER_IN_ROOM_NTY();
                        res = NEW_USER_IN_ROOM_NTY.Parser.ParseFrom(data.Data);

                        {
                            //상대방이름
                            //나갈때 초기화한다.

                            User.OppInfo.PhotoPath = Encoding.UTF8.GetString(res.VarRoomUser.PictureUri.ToByteArray());

                            User.OppInfo.NickName = Helper.ToStr(res.VarRoomUser.VarName.ToByteArray());
                        }
                        Device.BeginInvokeOnMainThread(() =>
                            {
                                pRoom.UpdateBattleInfo();
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktBitmapMessageRes:
                    {
                        BITMAP_MESSAGE_RES res = new BITMAP_MESSAGE_RES();
                        res = BITMAP_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        foreach (var msg in res.VarMessage)
                        {
                            JpegStream.Enqueue(new MemoryStream(msg.ToByteArray()));
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktRoomPassThroughRes:
                    {
                        ROOM_PASS_THROUGH_RES res = new ROOM_PASS_THROUGH_RES();
                        res = ROOM_PASS_THROUGH_RES.Parser.ParseFrom(data.Data);
                        if (res.VarCode == ErrorCode.Success)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                                {
                                    pRoom.ProcReceivePutStoneMessage(res);
                                });
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktRoomListRes:
                    {
                        Device.BeginInvokeOnMainThread(() =>
                            {
                                page.UpdateMessage(data);
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktAudioMessageRes:
                    {
                        AUDIO_MESSAGE_RES res = new AUDIO_MESSAGE_RES();
                        res = AUDIO_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        foreach (var msg in res.VarMessage)
                        {
                            AudioStream.Enqueue(new MemoryStream(msg.ToByteArray()));
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktRankRes:
                    {
                        RANK_RES res = new RANK_RES();
                        res = RANK_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                page.CreateRankPage(res.VarRankList);
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktLeaveRoomRes:
                    {
                        LEAVE_ROOM_RES res = new LEAVE_ROOM_RES();
                        res = LEAVE_ROOM_RES.Parser.ParseFrom(data.Data);

                        if (res.VarIndex == User.Id)
                        {
                            User.state = PlayerState.Lobby;

                            Device.BeginInvokeOnMainThread(() =>
                                {
                                    pRoom.ShowLeaveAd();

                                    page.PopRoomPopup();
                                });

                            if (User.Auto == true)
                            {
                                Thread.Sleep(1000);

                                Device.BeginInvokeOnMainThread(() =>
                                    {
                                        page.MatchAuto();
                                    });
                            }
                        }

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                page.UpdatePlayerInfo();
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktEnterRoomRes:
                    {
                        ENTER_ROOM_RES res = new ENTER_ROOM_RES();
                        res = ENTER_ROOM_RES.Parser.ParseFrom(data.Data);

                        if (res.VarCode == ErrorCode.Success)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                                {
                                    page.ClosePopup();

                                    pRoom = new Room();

                                    User.Color    = eTeam.White;
                                    User.IsMyTurn = false;

                                    User.state = PlayerState.Room;
                                    page.PushRoomPopup(pRoom);
                                });
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktGameResultNty:
                    {
                        GAME_RESULT_NTY res = new GAME_RESULT_NTY();
                        res = GAME_RESULT_NTY.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                if (User.Auto == true)
                                {
                                    pRoom.GameResult(res);
                                    pRoom.SendLeaveRoom();
                                }
                                else
                                {
                                    pRoom.GameResult(res);
                                }
                            });
                    }
                    break;
                    }
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                }
            }
        }
Esempio n. 2
0
        static public void Loop()
        {
            if (client.socket == null || client.socket.Connected == false)
            {
                return;
            }

            CompletePacket data;

            if (client.PacketQueue.TryDequeue(out data) == true)
            {
                try
                {
                    switch (data.Protocol)
                    {
                    case (int)PROTOCOL.IdPktVersionRes:
                    {
                        VERSION_RES res = new VERSION_RES();
                        res = VERSION_RES.Parser.ParseFrom(data.Data);

                        var currentVersion = VersionTracking.CurrentVersion;

                        double myversion;
                        if (double.TryParse(currentVersion, out myversion) == false)
                        {
                        }

                        const Double Eps = 0.000000000000001;

                        User.Version = res.VarVersion;

                        if (Math.Abs(res.VarVersion - myversion) > Eps)
                        {
                            //첫 검수라 임시 주석 2번째 패치 부터는 활성화
                            if (Device.RuntimePlatform == Device.Android && User.OnceVersionNotify == false)
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                    {
                                        User.OnceVersionNotify = true;
                                        DependencyService.Get <Toast>().Notification("New Version Updated");
                                    });
                            }
                        }


                        SQLLiteDB.LoadCacheData();
                        if (User.CacheData.UserName != null)
                        {
                            NetProcess.SendLogin(User.CacheData.UserName, User.CacheData.Passwd);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktLoginRes:
                    {
                        LOGIN_RES res = new LOGIN_RES();
                        res = LOGIN_RES.Parser.ParseFrom(data.Data);

                        var mainpage = (MainPage)Application.Current.MainPage;

                        if (res.VarCode == ErrorCode.Success)
                        {
                            User.LoginSuccess = true;
                            SQLLiteDB.Upsert(User.CacheData.FontSize, User.CacheData.BibleName, User.CacheData.Chapter, User.CacheData.Verse,
                                             User.CacheData.UserName, User.CacheData.Passwd);

                            Device.BeginInvokeOnMainThread(() =>
                                {
                                    mainpage.setting.UpdateLoginState("(Success)");
                                    mainpage.setting.UpdateNameEntry(User.CacheData.UserName);

                                    var page        = mainpage.CurrentView();
                                    var settingview = page as SettingView;

                                    if (settingview == null)
                                    {
                                        mainpage.LoadLobby();
                                    }
                                });
                        }
                        else
                        {
                            Device.BeginInvokeOnMainThread(() =>
                                {
                                    mainpage.setting.UpdateLoginState("(Failed)");
                                });

                            User.LoginSuccess = false;
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktRoomListRes:
                    {
                        ROOM_LIST_RES res = new ROOM_LIST_RES();
                        res = ROOM_LIST_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;

                                RoomsPageView roompage = mainpage.lobby.roompage as RoomsPageView;

                                roompage?.LoadRoomList(res);
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktNoticeRes:
                    {
                        NOTICE_RES res = new NOTICE_RES();
                        res = NOTICE_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;

                                mainpage.alarm.LoadList(res);
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktMailListRes:
                    {
                        MAIL_LIST_RES res = new MAIL_LIST_RES();
                        res = MAIL_LIST_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;

                                mainpage.mail.LoadList(res);
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktPrayMessageRes:
                    {
                        PRAY_MESSAGE_RES res = new PRAY_MESSAGE_RES();
                        res = PRAY_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;

                                PrayView prayview = mainpage.lobby.praypage as PrayView;

                                prayview?.LoadPrayList(res);
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktCreateRoomRes:
                    {
                        CREATE_ROOM_RES res = new CREATE_ROOM_RES();
                        res = CREATE_ROOM_RES.Parser.ParseFrom(data.Data);

                        if (res.VarCode != ErrorCode.Success)
                        {
                            break;
                        }

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;

                                RoomsPageView roompage = mainpage.lobby.roompage as RoomsPageView;

                                User.RoomIdList.Add(res.VarRoomId);

                                {
                                    User.CurrentChatViewNumber = res.VarRoomId;
                                    var chatview = new MainChatView();
                                    mainpage.lobby.chatpage.Add(res.VarRoomId, chatview);
                                    MainChatView chatpage = chatview;

                                    mainpage.LoadView(chatpage);
                                }
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktEnterRoomRes:
                    {
                        ENTER_ROOM_RES res = new ENTER_ROOM_RES();
                        res = ENTER_ROOM_RES.Parser.ParseFrom(data.Data);

                        if (res.VarCode != ErrorCode.DuplicateEnterRoom && res.VarCode != ErrorCode.Success)
                        {
                            break;
                        }

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                try
                                {
                                    var mainpage = (MainPage)Application.Current.MainPage;

                                    RoomsPageView roompage = mainpage.lobby.roompage as RoomsPageView;

                                    User.RoomIdList.Add(res.VarRoomId);
                                    {
                                        User.CurrentChatViewNumber = res.VarRoomId;

                                        MainChatView outivew;

                                        mainpage.lobby.chatpage.TryGetValue(res.VarRoomId, out outivew);
                                        if (outivew == null)     //없으면 새로 만들어서 넣는다.
                                        {
                                            var chatview = new MainChatView();
                                            mainpage.lobby.chatpage.Add(res.VarRoomId, chatview);
                                            mainpage.LoadView(chatview);

                                            foreach (var msg in res.VarMessages)
                                            {
                                                chatview.ReceiveMessage(msg.VarMessage, msg.VarName, msg.VarTime);
                                            }

                                            chatview.ScrollEnd();
                                        }
                                        else      //이미 존재하는 방이면 해당 방에 넣는다.
                                        {
                                            mainpage.LoadView(outivew);
                                            outivew.ScrollEnd();
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                }
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktRoomPassThroughRes:
                    {
                        ROOM_PASS_THROUGH_RES res = new ROOM_PASS_THROUGH_RES();
                        res = ROOM_PASS_THROUGH_RES.Parser.ParseFrom(data.Data);
                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;


                                MainChatView outivew;

                                mainpage.lobby.chatpage.TryGetValue(res.VarRoomNumber, out outivew);
                                if (outivew == null)
                                {
                                    return;
                                }

                                foreach (var msg in res.VarMessages)
                                {
                                    outivew.ReceiveMessage(msg.VarMessage, msg.VarName, msg.VarTime);
                                }

                                outivew.ScrollEnd();
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktLeaveRoomRes:
                    {
                        LEAVE_ROOM_RES res = new LEAVE_ROOM_RES();
                        res = LEAVE_ROOM_RES.Parser.ParseFrom(data.Data);

                        var mainpage = (MainPage)Application.Current.MainPage;

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                MainChatView outivew;

                                mainpage.lobby.chatpage.TryGetValue(res.VarRoomNumber, out outivew);
                                if (outivew == null)
                                {
                                    return;
                                }

                                outivew.UserList.Remove(res.VarName);

                                if (res.VarName == User.CacheData.UserName)
                                {
                                    User.RoomIdList.Remove(res.VarRoomNumber);

                                    mainpage.lobby.chatpage.Remove(res.VarRoomNumber);

                                    mainpage.lobby.LoadRoomPageView();
                                }
                                else
                                {
                                    MainChatView chatpage = outivew as MainChatView;
                                    chatpage.ReceiveMessage(res.VarName + " leaved.",
                                                            res.VarName, Message.type.Info);
                                }
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktAudioMessageRes:
                    {
                        AUDIO_MESSAGE_RES res = new AUDIO_MESSAGE_RES();
                        res = AUDIO_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        foreach (var msg in res.VarMessage)
                        {
                            StreamWrapper wra = new StreamWrapper();
                            wra.stream = new MemoryStream(msg.ToByteArray());
                            wra.pos    = res.VarPos;
                            AudioStream.Enqueue(wra);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktBitmapMessageRes:
                    {
                        BITMAP_MESSAGE_RES res = new BITMAP_MESSAGE_RES();
                        res = BITMAP_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        foreach (var msg in res.VarMessage)
                        {
                            StreamWrapper wra = new StreamWrapper();
                            wra.stream = new MemoryStream(msg.ToByteArray());
                            wra.pos    = res.VarPos;
                            JpegStream.Enqueue(wra);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktNewUserInRoomNty:
                    {
                        NEW_USER_IN_ROOM_NTY res = new NEW_USER_IN_ROOM_NTY();
                        res = NEW_USER_IN_ROOM_NTY.Parser.ParseFrom(data.Data);

                        var mainpage = (MainPage)Application.Current.MainPage;


                        Device.BeginInvokeOnMainThread(() =>
                            {
                                MainChatView outivew;

                                mainpage.lobby.chatpage.TryGetValue(res.VarRoomUser.VarRoomNumber, out outivew);
                                if (outivew == null)
                                {
                                    return;
                                }

                                outivew.UserList.Add(res.VarRoomUser.VarName);

                                if (res.VarType == 1)
                                {
                                    if (res.VarRoomUser.VarName != User.CacheData.UserName)
                                    {
                                        outivew.ReceiveMessage(res.VarRoomUser.VarName + " entered.",
                                                               res.VarRoomUser.VarName, Message.type.Info);
                                    }
                                }
                            });
                    }
                    break;
                    }
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                }
            }
        }
Esempio n. 3
0
        static public void Loop()
        {
            if (client.socket == null || client.socket.Connected == false)
            {
                return;
            }

            CompletePacket data;

            if (client.PacketQueue.TryDequeue(out data) == true)
            {
                try
                {
                    switch (data.Protocol)
                    {
                    case (int)PROTOCOL.IdPktVersionRes:
                    {
                        VERSION_RES res = new VERSION_RES();
                        res = VERSION_RES.Parser.ParseFrom(data.Data);

                        var currentVersion = VersionTracking.CurrentVersion;

                        double myversion;
                        if (double.TryParse(currentVersion, out myversion) == false)
                        {
                        }

                        const Double Eps = 0.000000000000001;

                        User.Version = res.VarVersion;

                        if (Math.Abs(res.VarVersion - myversion) > Eps)
                        {
                            //첫 검수라 임시 주석 2번째 패치 부터는 활성화
                            if (Device.RuntimePlatform == Device.Android && User.OnceVersionNotify == false)
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                    {
                                        User.OnceVersionNotify = true;
                                        DependencyService.Get <MethodExt>().Notification("New Version Updated");
                                    });
                            }
                        }

                        SQLLiteDB.LoadCacheData();
                        if (User.NickName != null)
                        {
                            NetProcess.SendLogin(User.Uid, User.Token);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktLoginRes:
                    {
                        LOGIN_RES res = new LOGIN_RES();
                        res = LOGIN_RES.Parser.ParseFrom(data.Data);

                        var mainpage = (MainPage)Application.Current.MainPage;

                        if (res.VarCode == ErrorCode.Success)
                        {
                            Xamarin.Forms.DependencyService.Register <MethodExt>();

                            DependencyService.Get <MethodExt>().Notification("New Version Updated");

                            User.LoginSuccess = true;
                            SQLLiteDB.Upsert(res.VarName, "");

                            if (PopupNavigation.Instance.PopupStack.Count > 0)
                            {
                                PopupNavigation.Instance.PopAsync();
                            }
                        }
                        else
                        {
                            Device.BeginInvokeOnMainThread(() =>
                                {
                                });

                            User.LoginSuccess = false;
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktRoomListRes:
                    {
                        ROOM_LIST_RES res = new ROOM_LIST_RES();
                        res = ROOM_LIST_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktNoticeRes:
                    {
                        NOTICE_RES res = new NOTICE_RES();
                        res = NOTICE_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktRegCameraRes:
                    {
                        REG_CAMERA_RES res = new REG_CAMERA_RES();
                        res = REG_CAMERA_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktCameraListRes:
                    {
                        CAMERA_LIST_RES res = new CAMERA_LIST_RES();
                        res = CAMERA_LIST_RES.Parser.ParseFrom(data.Data);

                        if (res.VarCode == ErrorCode.Success)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                                {
                                    var mainpage = (MainPage)Application.Current.MainPage;

                                    PopupNavigation.Instance.PushAsync(new CameraListPage(res.VarCamera));
                                });
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktMailListRes:
                    {
                        MAIL_LIST_RES res = new MAIL_LIST_RES();
                        res = MAIL_LIST_RES.Parser.ParseFrom(data.Data);
                    }
                    break;

                    case (int)PROTOCOL.IdPktPrayMessageRes:
                    {
                    }
                    break;

                    case (int)PROTOCOL.IdPktCameraWakeUpRes:
                    {
                        CAMERA_WAKE_UP_RES res = new CAMERA_WAKE_UP_RES();
                        res = CAMERA_WAKE_UP_RES.Parser.ParseFrom(data.Data);

                        TargetPlayerId.Add(res.VarToPlayerId);

                        if (PopupNavigation.Instance.PopupStack.Count == 0)
                        {
                            PopupNavigation.Instance.PushAsync(new CameraPage());
                        }
                        else
                        {
                            if (PopupNavigation.Instance.PopupStack[0].GetType() != typeof(CameraPage))
                            {
                                PopupNavigation.Instance.PopAsync();
                                PopupNavigation.Instance.PushAsync(new CameraPage());
                            }
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktStopStreamRes:
                    {
                        STOP_STREAM_RES res = new STOP_STREAM_RES();
                        res = STOP_STREAM_RES.Parser.ParseFrom(data.Data);

                        TargetPlayerId.Remove(res.VarToPlayerId);
                    }
                    break;

                    case (int)PROTOCOL.IdPktCreateRoomRes:
                    {
                        CREATE_ROOM_RES res = new CREATE_ROOM_RES();
                        res = CREATE_ROOM_RES.Parser.ParseFrom(data.Data);

                        if (res.VarCode != ErrorCode.Success)
                        {
                            break;
                        }

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;


                                User.RoomIdList.Add(res.VarRoomId);

                                {
                                }
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktEnterRoomRes:
                    {
                        ENTER_ROOM_RES res = new ENTER_ROOM_RES();
                        res = ENTER_ROOM_RES.Parser.ParseFrom(data.Data);

                        if (res.VarCode != ErrorCode.DuplicateEnterRoom && res.VarCode != ErrorCode.Success)
                        {
                            break;
                        }

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                try
                                {
                                    var mainpage = (MainPage)Application.Current.MainPage;
                                }
                                catch (Exception e)
                                {
                                }
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktRoomPassThroughRes:
                    {
                        ROOM_PASS_THROUGH_RES res = new ROOM_PASS_THROUGH_RES();
                        res = ROOM_PASS_THROUGH_RES.Parser.ParseFrom(data.Data);
                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktLeaveRoomRes:
                    {
                        LEAVE_ROOM_RES res = new LEAVE_ROOM_RES();
                        res = LEAVE_ROOM_RES.Parser.ParseFrom(data.Data);

                        var mainpage = (MainPage)Application.Current.MainPage;

                        Device.BeginInvokeOnMainThread(() =>
                            {
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktAudioMessageRes:
                    {
                        AUDIO_MESSAGE_RES res = new AUDIO_MESSAGE_RES();
                        res = AUDIO_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        foreach (var msg in res.VarMessage)
                        {
                            StreamWrapper wra = new StreamWrapper();
                            wra.stream = new MemoryStream(msg.ToByteArray());
                            wra.pos    = res.VarPos;
                            AudioStream.Enqueue(wra);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktBitmapMessageRes:
                    {
                        BITMAP_MESSAGE_RES res = new BITMAP_MESSAGE_RES();
                        res = BITMAP_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        foreach (var msg in res.VarMessage)
                        {
                            StreamWrapper wra = new StreamWrapper();
                            wra.stream = new MemoryStream(msg.ToByteArray());
                            JpegStream.Enqueue(wra);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktMpeg2TsMessageRes:
                    {
                        MPEG2TS_MESSAGE_RES res = new MPEG2TS_MESSAGE_RES();
                        res = MPEG2TS_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        foreach (var msg in res.VarMessage)
                        {
                            StreamWrapper wra = new StreamWrapper();
                            wra.stream = new MemoryStream(msg.ToByteArray());
                            wra.type   = res.VarType;
                            Mpeg2Stream.Enqueue(wra);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktNewUserInRoomNty:
                    {
                        NEW_USER_IN_ROOM_NTY res = new NEW_USER_IN_ROOM_NTY();
                        res = NEW_USER_IN_ROOM_NTY.Parser.ParseFrom(data.Data);

                        var mainpage = (MainPage)Application.Current.MainPage;
                    }
                    break;
                    }
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                }
            }
        }