Esempio n. 1
0
        /// <summary>
        /// Attempts to create a new Janus session. This is the first step to do anything
        /// with the Janus WebRTC or other features.
        /// </summary>
        /// <returns>A non-zero session ID. A zero value indicates a failure.</returns>
        private async Task <ulong> CreateSession(CancellationToken ct)
        {
            _logger.LogDebug("Creating Janus session...");

            RestClient client = new RestClient(_serverUrl);

            client.UseNewtonsoftJson();

            // Create session.
            var createSessionReq = new JanusRequest {
                janus = JanusOperationsEnum.create
            };
            var sessReq = new RestRequest(string.Empty, Method.POST, DataFormat.Json);

            sessReq.AddJsonBody(createSessionReq);
            var sessResp = await client.ExecutePostAsync <JanusResponse>(sessReq, ct).ConfigureAwait(false);

            ulong sessionID = sessResp.Data.data.id;

            _logger.LogDebug($"Result={sessResp.Data.janus}.");
            _logger.LogDebug($"Transaction={sessResp.Data.transaction}.");
            _logger.LogDebug($"SessionID={sessionID}.");

            return(sessionID);
        }
Esempio n. 2
0
        /// <summary>
        /// Closes and destroys a Janus session allowing the server to free any
        /// resources or plugins attached to it.
        /// </summary>
        public async Task DestroySession()
        {
            RestClient client = new RestClient(_serverUrl);

            client.UseNewtonsoftJson();

            var destroyReqBody = new JanusRequest {
                janus = JanusOperationsEnum.destroy
            };
            var destroyReq = new RestRequest(_sessionID.ToString(), Method.POST, DataFormat.Json);

            destroyReq.AddJsonBody(destroyReqBody);
            var destroyResp = await client.ExecutePostAsync <JanusResponse>(destroyReq).ConfigureAwait(false);

            _logger.LogDebug($"Destroy response: {destroyResp.Data.janus}.");
        }