public void Post(SendPlaystateCommand request) { var command = new PlaystateRequest { Command = request.Command, SeekPositionTicks = request.SeekPositionTicks }; var task = _sessionManager.SendPlaystateCommand(request.Id, command, CancellationToken.None); Task.WaitAll(task); }
private async Task SendPlaystateCommand(SendPlaystateCommand request) { var session = _sessionManager.Sessions.FirstOrDefault(i => i.Id == request.Id); if (session == null) { throw new ResourceNotFoundException(string.Format("Session {0} not found.", request.Id)); } if (!session.SupportsRemoteControl) { throw new ArgumentException(string.Format("Session {0} does not support remote control.", session.Id)); } var socket = session.WebSockets.OrderByDescending(i => i.LastActivityDate).FirstOrDefault(i => i.State == WebSocketState.Open); if (socket != null) { try { await socket.SendAsync(new WebSocketMessage <PlaystateRequest> { MessageType = "Playstate", Data = new PlaystateRequest { Command = request.Command, SeekPosition = request.SeekPosition } }, CancellationToken.None).ConfigureAwait(false); } catch (Exception ex) { Logger.ErrorException("Error sending web socket message", ex); } } else { throw new InvalidOperationException("The requested session does not have an open web socket."); } }
public void Post(SendPlaystateCommand request) { var task = SendPlaystateCommand(request); Task.WaitAll(task); }