Skip to content

Commit

Permalink
fix: implement pings for websocket on browser (#103)
Browse files Browse the repository at this point in the history
* fix: implement pings for websocket on browser

* chore: update CHANGELOG.md

* chore: revert pubspec.lock

* ci: attempt to fix doc

* ci: remove doc dead link check

* chore: upgrade dependencies

* chore: remove pubspec.lock
  • Loading branch information
Kuruyia authored Jan 22, 2024
1 parent 056a310 commit 2400c5f
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 444 deletions.
4 changes: 2 additions & 2 deletions .github/actions/dart-doc/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Generate DartDoc
description: Dart Documentation Generation
runs:
using: "composite"
steps:
steps:
- name: Run DartDoc
run: |
./docker_launch.sh
dartdoc
dart doc
shell: bash
44 changes: 22 additions & 22 deletions .github/workflows/pull_request.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,28 @@ jobs:
- uses: dart-lang/setup-dart@v1
- uses: ./.github/actions/unit-tests

doc-dead-links:
name: Check dead-links
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Extract references from context
shell: bash
id: extract-refs
run: |
echo "::set-output name=version::$(git describe --abbrev=0 --tags | cut -d. -f 1)"
echo "::set-output name=repo::$(echo $GITHUB_REPOSITORY | cut -d/ -f 2)"
echo "::set-output name=fw-branch::$(if [ $BASE_BRANCH == master ]; then echo master; else echo develop; fi)"
- uses: convictional/[email protected]
with:
owner: kuzzleio
repo: documentation
github_token: ${{ secrets.ACCESS_TOKEN_CI }}
workflow_file_name: dead_links.workflow.yml
ref: ${{ steps.extract-refs.outputs.fw-branch }}
inputs: '{"repo_name": "${{ steps.extract-refs.outputs.repo }}", "branch": "${{ github.head_ref }}", "version": "${{ steps.extract-refs.outputs.version }}"}'
# doc-dead-links:
# name: Check dead-links
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# with:
# fetch-depth: 0
# - name: Extract references from context
# shell: bash
# id: extract-refs
# run: |
# echo "::set-output name=version::$(git describe --abbrev=0 --tags | cut -d. -f 1)"
# echo "::set-output name=repo::$(echo $GITHUB_REPOSITORY | cut -d/ -f 2)"
# echo "::set-output name=fw-branch::$(if [ $BASE_BRANCH == master ]; then echo master; else echo develop; fi)"
# - uses: convictional/[email protected]
# with:
# owner: kuzzleio
# repo: documentation
# github_token: ${{ secrets.ACCESS_TOKEN_CI }}
# workflow_file_name: dead_links.workflow.yml
# ref: ${{ steps.extract-refs.outputs.fw-branch }}
# inputs: '{"repo_name": "${{ steps.extract-refs.outputs.repo }}", "branch": "${{ github.head_ref }}", "version": "${{ steps.extract-refs.outputs.version }}"}'

dart-doc:
name: Generate DartDoc
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ coverage

doc/framework
.ci/doc/project/*.dart
.vuepress
.vuepress
pubspec.lock
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [3.0.3]

- Bug fix: Implement periodic pings for the websocket protocol in browser environments.

## [3.0.2]

- Bug fix: Use proper HTTP method with query in the HTTP protocol connection
Expand Down
2 changes: 1 addition & 1 deletion docker_launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ sysctl -w vm.max_map_count=262144
docker-compose up -d
until curl "http://localhost:7512/?pretty"; do sleep 10; done
./adminauth.sh
pub get
dart pub get
2 changes: 1 addition & 1 deletion lib/src/protocols/websocket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class WebSocketProtocol extends KuzzleWebSocket {
bool autoReconnect = true,
Duration reconnectionDelay = const Duration(seconds: 1),
int reconnectionAttempts = 10,
Duration? pingInterval,
Duration pingInterval = const Duration(seconds: 2),
}) : super(
uri,
autoReconnect: autoReconnect,
Expand Down
14 changes: 12 additions & 2 deletions lib/src/protocols/websocket_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ class KuzzleWebSocket extends KuzzleProtocol {
bool autoReconnect = true,
Duration reconnectionDelay = const Duration(seconds: 1),
int reconnectionAttempts = 10,
this.pingInterval,
required this.pingInterval,
}) : super(uri,
autoReconnect: autoReconnect,
reconnectionDelay: reconnectionDelay,
reconnectionAttempts: reconnectionAttempts);

WebSocket? _webSocket;
StreamSubscription? _subscription;
Duration? pingInterval;
Duration pingInterval;
Timer? pingTimer;

@override
Future<void> protocolConnect() async {
Expand All @@ -42,6 +43,15 @@ class KuzzleWebSocket extends KuzzleProtocol {

_subscription = _webSocket!.onMessage.listen(_handlePayload);

pingTimer?.cancel();
pingTimer = Timer.periodic(pingInterval, (timer) {
if (_webSocket != null && _webSocket!.readyState == WebSocket.OPEN) {
_webSocket!.sendString('{"p":1}');
} else {
timer.cancel();
}
});

final onErrorSubscription =
_webSocket!.onError.listen(_connected.completeError);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/protocols/websocket_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class KuzzleWebSocket extends KuzzleProtocol {
bool autoReconnect = true,
Duration reconnectionDelay = const Duration(seconds: 1),
int reconnectionAttempts = 10,
this.pingInterval,
required this.pingInterval,
}) : super(uri,
autoReconnect: autoReconnect,
reconnectionDelay: reconnectionDelay,
reconnectionAttempts: reconnectionAttempts);

WebSocket? _webSocket;
StreamSubscription? _subscription;
Duration? pingInterval;
Duration pingInterval;

@override
Future<void> protocolConnect() async {
Expand Down
Loading

0 comments on commit 2400c5f

Please sign in to comment.