Esempio n. 1
0
        public void JoinChannel(Channel channel, Action <ChannelEvent> callback, YouMeUserRole role = YouMeUserRole.YOUME_USER_TALKER_FREE)
        {
            if (string.IsNullOrEmpty(GetUserID()))
            {
                Log.e("Need SetUserID(string userid).");
                if (callback != null)
                {
                    callback(new ChannelEvent(StatusCode.USER_ID_IS_EMPTY, ChannelEventType.JOIN_FAIL, channel.ChannelID));
                }
                return;
            }
            talkManager.AddJoinChannelCallback(channel.ChannelID, callback);
            YouMeErrorCode errorCode;

            if (_config.AllowMultiChannel)
            {
                errorCode = YouMeVoiceAPI.GetInstance().JoinChannelMultiMode(GetUserID(), channel.ChannelID);
            }
            else
            {
                errorCode = YouMeVoiceAPI.GetInstance().JoinChannelSingleMode(GetUserID(), channel.ChannelID, (int)role);
            }

            if (errorCode != YouMeErrorCode.YOUME_SUCCESS && callback != null)
            {
                talkManager.RemoveJoinChannelCallback(channel.ChannelID);
                callback(new ChannelEvent(Conv.ErrorCodeConvert(errorCode), ChannelEventType.JOIN_FAIL, channel.ChannelID));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 发送文本消息
        /// </summary>
        /// <param name="reciverID">接收者id,私聊就用用户id,频道聊天就用频道id</param>
        /// <param name="chatType">私聊消息还是频道消息</param>
        /// <param name="msgContent">文本消息内容</param>
        /// <param name="onSendCallBack">消息发送结果的回调通知</param>
        /// <returns>返回 TextMessage 实例</returns>
        public TextMessage SendTextMessage(string reciverID, ChatType chatType, string msgContent, Action <StatusCode, TextMessage> onSendCallBack)
        {
            ulong reqID = 0;

            YIMEngine.ErrorCode code = 0;
            code = IMAPI.Instance().SendTextMessage(reciverID, (YIMEngine.ChatType)chatType, msgContent, ref reqID);
            var msg = new TextMessage(GetCurrentUserID().UserID, reciverID, chatType, msgContent, false);

            if (code == YIMEngine.ErrorCode.Success)
            {
                msg.sendStatus = SendStatus.Sending;
                msg.requestID  = reqID;
                MessageCallbackObject callbackObj = new MessageCallbackObject(msg, MessageBodyType.TXT, onSendCallBack);
                IMInternalManager.Instance.AddMessageCallback(reqID, callbackObj);
            }
            else
            {
                msg.sendStatus = SendStatus.Fail;
                if (onSendCallBack != null)
                {
                    onSendCallBack(Conv.ErrorCodeConvert(code), msg);
                }
            }
            return(msg);
        }
Esempio n. 3
0
        /// <summary>
        /// 启动录音
        /// </summary>
        /// <param name="reciverID">接收者id,私聊就用用户id,频道聊天就用频道id</param>
        /// <param name="chatType">私聊消息还是频道消息</param>
        /// <param name="extraMsg">附带自定义文本消息内容</param>
        /// <param name="recognizeText">是否开启语音转文字识别功能</param>
        /// <param name="callback">语音消息发送回调通知,会通知多次,通过AudioMessage的sendStatus属性可以判断是哪个状态的回调</param>
        /// <returns></returns>
        public AudioMessage StartRecordAudio(string reciverID, ChatType chatType, string extraMsg, bool recognizeText, Action <StatusCode, AudioMessage> callback)
        {
            ulong reqID = 0;

            YIMEngine.ErrorCode code = 0;
            if (recognizeText)
            {
                code = IMAPI.Instance().SendAudioMessage(reciverID, (YIMEngine.ChatType)chatType, ref reqID);
            }
            else
            {
                code = IMAPI.Instance().SendOnlyAudioMessage(reciverID, (YIMEngine.ChatType)chatType, ref reqID);
            }
            var msg = new AudioMessage(GetCurrentUserID().UserID, reciverID, chatType, extraMsg, false);

            if (code == YIMEngine.ErrorCode.Success)
            {
                msg.requestID          = reqID;
                msg.sendStatus         = SendStatus.NotStartSend;
                lastRecordAudioMessage = msg;
                MessageCallbackObject callbackObj = new MessageCallbackObject(msg, MessageBodyType.Voice, callback);
                IMInternalManager.Instance.AddMessageCallback(reqID, callbackObj);
            }
            else
            {
                msg.sendStatus = SendStatus.Fail;
                Log.e("Start Record Fail! code:" + code.ToString());
                if (callback != null)
                {
                    callback(Conv.ErrorCodeConvert(code), msg);
                }
            }
            return(msg);
        }
Esempio n. 4
0
        public void LeaveChannel(Channel channel, Action <ChannelEvent> callback)
        {
            leaveChannelCallback = callback;
            var code = IMAPI.Instance().LeaveChatRoom(channel.ChannelID);

            if (code != YIMEngine.ErrorCode.Success && ChannelEventListener != null)
            {
                ChannelEventListener(new ChannelEvent(Conv.ErrorCodeConvert(code), ChannelEventType.LEAVE_FAIL, channel.ChannelID));
            }
        }
Esempio n. 5
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);
     }
 }
Esempio n. 6
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);
     }
 }
Esempio n. 7
0
 public void JoinMultiChannel(Channel[] channels, Action <ChannelEvent> callback)
 {
     joinChannelCallback = callback;
     for (int i = 0; i < channels.Length; i++)
     {
         var code = IMAPI.Instance().JoinChatRoom(channels[i].ChannelID);
         if (code != YIMEngine.ErrorCode.Success && ChannelEventListener != null)
         {
             ChannelEventListener(new ChannelEvent(Conv.ErrorCodeConvert(code), ChannelEventType.LEAVE_FAIL, channels[i].ChannelID));
         }
     }
 }
Esempio n. 8
0
        public void LeaveAllChannel(Action <ChannelEvent> callback)
        {
            YouMeErrorCode errorCode = YouMeVoiceAPI.GetInstance().LeaveChannelAll();

            if (errorCode != YouMeErrorCode.YOUME_SUCCESS && callback != null)
            {
                callback(new ChannelEvent(Conv.ErrorCodeConvert(errorCode), ChannelEventType.LEAVE_FAIL, ""));
            }
            else
            {
                talkManager.leaveAllChannelCallback = callback;
            }
        }
Esempio n. 9
0
 public void LeaveChannel(Channel channel, Action <ChannelEvent> callback)
 {
     if (channel.ChannelID == null)
     {
         Log.e("channel ID can't be null.");
         return;
     }
     if (_config.AllowMultiChannel)
     {
         YouMeErrorCode errorCode = YouMeVoiceAPI.GetInstance().LeaveChannelMultiMode(channel.ChannelID);
         if (errorCode != YouMeErrorCode.YOUME_SUCCESS && callback != null)
         {
             callback(new ChannelEvent(Conv.ErrorCodeConvert(errorCode), ChannelEventType.LEAVE_FAIL, channel.ChannelID));
         }
         else
         {
             talkManager.AddLeaveChannelCallback(channel.ChannelID, callback);
         }
     }
     else
     {
         LeaveAllChannel(callback);
     }
 }
Esempio n. 10
0
 /// <summary>
 /// 设置麦克风音量回调参数
 /// 你可以在初始化成功后随时调用这个接口。在整个APP生命周期只需要调用一次,除非你想修改参数。
 /// 设置成功后,当用户讲话时,你将收到回调事件 MY_MIC_LEVEL, 回调参数 iStatus 表示当前讲话的音量级别。
 /// </summary>
 ///
 /// <param name="maxMicLevel">
 /// 设为 0 表示关闭麦克风音量回调
 /// 设为 大于0的值表示音量最大时对应的值,这个可以根据你们的UI设计来设定。
 /// 比如你用10级的音量条来表示音量变化,则传10。这样当底层回传音量是10时,则表示当前mic音量达到最大值。
 /// </param>
 ///
 /// <returns>
 /// YouMeErrorCode.YOUME_SUCCESS 表示设置成功
 /// 返回其他值时请看 YouMeErrorCode 的定义
 /// </returns>
 ///
 public StatusCode SetMicLevelCallback(int maxMicLevel)
 {
     return(Conv.ErrorCodeConvert(YouMeVoiceAPI.GetInstance().SetMicLevelCallback(maxMicLevel)));
 }
Esempio n. 11
0
 /// <summary>
 /// 播放指定的音乐文件。播放的音乐将会通过扬声器输出,并和语音混合后发送给接收方。这个功能适合于主播/指挥等使用。
 /// 如果当前已经有一个音乐文件在播放,正在播放的音乐会被停止,然后播放新的文件。
 /// 这是一个异步调用接口,函数返回YouMeErrorCode.YOUME_SUCCESS后,将通过如下回调事件通知音乐播放的状态:
 /// YouMeEvent.YOUME_EVENT_BGM_STOPPED - 音乐播放结束了
 /// YouMeEvent.YOUME_EVENT_BGM_FAILED - 音乐文件无法播放(比如文件损坏,格式不支持等)
 /// </summary>
 ///
 /// <param name="strFilePath"> 音乐文件的路径 </param>
 /// <param name="bRepeat"> true 重复播放这个文件, false 只播放一次就停止播放 </param>
 ///
 /// <returns>
 /// YouMeErrorCode.YOUME_SUCCESS 表明成功启动了音乐播放流程
 /// 返回其他值时请看 YouMeErrorCode 的定义
 /// </returns>
 ///
 public StatusCode PlayBackgroundMusic(string strFilePath, bool bRepeat)
 {
     return(Conv.ErrorCodeConvert(YouMeVoiceAPI.GetInstance().PlayBackgroundMusic(strFilePath, bRepeat)));
 }
Esempio n. 12
0
 /// <summary>
 /// 设置不接收指定用户的语音
 /// </summary>
 ///
 /// <param name="userID">要屏蔽的用户的ID</param>
 /// <param name="isOn">true为打开,false为关闭</param>
 ///
 /// <returns>返回接口调用是否成功的状态码,YouMeErrorCode.YOUME_SUCCESS表示成功</returns>
 ///
 public StatusCode AvoidOtherVoiceStatus(string userID, bool isOn)
 {
     return(Conv.ErrorCodeConvert(YouMeVoiceAPI.GetInstance().AvoidOtherVoiceStatus(userID, isOn)));
 }
Esempio n. 13
0
 /// <summary>
 /// 停止播放当前正在播放的背景音乐。
 /// 这是一个同步调用接口,函数返回时,音乐播放也就停止了。
 /// </summary>
 ///
 /// <returns>
 /// YouMeErrorCode.YOUME_SUCCESS 表明成功停止了音乐播放流程
 /// 返回其他值时请看 YouMeErrorCode 的定义
 /// </returns>
 ///
 public StatusCode StopBackgroundMusic()
 {
     return(Conv.ErrorCodeConvert(YouMeVoiceAPI.GetInstance().StopBackgroundMusic()));
 }
Esempio n. 14
0
 /// <summary>
 /// 设定背景音乐的音量。这个接口用于调整背景音乐和语音之间的相对音量,使得背景音乐和语音混合听起来协调。
 /// 这是一个同步调用接口
 /// </summary>
 ///
 /// <param name="volume"> 背景音乐的音量,范围 [0-100], 100为最大音量 </param>
 ///
 /// <returns>
 /// YouMeErrorCode.YOUME_SUCCESS 表明成功设置了背景音乐的音量
 /// 返回其他值时请看 YouMeErrorCode 的定义
 /// </returns>
 ///
 public StatusCode SetBackgroundMusicVolume(int volume)
 {
     return(Conv.ErrorCodeConvert(YouMeVoiceAPI.GetInstance().SetBackgroundMusicVolume(volume)));
 }
Esempio n. 15
0
 /// <summary>
 /// 设置插耳机的情况下开启或关闭语音监听(即通过耳机听到自己说话的内容)
 /// 这是一个同步调用接口
 /// </summary>
 ///
 /// <param name="enabled"> true 开启监听,false 关闭监听 </param>
 ///
 /// <returns>
 /// YouMeErrorCode.YOUME_SUCCESS 表明成功设置了语音监听
 /// 返回其他值时请看 YouMeErrorCode 的定义
 /// </returns>
 ///
 public StatusCode SetHeadsetMonitorOn(bool enabled)
 {
     return(Conv.ErrorCodeConvert(YouMeVoiceAPI.GetInstance().SetHeadsetMonitorOn(enabled)));
 }
Esempio n. 16
0
 /// <summary>
 /// 设置是否开启语音检测回调
 /// 这是一个同步调用接口
 /// </summary>
 ///
 /// <param name="enabled"> true 开启语音检测,false 关闭语音检测 </param>
 ///
 /// <returns>
 /// YouMeErrorCode.YOUME_SUCCESS 表明成功设置了语音检测回调
 /// 返回其他值时请看 YouMeErrorCode 的定义
 /// </returns>
 ///
 public StatusCode SetVadCallbackEnabled(bool enabled)
 {
     return(Conv.ErrorCodeConvert(YouMeVoiceAPI.GetInstance().SetVadCallbackEnabled(enabled)));
 }
Esempio n. 17
0
 /// <summary>
 /// 恢复通话,调用PauseChannel暂停通话后,可调用这个接口恢复通话
 /// 这是一个异步调用接口,函数返回YouMeErrorCode.YOUME_SUCCESS后,还需要等待如下事件回调
 /// YouMeEvent.YOUME_EVENT_RESUMED - 成功恢复语音
 /// YouMeEvent.YOUME_EVENT_RESUME_FAILED - 恢复语音失败
 /// </summary>
 ///
 /// <returns>
 /// YouMeErrorCode.YOUME_SUCCESS 表明恢复通话正在进行当中
 /// 返回其他值时请看 YouMeErrorCode 的定义
 /// </returns>
 ///
 public StatusCode ResumeChannel()
 {
     return(Conv.ErrorCodeConvert(YouMeVoiceAPI.GetInstance().ResumeChannel()));
 }