private async Task CheckLineStatusOnCodecAsync(string sipAddress) { try { // Get codec template data from CCM // TODO: move this out (GetCodecInformationBySipAddress), it's redundant and being used in multiple locations var codecInformation = await _ccmService.GetCodecInformationBySipAddress(sipAddress); if (codecInformation == null) { log.Info($"Codec {sipAddress} is not currently registered in CCM, could't get codec information"); return; } var codecApiType = codecInformation?.CodecApiType; var codecApi = codecApiType != null?_serviceProvider.GetService(codecApiType) as ICodecApi : null; if (codecApi == null || string.IsNullOrEmpty(codecInformation.Ip)) { log.Info($"Missing information for connecting to codec {sipAddress}"); return; } var line = new LineStatusResponse(); var lineStatus = await codecApi.GetLineStatusAsync(codecInformation.Ip, "Line1"); // TODO: Create a GetLineStatuses, for multiple lines line.LineEncoder = string.IsNullOrEmpty(lineStatus.LineEncoder) ? "Line1" : lineStatus.LineEncoder; line.LineStatus = lineStatus.StatusCode.ToString(); line.DisconnectReasonCode = (int)lineStatus.DisconnectReason; line.DisconnectReasonDescription = lineStatus.DisconnectReason.Description(); line.RemoteAddress = lineStatus.RemoteAddress; var model = new UnitStateResponse() { IsOnline = true }; model.LineStatuses.Add(line); // TODO: Get actual connected to information form ccm. this is a very inefficient way, but deal with the rare condition of codec in call but not in ccm. await SendLineStatusToClients(sipAddress, model); } catch (CodecInvocationException ex) { log.Info($"Failed to check line status on {sipAddress}. {ex.Message}"); } catch (Exception ex) { log.Warn(ex, $"Exception when checking line status on {sipAddress}"); } }
private async Task SendLineStatusToClients(string sipAddress, UnitStateResponse unitStatus) { await _hub.Clients.Group(sipAddress).SendAsync("LineStatus", sipAddress, unitStatus); }