private void Client_ApplicationMessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e) { messageReceivingTopics.Add(e.ApplicationMessage.Topic); ByteQueue queue = e.ApplicationMessage.Payload; try { switch (e.ApplicationMessage.Topic) { case nameof(AllSongsShuffled): AllSongsShuffled = queue.DequeueSongs(); break; case nameof(AudioData): AudioData = queue; break; case nameof(CurrentSong): CurrentSong = queue.DequeueSong(); break; case nameof(Duration): Duration = queue.DequeueTimeSpan(); break; case nameof(Format): Format = queue.DequeueWaveFormat(); break; case nameof(IsAllShuffle): IsAllShuffle = queue.DequeueBool(); break; case nameof(IsOnlySearch): IsOnlySearch = queue.DequeueBool(); break; case nameof(IsSearchShuffle): IsSearchShuffle = queue.DequeueBool(); break; case nameof(MediaSources): MediaSources = queue.DequeueStrings(); break; case nameof(PlayState): PlayState = queue.DequeuePlayState(); break; case nameof(Position): Position = queue.DequeueTimeSpan(); break; case nameof(SearchKey): SearchKey = queue.DequeueString(); break; case nameof(Volume): Volume = queue.DequeueFloat(); break; } } catch (Exception exc) { try { MqttApplicationMessage message = new MqttApplicationMessage() { Topic = "Debug", Payload = Encoding.UTF8.GetBytes(Utils.GetTypeMessageAndStack(exc)), QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce, Retain = true }; client.PublishAsync(message); } catch { } } if (initProps != null && initProps.Contains(e.ApplicationMessage.Topic)) { lock (initProps) { initProps.Remove(e.ApplicationMessage.Topic); Monitor.Pulse(initProps); } } messageReceivingTopics.Remove(e.ApplicationMessage.Topic); }
private void OnApplicationMessageInterception(MqttApplicationMessageInterceptorContext context) { if (context.ClientId == null) { return; } messageInterceptingTopics.Add(context.ApplicationMessage.Topic); ByteQueue queue = context.ApplicationMessage.Payload; try { switch (context.ApplicationMessage.Topic) { case nameof(AllSongsShuffled): Reload(); queue = new ByteQueue(); queue.Enqueue(AllSongsShuffled); context.ApplicationMessage.Payload = queue; break; case nameof(CurrentSong): CurrentSong = queue.Any() ? (Song?)queue.DequeueSong() : null; break; case nameof(IsAllShuffle): IsAllShuffle = queue.DequeueBool(); break; case nameof(IsOnlySearch): IsOnlySearch = queue.DequeueBool(); break; case nameof(IsSearchShuffle): IsSearchShuffle = queue.DequeueBool(); break; case nameof(MediaSources): MediaSources = queue.Any() ? queue.DequeueStrings() : null; break; case nameof(PlayState): PlayState = queue.DequeuePlayState(); break; case nameof(Position): Position = queue.DequeueTimeSpan(); break; case nameof(SearchKey): SearchKey = queue.Any() ? queue.DequeueString() : null; break; case nameof(Volume): Volume = queue.DequeueFloat(); break; default: context.AcceptPublish = false; break; } } catch (Exception e) { context.AcceptPublish = false; try { MqttApplicationMessage message = new MqttApplicationMessage() { Topic = "Debug", Payload = Encoding.UTF8.GetBytes(Utils.GetTypeMessageAndStack(e)), QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce, Retain = true }; server.PublishAsync(message); } catch { } } messageInterceptingTopics.Remove(context.ApplicationMessage.Topic); }