produceData method
void
produceData({})
Create a DataProducer use dataProducerCallback to receive a new ProducerData.
Implementation
void produceData({
bool ordered = true,
int maxPacketLife = 0,
required int maxRetransmits,
Priority priority = Priority.Low,
String label = '',
String protocol = '',
Map<String, dynamic> appData = const <String, dynamic>{},
Function? accept,
}) {
_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, accept);
}));
}