initSocketServer method
Implementation
Future<void> initSocketServer(String roomName, BuildContext context) async {
this.context = context;
if (socket.connected) {
return;
}
socket.connect();
socket.on('connect', (_) {
socket.emit('joinRoom', roomName);
});
socket.on('disconnect', (_) {});
socket.on("broadcast", (data) async {
if (data is Map && data.containsKey('transactionId')) {
final id = data['transactionId'];
wasInBackground = false;
final checkoutReponse = await fetchDataFromApi(id, referrerId!);
if (checkoutReponse.data!.transInfo.status == "success") {
if (checkoutReponse.data!.checkoutPageConfig.displaySuccessPage ==
true) {
final tranInfoSuccesss = checkoutReponse.data!.transInfo;
final billerInfoSuccess = checkoutReponse.data!.biller;
final checkConfage = checkoutReponse.data!.checkoutPageConfig;
if (UniversalPlatform.isWeb) {
Navigator.of(context).pop();
BottomsheetWeb.show(
context,
MainSuccessWebDialog(
darkMode: B24PaymentSdk.storeDarkMode!,
biller: billerInfoSuccess,
transInfo: tranInfoSuccesss));
} else {
Navigator.of(context).popUntil((route) => route.isFirst);
Navigator.of(context).push(
MaterialPageRoute(
builder: (contents) => ScreenSuccess(
biller: billerInfoSuccess,
transInfo: tranInfoSuccesss,
checkoutPageConfig: checkConfage,
),
),
);
}
} else {
if (UniversalPlatform.isWeb) {
final redirectUrl = checkoutReponse.data!.transInfo.redirectUrl;
if (redirectUrl.isNotEmpty) {
html.window.open(redirectUrl, '_self');
}
} else {
wasInBackground = false;
var redirectUrl = checkoutReponse.data!.transInfo.redirectUrl;
if (redirectUrl.startsWith('https')) {
if (await canLaunchUrl(Uri.parse(redirectUrl))) {
await launchUrl(Uri.parse(redirectUrl),
mode: LaunchMode.externalApplication);
} else {
debugPrint(
'Cannot launch URL externally either: $redirectUrl');
}
} else {
try {
GoRouter.of(context).go(redirectUrl);
if (await canLaunchUrl(Uri.parse(redirectUrl))) {
await launchUrl(Uri.parse(redirectUrl),
mode: LaunchMode.externalApplication);
} else {
GoRouter.of(context).go(redirectUrl);
}
} catch (e) {
await launchUrl(Uri.parse(redirectUrl),
mode: LaunchMode.externalApplication);
}
}
// try {
// GoRouter.of(context).go(redirectUrl);
// wasInBackground = false;
// } catch (e) {
// wasInBackground = false;
// // showMessagePopup(context,
// // bgColor: Color(0XFFFDEDEE),
// // iconColor: Color(0XFFEE4D61),
// // textColor: Color(0XFF131C18),
// // content: translation.getTranslation('merchSuccessNotFond'),
// // icons: Icons.info_rounded);
// }
}
}
}
}
});
}