private void TaskAudioPlayback(Logger logger, CancellationToken cancelToken, BlockingCollection <IMsgPackTypeName> queue) { while (!cancelToken.IsCancellationRequested) { if (queue.TryTake(out IMsgPackTypeName data, 500)) { switch (data.GetType().Name) { case nameof(AudioRxDto): { var dto = (AudioRxDto)data; soundcardSampleProvider.AddOpusSamples(dto, dto.Transceivers); if (logger.IsTraceEnabled) { logger.Trace(dto.ToDebugString()); } break; } case nameof(CallRequestDto): { var dto = (CallRequestDto)data; if (incomingCallRequest != null) { Connection.VoiceServerTransmitQueue.Add(new CallResponseDto() { Request = dto, Event = CallResponseEvent.Busy }); } else { incomingCallRequest = dto; soundcardSampleProvider.LandLineRing(true); CallRequest?.Invoke(this, new CallRequestEventArgs() { Callsign = dto.FromCallsign }); } break; } case nameof(CallResponseDto): { var dto = (CallResponseDto)data; switch (dto.Event) { // Server events case CallResponseEvent.Routed: soundcardSampleProvider.LandLineRing(true); CallResponse?.Invoke(this, new CallResponseEventArgs() { Callsign = dto.Request.ToCallsign, Event = CallResponseEvent.Routed }); //Our request was routed break; case CallResponseEvent.NoRoute: CallResponse?.Invoke(this, new CallResponseEventArgs() { Callsign = dto.Request.ToCallsign, Event = CallResponseEvent.NoRoute }); //Our request was not routed break; //Remote party events case CallResponseEvent.Busy: soundcardSampleProvider.LandLineRing(false); //Play busy tone CallResponse?.Invoke(this, new CallResponseEventArgs() { Callsign = dto.Request.ToCallsign, Event = CallResponseEvent.Busy }); break; case CallResponseEvent.Accept: soundcardSampleProvider.LandLineRing(false); CallResponse?.Invoke(this, new CallResponseEventArgs() { Callsign = dto.Request.ToCallsign, Event = CallResponseEvent.Accept }); break; case CallResponseEvent.Reject: soundcardSampleProvider.LandLineRing(false); //Play reject tone CallResponse?.Invoke(this, new CallResponseEventArgs() { Callsign = dto.Request.ToCallsign, Event = CallResponseEvent.Reject }); break; } break; } } } } }