diff --git a/docs/adr/0056-web-socket-ping-strategy.md b/docs/adr/0056-web-socket-ping-strategy.md new file mode 100644 index 000000000..5c099d258 --- /dev/null +++ b/docs/adr/0056-web-socket-ping-strategy.md @@ -0,0 +1,24 @@ +# 56. Web Socket Ping Strategy + +Date: 2024-12-16 + +## Status + +Accepted + +## Context + +- Echo ping method takes too much resources from the server +- Server implemented ping frame + +## Decision + +- Twake Mail no longer have to implement Echo ping +- Browser will automatically send pong frame as default implementation +- Echo ping will still be left as an option in `env.file` through `WS_ECHO_PING` + - Set it to `true` if you want to use Echo ping + - Set it to `false` or left it as is if you don't want to use Echo ping + +## Consequences + +- Server resources used will be reduced diff --git a/docs/configuration/ws_echo_ping_configuration.md b/docs/configuration/ws_echo_ping_configuration.md new file mode 100644 index 000000000..1a5107877 --- /dev/null +++ b/docs/configuration/ws_echo_ping_configuration.md @@ -0,0 +1,12 @@ +## Configuration Web Socket Echo Ping + +### Context +- Echo ping method is optional +### How to config +In [env.file]: +- If you want to use Echo ping: +```WS_ECHO_PING=true``` +- If you don't want to use Echo ping: +```WS_ECHO_PING=false``` + or +```WS_ECHO_PING=``` \ No newline at end of file diff --git a/env.file b/env.file index f3ff169d6..a072f6896 100644 --- a/env.file +++ b/env.file @@ -6,4 +6,5 @@ APP_GRID_AVAILABLE=supported FCM_AVAILABLE=supported IOS_FCM=supported FORWARD_WARNING_MESSAGE= -PLATFORM=other \ No newline at end of file +PLATFORM=other +WS_ECHO_PING= \ No newline at end of file diff --git a/lib/features/push_notification/presentation/controller/web_socket_controller.dart b/lib/features/push_notification/presentation/controller/web_socket_controller.dart index a262e7508..f0dbeedc3 100644 --- a/lib/features/push_notification/presentation/controller/web_socket_controller.dart +++ b/lib/features/push_notification/presentation/controller/web_socket_controller.dart @@ -17,6 +17,7 @@ import 'package:tmail_ui_user/features/push_notification/presentation/extensions import 'package:tmail_ui_user/features/push_notification/presentation/listener/email_change_listener.dart'; import 'package:tmail_ui_user/features/push_notification/presentation/listener/mailbox_change_listener.dart'; import 'package:tmail_ui_user/main/routes/route_navigation.dart'; +import 'package:tmail_ui_user/main/utils/app_config.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; class WebSocketController extends PushBaseController { @@ -79,7 +80,9 @@ class WebSocketController extends PushBaseController { _retryRemained = 3; _webSocketChannel = success.webSocketChannel; _enableWebSocketPush(); - _pingWebSocket(); + if (AppConfig.isWebSocketEchoPingEnabled) { + _pingWebSocket(); + } _listenToWebSocket(); } diff --git a/lib/main/utils/app_config.dart b/lib/main/utils/app_config.dart index f749c7c46..9f165e945 100644 --- a/lib/main/utils/app_config.dart +++ b/lib/main/utils/app_config.dart @@ -68,4 +68,6 @@ class AppConfig { static String get _platformEnv => dotenv.get('PLATFORM', fallback: 'other'); static bool get isSaasPlatForm => _platformEnv.toLowerCase() == saasPlatform; + + static bool get isWebSocketEchoPingEnabled => dotenv.get('WS_ECHO_PING', fallback: 'false') == 'true'; } \ No newline at end of file