示例#1
0
        /// <summary>
        /// <para>Events:</para>
        /// <para>@emits transportclose</para>
        /// <para>@emits @close</para>
        /// <para>Observer events:</para>
        /// <para>@emits close</para>
        /// </summary>
        /// <param name="loggerFactory"></param>
        /// <param name="dataProducerInternalData"></param>
        /// <param name="sctpStreamParameters"></param>
        /// <param name="label"></param>
        /// <param name="protocol"></param>
        /// <param name="channel"></param>
        /// <param name="payloadChannel"></param>
        /// <param name="appData"></param>
        public DataProducer(ILoggerFactory loggerFactory,
                            DataProducerInternalData dataProducerInternalData,
                            SctpStreamParameters sctpStreamParameters,
                            string label,
                            string protocol,
                            Channel channel,
                            PayloadChannel payloadChannel,
                            Dictionary <string, object>?appData
                            )
        {
            _logger = loggerFactory.CreateLogger <DataProducer>();

            // Internal
            _internal = dataProducerInternalData;

            // Data
            SctpStreamParameters = sctpStreamParameters;
            Label    = label;
            Protocol = protocol;

            _channel        = channel;
            _payloadChannel = payloadChannel;
            AppData         = appData;

            HandleWorkerNotifications();
        }
示例#2
0
        /// <summary>
        /// Validates SctpStreamParameters. It may modify given data by adding missing
        /// fields with default values.
        /// It throws if invalid.
        /// </summary>
        public static void ValidateSctpStreamParameters(SctpStreamParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            // streamId is mandatory.
            // 在 Node.js 实现中,判断了 streamId 的数据类型。在强类型语言中不需要。

            // ordered is optional.
            var orderedGiven = true;

            if (!parameters.Ordered.HasValue)
            {
                orderedGiven       = false;
                parameters.Ordered = true;
            }

            // maxPacketLifeTime is optional.
            // 在 Node.js 实现中,判断了 maxPacketLifeTime 的数据类型。在强类型语言中不需要。

            // maxRetransmits is optional.
            // 在 Node.js 实现中,判断了 maxRetransmits 的数据类型。在强类型语言中不需要。

            if (parameters.MaxPacketLifeTime.HasValue && parameters.MaxRetransmits.HasValue)
            {
                throw new ArgumentException("cannot provide both maxPacketLifeTime and maxRetransmits");
            }

            if (orderedGiven &&
                parameters.Ordered.Value &&
                (parameters.MaxPacketLifeTime.HasValue || parameters.MaxRetransmits.HasValue)
                )
            {
                throw new ArgumentException("cannot be ordered with maxPacketLifeTime or maxRetransmits");
            }
            else if (!orderedGiven && (parameters.MaxPacketLifeTime.HasValue || parameters.MaxRetransmits.HasValue))
            {
                parameters.Ordered = false;
            }
        }