Пример #1
0
    //回调函数
    void OnEvent(string strParam)
    {
        string[] strSections = strParam.Split(new char[] { ',' }, 4);
        if (strSections == null)
        {
            return;
        }
        //解析后得到两个字段,第一个为事件类型,第二个为错误码类型
        YouMe.YouMeEvent     eventType = (YouMeEvent)int.Parse(strSections [0]);
        YouMe.YouMeErrorCode errorCode = (YouMeErrorCode)int.Parse(strSections [1]);

        switch (eventType)
        {
        case YouMe.YouMeEvent.YOUME_EVENT_INIT_OK:
            tipsText.text = "初始化成功";
            inited        = true;
            InitedUI();
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_INIT_FAILED:
            tipsText.text = "初始化失败,错误码:" + errorCode;
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_JOIN_OK:
            tipsText.text = "加入频道成功";
            nextRole      = YouMe.YouMeUserRole.YOUME_USER_NONE;
            nextRoomID    = null;
            state         = YouMe.ChannelState.CHANNEL_STATE_JOINED;
            JoinedUI();
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_LEAVED_ALL:
            if (YouMe.YouMeUserRole.YOUME_USER_NONE != nextRole)
            {
                //需要加入新频道
                errorCode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(userID, nextRoomID, nextRole);
                if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode)
                {
                    state = YouMe.ChannelState.CHANNEL_STATE_JOINING;
                    JoiningUI();
                }
            }
            else
            {
                tipsText.text             = "离开频道成功";
                labelDropdown.text        = "静音";
                roomDropdown.interactable = true;
                LeavedUI();
                state = YouMe.ChannelState.CHANNEL_STATE_LEAVED;
            }
            break;

        default:
            tipsText.text = tipsText.text + "\n事件类型" + eventType + ",错误码" + errorCode;
            break;
        }
    }
Пример #2
0
    public void onDropdown()
    {
        roomDropdown.interactable = false;
        LeavedUI();
        switch (roomDropdown.value)
        {
        case 0:
            tipsText.text = "静音模式";
            //调用离开频道
            var errorCode = YouMe.YouMeVoiceAPI.GetInstance().LeaveChannelAll();
            if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode)
            {
                state = YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL;
                LeavingUI();
            }
            break;

        case 1:
            tipsText.text = "主播模式";

            if (YouMe.ChannelState.CHANNEL_STATE_LEAVED == state)
            {
                //当前状态为不在房间,则可直接加入新房间
                if (hostAuthority)
                {
                    //为主播身份
                    GetID();
                    errorCode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(userID, hostRoomID, YouMe.YouMeUserRole.YOUME_USER_HOST);
                    if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode)
                    {
                        state = YouMe.ChannelState.CHANNEL_STATE_JOINING;
                        JoiningUI();
                    }

                    //SpeakerUI ();
                }
                else
                {
                    //为听众身份
                    GetID();
                    errorCode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(userID, hostRoomID, YouMe.YouMeUserRole.YOUME_USER_LISTENER);
                    if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode)
                    {
                        state = YouMe.ChannelState.CHANNEL_STATE_JOINING;
                        JoiningUI();
                    }
                    //ListenerUI ();
                }
            }

            if (YouMe.ChannelState.CHANNEL_STATE_JOINED == state)
            {
                //当前状态为已经在房间,需要先退出并等回调成功,再重新加入
                nextRoomID = hostRoomID;
                if (hostAuthority)
                {
                    //准备以主播身份加入主播频道
                    nextRole = YouMe.YouMeUserRole.YOUME_USER_HOST;
                }
                else
                {
                    //准备以听众身份加入主播频道
                    nextRole = YouMe.YouMeUserRole.YOUME_USER_LISTENER;
                }
                //先调用离开频道
                errorCode = YouMe.YouMeVoiceAPI.GetInstance().LeaveChannelAll();
                if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode)
                {
                    state = YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL;
                    LeavingUI();
                }
            }
            break;

        case 2:
            tipsText.text = "指挥模式";

            if (YouMe.ChannelState.CHANNEL_STATE_LEAVED == state)
            {
                //当前状态为不在房间,则可直接加入新房间
                if (commanderAuthority)
                {
                    //为指挥身份
                    GetID();
                    errorCode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(userID, commanderRoomID, YouMe.YouMeUserRole.YOUME_USER_COMMANDER);
                    if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode)
                    {
                        state = YouMe.ChannelState.CHANNEL_STATE_JOINING;
                        JoiningUI();
                    }
                }
                else
                {
                    //为听众身份
                    GetID();
                    errorCode = YouMe.YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(userID, commanderRoomID, YouMe.YouMeUserRole.YOUME_USER_LISTENER);
                    if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode)
                    {
                        state = YouMe.ChannelState.CHANNEL_STATE_JOINING;
                        JoiningUI();
                    }
                }
            }

            if (YouMe.ChannelState.CHANNEL_STATE_JOINED == state)
            {
                //当前状态为已经在房间,需要先退出并等回调成功,再重新加入
                nextRoomID = commanderRoomID;
                if (hostAuthority)
                {
                    //准备以指挥身份加入指挥频道
                    nextRole = YouMe.YouMeUserRole.YOUME_USER_COMMANDER;
                }
                else
                {
                    //准备以听众身份加入指挥频道
                    nextRole = YouMe.YouMeUserRole.YOUME_USER_LISTENER;
                }
                //先调用离开频道
                errorCode = YouMe.YouMeVoiceAPI.GetInstance().LeaveChannelAll();
                if (YouMe.YouMeErrorCode.YOUME_SUCCESS == errorCode)
                {
                    state = YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL;
                    LeavingUI();
                }
            }
            break;
        }
    }