init method Null safety
used internally for initializing plugin, exposed only to be called via JanusSession attach method.
not useful for external operations
Implementation
Future<void> init() async {
if (!_initialized) {
_initialized = true;
_context._logger.info("Plugin Initialized");
if (webRTCHandle != null) {
return;
}
// initializing WebRTC Handle
Map<String, dynamic> configuration = {"iceServers": _context._iceServers != null ? _context._iceServers!.map((e) => e.toMap()).toList() : []};
if (_context._isUnifiedPlan && !_context._usePlanB) {
configuration.putIfAbsent('sdpSemantics', () => 'unified-plan');
} else {
configuration.putIfAbsent('sdpSemantics', () => 'plan-b');
}
_context._logger.fine('peer connection configuration');
_context._logger.fine(configuration);
//initialize stream controllers and streams
_initStreamControllersAndStreams();
RTCPeerConnection peerConnection = await createPeerConnection(configuration, {});
//add Event emitter logic
_handleEventMessageEmitter();
//unified plan webrtc tracks emitter
_handleUnifiedWebRTCTracksEmitter(peerConnection);
//send ice candidates to janus server on this specific handle
_handleIceCandidatesSending(peerConnection);
webRTCHandle = JanusWebRTCHandle(peerConnection: peerConnection);
this.pollingActive = true;
// Warning no code should be placed after code below in init function
// depending on transport setup events and messages for session and plugin
_handleTransportInitialization();
} else {
_context._logger.info("Plugin already Initialized! skipping");
}
}