Example #1
0
        /// <summary>
        /// 结束录音并发送语音消息
        /// </summary>
        /// <returns>false表示启动发送失败,true表示启动发送成功</returns>
        public bool StopRecordAndSendAudio()
        {
            if (lastRecordAudioMessage == null)
            {
                return(false);
            }
            var audioMsg = lastRecordAudioMessage;

            if (audioMsg.sendStatus == SendStatus.Fail)
            {
                Log.e("StopRecordAndSendAudio Fail! SendStatus is Fail!");
                lastRecordAudioMessage = null;
                return(false);
            }
            YIMEngine.ErrorCode code = IMAPI.Instance().StopAudioMessage(audioMsg.extraParam);
            lastRecordAudioMessage = null;
            if (code == YIMEngine.ErrorCode.Success)
            {
                return(true);
            }
            else
            {
                Log.e("StopRecordAndSendAudio Fail! code:" + code.ToString());
                return(false);
            }
        }
Example #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);
        }
Example #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);
        }
Example #4
0
 void OnApplicationQuit()
 {
     #if UNITY_EDITOR
     IMAPI.Instance().Logout();
     #else
     IMAPI.Instance().UnInit();
     #endif
 }
Example #5
0
 /// <summary>
 /// 设置配置信息
 /// </summary>
 /// <param name="appKey">游密官方分配的APP唯一标识,在www.youme.im注册后可以自助获取</param>
 /// <param name="secretKey">游密官方分配的接入密钥,和appkey配对使用,在www.youme.im注册后可以自助获取</param>
 /// <param name="config">SDK配置对象,可以通过该对象的参数设置SDK的可选参数,比如服务器区域、日志级别、方言识别</param>
 /// <returns>IMClient对象</returns>
 public IMClient Initialize(string appKey, string secretKey, IMConfig config)
 {
     if (config != null)
     {
         IMAPI.Instance().SetServerZone((YIMEngine.ServerZone)config.ServerZone);
     }
     IMAPI.Instance().Init(appKey, secretKey);
     return(this);
 }
Example #6
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));
            }
        }
Example #7
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);
     }
 }
Example #8
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);
     }
 }
Example #9
0
 void OnApplicationPause(bool isPause)
 {
     if (isPause)
     {
         IMAPI.Instance().OnPause();
     }
     else
     {
         IMAPI.Instance().OnResume();
     }
 }
Example #10
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));
         }
     }
 }
Example #11
0
 public IMClient SetDebug(bool isDebug)
 {
     if (isDebug)
     {
         IMAPI.SetMode(0);
     }
     else
     {
         IMAPI.SetMode(2);
     }
     return(this);
 }
Example #12
0
        public void DownloadFile(ulong requestID, string targetFilePath, Action <YouMe.StatusCode, string> downloadCallback)
        {
            YIMEngine.ErrorCode code = IMAPI.Instance().DownloadAudioFile(requestID, targetFilePath);
            bool ret = false;

            if (code == YIMEngine.ErrorCode.Success)
            {
                ret = IMInternalManager.Instance.AddDownloadCallback(requestID, downloadCallback);
            }
            if (!ret && downloadCallback != null)
            {
                downloadCallback(YouMe.StatusCode.START_DOWNLOAD_FAIL, "");
            }
        }