OnChatStateChange









How do I use On Chat State Change
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: ChatGui.cs Copy
311     public void OnChatStateChange(ChatState state)
312     {
313         // use OnConnected() and OnDisconnected()
314         // this method might become more useful in the future, when more complex states are being used.
315     }
File name: ChatClient.cs Copy
620         void IPhotonPeerListener.OnStatusChanged(StatusCode statusCode)
621         {
622             switch (statusCode)
623             {
624                 case StatusCode.Connect:
625                     this.chatPeer.EstablishEncryption();
626                     if (this.State == ChatState.ConnectingToNameServer)
627                     {
628                         this.State = ChatState.ConnectedToNameServer;
629                         this.listener.OnChatStateChange(this.State);
630                     }
631                     else if (this.State == ChatState.ConnectingToFrontEnd)
632                     {
633                         this.AuthenticateOnFrontEnd();
634                     }
635                     break;
636                 case StatusCode.EncryptionEstablished:
637                     // once encryption is availble, the client should send one (secure) authenticate. it includes the AppId (which identifies your app on the Photon Cloud)
638                     if (!this.didAuthenticate)
639                     {
640                         this.didAuthenticate = this.chatPeer.AuthenticateOnNameServer(this.AppId, this.AppVersion, this.chatRegion, this.UserId, this.CustomAuthenticationValues);
641                         if (!this.didAuthenticate)
642                         {
643                             ((IPhotonPeerListener) this).DebugReturn(DebugLevel.ERROR, "Error calling OpAuthenticate! Did not work. Check log output, CustomAuthenticationValues and if you're connected. State: " + this.State);
644                         }
645                     }
646                     break;
647                 case StatusCode.EncryptionFailedToEstablish:
648                     this.State = ChatState.Disconnecting;
649                     this.chatPeer.Disconnect();
650                     break;
651                 case StatusCode.Disconnect:
652                     if (this.State == ChatState.Authenticated)
653                     {
654                         this.ConnectToFrontEnd();
655                     }
656                     else
657                     {
658                         this.State = ChatState.Disconnected;
659                         this.listener.OnChatStateChange(ChatState.Disconnected);
660                         this.listener.OnDisconnected();
661                     }
662                     break;
663             }
664         }
File name: ChatClient.cs Copy
768         private void HandleAuthResponse(OperationResponse operationResponse)
769         {
770             ((IPhotonPeerListener)this).DebugReturn(DebugLevel.INFO, operationResponse.ToStringFull() + " on: " + this.NameServerAddress);
771             if (operationResponse.ReturnCode == 0)
772             {
773                 if (this.State == ChatState.ConnectedToNameServer)
774                 {
775                     this.State = ChatState.Authenticated;
776                     this.listener.OnChatStateChange(this.State);
777
778                     if (operationResponse.Parameters.ContainsKey(ParameterCode.Secret))
779                     {
780                         if (this.CustomAuthenticationValues == null)
781                         {
782                             this.CustomAuthenticationValues = new AuthenticationValues();
783                         }
784                         this.CustomAuthenticationValues.Secret = operationResponse[ParameterCode.Secret] as string;
785                         this.FrontendAddress = (string) operationResponse[ParameterCode.Address];
786
787                         // we disconnect and status handler starts to connect to front end
788                         this.chatPeer.Disconnect();
789                     }
790                     else
791                     {
792                         //TODO: error reaction!
793                     }
794                 }
795                 else if (this.State == ChatState.ConnectingToFrontEnd)
796                 {
797                     this.msDeltaForServiceCalls = this.msDeltaForServiceCalls * 4; // when we arrived on chat server: limit Service calls some more
798
799                     this.State = ChatState.ConnectedToFrontEnd;
800                     this.listener.OnChatStateChange(this.State);
801                     this.listener.OnConnected();
802                 }
803             }
804             else
805             {
806                 //((IPhotonPeerListener)this).DebugReturn(DebugLevel.INFO, operationResponse.ToStringFull() + " NS: " + this.NameServerAddress + " FrontEnd: " + this.frontEndAddress);
807
808                 switch (operationResponse.ReturnCode)
809                 {
810                     case ErrorCode.InvalidAuthentication:
811                         this.DisconnectedCause = ChatDisconnectCause.InvalidAuthentication;
812                         break;
813                     case ErrorCode.CustomAuthenticationFailed:
814                         this.DisconnectedCause = ChatDisconnectCause.CustomAuthenticationFailed;
815                         break;
816                     case ErrorCode.InvalidRegion:
817                         this.DisconnectedCause = ChatDisconnectCause.InvalidRegion;
818                         break;
819                     case ErrorCode.MaxCcuReached:
820                         this.DisconnectedCause = ChatDisconnectCause.MaxCcuReached;
821                         break;
822                     case ErrorCode.OperationNotAllowedInCurrentState:
823                         this.DisconnectedCause = ChatDisconnectCause.OperationNotAllowedInCurrentState;
824                         break;
825                 }
826
827                 this.State = ChatState.Disconnecting;
828                 this.chatPeer.Disconnect();
829             }
830         }

OnChatStateChange 122 lượt xem

Gõ tìm kiếm nhanh...