Example #1
0
        private async void LoginButton_Click(object sender, System.EventArgs e)
        {
            LoginModelView login = new LoginModelView()
            {
                Email    = LogincomboBox.Text,
                Password = PasswordcomboBox.Text,
            };

            AuthorizationResult = await HttpRestClient.LoginAsync(login);

            if (AuthorizationResult.Code == HttpStatusCode.OK)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("Błędny login lub hasło");
            }
        }
Example #2
0
        public static async Task <Connection> Create(HttpAuthorizationResult authorization)
        {
            HubConnection hub = new HubConnectionBuilder().WithUrl(Routes.SignalR.Connection, options =>
            {
                options.AccessTokenProvider = () => Task.FromResult(authorization.Token);
                options.Headers.Add("Id", authorization.Id);
                options.Headers.Add("UserName", authorization.User);
            }).AddMessagePackProtocol().Build();

            Connection connection = new Connection(authorization.User)
            {
                Friends = await HttpRestClient.GetFriendsWithStatus(authorization.Id)
            };


            hub.On("NotificationFriendChangeStatus", async(string userName, bool state) =>
            {
                try
                {
                    var isUserExist = connection.Friends.ContainsKey(userName);
                    if (isUserExist)
                    {
                        connection.Friends[userName] = state;
                        var args = new ChangeStatusFriendDelegateArgs()
                        {
                            Status   = state,
                            UserName = userName,
                        };
                        connection.OnChangeStatusFriend(args);
                    }
                    else
                    {
                        await Log.WriteAsync($"Error:Nie znaleziono użytkownika:{userName} którego status miał zostać zmieniony");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            });

            hub.On("IncomingCall", async(string userName, string connectionId) =>
            {
                Console.WriteLine("Połączenie przychodzące");
                connection.OnIncomingCall(new ConnectionDelegateArgs()
                {
                    User = userName
                });
            });

            hub.On("CallAccepted", async(string userName) =>
            {
                Console.WriteLine("Połączenie zaakceptowane");
                connection.Session.UserNameFriend = userName;
                connection.Session.CreateOfferConnection();
            });

            hub.On("CallDeclined", async(string userName) =>
            {
                Console.WriteLine("Połączenie odrzucono");
            });

            hub.On("ReceivingMessagesAsync", (string username, string message) =>
            {
                var args = new MessageDelegateArgs()
                {
                    UserName = username,
                    Message  = message,
                };

                connection.OnReceiveMessage(args);
            });

            hub.On("SdpMessageReceivedConfigurationWebRtc", async(string userName, SdpMessage sdpMessage) =>
            {
                await connection.Session.SetRemoteDescriptionAsync(sdpMessage);
                connection.Session.CreateAnswerConnection();
                Console.WriteLine("Odebranie konfiguracji SDP");
            });

            hub.On("IceCandidateReceivedConfigurationWebRtc", (string userName, IceCandidate iceCandidate) =>
            {
                connection.Session.AddIceCandidate(iceCandidate);
                Console.WriteLine("Odebranie konfiguracji ICE");
            });

            await hub.StartAsync();

            connection.HubConnection = hub;
            return(connection);
        }