public Recording(JsonObject json)
        {
            json.TryGetValue("id", out var idAsJsonValue);
            Id = idAsJsonValue?.ToString();

            json.TryGetValue("name", out var nameAsJsonValue);
            var name = nameAsJsonValue?.ToString();

            json.TryGetValue("resolution", out var resolutionAsJsonValue);
            var resolution = resolutionAsJsonValue?.ToString();

            json.TryGetValue("sessionId", out var sessionIdAsJsonValue);
            SessionId = sessionIdAsJsonValue?.ToString();

            json.TryGetValue("createdAt", out var createdAtAsJsonValue);
            long.TryParse(createdAtAsJsonValue?.ToString(), out var createdAt);
            CreatedAt = createdAt;

            json.TryGetValue("size", out var sizeAsJsonValue);
            long.TryParse(sizeAsJsonValue?.ToString(), out var size);
            Size = size;

            json.TryGetValue("duration", out var durationAsJsonValue);
            double.TryParse(durationAsJsonValue?.ToString(), out var duration);
            Duration = duration;

            json.TryGetValue("url", out var urlAsJsonValue);
            Url = urlAsJsonValue?.ToString();

            json.TryGetValue("status", out var statusAsJsonValue);
            Enum.TryParse(statusAsJsonValue?.ToString(), out RecordingStatus status);
            Status = status;

            json.TryGetValue("hasAudio", out var hasAudioAsJsonValue);
            bool.TryParse(hasAudioAsJsonValue?.ToString(), out var hasAudio);

            json.TryGetValue("hasVideo", out var hasVideoAsJsonValue);
            bool.TryParse(hasVideoAsJsonValue?.ToString(), out var hasVideo);

            json.TryGetValue("outputMode", out var outputModeAsJsonValue);
            Enum.TryParse(outputModeAsJsonValue?.ToString(), out OutputMode outputMode);

            json.TryGetValue("recordingLayout", out var recordingLayoutAsJsonValue);
            Enum.TryParse(recordingLayoutAsJsonValue?.ToString(), out RecordingLayout recordingLayout);

            json.TryGetValue("customLayout", out var customLayoutAsJsonValue);

            var builder = new RecordingPropertiesBuilder().name(name).outputMode(outputMode).hasAudio(hasAudio).hasVideo(hasVideo);

            if (OutputMode.COMPOSED.Equals(outputMode) && hasVideo)
            {
                builder.resolution(resolution).recordingLayout(recordingLayout);
                if (!string.IsNullOrEmpty(customLayoutAsJsonValue.ToString()))
                {
                    builder.customLayout(customLayoutAsJsonValue.ToString());
                }
            }

            this._recordingProperties = builder.build();
        }
예제 #2
0
        public async Task <Recording> startRecording(string sessionId, RecordingProperties properties)
        {
            HttpResponseMessage response;

            var json = new JsonObject
            {
                { "session", sessionId },
                { "name", properties.Name },
                { "outputMode", properties.OutputMode.ToString() },
                { "hasAudio", properties.HasAudio },
                { "hasVideo", properties.HasVideo }
            };

            if (OutputMode.COMPOSED.Equals(properties.OutputMode) && properties.HasVideo)
            {
                json.Add("resolution", properties.Resolution);
                json.Add("recordingLayout", properties.RecordingLayout > 0 ? properties.RecordingLayout.ToString() : "");
                if (RecordingLayout.CUSTOM.Equals(properties.RecordingLayout))
                {
                    json.Add("customLayout", !string.IsNullOrEmpty(properties.CustomLayout) ? properties.CustomLayout : "");
                }
            }

            var content = new StringContent(json.ToString(), Encoding.UTF8, "application/json");

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            try
            {
                response = await HttpClient.PostAsync(ApiRecordings + ApiRecordingsStart, content);
            }
            catch (HttpRequestException ex)
            {
                throw new OpenViduClientException(ex.Message, ex.InnerException);
            }

            try
            {
                if (response.IsSuccessStatusCode)
                {
                    var r = new Recording(await httpResponseToJson(response));
                    this._activeSessions.TryGetValue(r.SessionId, out var activeSession);

                    if (activeSession != null)
                    {
                        activeSession.IsBeingRecorded = true;
                    }
                    else
                    {
                        _logger.LogWarning("No active session found for sessionId '" + r.SessionId + "'. This instance of OpenVidu Client didn't create this session");
                    }
                    return(r);
                }
                else
                {
                    throw new OpenViduHttpException((int)response.StatusCode);
                }
            }
            catch (Exception e)
            {
                throw new OpenViduClientException(e.Message);
            }
        }