prepareWebrtcPeer method
dynamic
prepareWebrtcPeer
(- int handleId,
- dynamic callbacks
)
Implementation
prepareWebrtcPeer(int handleId, callbacks) {
RTCSessionDescription jsep =
RTCSessionDescription(callbacks.jsep["sdp"], callbacks.jsep["type"]);
Plugin pluginHandle = this.pluginHandles[handleId.toString()];
if (pluginHandle == null) {
Janus.warn("Invalid handle");
callbacks.error("Invalid handle");
return;
}
if (jsep != null) {
if (pluginHandle.pc == null) {
Janus.warn(
"Wait, no PeerConnection?? if this is an answer, use createAnswer and not handleRemoteJsep");
callbacks.error(
"No PeerConnection: if this is an answer, use createAnswer and not handleRemoteJsep");
return;
}
pluginHandle.pc.setRemoteDescription(jsep).then((void v) {
Janus.log("Remote description accepted!");
pluginHandle.remoteSdp = callbacks.jsep["sdp"];
// Any trickle candidate we cached?
if (pluginHandle.candidates != null &&
pluginHandle.candidates.length > 0) {
for (var i = 0; i < pluginHandle.candidates.length; i++) {
RTCIceCandidate candidate = pluginHandle.candidates[i];
Janus.debug("Adding remote candidate:", candidate);
if (candidate == null) {
// end-of-candidates
pluginHandle.pc.addCandidate(Janus.endOfCandidates);
} else {
// New candidate
pluginHandle.pc.addCandidate(candidate);
}
}
pluginHandle.candidates = [];
}
// Done
callbacks.success();
}).catchError((error, StackTrace stackTrace) {
callbacks.error(error);
});
} else {
callbacks.error("Invalid JSEP");
}
}