예제 #1
0
    public void OnLoginClick()
    {
        userIDInput.interactable = false;

        // 注册接收新消息的方法
        IM.SetReceiveMessageListener(OnReceiveMessage);
        // 断线事件监听
        IM.SetDisconnectListener((disconnectEvt) => {
            Debug.Log("断线了");
        });
        // 被踢下线事件监听
        IM.SetKickOffListener((kickoffEvt) => {
            Debug.Log("被踢下线了");
        });

        //开始登陆
        IM.Login(userIDInput.text, "", (evt) => {
            if (evt.Code == StatusCode.Success)
            {
                userIDInput.interactable = false; loginButton.interactable = false; logoutButton.interactable = true;
                //进入聊天频道
                IM.JoinChannel(new Channel("5678"), (channelEvt) => {
                    if (channelEvt.code == StatusCode.Success)
                    {
                        Log2UI("进入频道:5678 成功");
                    }
                    else
                    {
                        Log2UI("进入频道:5678 失败");
                    }
                });
                Log2UI("登陆成功");
                Log2UI("开始进入频道:5678");
            }
            else
            {
                userIDInput.interactable = true; loginButton.interactable = true; logoutButton.interactable = false;
                Log2UI("登陆失败,错误码:" + evt.Code);
            }
        });
    }