produceData method

void produceData({
  1. bool ordered = true,
  2. required int maxPacketLife,
  3. required int maxRetransmits,
  4. Priority priority = Priority.Low,
  5. String label = '',
  6. String protocol = '',
  7. Map<String, dynamic> appData = const <String, dynamic>{},
})

Create a DataProducer use dataProducerCallback to receive a new ProducerData.

Implementation

void produceData({
  bool ordered = true,
  required int maxPacketLife,
  required int maxRetransmits,
  Priority priority = Priority.Low,
  String label = '',
  String protocol = '',
  Map<String, dynamic> appData = const <String, dynamic>{},
}) {
  _logger.debug('produceData()');

  if (_direction != Direction.send) {
    throw ('not a sending Transport');
  } else if (_maxSctpMessageSize == null) {
    throw ('SCTP not enabled by remote Transport');
  } if (listeners('connect').isEmpty && _connectionState == 'new') {
    throw ('no "connect" listener set into this transport');
  } else if (listeners('producedata').isEmpty) {
    throw ('no "producedata" listener set into this transport');
  }

  if (maxPacketLife != 0 || maxRetransmits != 0) {
    ordered = false;
  }

  // Enqueue command.
  _flexQueue.addTask(FlexTaskAdd(
      id: '',
      execFun: () async {
        HandlerSendDataChannelResult sendDataResult =
            await _handler.sendDataChannel(
          SendDataChannelArguments(
            ordered: ordered,
            maxPacketLifeTime: maxPacketLife,
            maxRetransmits: maxRetransmits,
            priority: priority,
            label: label,
            protocol: protocol,
          ),
        );

        // This will fill sctpStreamParameters's missing fields with default values.
        Ortc.validateSctpStreamParameters(
            sendDataResult.sctpStreamParameters);

        String id = await safeEmitAsFuture('producedata', {
          'sctpStreamParameters': sendDataResult.sctpStreamParameters,
          'label': label,
          'protocol': protocol,
          'appData': appData,
        });

        DataProducer dataProducer = DataProducer(
          id: id,
          dataChannel: sendDataResult.dataChannel,
          sctpStreamParameters: sendDataResult.sctpStreamParameters,
          appData: appData,
        );

        _dataProducers[dataProducer.id] = dataProducer;
        _handleDataProducer(dataProducer);

        // Emit observer event.
        _observer.safeEmit('newdataproducer', {
          'dataProducer': dataProducer,
        });

        dataProducerCallback?.call(dataProducer);
      }));
}