/// <summary> /// Handler for the Client Exited Channel event /// </summary> private void TeamspeakService_ClientExitedChannel(object sender, TS3.Data.ClientEventArgs e) { Task.Factory.StartNew(() => { var notification = new TSNotificationViewModel(e.ClientID, e.ClientName, TSNotificationType.UserExited); Threading.InvokeOnUI(() => this.Notifications.Add(notification)); Thread.Sleep(5000); // Let channel notifications stay for 5 seconds Threading.InvokeOnUI(() => this.Notifications.Remove(notification)); }); }
/// <summary> /// Handles the text message received event /// </summary> private void TeamspeakService_TextMessageReceived(object sender, TS3.Data.TextMessageEventArgs e) { Task.Factory.StartNew(() => { var messageNotification = new TSNotificationViewModel(e.ClientID, e.ClientName, TSNotificationType.Text, e.Message); Threading.InvokeOnUI(() => this.Notifications.Add(messageNotification)); Thread.Sleep(10000); // Let text messages stay for 10 seconds Threading.InvokeOnUI(() => this.Notifications.Remove(messageNotification)); }); }
/// <summary> /// Compares an input object to this object. Value compare /// </summary> public override bool Equals(object obj) { if (obj != null && obj is TSNotificationViewModel) { TSNotificationViewModel other = obj as TSNotificationViewModel; return((other.ClientID == this.ClientID) && (other.User == this.User) && (other.NotificationType == this.NotificationType) && (other.Message == this.Message)); } else { return(false); } }
/// <summary> /// Connection was refused, meaning teamspeak is not running /// </summary> private void TeamspeakService_ConnectionRefused(object sender, EventArgs e) { Task.Factory.StartNew(() => { this.TeamspeakService.ConnectionRefused -= TeamspeakService_ConnectionRefused; var cannotConnectNotification = new TSNotificationViewModel(0, "Please start Teamspeak", TSNotificationType.CannotConnect); Threading.InvokeOnUI(() => this.Notifications.Add(cannotConnectNotification)); // Start a loop attempting to connect while (!this.isShuttingDown && this.TeamspeakService.ConnectionState != TS3.Data.Enums.ConnectionState.Connected) { Threading.InvokeOnUI(() => this.TeamspeakService.Connect()); Thread.Sleep(5000); // attempt to connect once every 5 seconds } if (!this.isShuttingDown) { this.TeamspeakService.ConnectionRefused += TeamspeakService_ConnectionRefused; Threading.InvokeOnUI(() => this.Notifications.Remove(cannotConnectNotification)); } }); }
/// <summary> /// Handles the talk status changed event /// </summary> private void TeamspeakService_TalkStatusChanged(object sender, TS3.Data.TalkStatusEventArgs e) { var speachNotification = new TSNotificationViewModel(e.ClientID, e.ClientName, TSNotificationType.Speech); switch (e.Status) { case TS3.Data.Enums.TalkStatus.TalkStarted: // Add to our collection of speaking users Threading.BeginInvokeOnUI(() => this.Notifications.Add(speachNotification)); break; case TS3.Data.Enums.TalkStatus.TalkStopped: // Remove from our collection of speaking users var vm = this.Notifications.FirstOrDefault(notification => notification.Equals(speachNotification)); if (vm != null) { Threading.BeginInvokeOnUI(() => this.Notifications.Remove(vm)); } break; default: break; } }