onInit method
override
Called immediately after the widget is allocated in memory. You might use this to initialize something for the controller.
Implementation
@override
void onInit() {
WebStoredCall? stored = WebUtils.getCall(chatId);
if (stored == null || WebUtils.getCredentials(me) == null) {
return WebUtils.closeWindow();
}
call = _callService.addStored(
stored,
withAudio: router.arguments?['audio'] != 'false',
withVideo: router.arguments?['video'] == 'true',
withScreen: router.arguments?['screen'] == 'true',
);
_stateWorker = ever(call!.value.state, (OngoingCallState state) {
WebUtils.setCall(call!.value.toStored());
if (state == OngoingCallState.ended) {
WebUtils.closeWindow();
}
});
_storageSubscription = WebUtils.onStorageChange.listen((e) {
Log.debug(
'WebUtils.onStorageChange(${e.key}): ${e.newValue}',
'$runtimeType',
);
if (e.key == null) {
WebUtils.closeWindow();
} else if (e.newValue == null) {
if (e.key == 'credentials_$me' ||
e.key == 'call_${call?.value.chatId}') {
WebUtils.closeWindow();
}
} else if (e.key == 'call_${call?.value.chatId}') {
var stored = WebStoredCall.fromJson(json.decode(e.newValue!));
call?.value.call.value = stored.call;
call?.value.creds = call?.value.creds ?? stored.creds;
call?.value.deviceId = call?.value.deviceId ?? stored.deviceId;
call?.value.chatId.value = stored.chatId;
_tryToConnect();
}
});
_tryToConnect();
WakelockPlus.enable().onError((_, __) => false);
_pingTimer = Timer.periodic(
const Duration(milliseconds: 500),
(_) => WebUtils.pingCall(chatId),
);
_hotKey =
_settingsRepository.applicationSettings.value?.muteHotKey ??
MuteHotKeyExtension.defaultHotKey;
super.onInit();
}