Skip to content

Commit

Permalink
update .
Browse files Browse the repository at this point in the history
  • Loading branch information
lambiengcode committed May 22, 2024
1 parent 1079133 commit 0ece6d9
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 181 deletions.
157 changes: 105 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,125 @@
> [!IMPORTANT]
> Waterbus is an open source video conferencing app built on latest WebRTC SDK. Currently, Waterbus is an early release that is subject to the following limitations: it may have limited support, changes may not be compatible with other pre-general availability versions, and availability may change without notice.
## Flutter [Waterbus](https://docs.waterbus.tech) SDK

# Flutter [Waterbus](https://docs.waterbus.tech) SDK
Flutter plugin of [Waterbus](https://docs.waterbus.tech). Build video call or online meeting application with SFU model. Supports iOS, Android. [ExampleApp](https://github.com/waterbustech/waterbus)

<img src="/.github/waterbus-sdk-banner.png" width="100%"/>
<img src="./.github/waterbus-sdk-banner.png" width="100%"/>

Flutter plugin of [Waterbus](https://docs.waterbus.tech). Build video call or online meeting application with SFU model. Supports iOS, Android. [ExampleApp](https://github.com/lambiengcode/waterbus)
<a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/License-Apache%202.0-green.svg"/></a>
<img src="https://img.shields.io/github/issues/waterbustech/waterbus-flutter-sdk" alt="GitHub issues"><a href="https://chromium.googlesource.com/external/webrtc/+/branch-heads/6099"><img src="https://img.shields.io/badge/libwebrtc-122.6261.01-yellow.svg" alt="libwebrtc"></a><img src="https://img.shields.io/cocoapods/v/KaiRTC" alt="Cocoapods Version"><a href="https://github.com/lambiengcode"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat&amp;logo=github" alt="PRs Welcome"></a>

## Codec supported
| Codec | VP8 | VP9 | H264 | H265 | AV1 |
| :-----: | :---------------: | :------------: | :------------: | :----------------: | :--------------------------------: |
| iOS | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 |
| Android | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 |
## ⚡ Current supported features

## Features
| Feature | Subscribe/Publish | Screen Sharing | Picture in Picture | Virtual Background | Beauty Filters | End to End Encryption |
| ------------------ | ----------------- | -------------- | ------------------ | ------------------ | -------------- | --------------------- |
| Android | 🟢 | 🟢 | 🟢 | 🟢 | 🟡 | 🟢 |
| iOS | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 |
| MacOS | 🟢 | 🟢 | 🔴 | 🟢 | 🟢 | 🟢 |
| Web | 🟢 | 🟢 | 🟢 | 🟢 | 🟡 | 🟢 |

- Join room

🟢 = Available

🟡 = Coming soon (Work in progress)

🔴 = Not currently available (Possibly in the future)

## Installation

### Add dependency

Add the dependency from command-line

```bash
$ flutter pub add waterbus_sdk
```

The command above will add this to the `pubspec.yaml` file in your project (you can do this manually):
```yaml
dependencies:
waterbus_sdk: ^1.3.13
```
## Usage
### Initialize
Firstly, call `WaterbusSdk.instance.initial` to set your server url and sdk connect WebSocket.

```dart
await WaterbusSdk.instance.joinRoom(
roomId: roomCode,
participantId: participantId,
onNewEvent: (event) {
switch (event.event) {
case CallbackEvents.shouldBeUpdateState:
// rebuild your ui
break;
case CallbackEvents.newParticipant:
final String? participantId = event.participantId;
if (participantId == null) return;
// add new participant to your ui
break;
case CallbackEvents.participantHasLeft:
final String? participantId = event.participantId;
if (participantId == null) return;
// remove participant to your ui
break;
default:
break;
}
},
);
await WaterbusSdk.instance.initial(
waterbusUrl: ApiEndpoints.wsUrl,
apiWaterbusUrl: ApiEndpoints.baseUrl,
recordBenchmarkPath: '',
);
```

- Leave room
### Create room

```dart
await WaterbusSdk.instance.leaveRoom();
final Meeting? meeting = await WaterbusSdk.instance.createRoom(
meeting: Meeting(title: 'Meeting with Kai Dao'),
password: 'password',
userId: 1, // <- modify to your user id
);
```

- Prepare Media (will prepare the camera and microphone for you to turn on and off before entering the meeting)
### Update room

```dart
await WaterbusSdk.instance.prepareMedia();
final Meeting? meeting = await WaterbusSdk.instance.updateRoom(
meeting: Meeting(title: 'Meeting with Kai Dao - 2'),
password: 'new-password',
userId: 1, // <- modify to your user id
);
```

## Getting started
### Join room

- Include this package to your pubspec.yaml
```dart
final Meeting? meeting = await WaterbusSdk.instance.joinRoom(
meeting: _currentMeeting,
password: 'room-password-here',
userId: 1, // <- modify to your user id
);
```

```yaml
waterbus_sdk:
git:
url: https://github.com/waterbustech/waterbus-flutter-sdk.git
path: '.'
ref: 0.0.1
### Set callback room events

```dart
void _onEventChanged(CallbackPayload event) {
switch (event.event) {
case CallbackEvents.shouldBeUpdateState:
break;
case CallbackEvents.newParticipant:
break;
case CallbackEvents.participantHasLeft:
break;
case CallbackEvents.meetingEnded:
break;
default:
break;
}
}
```

```dart
WaterbusSdk.instance.onEventChangedRegister = _onEventChanged;
```

### Leave room

```dart
await WaterbusSdk.instance.leaveRoom();
```

#### Prepare Media (will prepare the camera and microphone for you to turn on and off before entering the meeting)

```dart
await WaterbusSdk.instance.prepareMedia();
```

## Configuration

### Android

Ensure the following permission is present in your Android Manifest file, located in `<project root>/android/app/src/main/AndroidManifest.xml`:
Expand Down Expand Up @@ -139,9 +190,11 @@ Contributions are welcome! Please feel free to submit a pull request or open an

## Contact Information

If you have any questions or suggestions related to this application, please contact me via email: [email protected] or [email protected].
If you have any questions or suggestions related to this application, please contact me via email: [email protected].

## Reference

## Reference: [flutter_webrtc](https://github.com/flutter-webrtc/flutter-webrtc)
- [flutter_webrtc](https://github.com/flutter-webrtc/flutter-webrtc)

## License

Expand Down
4 changes: 2 additions & 2 deletions ios/Classes/WaterbusSdkPlugin.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Flutter
import UIKit
import flutter_callkit_incoming
import waterbus_callkit_incoming

public class WaterbusSdkPlugin: NSObject, FlutterPlugin {
var uuidCall: String = ""
Expand Down Expand Up @@ -28,7 +28,7 @@ public class WaterbusSdkPlugin: NSObject, FlutterPlugin {
info["handle"] = "0123456789"
info["type"] = 1

SwiftFlutterCallkitIncomingPlugin.sharedInstance?.startCall(flutter_callkit_incoming.Data(args: info), fromPushKit: true)
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.startCall(waterbus_callkit_incoming.Data(args: info), fromPushKit: true)
result(true)
break
case "getCurrentUuid":
Expand Down
2 changes: 1 addition & 1 deletion ios/waterbus_sdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.dependency 'flutter_callkit_incoming', '0.0.2'
s.dependency 'waterbus_callkit_incoming', '0.0.2'
s.platform = :ios, '11.0'

# Flutter.framework does not contain a i386 slice.
Expand Down
4 changes: 2 additions & 2 deletions lib/core/api/auth/datasources/auth_local_datasource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ abstract class AuthLocalDataSource {
required String? refreshToken,
});
void clearToken();
String? get accessToken;
String? get refreshToken;
String get accessToken;
String get refreshToken;
}

@LazySingleton(as: AuthLocalDataSource)
Expand Down
12 changes: 8 additions & 4 deletions lib/core/api/base/base_remote_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import 'package:waterbus_sdk/utils/extensions/duration_extensions.dart';

@Singleton()
class BaseRemoteData {
final AuthLocalDataSource _authLocal;

BaseRemoteData(this._authLocal);

Dio dio = Dio(
BaseOptions(
baseUrl: WaterbusSdk.apiWaterbusUrl,
Expand Down Expand Up @@ -215,14 +219,14 @@ class BaseRemoteData {
return Options(
validateStatus: (status) {
if (status == StatusCode.notAcceptable &&
AuthLocalDataSourceImpl().accessToken.isNotEmpty) {
AuthLocalDataSourceImpl().clearToken();
_authLocal.accessToken.isNotEmpty) {
_authLocal.clearToken();
}

return true;
},
headers: {
'Authorization': 'Bearer ${AuthLocalDataSourceImpl().refreshToken}',
'Authorization': 'Bearer ${_authLocal.refreshToken}',
'api_key': 'waterbus@2024',
'Content-Type': 'application/json; charset=UTF-8',
'Connection': 'keep-alive',
Expand All @@ -243,7 +247,7 @@ class BaseRemoteData {

getHeaders() {
return {
'Authorization': 'Bearer ${AuthLocalDataSourceImpl().accessToken}',
'Authorization': 'Bearer ${_authLocal.accessToken}',
'api_key': 'waterbus@2024',
'Content-Type': 'application/json; charset=UTF-8',
'Connection': 'keep-alive',
Expand Down
8 changes: 4 additions & 4 deletions lib/core/api/base/dio_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import 'package:waterbus_sdk/utils/queues/completer_queue.dart';
@singleton
class DioConfiguration {
final BaseRemoteData _remoteData;
final AuthLocalDataSource _localDataSource;
final AuthLocalDataSource _authLocal;

DioConfiguration(this._remoteData, this._localDataSource);
DioConfiguration(this._remoteData, this._authLocal);

bool _isRefreshing = false;
final CompleterQueue<(String, String)> _refreshTokenCompleters =
Expand Down Expand Up @@ -51,8 +51,8 @@ class DioConfiguration {
if (isRefreshingToken) {
handler.next(response);
_logOut();
} else if (_localDataSource.refreshToken != null &&
_localDataSource.accessToken != null) {
} else if (_authLocal.refreshToken.isNotEmpty &&
_authLocal.accessToken.isNotEmpty) {
try {
final String oldAccessToken =
response.requestOptions.headers['Authorization'];
Expand Down
5 changes: 1 addition & 4 deletions lib/core/websocket/interfaces/socket_handler_interface.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import 'package:socket_io_client/socket_io_client.dart';

abstract class SocketHandler {
void establishConnection({
required String accessToken,
bool forceConnection = false,
});
void establishConnection({bool forceConnection = false});
void disconnection();

Socket? get socket;
Expand Down
12 changes: 6 additions & 6 deletions lib/core/websocket/socket_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:injectable/injectable.dart';
import 'package:socket_io_client/socket_io_client.dart';

import 'package:waterbus_sdk/constants/socket_events.dart';
import 'package:waterbus_sdk/core/api/auth/datasources/auth_local_datasource.dart';
import 'package:waterbus_sdk/core/webrtc/webrtc_interface.dart';
import 'package:waterbus_sdk/core/websocket/interfaces/socket_handler_interface.dart';
import 'package:waterbus_sdk/flutter_waterbus_sdk.dart';
Expand All @@ -13,18 +14,17 @@ import 'package:waterbus_sdk/utils/logger/logger.dart';
class SocketHandlerImpl extends SocketHandler {
final WaterbusWebRTCManager _rtcManager;
final WaterbusLogger _logger;
final AuthLocalDataSource _authLocal;
SocketHandlerImpl(
this._rtcManager,
this._logger,
this._authLocal,
);

Socket? _socket;

@override
void establishConnection({
required String accessToken,
bool forceConnection = false,
}) {
void establishConnection({bool forceConnection = false}) {
if (_socket != null && !forceConnection) return;

_socket = io(
Expand All @@ -34,14 +34,14 @@ class SocketHandlerImpl extends SocketHandler {
.enableReconnection()
.enableForceNew()
.setExtraHeaders({
'Authorization': 'Bearer $accessToken',
'Authorization': 'Bearer ${_authLocal.accessToken}',
}).build(),
);

_socket?.connect();

_socket?.onError((data) async {
establishConnection(accessToken: accessToken);
establishConnection();
});

_socket?.onConnect((_) async {
Expand Down
4 changes: 1 addition & 3 deletions lib/flutter_waterbus_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ class WaterbusSdk {
await _baseRemoteData.initialize();

_socketHandler.disconnection();
_socketHandler.establishConnection(
accessToken: AuthLocalDataSourceImpl().accessToken,
);
_socketHandler.establishConnection();

_sdk.initialize();
}
Expand Down
Loading

0 comments on commit 0ece6d9

Please sign in to comment.