コード例 #1
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);
        }
コード例 #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);
        }
コード例 #3
0
 public bool AddMessageCallback(ulong reqID, MessageCallbackObject callback)
 {
     if (!messageCallbackQueue.ContainsKey(reqID))
     {
         messageCallbackQueue.Add(reqID, callback);
     }
     else
     {
         Log.e("message id is already in sending queue.");
         return(false);
     }
     return(true);
 }
コード例 #4
0
    public void OnSendMessageStatus(ulong iRequestID, YIMEngine.ErrorCode errorcode)
    {
        MessageCallbackObject callbackObj = null;
        bool finded = messageCallbackQueue.TryGetValue(iRequestID, out callbackObj);

        if (finded)
        {
            if (callbackObj != null && callbackObj.callback != null)
            {
                try
                {
                    switch (callbackObj.msgType)
                    {
                    case MessageBodyType.TXT:
                        Action <YouMe.StatusCode, TextMessage> call = (Action <YouMe.StatusCode, TextMessage>)callbackObj.callback;
                        var msg = (TextMessage)callbackObj.message;
                        msg.sendTime = TimeUtil.ConvertToTimestamp(System.DateTime.Now);
                        if (errorcode == YIMEngine.ErrorCode.Success)
                        {
                            msg.sendStatus = SendStatus.Sended;
                        }
                        else
                        {
                            msg.sendStatus = SendStatus.Fail;
                        }
                        msg.isReceiveFromServer = false;
                        call(Conv.ErrorCodeConvert(errorcode), msg);
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception e)
                {
                    Log.e(e.ToString());
                }
            }
            messageCallbackQueue.Remove(iRequestID);
        }
    }
コード例 #5
0
    private void OnSendAudioMessageStatusChange(ulong iRequestID, YIMEngine.ErrorCode errorcode, string strText, string strAudioPath, int iDuration, bool isFinish)
    {
        MessageCallbackObject callbackObj = null;
        bool finded = messageCallbackQueue.TryGetValue(iRequestID, out callbackObj);

        if (finded)
        {
            if (callbackObj != null && callbackObj.callback != null)
            {
                Action <YouMe.StatusCode, AudioMessage> call = (Action <YouMe.StatusCode, AudioMessage>)callbackObj.callback;
                var msg = (AudioMessage)callbackObj.message;
                msg.recognizedText = strText;
                msg.audioFilePath  = strAudioPath;
                msg.audioDuration  = iDuration;
                if (!isFinish)
                {
                    msg.sendTime = TimeUtil.ConvertToTimestamp(System.DateTime.Now);
                }
                if (errorcode == YIMEngine.ErrorCode.Success)
                {
                    msg.sendStatus = isFinish ? SendStatus.Sended : SendStatus.Sending;
                    if (isFinish)
                    {
                        msg.downloadStatus = MessageDownloadStatus.DOWNLOADED;
                    }
                }
                else
                {
                    msg.sendStatus = SendStatus.Fail;
                }
                msg.isReceiveFromServer = false;
                call(Conv.ErrorCodeConvert(errorcode), msg);
            }
            messageCallbackQueue.Remove(iRequestID);
        }
    }