Ejemplo n.º 1
0
        public Task <Tuple <int, IDictionary <string, object> > > RunCommandAsync(AVIMCommand command, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!webSocketClient.IsOpen)
            {
                throw new AVIMException(AVIMException.ErrorCode.CAN_NOT_EXCUTE_COMMAND, "当前连接失效,无法发送指令");
            }
            command = command.IDlize();
            var tcs           = new TaskCompletionSource <Tuple <int, IDictionary <string, object> > >();
            var requestString = command.EncodeJsonString();

            webSocketClient.Send(requestString);
            var requestJson = command.Encode();

            Action <string> onMessage = null;

            onMessage = (response) =>
            {
                var responseJson = AVClient.DeserializeJsonString(response);
                if (responseJson.Keys.Contains("i"))
                {
                    if (requestJson["i"].ToString() == responseJson["i"].ToString())
                    {
                        var result = new Tuple <int, IDictionary <string, object> >(-1, responseJson);
                        if (responseJson.Keys.Contains("code"))
                        {
                            var errorCode = int.Parse(responseJson["code"].ToString());
                            var reason    = string.Empty;
                            int appCode   = 0;
                            //result = new Tuple<int, IDictionary<string, object>>(errorCode, responseJson);
                            if (responseJson.Keys.Contains("reason"))
                            {
                                reason = responseJson["reason"].ToString();
                            }
                            if (responseJson.Keys.Contains("appCode"))
                            {
                                appCode = int.Parse(responseJson["appCode"].ToString());
                            }
                            tcs.SetException(new AVIMException(errorCode, appCode, reason, null));
                        }
                        tcs.SetResult(result);
                        webSocketClient.OnMessage -= onMessage;
                    }
                }
            };
            webSocketClient.OnMessage += onMessage;
            return(tcs.Task);
        }
Ejemplo n.º 2
0
        protected AVIMCommand(AVIMCommand source,
                              string cmd    = null,
                              string op     = null,
                              string appId  = null,
                              string peerId = null,
                              IDictionary <string, object> arguments = null,
                              AVIMSignature signature = null)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            this.cmd       = source.cmd;
            this.op        = source.op;
            this.arguments = source.arguments;
            this.peerId    = source.peerId;
            this.appId     = source.appId;
            this.signature = source.signature;

            if (cmd != null)
            {
                this.cmd = cmd;
            }
            if (op != null)
            {
                this.op = op;
            }
            if (arguments != null)
            {
                this.arguments = arguments;
            }
            if (peerId != null)
            {
                this.peerId = peerId;
            }
            if (appId != null)
            {
                this.appId = appId;
            }
            if (signature != null)
            {
                this.signature = signature;
            }
        }
 public ConversationCommand(AVIMCommand source)
     : base(source: source)
 {
 }
Ejemplo n.º 4
0
 public MessageCommand(AVIMCommand source)
     : base(source: source)
 {
 }
Ejemplo n.º 5
0
 public SessionCommand(AVIMCommand source)
     : base(source: source)
 {
 }