Пример #1
0
        public async Task StartAsync()
        {
            if (!_started)
            {
                // create the connection using the .NET SignalR client
                _hubConnection = new HubConnectionBuilder()
                                 .WithUrl(_hubUrl)
                                 .Build();
                Console.WriteLine("ChatClient: calling Start()");

                // add handler for receiving messages
                _hubConnection.On <Message>(MessageFunctions.RECEIVE, (message) =>
                {
                    HandleReceiveMessage(message);
                });

                _hubConnection.On(MessageFunctions.USEREVENT, () =>
                {
                    UserEvent?.Invoke(this, EventArgs.Empty);
                });

                // start the connection
                await _hubConnection.StartAsync();

                Console.WriteLine("ChatClient: Start returned");
                _started = true;

                // register user on hub to let other clients know they've joined
                await _hubConnection.SendAsync(MessageFunctions.REGISTER, _username);
            }
        }
Пример #2
0
 // Method to invoke event
 public void OnUserEvent()
 {
     //if(UserEvent != null)
     //{
     UserEvent.Invoke();
     //}
 }
Пример #3
0
 public void RaiseEvent(object sender, string eventType)
 {
     UserEvent?.Invoke(sender, eventType);
 }
Пример #4
0
 private void button1_Click(object sender, EventArgs e)
 {
     UserEvent?.Invoke(textBox1.Text.Trim(), textBox2.Text.Trim());
     this.Close();
 }
Пример #5
0
 protected virtual void RaiseUserEvent(TokenEventArgs e)
 {
     UserEvent?.Invoke(this, e);
 }
Пример #6
0
 public void UserLeave(NetworkUser user)
 {
     roomUsers.Remove(user);
     userLeaveEvent.Invoke(user);
 }
Пример #7
0
 public void UserJoin(NetworkUser user)
 {
     roomUsers.Add(user);
     userJoinEvent.Invoke(user);
 }