/// <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); }
/// <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); } }
/// <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); }
public void OnLeaveRoom(YIMEngine.ErrorCode errorcode, string iChatRoomID) { if (IMClient.Instance.ChannelEventListener != null) { ChannelEventType et = errorcode == YIMEngine.ErrorCode.Success ? ChannelEventType.LEAVE_SUCCESS : ChannelEventType.LEAVE_FAIL; IMClient.Instance.ChannelEventListener(new ChannelEvent(Conv.ErrorCodeConvert(errorcode), et, iChatRoomID)); } }
/// <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); } }
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); } }
public void OnLogin(YIMEngine.ErrorCode errorcode, string iYouMeID) { if (errorcode == YIMEngine.ErrorCode.Success) { _lastLoginUser = new IMUser(iYouMeID); } if (IMClient.Instance.ConnectListener != null) { IMConnectEvent e = new IMConnectEvent(Conv.ErrorCodeConvert(errorcode), errorcode == 0 ? ConnectEventType.CONNECTED:ConnectEventType.CONNECT_FAIL, iYouMeID); IMClient.Instance.ConnectListener(e); } }
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, ""); } }
public void OnDownload(ulong iRequestID, YIMEngine.ErrorCode errorcode, string strSavePath) { Action <YouMe.StatusCode, string> callbackObj = null; bool finded = downloadCallbackQueue.TryGetValue(iRequestID, out callbackObj); if (finded) { if (callbackObj != null) { try{ callbackObj(Conv.ErrorCodeConvert(errorcode), strSavePath); }catch (Exception e) { Log.e("OnDownload error:" + e.ToString()); } } downloadCallbackQueue.Remove(iRequestID); } }
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); } }
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); } }
public void OnQueryUserStatus(YIMEngine.ErrorCode code, string userID, UserStatus status) { }
public void OnGetNearbyObjects(YIMEngine.ErrorCode errorcode, List <YIMEngine.RelativeLocation> neighbourList, uint startDistance, uint endDistance) { }
/*发送结束 */ public void OnSendAudioMessageStatus(ulong iRequestID, YIMEngine.ErrorCode errorcode, string strText, string strAudioPath, int iDuration) { OnSendAudioMessageStatusChange(iRequestID, errorcode, strText, strAudioPath, iDuration, true); }
//获取消息历史纪录回调 public void OnQueryHistoryMessage(YIMEngine.ErrorCode errorcode, string targetID, int remain, List <YIMEngine.HistoryMsg> messageList) { }
public static StatusCode ErrorCodeConvert(YIMEngine.ErrorCode errorcode) { return((StatusCode)errorcode); }
//语音上传后回调 public void OnStopAudioSpeechStatus(YIMEngine.ErrorCode errorcode, ulong iRequestID, string strDownloadURL, int iDuraton, int iFileSize, string strLocalPath, string strText) { }
public void OnPlayCompletion(YIMEngine.ErrorCode errorcode, string path) { }
public void OnGetNearbyObjects(YIMEngine.ErrorCode errorcode, List <YIMEngine.RelativeLocation> neighbourList) { }
public void OnUpdateLocation(YIMEngine.ErrorCode errorcode, YIMEngine.GeographyLocation location) { }
public void OnDownloadByUrl(YIMEngine.ErrorCode errorcode, string strFromUrl, string strSavePath) { }
public void OnGetUserInfo(YIMEngine.ErrorCode code, IMUserInfo userInfo) { }