コード例 #1
0
 /// <summary>
 /// 登录IM系统。成功登录IM系统后就可以进行私聊消息的收发,以及进出聊天频道,进行频道消息的收发。
 /// </summary>
 /// <param name="userID">用户ID或者游戏角色ID,唯一标识一个用户在应用里的身份</param>
 /// <param name="token">使用服务器token验证模式时使用该参数,否则使用空字符串""即可</param>
 /// <param name="callback">登录结果的回调通知,在此回调里判读登录是否成功</param>
 public void Login(string userID, string token, Action <LoginEvent> callback)
 {
     // login
     loginCallback = callback;
     YIMEngine.ErrorCode code = IMAPI.Instance().Login(userID, FAKE_PAPSSWORD, token);
     if (code != YIMEngine.ErrorCode.Success && ConnectListener != null)
     {
         IMConnectEvent e = new IMConnectEvent(Conv.ErrorCodeConvert(code), ConnectEventType.CONNECT_FAIL, userID);
         ConnectListener(e);
     }
 }
コード例 #2
0
 public void Logout(Action <LogoutEvent> callback)
 {
     // logout
     logoutCallback = callback;
     YIMEngine.ErrorCode code = IMAPI.Instance().Logout();
     if (code != YIMEngine.ErrorCode.Success && ConnectListener != null)
     {
         IMConnectEvent e = new IMConnectEvent(Conv.ErrorCodeConvert(code), ConnectEventType.DISCONNECTED, "");
         ConnectListener(e);
     }
 }
コード例 #3
0
        private void OnConnect(IMConnectEvent connectEvent)
        {
            switch (connectEvent.EventType)
            {
            case ConnectEventType.CONNECTED:
                if (loginCallback != null)
                {
                    loginCallback(new LoginEvent(connectEvent.Code, connectEvent.UserID));
                }
                break;

            case ConnectEventType.CONNECT_FAIL:
                if (loginCallback != null)
                {
                    loginCallback(new LoginEvent(connectEvent.Code, connectEvent.UserID));
                }
                break;

            case ConnectEventType.OFF_LINE:
                if (disconnectCallback != null)
                {
                    disconnectCallback(new DisconnectEvent(connectEvent.Code, connectEvent.UserID));
                }
                break;

            case ConnectEventType.DISCONNECTED:
                if (logoutCallback != null)
                {
                    logoutCallback(new LogoutEvent(connectEvent.Code, connectEvent.UserID));
                }
                break;

            case ConnectEventType.KICKED:
                if (kickOffCallback != null)
                {
                    kickOffCallback(new KickOffEvent(connectEvent.Code, connectEvent.UserID));
                }
                break;

            default:
                break;
            }
        }