コード例 #1
0
 public void TestLocalEngineRequest()
 {
     AVCloud.CallFunctionAsync <string>("hello", null).ContinueWith(engineResponse =>
     {
         Debug.Log("local engine response" + engineResponse.Result);
     });
 }
コード例 #2
0
ファイル: CloudTests.cs プロジェクト: longyunzhou/NFC
        public Task TestRequestRealtimeSignature()
        {
            AVClient.HttpLog(Console.WriteLine);
            var    u    = Utils.RandomUsername();
            var    p    = Utils.RandomString(10);
            AVUser user = new AVUser()
            {
                Username = u,
                Password = p
            };

            return(user.SignUpAsync().ContinueWith(t =>
            {
                Assert.False(t.IsFaulted);
                Assert.False(t.IsCanceled);
                return AVCloud.RequestRealtimeSignatureAsync();
            }).Unwrap().ContinueWith((Task <AVCloud.RealtimeSignature> t) =>
            {
                Assert.IsFalse(t.IsCanceled);
                Assert.IsFalse(t.IsFaulted);
                Assert.IsNotEmpty(t.Result.ClientId);
                Assert.AreNotEqual(t.Result.Timestamp, 0);
                Assert.IsNotEmpty(t.Result.Signature);
                Assert.IsNotEmpty(t.Result.Nonce);
            }));
        }
コード例 #3
0
ファイル: CloudTests.cs プロジェクト: longyunzhou/NFC
        public Task TestCloudFunctions()
        {
            IDictionary <string, object> response = new Dictionary <string, object>()
            {
                { "fosco", "ben" },
                { "list", new List <object> {
                      1, 2, 3
                  } }
            };

            var mockController = new Mock <IAVCloudCodeController>();

            mockController.Setup(obj => obj.CallFunctionAsync <IDictionary <string, object> >(It.IsAny <string>(),
                                                                                              It.IsAny <IDictionary <string, object> >(),
                                                                                              It.IsAny <string>(),
                                                                                              It.IsAny <CancellationToken>())).Returns(Task.FromResult(response));
            var mockCurrentUserController = new Mock <IAVCurrentUserController>();

            mockCurrentUserController.Setup(obj => obj.GetCurrentSessionTokenAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult("testsessiontoken"));

            AVPlugins plugins = new AVPlugins();

            plugins.CloudCodeController   = mockController.Object;
            plugins.CurrentUserController = mockCurrentUserController.Object;
            AVPlugins.Instance            = plugins;

            return(AVCloud.CallFunctionAsync <IDictionary <string, object> >("someFunction", null).ContinueWith(t =>
            {
                Assert.IsFalse(t.IsFaulted);
                Assert.IsFalse(t.IsCanceled);
                Assert.IsInstanceOf <IDictionary <string, object> >(t.Result);
                Assert.AreEqual("ben", t.Result["fosco"]);
                Assert.IsInstanceOf <IList <object> >(t.Result["list"]);
            }));
        }
コード例 #4
0
 public async Task CallFunction()
 {
     await AVCloud.CallFunctionAsync <double>("AverageStars", new Dictionary <string, object>()
     {
         { "movieName", "夏洛特烦恼" }
     });
 }
コード例 #5
0
        /// <summary>
        /// Exists to ensure that generic types are AOT-compiled for the conversions we support.
        /// Any new value types that we add support for will need to be registered here.
        /// The method itself is never called, but by virtue of the Preserve attribute being set
        /// on the class, these types will be AOT-compiled.
        ///
        /// This also applies to Unity.
        /// </summary>
        private static List <object> CreateWrapperTypes()
        {
            return(new List <object> {
                (Action)(() => AVCloud.CallFunctionAsync <object>(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <bool>(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <byte>(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <sbyte>(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <short>(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <ushort>(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <int>(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <uint>(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <long>(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <ulong>(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <char>(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <double>(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <float>(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <IDictionary <string, object> >(null, null, null, CancellationToken.None)),
                (Action)(() => AVCloud.CallFunctionAsync <IList <object> >(null, null, null, CancellationToken.None)),

                typeof(FlexibleListWrapper <object, AVGeoPoint>),
                typeof(FlexibleListWrapper <AVGeoPoint, object>),
                typeof(FlexibleDictionaryWrapper <object, AVGeoPoint>),
                typeof(FlexibleDictionaryWrapper <AVGeoPoint, object>),
            });
        }
コード例 #6
0
    public void CallLocalEngine()
    {
        AVClient.HttpLog(Debug.Log);

        AVCloud.CallFunctionAsync <string>("hello", null).ContinueWith(t =>
        {
            Debug.Log(t.Result);
        });
    }
コード例 #7
0
    async private void DeleteUser(string objectId)
    {
        var dict = new Dictionary <string, object>();

        dict["userId"] = objectId;

        var   callTask = AVCloud.CallFunctionAsync <string>("deleteUser", dict);
        await callTask;
    }
コード例 #8
0
ファイル: CloudTests.cs プロジェクト: longyunzhou/NFC
 public Task TestGetCustomParameters()
 {
     return(AVCloud.GetCustomParametersAsync().ContinueWith(t =>
     {
         Assert.False(t.IsFaulted);
         Assert.False(t.IsCanceled);
         var cp = t.Result;
         Assert.True(cp.Keys.Count > 0);
         return Task.FromResult(0);
     }));
 }
コード例 #9
0
        /// <summary>
        /// 登陆签名
        /// </summary>
        /// <param name="clientId">当前的 clientId</param>
        /// <returns></returns>
        public Task <AVIMSignatureV2> CreateConnectSignature(string clientId)
        {
            var data = new Dictionary <string, object>();

            data.Add("client_id", clientId);//表示当前是谁要求连接服务器。

            //调用云代码进行签名。
            return(AVCloud.CallFunctionAsync <IDictionary <string, object> >("signConnect", data).ContinueWith <AVIMSignatureV2>(t =>
            {
                return MakeSignature(t.Result);; //拼装成一个 Signature 对象
            }));
        }
コード例 #10
0
        /// <summary>
        /// 为获取聊天记录的操作签名
        /// </summary>
        /// <param name="clientId">当前的 clientId </param>
        /// <param name="conversationId">对话 Id</param>
        /// <returns></returns>
        public Task <AVIMSignatureV2> CreateQueryHistorySignature(string clientId, string conversationId)
        {
            var data = new Dictionary <string, object>();

            data.Add("client_id", clientId);    //表示当前是谁在操作。
            data.Add("convid", conversationId); //memberIds不要包含当前的ClientId。

            //调用云代码进行签名。
            return(AVCloud.CallFunctionAsync <IDictionary <string, object> >("signQueryHistory", data).ContinueWith <AVIMSignatureV2>(t =>
            {
                return MakeSignature(t.Result);; //拼装成一个 Signature 对象
            }));
        }
コード例 #11
0
        /// <summary>
        /// 为创建对话签名
        /// </summary>
        /// <param name="clientId">当前的 clientId </param>
        /// <param name="targetIds">被影响的 clientIds </param>
        /// <returns></returns>
        public Task <AVIMSignatureV2> CreateStartConversationSignature(string clientId, IList <string> targetIds)
        {
            var data = new Dictionary <string, object>();

            data.Add("client_id", clientId);   //表示当前是谁在操作。
            data.Add("member_ids", targetIds); //memberIds不要包含当前的ClientId。

            //调用云代码进行签名。
            return(AVCloud.CallFunctionAsync <IDictionary <string, object> >("signStartConversation", data).ContinueWith <AVIMSignatureV2>(t =>
            {
                return MakeSignature(t.Result);; //拼装成一个 Signature 对象
            }));
        }
コード例 #12
0
        public Task <AVIMSignature> CreateConnectSignature(string clientId)
        {
            var data = new Dictionary <string, object>();

            data.Add("client_id", clientId);
            return(AVCloud.CallFunctionAsync <IDictionary <string, object> >("connect", data).OnSuccess(_ =>
            {
                var jsonData = _.Result;
                var s = jsonData["signature"].ToString();
                var n = jsonData["nonce"].ToString();
                var t = long.Parse(jsonData["timestamp"].ToString());
                var signature = new AVIMSignature(s, t, n);
                return signature;
            }));
        }
コード例 #13
0
        public Task <AVIMSignature> CreateStartConversationSignature(string clientId, IEnumerable <string> targetIds)
        {
            var data = new Dictionary <string, object>();

            data.Add("client_id", clientId);
            data.Add("members", targetIds.ToList());
            return(AVCloud.CallFunctionAsync <IDictionary <string, object> >("startConversation", data).OnSuccess(_ =>
            {
                var jsonData = _.Result;
                var s = jsonData["signature"].ToString();
                var n = jsonData["nonce"].ToString();
                var t = long.Parse(jsonData["timestamp"].ToString());
                var signature = new AVIMSignature(s, t, n);
                return signature;
            }));
        }
コード例 #14
0
        /// <summary>
        /// 为更新对话成员的操作进行签名
        /// </summary>
        /// <param name="conversationId">对话的Id</param>
        /// <param name="clientId">当前的 clientId</param>
        /// <param name="targetIds">被操作所影响到的 clientIds</param>
        /// <param name="action">执行的操作,目前只有 add,remove</param>
        /// <returns></returns>
        public Task <AVIMSignatureV2> CreateConversationSignature(string conversationId, string clientId, IList <string> targetIds, string action)
        {
            var data = new Dictionary <string, object>();

            data.Add("client_id", clientId);             //表示当前是谁在操作。
            data.Add("member_ids", targetIds);           //memberIds不要包含当前的ClientId。
            data.Add("conversation_id", conversationId); //conversationId是签名必须的参数。

            data.Add("action", action);                  //conversationId是签名必须的参数。


            //调用云代码进行签名。
            return(AVCloud.CallFunctionAsync <IDictionary <string, object> >("signActionOnCoversation", data).ContinueWith <AVIMSignatureV2>(t =>
            {
                return MakeSignature(t.Result);; //拼装成一个 Signature 对象
            }));
            //以上这段代码,开发者无需手动调用,只要开发者对一个 AVIMClient 设置了 SignatureFactory,SDK 会在执行对应的操作时主动调用这个方法进行签名。
        }
コード例 #15
0
ファイル: CloudTests.cs プロジェクト: longyunzhou/NFC
 public Task TestRequestCaptchaAsync()
 {
     return(AVCloud.RequestCaptchaAsync(height: 100).ContinueWith(t =>
     {
         Assert.False(t.IsCanceled);
         if (t.IsFaulted)
         {
             // current  test app's captcha feature is disabled
             var typeName = t.Exception.InnerException.GetType().Name;
             Assert.IsTrue(t.Exception.InnerException is AVException);
             var e = t.Exception.InnerException as AVException;
             Assert.AreEqual(e.Code, AVException.ErrorCode.OperationForbidden);
             return;
         }
         Assert.IsNotEmpty(t.Result.Token);
         Assert.IsNotEmpty(t.Result.Url);
     }));
 }
コード例 #16
0
        public Task <AVIMSignature> CreateConversationSignature(string conversationId, string clientId, IEnumerable <string> targetIds, ConversationSignatureAction action)
        {
            var actionList = new string[] { "invite", "kick" };
            var data       = new Dictionary <string, object>();

            data.Add("client_id", clientId);
            data.Add("conv_id", conversationId);
            data.Add("members", targetIds.ToList());
            data.Add("action", actionList[(int)action]);
            return(AVCloud.CallFunctionAsync <IDictionary <string, object> >("oprateConversation", data).OnSuccess(_ =>
            {
                var jsonData = _.Result;
                var s = jsonData["signature"].ToString();
                var n = jsonData["nonce"].ToString();
                var t = long.Parse(jsonData["timestamp"].ToString());
                var signature = new AVIMSignature(s, t, n);
                return signature;
            }));
        }
コード例 #17
0
        /// <summary>
        /// Creates the client async.
        /// </summary>
        /// <returns>The client async.</returns>
        /// <param name="user">User.</param>
        /// <param name="tag">Tag.</param>
        /// <param name="deviceId">Device identifier.</param>
        /// <param name="secure">If set to <c>true</c> secure.</param>
        public Task <AVIMClient> CreateClientAsync(AVUser user     = null,
                                                   string tag      = null,
                                                   string deviceId = null,
                                                   bool secure     = true,
                                                   CancellationToken cancellationToken = default(CancellationToken))
        {
            AVIMClient client = null;

            AVRealtime.PrintLog("begin OpenAsync.");
            return(OpenAsync(secure, Subprotocol, true, cancellationToken).OnSuccess(openTask =>
            {
                AVRealtime.PrintLog("OpenAsync OnSuccess. begin send open sesstion cmd.");
                var userTask = Task.FromResult(user);
                if (user == null)
                {
                    userTask = AVUser.GetCurrentUserAsync();
                }

                return userTask;
            }).Unwrap().OnSuccess(u =>
            {
                var theUser = u.Result;
                return AVCloud.RequestRealtimeSignatureAsync(theUser);
            }).Unwrap().OnSuccess(signTask =>
            {
                var signResult = signTask.Result;
                var clientId = signResult.ClientId;
                var nonce = signResult.Nonce;
                var singnature = signResult.Signature;
                var ts = signResult.Timestamp;

                client = PreLogIn(clientId, tag, deviceId);
                ToggleNotification(true);
                return this.OpenSessionAsync(clientId, tag, deviceId, nonce, ts, singnature, secure);
            }).Unwrap().OnSuccess(s =>
            {
                ToggleHeartBeating(true);
                AfterLogIn(client);
                return client;
            }));
        }
コード例 #18
0
        /// <summary>
        /// Creates the client async.
        /// </summary>
        /// <returns>The client async.</returns>
        /// <param name="user">User.</param>
        /// <param name="tag">Tag.</param>
        /// <param name="deviceId">Device identifier.</param>
        /// <param name="secure">If set to <c>true</c> secure.</param>
        public Task <AVIMClient> CreateClientAsync(AVUser user     = null,
                                                   string tag      = null,
                                                   string deviceId = null,
                                                   bool secure     = true)
        {
            var userTask = Task.FromResult(user);

            if (user == null)
            {
                userTask = AVUser.GetCurrentUserAsync();
            }

            AVIMClient client = null;

            return(userTask.OnSuccess(u =>
            {
                var theUser = u.Result;
                return AVCloud.RequestRealtimeSignatureAsync(theUser);
            }).Unwrap().OnSuccess(signTask =>
            {
                var signResult = signTask.Result;
                var clientId = signResult.ClientId;
                var nonce = signResult.Nonce;
                var singnature = signResult.Signature;
                var ts = signResult.Timestamp;

                client = PreLogIn(clientId, tag, deviceId);
                ToggleNotification(true);
                return this.OpenSessionAsync(clientId, tag, deviceId, nonce, ts, singnature, secure);
            }).Unwrap().OnSuccess(s =>
            {
                ToggleHeartBeating(_heartBeatingToggle);

                return client;
            }));
        }
コード例 #19
0
 private void btn_sendSMSCode_Click(object sender, RoutedEventArgs e)
 {
     PopupMsg(AVCloud.RequestSMSCode(txb_phone.Text.Trim()), "发送验证码到 " + txb_phone.Text.Trim() + " 成功。");
 }
コード例 #20
0
 private void btn_Verify_Click(object sender, RoutedEventArgs e)
 {
     AVCloud.VerifySmsCode(txb_smsCode.Text.Trim(), "18612438929");
 }
コード例 #21
0
 private void Button_Click_3(object sender, RoutedEventArgs e)
 {
     AVCloud.RequestSMSCode(txb_phone.Text.Trim(), txb_appName.Text.Trim(), txb_operationName.Text.Trim(), int.Parse(txb_ttl.Text.Trim()));
 }