Hi i have made a backend code and for frontend i have implemented this thing on react js, which is working fine
Now i am try to implement this thing in flutter using mediasfu_mediasoup_client package
After checking logs i find the producer transport ‘connect’ on method is never getting fired why?
Here is the log of it (flutter)
transportsParams {id: 23666f5e-d7dd-4a08-a86d-722c04274b08, iceParameters: {usernameFragment: ictr9rer45skcjxgf5y460jkhydl9ca5, password: 4ajp7pg52nyi65r6tn4yk2lmns73j6ov, iceLite: true}, iceCandidates: [{foundation: udpcandidate, priority: 1076302079, ip: 192.168.1.2, address: 192.168.1.2, protocol: udp, port: 2015, type: host}, {foundation: tcpcandidate, priority: 1076276479, ip: 192.168.1.2, address: 192.168.1.2, protocol: tcp, port: 2025, type: host, tcpType: passive}], dtlsParameters: {fingerprints: [{algorithm: sha-512, value: 3C:B9:99:4F:4C:36:EA:E6:BE:B7:FB:AD:A1:EC:95:E4:78:9D:5C:DB:98:7C:FF:68:8B:48:62:5C:B2:24:90:B2:16:1D:98:C0:77:BC:A2:C1:D8:79:F9:4F:D5:43:F1:00:23:A1:AB:27:3C:BA:66:53:1A:1D:67:28:37:2A:00:23}, {algorithm: sha-224, value: E1:8A:98:43:AF:22:66:55:A9:7C:D4:F2:0C:EE:76:46:50:60:CB:F6:6E:BB:3C:EB:03:21:A0:81}, {algorithm: sha-1, value: FB:AC:5D:80:AE:7F:19:3D:69:31:38:D2:7F:04:2D:62:EE:F1:39:7B}, {algorithm: sha-384, value: F9:60:9D:95:EE:72:6D:DE:54:83:1B:DD:29:CB:47:C2:B0:B7:C1:76:
I/flutter ( 7626): Invalid protocol value: udp
I/flutter ( 7626): Instance of ‘IceParameters’
I/flutter ( 7626): [Instance of ‘IceCandidate’, Instance of ‘IceCandidate’]
I/flutter ( 7626): Instance of ‘DtlsParameters’
I/flutter ( 7626): pTrans new
I/flutter ( 7626): producerTransport id here 23666f5e-d7dd-4a08-a86d-722c04274b08
2
I/org.webrtc.Logging( 7626): EglRenderer: Duration: 4003 ms. Frames received: 0. Dropped: 0. Rendered: 0. Render fps: .0. Average render time: NA. Average swapBuffer time: NA.
I/org.webrtc.Logging( 7626): EglRenderer: Duration: 4002 ms. Frames received: 27. Dropped: 0. Rendered: 27. Render fps: 6.7. Average render time: 156 us. Average swapBuffer time: 1154 us.
I/org.webrtc.Logging( 7626): EglRenderer: Duration: 4006 ms. Frames received: 0. Dropped: 0. Rendered: 0. Render fps: .0. Average render time: NA. Average swapBuffer time: NA.
I/org.webrtc.Logging( 7626): EglRenderer: Duration: 4003 ms. Frames received: 0. Dropped: 0. Rendered: 0. Render fps: .0. Average render time: NA. Average swapBuffer time: NA.
void createSendTransport(MediaStream sstream) {
_socket.emitWithAck(‘createWebRtcTransport’, {
‘consumer’: false,
}, ack: (params) async {
var transportParams = params[‘params’];
print(‘transportsParams $transportParams’);
final iceParameters = IceParameters(
usernameFragment: transportParams['iceParameters']['usernameFragment'],
password: transportParams['iceParameters']['password'],
iceLite: transportParams['iceParameters']['iceLite'],
);
final iceCandidates =
(transportParams['iceCandidates'] as List).map((candidate) {
return IceCandidate(
foundation: candidate['foundation'],
priority: candidate['priority'] as int,
ip: candidate['ip'] as String,
protocol: Protocol.values.firstWhere(
(e) => e.toString().split(‘.’).last.toLowerCase() == candidate[‘protocol’].toString().toLowerCase(),
orElse: () {
print(‘Invalid protocol value: ${candidate[‘protocol’]}’);
return Protocol.tcp; // default fallback
},
),
port: candidate['port'] as int,
type: IceCandidateType.values.firstWhere(
(e) => e.toString().split('.').last == candidate['type'],
orElse: () => throw Exception('Invalid type value'),
),
tcpType: candidate['tcpType'] != null
? TcpType.values.firstWhere(
(e) => e.toString().split('.').last == candidate['tcpType'],
orElse: () => throw Exception('Invalid tcpType value'),
)
: null,
transport: candidate['transport'] as String? ?? '',
raddr: candidate['raddr'] as String? ?? '',
rport: candidate['rport'] as int? ?? 0,
);
}).toList();
final dtlsParameters = DtlsParameters(
fingerprints:
(transportParams['dtlsParameters']['fingerprints'] as List)
.map((fingerprint) => DtlsFingerprint(
algorithm: fingerprint['algorithm'],
value: fingerprint['value'],
))
.toList(),
role: DtlsRole.auto,
);
print(iceParameters.toString());
print(iceCandidates.toString());
print(dtlsParameters.toString());
var createSendTransport = device.createSendTransport(
id: transportParams['id'],
iceParameters: iceParameters,
iceCandidates: iceCandidates,
dtlsParameters: dtlsParameters,
);
print('pTrans ${createSendTransport.connectionState}');
producerTransport = createSendTransport;
print('producerTransport id here ${createSendTransport.id}');
producerTransport.on('connect', (data) async {
final dtlsParameters = data['dtlsParameters'];
try {
_socket.emitWithAck('transport-connect', {
'dtlsParameters': dtlsParameters,
}, ack: (res) {
data['callback']();
});
} catch (e) {
data['errback'](e);
}
});
producerTransport.on('produce', (Map data, Function callback, Function errback) async {
try {
_socket.emitWithAck('transport-produce', {
'kind': data['kind'],
'rtpParameters': data['rtpParameters'],
'appData': data['appData'],
}, ack: (response) {
callback({'id': response['id']});
});
} catch (e) {
errback(e);
}
});
producerTransport.on('connectionstatechange', (state) async {
print("Transport connection state: $state");
if (state == 'connected') {
print("✅ Transport is connected. Now safe to produce.");
try {
final videoTrack = sstream.getVideoTracks().first;
print("Tracks in stream: ${sstream.getVideoTracks()}");
print("Using track: $videoTrack");
producerTransport.produce(
source: 'webcam',
stream: sstream,
track: videoTrack,
codecOptions: ProducerCodecOptions(
videoGoogleStartBitrate: 1000,
),
appData: {'mediaTag': 'cam-video'},
);
} catch (e) {
print("Error in creating producer: $e");
}
}
});
});
}