Beispiel #1
0
        public void RunCommand(AVIMCommand command)
        {
            command.IDlize();
            var requestString = command.EncodeJsonString();

            AVRealtime.PrintLog("websocket=>" + requestString);
            webSocketClient.Send(requestString);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="command"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task <Tuple <int, IDictionary <string, object> > > RunCommandAsync(AVIMCommand command, CancellationToken cancellationToken = default(CancellationToken))
        {
            var tcs = new TaskCompletionSource <Tuple <int, IDictionary <string, object> > >();

            command.IDlize();

            var requestString = command.EncodeJsonString();

            if (!command.IsValid)
            {
                requestString = "{}";
            }
            AVRealtime.PrintLog("websocket=>" + requestString);
            webSocketClient.Send(requestString);
            var requestJson = command.Encode();


            Action <string> onMessage = null;

            onMessage = (response) =>
            {
                //AVRealtime.PrintLog("response<=" + response);
                var responseJson = Json.Parse(response) as IDictionary <string, object>;
                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;

                            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));
                        }
                        if (tcs.Task.Exception == null)
                        {
                            tcs.SetResult(result);
                        }
                        webSocketClient.OnMessage -= onMessage;
                    }
                    else
                    {
                    }
                }
            };
            webSocketClient.OnMessage += onMessage;
            return(tcs.Task);
        }
Beispiel #3
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", "Source can not be null");
            }
            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;
            }
        }
        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 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 = Json.Parse(response) as IDictionary<string,object>;
                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;
        }
Beispiel #6
0
 public SessionCommand(AVIMCommand source)
     : base(source: source)
 {
 }
 public MessageCommand(AVIMCommand source)
     : base(source: source)
 {
 }
Beispiel #8
0
 public ReadCommand(AVIMCommand source)
     : base(source)
 {
 }
 public MessageCommand(AVIMCommand source)
     : base(source: source)
 {
 }
Beispiel #10
0
 public ConversationCommand(AVIMCommand source)
     : base(source: source)
 {
 }
Beispiel #11
0
 public PatchCommand(AVIMCommand source, ICollection <Patch> sourcePatchs)
     : base(source: source)
 {
     this.Patches = sourcePatchs;
 }
 public ConversationCommand(AVIMCommand source)
     : base(source: source)
 {
 }
Beispiel #13
0
 public AckCommand(AVIMCommand source)
     : base(source)
 {
 }
 public SessionCommand(AVIMCommand source)
     : base(source: source)
 {
 }