private IHttpContext HandlePlaySession(IHttpContext context) { try { var source = GetParam(context, ParamSource); var sessionName = GetParam(context, ParamSessionName); if (!uint.TryParse(GetParam(context, ParamStart, "0"), out var start)) { start = 0; } if (!int.TryParse(GetParam(context, ParamEnd, "-1"), out var end)) { end = -1; } var session = OnPlayCalled?.Invoke(source, sessionName, start, end); context.Response.StatusCode = HttpStatusCode.Accepted; var hostParam = GetParam(context, ParamHost); var portParam = GetParam(context, ParamPort); if (hostParam != string.Empty && portParam != string.Empty) { var ipAddress = IPAddress.Parse(hostParam); if (int.TryParse(portParam, out var port)) { _streamingServer.AddReceiver(new IPEndPoint(ipAddress, port)); _serializer.ToProtoBuf(session, out SessionMetadata meta); _responseWriter.SendProtobufMessage(meta, context); } else { _responseWriter.SendError(HttpStatusCode.BadRequest, $"Invalid receiver configuration ${hostParam}:${portParam}", context); } } else { _responseWriter.SendError(HttpStatusCode.BadRequest, "host and port must be set", context); } } catch (InvalidArgumentException e) { _responseWriter.SendError(HttpStatusCode.BadRequest, e.Message, context); } return(context); }
private IHttpContext HandleGetSessions(IHttpContext context) { var sessionsMetadata = new SessionsMetadata(); foreach (var queryService in _queryServices) { var inputSourceMetadata = new SessionsMetadata.Types.InputSourceMetadata { SourceId = queryService.GetStorageName() }; var sessions = queryService.GetSessions().Select(s => { _serializer.ToProtoBuf(s, out SessionMetadata meta); var sessionMetadata = meta; return(sessionMetadata); }); inputSourceMetadata.SessionMeta.AddRange(sessions); sessionsMetadata.InputSourceMeta.Add(inputSourceMetadata); } _responseWriter.SendProtobufMessage(sessionsMetadata, context); return(context); }