void _mainClient_ReceiveDataChange(object sender, ReceiveDataEventArgs e) { try { JObject response = JObject.Parse(e.Data); if (response["type"] != null) { if (CleanJson(response["type"].ToString()) == "registered") { if (response["id"] != null) { if (CleanJson(response["id"].ToString()) == "register_0") { if (response["payload"]["client-key"] != null) { _clientKey = CleanJson(response["payload"]["client-key"].ToString()); using (StreamWriter writer = new StreamWriter(File.Create(_keyFilePath))) { writer.WriteLine(_clientKey); } _mainClient.SendData(_verifyClientKey()); } } else if (CleanJson(response["id"].ToString()) == "register_1") { CTimer waitToGetInfo = new CTimer(DisplayGetInfo, 2500); } } } else if (CleanJson(response["type"].ToString()) == "response") { if (response["id"] != null) { if (CleanJson(response["id"].ToString()) == "powerOff" && response["payload"] != null) { if (CleanJson(response["payload"]["returnValue"].ToString()) == "true") { _mainClient.TemporaryDisconnect(); } } else if (CleanJson(response["id"].ToString()) == "getInputSocket") { _inputControls = new InputControls(_ipAddress, _port, CleanJson(response["payload"]["socketPath"].ToString())); _mainClient.SendData("{\"type\":\"request\",\"id\":\"getVolume\",\"uri\":\"ssap://audio/getVolume\"}"); } else if (CleanJson(response["id"].ToString()).Contains("changeInput_")) { if (CleanJson(response["payload"]["returnValue"].ToString()) == "true") { _currentInput = CleanJson(response["id"].ToString()).Replace("changeInput_", string.Empty); if (onCurrentInputValue != null) { ExternalInput input = _externalInputs.Find(x => x.id == _currentInput); onCurrentInputValue(Convert.ToUInt16(_externalInputs.IndexOf(input))); } } } else if (CleanJson(response["id"].ToString()) == "getExternalInputs") { _externalInputs = JsonConvert.DeserializeObject <List <ExternalInput> >(response["payload"]["devices"].ToString()); List <string> inputNames = new List <string>(); List <string> inputIcons = new List <string>(); foreach (var input in _externalInputs) { inputNames.Add(input.label); inputIcons.Add(input.icon.Replace("http:", string.Format("http://{0}:{1}", _ipAddress, _port))); } if (onInputCount != null) { onInputCount(Convert.ToUInt16(_externalInputs.Count)); } if (onExternalInputNames != null) { foreach (var inputName in inputNames) { var encodedBytes = XSigHelpers.GetBytes(inputNames.IndexOf(inputName) + 1, inputName); onExternalInputNames(Encoding.GetEncoding(28591).GetString(encodedBytes, 0, encodedBytes.Length)); } } if (onExternalInputIcons != null) { foreach (var inputIcon in inputIcons) { var encodedBytes = XSigHelpers.GetBytes(inputIcons.IndexOf(inputIcon) + 1, inputIcon); onExternalInputIcons(Encoding.GetEncoding(28591).GetString(encodedBytes, 0, encodedBytes.Length)); } } } else if (CleanJson(response["id"].ToString()) == "getAllApps") { _apps = JsonConvert.DeserializeObject <List <App> >(response["payload"]["launchPoints"].ToString()); List <string> appNames = new List <string>(); List <string> appIcons = new List <string>(); foreach (var input in _apps) { appNames.Add(input.title); appIcons.Add(input.icon.Replace("http:", string.Format("http://{0}:{1}", _ipAddress, _port))); } if (onAppCount != null) { onAppCount(Convert.ToUInt16(_apps.Count)); } if (onAppNames != null) { foreach (var appName in appNames) { var encodedBytes = XSigHelpers.GetBytes(appNames.IndexOf(appName) + 1, appName); onAppNames(Encoding.GetEncoding(28591).GetString(encodedBytes, 0, encodedBytes.Length)); } } if (onAppIcons != null) { foreach (var appIcon in appIcons) { var encodedBytes = XSigHelpers.GetBytes(appIcons.IndexOf(appIcon) + 1, appIcon); onAppIcons(Encoding.GetEncoding(28591).GetString(encodedBytes, 0, encodedBytes.Length)); } } } else if (CleanJson(response["id"].ToString()) == "setVolume") { if (CleanJson(response["payload"]["returnValue"].ToString()) == "true") { _mainClient.SendData("{\"type\":\"request\",\"id\":\"getVolume\",\"uri\":\"ssap://audio/getVolume\"}"); } } else if (CleanJson(response["id"].ToString()) == "volumeUp") { if (CleanJson(response["payload"]["returnValue"].ToString()) == "true") { _mainClient.SendData("{\"type\":\"request\",\"id\":\"getVolume\",\"uri\":\"ssap://audio/getVolume\"}"); } } else if (CleanJson(response["id"].ToString()) == "volumeDown") { if (CleanJson(response["payload"]["returnValue"].ToString()) == "true") { _mainClient.SendData("{\"type\":\"request\",\"id\":\"getVolume\",\"uri\":\"ssap://audio/getVolume\"}"); } } else if (CleanJson(response["id"].ToString()) == "getVolume") { if (CleanJson(response["payload"]["returnValue"].ToString()) == "true") { var value = ScaleUp(Convert.ToInt16(CleanJson(response["payload"]["volume"].ToString()))); if (onVolumeValue != null) { onVolumeValue(Convert.ToUInt16(value)); } if (onVolumeMuteState != null) { if (CleanJson(response["payload"]["muted"].ToString()) == "true") { onVolumeMuteState(1); } else if (CleanJson(response["payload"]["muted"].ToString()) == "false") { onVolumeMuteState(0); } } } } else if (CleanJson(response["id"].ToString()) == "volumeMuteOn") { if (CleanJson(response["payload"]["returnValue"].ToString()) == "true") { if (onVolumeMuteState != null) { onVolumeMuteState(1); } } } else if (CleanJson(response["id"].ToString()) == "volumeMuteOff") { if (CleanJson(response["payload"]["returnValue"].ToString()) == "true") { if (onVolumeMuteState != null) { onVolumeMuteState(0); } } } } } } } catch (Exception ex) { if (_debugMode) { ErrorLog.Exception(string.Format("LgWebOs.Display._mainClient_ReceiveDataChange ID={0} Exeption Occured", _id), ex); } } }