publish method Null safety
Establish WebRTC connection with Millicast Server as Publisher role.
sdp
- The SDP information created by your offer.
options
- Signaling Publish Options.
Returns Future object which represents the SDP command response.
var response = await millicastSignaling.publish(sdp, {codec: 'h264'})
Implementation
Future<String> publish(String? sdp, {Map<String, dynamic>? options}) async {
_logger.i('Starting publishing to streamName: '
'$streamName, codec: ${options?['codec']}');
_logger.d('Publishing local description: $sdp');
if (options != null) {
if (!videoCodec.containsValue(options['codec'])) {
_logger.e('Invalid codec. Possible values are: $videoCodec');
throw Exception('Invalid codec. Possible values are: $videoCodec');
}
List<String?> codecs = (await NativeChannel.supportedCodecs);
if (!codecs.contains(options['codec'])) {
options['codec'] = codecs[0];
_logger
.w('Codec not supported by this device. Fallback to: ${codecs[0]}');
}
if (options['codec'] == videoCodec['AV1']) {
sdp = SdpParser.adaptCodecName(sdp, 'AV1X', videoCodec['AV1']!);
}
}
Map data = {
'name': streamName,
'sdp': sdp,
'codec': options?['codec'],
'sourceId': options?['sourceId']
};
if (options?['record'] != null) {
data['record'] = options?['record'];
}
if (options?['events'] != null) {
data['events'] = options?['events'];
}
try {
await connect();
_logger.i('Sending publish command');
var result = await transactionManager?.cmd('publish', data);
return result['data']['sdp'];
} catch (e) {
_logger.e('Error sending publish command, error: $e');
throw Exception(e);
}
}