private IHttpContext HandleStopSession(IHttpContext context)
        {
            try
            {
                OnStopPlaybackCalled?.Invoke(this, EventArgs.Empty);
                context.Response.StatusCode = HttpStatusCode.Accepted;
                var response = ToDict("msg", "Session playback stopped");
                _responseWriter.SendJsonResponse(response, context);
            }
            catch (Exception e)
            {
                _responseWriter.SendError(HttpStatusCode.InternalServerError,
                                          "Could not stop playback; cause: " + e.Message, context);
            }

            return(context);
        }
        private IHttpContext HandleStopRecord(IHttpContext context)
        {
            var session = OnStopRecordCalled?.Invoke();

            if (session == null)
            {
                context.Response.StatusCode = HttpStatusCode.NotModified;
                var msg = new Dictionary <string, string> {
                    { "msg", "No record to stop" }
                };
                _responseWriter.SendJsonResponse(msg, context);
            }
            else
            {
                context.Response.StatusCode = HttpStatusCode.Accepted;
                _serializer.ToProtoBuf(session, out SessionMetadata meta);
                _responseWriter.SendProtobufMessage(meta, context);
            }
            return(context);
        }