start method
Implementation
void start(PitelSettings uaSettings) async {
//! WARNING
if (_ua != null) {
logger.warn(
'UA instance already exist!, stopping UA and creating a one...');
_ua!.stop();
}
_uaSettings = uaSettings;
_settings = PitelSipSettings();
WebSocketInterface socket = WebSocketInterface(
uaSettings.webSocketUrl, uaSettings.webSocketSettings);
_settings!.sockets = <WebSocketInterface>[socket];
_settings!.uri = uaSettings.uri;
_settings!.contactUri = uaSettings.contactUri;
_settings!.password = uaSettings.password;
//! sip_domain
_settings!.sipDomain = uaSettings.sipDomain;
_settings!.ha1 = uaSettings.ha1;
_settings!.displayName = uaSettings.displayName;
_settings!.authorizationUser = uaSettings.authorizationUser;
_settings!.userAgent = uaSettings.userAgent ?? dart_sip_c.USER_AGENT;
_settings!.register = uaSettings.register;
_settings!.registerExpires = uaSettings.register_expires;
_settings!.registerExtraContactUriParams =
uaSettings.registerParams.extraContactUriParams;
_settings!.dtmfMode = uaSettings.dtmfMode;
_settings!.sessionTimers = uaSettings.sessionTimers;
_settings!.ice_gathering_timeout = uaSettings.iceGatheringTimeout;
try {
_ua = PitelUA(_settings);
List<String> extraHeaders = [];
uaSettings.webSocketSettings.extraHeaders.forEach((key, value) {
extraHeaders.add('$key: $value');
});
_ua!.registrator()?.setExtraHeaders(extraHeaders);
_ua!.on(EventSocketConnecting(), (EventSocketConnecting event) {
logger.debug('connecting => ' + event.toString());
_notifyTransportStateListeners(
PitelTransportState(TransportStateEnum.CONNECTING));
});
_ua!.on(EventSocketConnected(), (EventSocketConnected event) {
logger.debug('connected => ' + event.toString());
_notifyTransportStateListeners(
PitelTransportState(TransportStateEnum.CONNECTED));
});
_ua!.on(EventSocketDisconnected(), (EventSocketDisconnected event) {
logger.debug('disconnected => ' + (event.cause.toString()));
_notifyTransportStateListeners(PitelTransportState(
TransportStateEnum.DISCONNECTED,
cause: event.cause));
});
_ua!.on(EventRegistered(), (EventRegistered event) {
logger.debug('registered => ' + event.cause.toString());
_registerState = RegistrationState(
state: RegistrationStateEnum.registered, cause: event.cause);
_notifyRegsistrationStateListeners(_registerState);
});
_ua!.on(EventUnregister(), (EventUnregister event) {
logger.debug('unregistered => ' + event.cause.toString());
_registerState = RegistrationState(
state: RegistrationStateEnum.unregistered, cause: event.cause);
_notifyRegsistrationStateListeners(_registerState);
});
_ua!.on(EventRegistrationFailed(), (EventRegistrationFailed event) {
logger.debug('registrationFailed => ' + (event.cause.toString()));
_registerState = RegistrationState(
state: RegistrationStateEnum.registrationFailed,
cause: event.cause);
_notifyRegsistrationStateListeners(_registerState);
});
_ua!.on(EventNewRTCSession(), (EventNewRTCSession event) {
logger.debug('newRTCSession => ' + event.toString());
RTCSession session = event.session!;
if (session.direction == 'incoming') {
// Set event handlers.
session.addAllEventHandlers(
buildCallOptions()['eventHandlers'] as EventManager);
}
_calls[event.id] =
Call(event.id, session, PitelCallStateEnum.CALL_INITIATION);
_notifyCallStateListeners(
event, PitelCallState(PitelCallStateEnum.CALL_INITIATION));
});
_ua!.on(EventNewMessage(), (EventNewMessage event) {
logger.debug('newMessage => ' + event.toString());
//Only notify incoming message to listener
if (event.message!.direction == 'incoming') {
SIPMessageRequest message =
SIPMessageRequest(event.message, event.originator, event.request);
_notifyNewMessageListeners(message);
}
});
_ua!.start();
} catch (event, s) {
logger.error(event.toString(), null, s);
}
}