Skip to content

Commit 4147181

Browse files
tddang-linagorahoangdat
authored andcommitted
TF-3336 Make Echo ping of web socket optional
1 parent 809284d commit 4147181

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# 56. Web Socket Ping Strategy
2+
3+
Date: 2024-12-16
4+
5+
## Status
6+
7+
Accepted
8+
9+
## Context
10+
11+
- Echo ping method takes too much resources from the server
12+
- Server implemented ping frame
13+
14+
## Decision
15+
16+
- Twake Mail no longer have to implement Echo ping
17+
- Browser will automatically send pong frame as default implementation
18+
- Echo ping will still be left as an option in `env.file` through `WS_ECHO_PING`
19+
- Set it to `true` if you want to use Echo ping
20+
- Set it to `false` or left it as is if you don't want to use Echo ping
21+
22+
## Consequences
23+
24+
- Server resources used will be reduced
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Configuration Web Socket Echo Ping
2+
3+
### Context
4+
- Echo ping method is optional
5+
### How to config
6+
In [env.file]:
7+
- If you want to use Echo ping:
8+
```WS_ECHO_PING=true```
9+
- If you don't want to use Echo ping:
10+
```WS_ECHO_PING=false```
11+
or
12+
```WS_ECHO_PING=```

env.file

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ APP_GRID_AVAILABLE=supported
66
FCM_AVAILABLE=supported
77
IOS_FCM=supported
88
FORWARD_WARNING_MESSAGE=
9-
PLATFORM=other
9+
PLATFORM=other
10+
WS_ECHO_PING=

lib/features/push_notification/presentation/controller/web_socket_controller.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:tmail_ui_user/features/push_notification/presentation/extensions
1717
import 'package:tmail_ui_user/features/push_notification/presentation/listener/email_change_listener.dart';
1818
import 'package:tmail_ui_user/features/push_notification/presentation/listener/mailbox_change_listener.dart';
1919
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
20+
import 'package:tmail_ui_user/main/utils/app_config.dart';
2021
import 'package:web_socket_channel/web_socket_channel.dart';
2122

2223
class WebSocketController extends PushBaseController {
@@ -79,7 +80,9 @@ class WebSocketController extends PushBaseController {
7980
_retryRemained = 3;
8081
_webSocketChannel = success.webSocketChannel;
8182
_enableWebSocketPush();
82-
_pingWebSocket();
83+
if (AppConfig.isWebSocketEchoPingEnabled) {
84+
_pingWebSocket();
85+
}
8386
_listenToWebSocket();
8487
}
8588

lib/main/utils/app_config.dart

+2
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,6 @@ class AppConfig {
6868
static String get _platformEnv => dotenv.get('PLATFORM', fallback: 'other');
6969

7070
static bool get isSaasPlatForm => _platformEnv.toLowerCase() == saasPlatform;
71+
72+
static bool get isWebSocketEchoPingEnabled => dotenv.get('WS_ECHO_PING', fallback: 'false') == 'true';
7173
}

0 commit comments

Comments
 (0)