Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="conversation"></param>
        /// <param name="avMessage"></param>
        /// <returns></returns>
        public Task <AVIMMessage> SendMessageAsync(AVIMConversation conversation, AVIMMessage avMessage)
        {
            var cmd = new MessageCommand()
                      .Message(avMessage.EncodeJsonString())
                      .ConvId(conversation.ConversationId)
                      .Receipt(avMessage.Receipt)
                      .Transient(avMessage.Transient)
                      .AppId(AVClient.ApplicationId)
                      .PeerId(this.clientId);

            return(AVIMClient.AVCommandRunner.RunCommandAsync(cmd).ContinueWith <AVIMMessage>(t =>
            {
                if (t.IsFaulted)
                {
                    throw t.Exception;
                }
                else
                {
                    var response = t.Result.Item2;
                    avMessage.Id = response["uid"].ToString();
                    avMessage.ServerTimestamp = long.Parse(response["t"].ToString());

                    return avMessage;
                }
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="invoker"></param>
        /// <param name="adpater"></param>
        public void RegisterMessage <T>(Action <IAVIMMessage> invoker, IAVIMMessage adpater)
            where T : AVIMMessage
        {
            int typeEnum = AVIMMessage.GetMessageType <T>();

            if (typeEnum < 0)
            {
                return;
            }
            messageHandlers[typeEnum] = invoker;
            adpaters[typeEnum]        = adpater;
        }
Exemplo n.º 3
0
        ///// <summary>
        ///// 向该对话发送普通的文本消息。
        ///// </summary>
        ///// <param name="textContent">文本消息的内容,一般就是一个不超过5KB的字符串。</param>
        ///// <returns></returns>
        //public Task<Tuple<bool, AVIMTextMessage>> SendTextMessageAsync(AVIMTextMessage textMessage)
        //{
        //    return SendMessageAsync<AVIMTextMessage>(textMessage);
        //}

        /// <summary>
        /// 向该对话发送消息。
        /// </summary>
        /// <param name="avMessage"></param>
        /// <returns></returns>
        public Task <AVIMMessage> SendMessageAsync(AVIMMessage avMessage)
        {
            if (this.CurrentClient == null)
            {
                throw new Exception("当前对话未指定有效 AVIMClient,无法发送消息。");
            }
            if (this.CurrentClient.State != AVIMClient.Status.Connecting)
            {
                throw new Exception("未能连接到服务器,无法发送消息。");
            }
            return(this.CurrentClient.SendMessageAsync(this, avMessage));
        }