Ejemplo n.º 1
0
        protected async Task StartChatHub()
        {
            try
            {
                var messenger = Mvx.Resolve <IMvxMessenger>();

                ChatHub = new Microsoft.AspNetCore.SignalR.Client
                          .HubConnectionBuilder()
                          .WithUrl("http://127.0.0.1:5000/chat")
                          .WithConsoleLogger()
                          .Build();

                BeforeStartChatHub();

                ChatHub.On("on_connect_to_group", new Action <string>(obj =>
                                                                      messenger.Publish(new ConnectToGroupMessage(this, obj))));
                ChatHub.On("new_message", new Action <string, string>((group, message) =>
                                                                      messenger.Publish(new NewMessage(this, group, message))));;

                await ChatHub.StartAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Ejemplo n.º 2
0
        public override Task <bool> Start()
        {
            var connectionBuilder = new Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilder();

            _hubConnection = connectionBuilder.WithUrl($"http://{RemoteIpAddress}:{RemotePort}/signalr/dataHub").Build();

            _hubConnection.On <DispatchableType, Guid, object>("dispatchValue", ValueDispatched);

            _hubConnection.StartAsync().ContinueWith(async(a) =>
            {
                if (a.IsCompletedSuccessfully)
                {
                    await _hubConnection.SendAsync("SubscribeAll");
                }
            });

            return(base.Start());
        }