Exemple #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;
        }
    }
Exemple #2
0
    void CallbackProcess(string strParam)
    {
        string[] strSections = strParam.Split(new char[] { ',' });
        if (strSections == null)
        {
            return;
        }
        Log.e("strParam:" + strParam);
        //解析后得到两个字段,第一个为事件类型,第二个为错误码类型
        YouMe.YouMeEvent     eventType = (YouMeEvent)int.Parse(strSections[0]);
        YouMe.YouMeErrorCode errorCode = (YouMeErrorCode)int.Parse(strSections[1]);
        string channelID = strSections[2];
        string param     = strSections[3];

        switch (eventType)
        {
        case YouMe.YouMeEvent.YOUME_EVENT_INIT_OK:
            // 初始化成功
            if (initCallBack != null)
            {
                initCallBack(new InitEvent(errorCode));
            }
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_INIT_FAILED:
            // 初始化成功
            if (initCallBack != null)
            {
                initCallBack(new InitEvent(errorCode));
            }
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_JOIN_OK:
            // if (string.Equals (channelID, ARoomID))
            CallJoinChannelCallback(channelID, new ChannelEvent(Conv.ErrorCodeConvert(errorCode), ChannelEventType.JOIN_SUCCESS, channelID));
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_JOIN_FAILED:
            CallJoinChannelCallback(channelID, new ChannelEvent(Conv.ErrorCodeConvert(errorCode), ChannelEventType.JOIN_FAIL, channelID));
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_LEAVED_ONE:
            CallLeaveChannelCallback(channelID, new ChannelEvent(Conv.ErrorCodeConvert(errorCode), ChannelEventType.LEAVE_SUCCESS, channelID));
            // if (string.Equals (channelID, ARoomID))
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_LEAVED_ALL:
            if (leaveAllChannelCallback != null)
            {
                leaveAllChannelCallback(new ChannelEvent(Conv.ErrorCodeConvert(errorCode), ChannelEventType.LEAVE_SUCCESS, ""));
            }
            // tipsText.text = "已退出所有频道";
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_SPEAK_SUCCESS:
        case YouMe.YouMeEvent.YOUME_EVENT_SPEAK_FAILED:
            // tipsText.text = "可以对"+channelID+"房间说话";
            if (speakToChannelCallback != null)
            {
                speakToChannelCallback(new SpeakToChannelEvent(errorCode, channelID));
            }
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_VOICE_ON:
            Debug.LogError("YOUME_EVENT_OTHERS_VOICE_ON:" + param);
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_VOICE_OFF:
            Debug.LogError("YOUME_EVENT_OTHERS_VOICE_OFF:" + param);
            break;

        default:
            // tipsText.text + "\n事件类型" + eventType + ",错误码" + errorCode;
            break;
        }
    }
Exemple #3
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]);
        string channelID = strSections[2];
        string param     = strSections[3];

        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:
            //如果已调用了离开接口,则无须再等此类回调
            if (YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL == state)
            {
                return;
            }
            tipsText.text = tipsText.text + "\n加入频道成功";
            JoinedUI();
            state = YouMe.ChannelState.CHANNEL_STATE_JOINED;

            break;

        case YouMe.YouMeEvent.YOUME_EVENT_LEAVED_ALL:
            tipsText.text = tipsText.text + "\n离开频道成功";
            LeavedUI();
            state = YouMe.ChannelState.CHANNEL_STATE_LEAVED;

            break;

        case YouMe.YouMeEvent.YOUME_EVENT_JOIN_FAILED:
            //进入语音频道失败
            tipsText.text = tipsText.text + "\n加入频道失败,错误码:" + errorCode;
            LeavedUI();
            state = YouMe.ChannelState.CHANNEL_STATE_LEAVED;

            break;

        case YouMe.YouMeEvent.YOUME_EVENT_REC_PERMISSION_STATUS:
            if (errorCode == YouMe.YouMeErrorCode.YOUME_ERROR_REC_NO_PERMISSION)
            {
                tipsText.text = tipsText.text + "\n录音启动失败(此时不管麦克风mute状态如何,都没有声音输出";
            }

            break;

        case YouMe.YouMeEvent.YOUME_EVENT_RECONNECTING:
            tipsText.text = tipsText.text + "\n断网了,正在重连";

            break;

        case YouMe.YouMeEvent.YOUME_EVENT_RECONNECTED:
            tipsText.text = tipsText.text + "\n断网重连成功";

            break;

        case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_MIC_OFF:
            //其他用户的麦克风关闭:
            //Send Event callback, event(18):OTHERS_SPEAKER_ON, errCode:0, room:, param:3026935
            tipsText.text = tipsText.text + "\n用户" + param + "的麦克风关闭";

            break;

        case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_MIC_ON:
            //其他用户的麦克风打开:
            tipsText.text = tipsText.text + "\n用户" + param + "的麦克风打开";

            break;

        case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_SPEAKER_ON:
            //其他用户的扬声器打开:
            tipsText.text = tipsText.text + "\n用户" + param + "的扬声器打开";

            break;

        case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_SPEAKER_OFF:
            //其他用户的扬声器关闭
            tipsText.text = tipsText.text + "\n用户" + param + "的扬声器关闭";

            break;

        default:
            tipsText.text = tipsText.text + "\n事件类型" + eventType + ",错误码" + errorCode;
            break;
        }
    }
    //回调函数
    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]);
        string channelID = strSections [2];
        string param     = strSections [3];

        //打印输出
        //Debug.LogError ("eventType:" + eventType.ToString ());
        //Debug.LogError ("iErrorCode:" + iErrorCode.ToString ());

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

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

        case YouMe.YouMeEvent.YOUME_EVENT_JOIN_OK:
            YouMe.YouMeVoiceAPI.GetInstance().SetMicrophoneMute(false);
            Debug.LogError(YouMe.YouMeVoiceAPI.GetInstance().SetVadCallbackEnabled(true));
            if (YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL == stateA)
            {
                //说明已经调用了离开所有频道的操作,此时只需要等离开所有频道的回调就行
                return;
            }

            tipsText.text = "";
            micToggle.gameObject.SetActive(true);
            YouMe.YouMeVoiceAPI.GetInstance().SetSpeakerMute(false);
            if (string.Equals(channelID, ARoomID))
            {
                stateA         = YouMe.ChannelState.CHANNEL_STATE_JOINED;
                ATipsText.text = "已进入";

                //加入A频道成功后,则离开A频道按钮变为可交互。B频道根据状态恢复UI
                leaveAButton.interactable = true;
                AMicToggle.gameObject.SetActive(true);
                if (YouMe.ChannelState.CHANNEL_STATE_JOINED == stateB)
                {
                    BMicToggle.gameObject.SetActive(true);
                    leaveBButton.interactable = true;
                }
                else
                {
                    joinBButton.interactable = true;
                }
            }
            else if (string.Equals(channelID, BRoomID))
            {
                BTipsText.text = "已进入";

                stateB = YouMe.ChannelState.CHANNEL_STATE_JOINED;
                //加入B频道成功后,则离开B频道按钮变为可交互。A频道根据状态恢复UI
                leaveBButton.interactable = true;
                BMicToggle.gameObject.SetActive(true);
                if (YouMe.ChannelState.CHANNEL_STATE_JOINED == stateA)
                {
                    AMicToggle.gameObject.SetActive(true);
                    leaveAButton.interactable = true;
                }
                else
                {
                    joinAButton.interactable = true;
                }
            }
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_LEAVED_ONE:

            if (YouMe.ChannelState.CHANNEL_STATE_LEAVING_ALL == stateA)
            {
                //说明已经调用了离开所有频道的操作,此时只需要等离开所有频道的回调就行
                return;
            }

            if (string.Equals(channelID, ARoomID))
            {
                stateA         = YouMe.ChannelState.CHANNEL_STATE_LEAVED;
                ATipsText.text = "已离开";

                //离开A频道成功后,则加入A频道按钮变为可交互。B频道根据状态恢复UI
                joinAButton.interactable = true;
                if (YouMe.ChannelState.CHANNEL_STATE_JOINED == stateB)
                {
                    BMicToggle.gameObject.SetActive(true);
                    micToggle.gameObject.SetActive(true);

                    leaveBButton.interactable = true;
                }
                else
                {
                    joinBButton.interactable = true;
                }
            }
            else if (string.Equals(channelID, BRoomID))
            {
                BTipsText.text = "已离开";

                stateB = YouMe.ChannelState.CHANNEL_STATE_LEAVED;
                //加入B频道成功后,则加入B频道按钮变为可交互。A频道根据状态恢复UI
                joinBButton.interactable = true;
                if (YouMe.ChannelState.CHANNEL_STATE_JOINED == stateA)
                {
                    AMicToggle.gameObject.SetActive(true);
                    leaveAButton.interactable = true;
                    micToggle.gameObject.SetActive(true);
                }
                else
                {
                    joinAButton.interactable = true;
                }
            }
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_LEAVED_ALL:
            tipsText.text               = "已退出所有频道";
            stateA                      = YouMe.ChannelState.CHANNEL_STATE_LEAVED;
            ATipsText.text              = "已离开";
            stateB                      = YouMe.ChannelState.CHANNEL_STATE_LEAVED;
            BTipsText.text              = "已离开";
            joinAButton.interactable    = true;
            joinBButton.interactable    = true;
            leaveAllButton.interactable = true;
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_SPEAK_SUCCESS:
            AMicToggle.interactable = true;
            BMicToggle.interactable = true;
            micToggle.interactable  = true;

            if (string.Equals(channelID, ARoomID))
            {
                tipsText.text = "可以对A房间说话";
            }
            else if (string.Equals(channelID, BRoomID))
            {
                tipsText.text = "可以对B房间说话";
            }
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_SPEAK_FAILED:
            AMicToggle.interactable = true;
            BMicToggle.interactable = true;
            micToggle.interactable  = true;
            if (string.Equals(channelID, ARoomID))
            {
                tipsText.text   = "对A房间说话的操作失败";
                AMicToggle.isOn = false;
                YouMe.YouMeVoiceAPI.GetInstance().SetMicrophoneMute(true);
                micToggle.isOn = true;
            }
            else if (string.Equals(channelID, BRoomID))
            {
                tipsText.text   = "对B房间说话的操作失败";
                BMicToggle.isOn = false;
                YouMe.YouMeVoiceAPI.GetInstance().SetMicrophoneMute(true);
                micToggle.isOn = true;
            }
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_VOICE_ON:
            Debug.LogError("YOUME_EVENT_OTHERS_VOICE_ON:" + param);
            break;

        case YouMe.YouMeEvent.YOUME_EVENT_OTHERS_VOICE_OFF:
            Debug.LogError("YOUME_EVENT_OTHERS_VOICE_OFF:" + param);
            break;

        default:
            tipsText.text = tipsText.text + "\n事件类型" + eventType + ",错误码" + errorCode;
            break;
        }
    }