async Task <bool> SetupAsync()
        {
            var task  = new TaskCompletionSource <bool>();
            var token = await TwilioHelper.GetTokenAsync();

            var accessManager = TwilioAccessManagerFactory.CreateAccessManager(token, this);

            Client = TwilioIPMessagingSDK.CreateIPMessagingClientWithAccessManager(accessManager, this);

            Client.Channels.LoadChannelsWithListener(new StatusListener
            {
                SuccessHandler = () =>
                {
                    GeneralChannel = Client.Channels.GetChannelByUniqueName("general");

                    if (GeneralChannel != null)
                    {
                        GeneralChannel.Listener = this;
                        JoinGeneralChannel();
                    }
                    else
                    {
                        CreateAndJoinGeneralChannel();
                    }

                    task.SetResult(true);
                }
            });

            return(await task.Task.ConfigureAwait(false));
        }
        async Task Setup()
        {
            var token = await GetIdentity();

            var accessManager = TwilioAccessManagerFactory.CreateAccessManager(token, this);

            client = TwilioIPMessagingSDK.CreateIPMessagingClientWithAccessManager(accessManager, this);

            client.Channels.LoadChannelsWithListener(new StatusListener
            {
                SuccessHandler = () =>
                {
                    generalChannel = client.Channels.GetChannelByUniqueName("general");

                    if (generalChannel != null)
                    {
                        generalChannel.Listener = this;
                        JoinGeneralChannel();
                    }
                    else
                    {
                        CreateAndJoinGeneralChannel();
                    }
                }
            });
        }
        public async Task <bool> Initialize()
        {
            var task = new TaskCompletionSource <bool>();

            if (!TwilioIPMessagingSDK.IsInitialized)
            {
                TwilioIPMessagingSDK.InitializeSDK(Xamarin.Forms.Forms.Context, new InitListener
                {
                    InitializedHandler = async delegate
                    {
                        await SetupAsync();
                        task.SetResult(true);
                    },
                    ErrorHandler = err =>
                    {
                        task.SetResult(false);
                    }
                });
            }
            else
            {
                return(await SetupAsync());
            }

            return(await task.Task.ConfigureAwait(false));
        }
예제 #4
0
		public async void initializeChat()
		{

			TwilioIPMessagingSDK.SetLogLevel((int)Android.Util.LogPriority.Debug);

			if (!TwilioIPMessagingSDK.IsInitialized)
			{
				Console.WriteLine("Initialize");

				TwilioIPMessagingSDK.InitializeSDK(ctx, new InitListener
				{
					InitializedHandler = async delegate
					{
						await Setup();
					},
					ErrorHandler = err =>
					{
						Console.WriteLine(err.Message);
					}
				});
			}
			else {
				await Setup();
			}
		}
예제 #5
0
        async Task <bool> Conectar()
        {
            var task  = new TaskCompletionSource <bool>();
            var token = await TokenControll.RecuperarToken();

            var accessManager = TwilioAccessManagerFactory.CreateAccessManager(token, this);

            Client = TwilioIPMessagingSDK.CreateIPMessagingClientWithAccessManager(accessManager, this);

            return(await task.Task.ConfigureAwait(false));
        }
예제 #6
0
        async Task Setup()
        {
            var token = await GetIdentity();

            twilio = TwilioIPMessagingSDK.CreateIPMessagingClientWithToken(token, this);

            twilio.Channels.LoadChannelsWithListener(new StatusListener {
                SuccessHandler = () => {
                    generalChannel          = twilio.Channels.GetChannelByUniqueName("general");
                    generalChannel.Listener = this;
                    generalChannel.Join(new StatusListener {
                        SuccessHandler = () => {
                            RunOnUiThread(() =>
                                          Toast.MakeText(this, "Joined general channel!", ToastLength.Short).Show());
                        }
                    });
                }
            });
        }
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            this.ActionBar.Subtitle = "logging in...";

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            sendButton  = FindViewById <Button>(Resource.Id.sendButton);
            textMessage = FindViewById <EditText>(Resource.Id.messageTextField);
            listView    = FindViewById <ListView>(Resource.Id.listView);

            adapter          = new MessagesAdapter(this);
            listView.Adapter = adapter;

            TwilioIPMessagingSDK.SetLogLevel((int)Android.Util.LogPriority.Debug);

            if (!TwilioIPMessagingSDK.IsInitialized)
            {
                Console.WriteLine("Initialize");

                TwilioIPMessagingSDK.InitializeSDK(this, new InitListener
                {
                    InitializedHandler = async delegate
                    {
                        await Setup();
                    },
                    ErrorHandler = err =>
                    {
                        Console.WriteLine(err.Message);
                    }
                });
            }
            else
            {
                await Setup();
            }

            sendButton.Click += ButtonSend_Click;
        }