/// <summary> /// Terminate a proxy connection to a device. /// </summary> /// <param name="deviceAddress">The service address(e.g.service ID) for the device you connected to, but now you want to terminate the proxy for that connection.</param> /// <param name="connectionId">The connection ID returned from the /device/connect API call</param> public async Task TerminateDeviceConnection(string deviceAddress, string connectionId) { if (_isInvalidSession) { CurrentSession.CurrentSessionData = await CurrentSession.GenerateSession(_userName, _userPassword, DeveloperKey); } string requestBodyJsonData = JsonSerializer.Serialize(new Dictionary <string, string>() { { "deviceaddress", deviceAddress }, { "connectionid", connectionId } }); var httpRequest = new HttpRequestMessage() { Method = HttpMethod.Post, RequestUri = new Uri(string.Concat(_httpApiClient.BaseAddress, "/device/connect/stop")), Content = new StringContent(requestBodyJsonData) }; httpRequest.Headers.Add("developerkey", DeveloperKey); httpRequest.Headers.Add("token", CurrentSession.CurrentSessionData.Token); var apiRequestSender = new RemoteitApiRequest <ConnectionTerminationEndpointResponse>(_httpApiClient); ConnectionTerminationEndpointResponse response = await apiRequestSender.SendAsync(httpRequest); if (response.Status != "true") { throw new RemoteitException($"Unable to terminate connection with id {connectionId} to device {deviceAddress}."); } }
/// <summary> /// Generate a connection to a remote.it device/service. API Documentation: https://docs.remote.it/api-reference/devices/connect /// </summary> /// <param name="deviceAddress">The service address (e.g. service ID) for the device you'd like to connect to.</param> public async Task <ServiceConnection> ConnectToService(string deviceAddress, string hostIp = null) { if (_isInvalidSession) { CurrentSession.CurrentSessionData = await CurrentSession.GenerateSession(_userName, _userPassword, DeveloperKey); } var requestBodyAttributes = new Dictionary <string, dynamic>(); requestBodyAttributes.Add("deviceaddress", deviceAddress); requestBodyAttributes.Add("wait", true); if (!string.IsNullOrEmpty(hostIp)) { requestBodyAttributes.Add("hostip", hostIp); } string requestBodyJsonData = JsonSerializer.Serialize(requestBodyAttributes); var httpRequest = new HttpRequestMessage() { Method = HttpMethod.Post, RequestUri = new Uri(string.Concat(_httpApiClient.BaseAddress, "/device/connect")), Content = new StringContent(requestBodyJsonData) }; httpRequest.Headers.Add("developerkey", DeveloperKey); httpRequest.Headers.Add("token", CurrentSession.CurrentSessionData.Token); var apiRequestSender = new RemoteitApiRequest <ServiceConnectionEndpointResponse>(_httpApiClient); ServiceConnectionEndpointResponse results = await apiRequestSender.SendAsync(httpRequest); return(results.Connection); }
/// <summary> /// Get a list of your remote.it devices and data. API Documentation: https://docs.remote.it/api-reference/devices/list /// </summary> public async Task <List <RemoteitDevice> > GetDevices() { if (_isInvalidSession) { CurrentSession.CurrentSessionData = await CurrentSession.GenerateSession(_userName, _userPassword, DeveloperKey); } var httpRequest = new HttpRequestMessage() { Method = HttpMethod.Get, RequestUri = new Uri(string.Concat(_httpApiClient.BaseAddress, "/device/list/all")) }; httpRequest.Headers.Add("developerkey", DeveloperKey); httpRequest.Headers.Add("token", CurrentSession.CurrentSessionData.Token); var apiRequestSender = new RemoteitApiRequest <DevicesListEndpointResponse>(_httpApiClient); DevicesListEndpointResponse results = await apiRequestSender.SendAsync(httpRequest); return(results.Devices); }