示例#1
0
        /// <summary>
        /// Add a participant to a session.
        /// Subscriptions can optionally be provided as part of this call.
        /// </summary>
        /// <param name="accountId">Required parameter: Account ID.</param>
        /// <param name="sessionId">Required parameter: Session ID.</param>
        /// <param name="participantId">Required parameter: Participant ID.</param>
        /// <param name="body">Optional parameter: Subscriptions the participant should be created with.</param>
        public void AddParticipantToSession(
            string accountId,
            string sessionId,
            string participantId,
            Models.Subscriptions body = null)
        {
            Task t = this.AddParticipantToSessionAsync(accountId, sessionId, participantId, body);

            ApiHelper.RunTaskSynchronously(t);
        }
示例#2
0
        /// <summary>
        /// Update a participant's subscriptions
        /// This is a full update that will replace the participant's subscriptions. First call `getParticipantSubscriptions` if you need the current subscriptions. Call this function with no `Subscriptions` object to remove all subscriptions
        /// </summary>
        /// <param name="accountId">Required parameter: Account ID</param>
        /// <param name="participantId">Required parameter: Participant ID</param>
        /// <param name="sessionId">Required parameter: Session ID</param>
        /// <param name="body">Optional parameter: Initial state</param>
        /// <return>Returns the void response from the API call</return>
        public void UpdateParticipantSubscriptions(
            string accountId,
            string participantId,
            string sessionId,
            Models.Subscriptions body = null)
        {
            Task t = UpdateParticipantSubscriptionsAsync(accountId, participantId, sessionId, body);

            ApiHelper.RunTaskSynchronously(t);
        }
示例#3
0
 public Participant(string id          = null,
                    string callbackUrl = null,
                    List <Models.PublishPermissionEnum> publishPermissions = null,
                    List <string> sessions             = null,
                    Models.Subscriptions subscriptions = null,
                    string tag = null)
 {
     Id                 = id;
     CallbackUrl        = callbackUrl;
     PublishPermissions = publishPermissions;
     Sessions           = sessions;
     Subscriptions      = subscriptions;
     Tag                = tag;
 }
示例#4
0
        public async Task <ResourceResponse <Document> > CreateSubscriptionsAsync(Models.Subscriptions subscriptions)
        {
            var collectionUri = DocumentDBHelper.CreateSubscriptionDocumentCollectionUri();

            var client = DocumentDBClient.CreateDocumentClient();

            if (client == null)
            {
                return(null);
            }

            var response = await client.CreateDocumentAsync(collectionUri, subscriptions);

            return(response);
        }
        public async Task <ResourceResponse <Document> > UpdateSubscriptionsAsync(Models.Subscriptions subscriptions)
        {
            var documentUri = DocumentDBHelper.CreateDocumentUri(subscriptions.SubscriptionId);

            var client = DocumentDBClient.CreateDocumentClient();

            if (client == null)
            {
                return(null);
            }

            var response = await client.ReplaceDocumentAsync(documentUri, subscriptions);

            return(response);
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Participant"/> class.
        /// </summary>
        /// <param name="id">id.</param>
        /// <param name="callbackUrl">callbackUrl.</param>
        /// <param name="publishPermissions">publishPermissions.</param>
        /// <param name="sessions">sessions.</param>
        /// <param name="subscriptions">subscriptions.</param>
        /// <param name="tag">tag.</param>
        /// <param name="deviceApiVersion">deviceApiVersion.</param>
        public Participant(
            string id          = null,
            string callbackUrl = null,
            List <Models.PublishPermissionEnum> publishPermissions = null,
            List <string> sessions             = null,
            Models.Subscriptions subscriptions = null,
            string tag = null,
            Models.DeviceApiVersionEnum?deviceApiVersion = Models.DeviceApiVersionEnum.V2)
        {
            this.Id = id;
            if (callbackUrl != null)
            {
                this.CallbackUrl = callbackUrl;
            }

            this.PublishPermissions = publishPermissions;
            this.Sessions           = sessions;
            this.Subscriptions      = subscriptions;
            this.Tag = tag;
            this.DeviceApiVersion = deviceApiVersion;
        }
示例#7
0
        public async Task <Models.Subscriptions> UpdateAsync(Models.Subscriptions subscriptions, Models.SubscriptionsPatch subscriptionsPatch)
        {
            if (subscriptions == null)
            {
                return(null);
            }

            if (!subscriptionsPatch.LastModifiedDate.HasValue)
            {
                subscriptionsPatch.LastModifiedDate = DateTime.Now;
            }

            subscriptions.Patch(subscriptionsPatch);

            var documentDbProvider = new DocumentDBProvider();
            var response           = await documentDbProvider.UpdateSubscriptionsAsync(subscriptions);

            var responseStatusCode = response.StatusCode;

            return(responseStatusCode == HttpStatusCode.OK ? subscriptions : null);
        }
示例#8
0
        public async Task <Models.Subscriptions> CreateAsync(Models.Subscriptions subscriptions)
        {
            if (subscriptions == null)
            {
                return(null);
            }

            var subscriptionId = Guid.NewGuid();

            subscriptions.SubscriptionId = subscriptionId;

            if (!subscriptions.LastModifiedDate.HasValue)
            {
                subscriptions.LastModifiedDate = DateTime.Now;
            }

            var documentDbProvider = new DocumentDBProvider();

            var response = await documentDbProvider.CreateSubscriptionsAsync(subscriptions);

            return(response.StatusCode == HttpStatusCode.Created ? (dynamic)response.Resource : (Guid?)null);
        }
示例#9
0
        /// <summary>
        /// Add a participant to a session.
        /// Subscriptions can optionally be provided as part of this call.
        /// </summary>
        /// <param name="accountId">Required parameter: Account ID.</param>
        /// <param name="sessionId">Required parameter: Session ID.</param>
        /// <param name="participantId">Required parameter: Participant ID.</param>
        /// <param name="body">Optional parameter: Subscriptions the participant should be created with.</param>
        /// <param name="cancellationToken"> cancellationToken. </param>
        /// <returns>Returns the void response from the API call.</returns>
        public async Task AddParticipantToSessionAsync(
            string accountId,
            string sessionId,
            string participantId,
            Models.Subscriptions body           = null,
            CancellationToken cancellationToken = default)
        {
            // the base uri for api requests.
            string baseUri = this.Config.GetBaseUri(Server.WebRtcDefault);

            // prepare query string for API call.
            StringBuilder queryBuilder = new StringBuilder(baseUri);

            queryBuilder.Append("/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}");

            // process optional template parameters.
            ApiHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>()
            {
                { "accountId", accountId },
                { "sessionId", sessionId },
                { "participantId", participantId },
            });

            // append request with appropriate headers and parameters
            var headers = new Dictionary <string, string>()
            {
                { "user-agent", this.UserAgent },
                { "content-type", "application/json; charset=utf-8" },
            };

            // append body params.
            var bodyText = ApiHelper.JsonSerialize(body);

            // prepare the API call request to fetch the response.
            HttpRequest httpRequest = this.GetClientInstance().PutBody(queryBuilder.ToString(), headers, bodyText);

            if (this.HttpCallBack != null)
            {
                this.HttpCallBack.OnBeforeHttpRequestEventHandler(this.GetClientInstance(), httpRequest);
            }

            httpRequest = await this.AuthManagers["webRtc"].ApplyAsync(httpRequest).ConfigureAwait(false);

            // invoke request and get response.
            HttpStringResponse response = await this.GetClientInstance().ExecuteAsStringAsync(httpRequest, cancellationToken).ConfigureAwait(false);

            HttpContext context = new HttpContext(httpRequest, response);

            if (this.HttpCallBack != null)
            {
                this.HttpCallBack.OnAfterHttpResponseEventHandler(this.GetClientInstance(), response);
            }

            if (response.StatusCode == 401)
            {
                throw new ApiException("Unauthorized", context);
            }

            if (response.StatusCode == 403)
            {
                throw new ApiException("Access Denied", context);
            }

            if (response.StatusCode == 404)
            {
                throw new ApiException("Not Found", context);
            }

            // [200,208] = HTTP OK
            if ((response.StatusCode < 200) || (response.StatusCode > 208))
            {
                throw new ErrorException("Unexpected Error", context);
            }

            // handle errors defined at the API level.
            this.ValidateResponse(response, context);
        }
示例#10
0
        /// <summary>
        /// Update a participant's subscriptions
        /// This is a full update that will replace the participant's subscriptions. First call `getParticipantSubscriptions` if you need the current subscriptions. Call this function with no `Subscriptions` object to remove all subscriptions
        /// </summary>
        /// <param name="accountId">Required parameter: Account ID</param>
        /// <param name="participantId">Required parameter: Participant ID</param>
        /// <param name="sessionId">Required parameter: Session ID</param>
        /// <param name="body">Optional parameter: Initial state</param>
        /// <return>Returns the void response from the API call</return>
        public async Task UpdateParticipantSubscriptionsAsync(
            string accountId,
            string participantId,
            string sessionId,
            Models.Subscriptions body = null, CancellationToken cancellationToken = default)
        {
            //the base uri for api requests
            string _baseUri = config.GetBaseUri(Server.WebRtcDefault);

            //prepare query string for API call
            StringBuilder _queryBuilder = new StringBuilder(_baseUri);

            _queryBuilder.Append("/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}/subscriptions");

            //process optional template parameters
            ApiHelper.AppendUrlWithTemplateParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "accountId", accountId },
                { "participantId", participantId },
                { "sessionId", sessionId }
            });

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", userAgent },
                { "content-type", "application/json; charset=utf-8" }
            };

            //append body params
            var _body = ApiHelper.JsonSerialize(body);

            //prepare the API call request to fetch the response
            HttpRequest _request = GetClientInstance().PutBody(_queryBuilder.ToString(), _headers, _body);

            _request = await authManagers["webRtc"].ApplyAsync(_request).ConfigureAwait(false);

            //invoke request and get response
            HttpStringResponse _response = await GetClientInstance().ExecuteAsStringAsync(_request, cancellationToken).ConfigureAwait(false);

            HttpContext _context = new HttpContext(_request, _response);

            //Error handling using HTTP status codes
            if (_response.StatusCode == 400)
            {
                throw new ApiException("Bad Request", _context);
            }

            if (_response.StatusCode == 401)
            {
                throw new ApiException("Unauthorized", _context);
            }

            if (_response.StatusCode == 403)
            {
                throw new ApiException("Access Denied", _context);
            }

            if (_response.StatusCode == 404)
            {
                throw new ApiException("Not Found", _context);
            }

            if ((_response.StatusCode < 200) || (_response.StatusCode > 208)) //[200,208] = HTTP OK
            {
                throw new ErrorException("Unexpected Error", _context);
            }

            //handle errors defined at the API level
            base.ValidateResponse(_response, _context);
        }