signal method
Call this method whenever signaling data is received from remote peer
Implementation
// The data will encapsulate a webrtc offer, answer, or ice candidate. These
// messages help the peers to eventually establish a direct connection to
// each other. The contents of these strings are an implementation detail
// that can be ignored by the user of this module; simply pass the data
// from 'signal' events to the remote peer and call peer.signal(data) to
// get connected.
signal(SignalingInfo info) async {
var payload = info.payload;
if (info.isOffer || info.isAnswer) {
var sdp = payload['sdp'] as String?;
var type = payload['type'] as String?;
var description = RTCSessionDescription(sdp, type);
connection.setRemoteDescription(description);
_print('Remote description set');
if (info.isOffer) {
var answer = await connection.createAnswer();
await connection.setLocalDescription(answer);
await _signaling('answer', answer.toMap());
}
await postIceCandidates();
} else if (info.isIceCandidate) {
var candidate = payload['candidate'] as String?;
var sdpMid = payload['sdpMid'] as String?;
var sdpMLineIndex = payload['sdpMLineIndex'] as int?;
var iceCandidate = RTCIceCandidate(candidate, sdpMid, sdpMLineIndex);
await connection.addCandidate(iceCandidate);
var type = candidate?.split(' ')[7];
_print('Ice candidate $type added');
}
}