Skip to content

Commit

Permalink
fix: Conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
chopper985 committed Jun 17, 2024
2 parents 3205ed6 + 6db47dd commit 777dcf1
Show file tree
Hide file tree
Showing 22 changed files with 370 additions and 209 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## 1.4.0

* Vendor: Upgrade WebRTC SDK to M125.6422
* Fix: transceiver setCodecPreferences

## 1.3.19

* Refactor: use PlatformView for iOS

## 1.3.18

* Fix(Hive): Open box before create getIt

## 1.3.17

* Upgrade flutter_webrtc to support GPUPixel on Android
* Fix socket connection

## 1.3.16

* Refactor: websocket connection
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ Flutter plugin of [Waterbus](https://docs.waterbus.tech). Build video call or on
<img src="https://github.com/waterbustech/waterbus-flutter-sdk/blob/migration/v2/.github/waterbus-sdk-banner.png?raw=true" width="100%"/>

<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-124.6367.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>
<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-125.6422.02-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>

## ⚡ Current supported features

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


🟢 = Available
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 @@ -34,9 +34,9 @@ class AuthLocalDataSourceImpl implements AuthLocalDataSource {

@override
String get accessToken =>
_hiveBox.get(StorageKeys.accessToken, defaultValue: null) ?? "";
_hiveBox.get(StorageKeys.accessToken, defaultValue: "");

@override
String get refreshToken =>
_hiveBox.get(StorageKeys.refreshToken, defaultValue: null) ?? "";
_hiveBox.get(StorageKeys.refreshToken, defaultValue: "");
}
6 changes: 2 additions & 4 deletions lib/core/api/base/base_local_storage.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import 'package:hive/hive.dart';
import 'package:injectable/injectable.dart';

import 'package:waterbus_sdk/constants/storage_keys.dart';
import 'package:waterbus_sdk/utils/path_helper.dart';

@Singleton()
class BaseLocalData {
Future<void> initialize() async {
static Future<void> initialize() async {
await PathHelper.createDirWaterbus();
final String? path = await PathHelper.localStoreDirWaterbus;
Hive.init(path);

await _openBoxApp();
}

Future<void> _openBoxApp() async {
static Future<void> _openBoxApp() async {
await Hive.openBox(StorageKeys.boxAuth);
}
}
22 changes: 11 additions & 11 deletions lib/core/api/base/dio_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import 'package:waterbus_sdk/core/api/base/base_remote_data.dart';
import 'package:waterbus_sdk/utils/extensions/duration_extensions.dart';
import 'package:waterbus_sdk/utils/queues/completer_queue.dart';

typedef TokensCallback = Function(
String accessToken,
String refreshToken,
);

@singleton
class DioConfiguration {
final BaseRemoteData _remoteData;
Expand Down Expand Up @@ -56,8 +61,9 @@ class DioConfiguration {
final String oldAccessToken =
response.requestOptions.headers['Authorization'];

final (String accessToken, String _) =
await onRefreshToken(oldAccessToken: oldAccessToken);
final (String accessToken, String _) = await onRefreshToken(
oldAccessToken: oldAccessToken.split(' ').last,
);

response.requestOptions.headers['Authorization'] =
'Bearer $accessToken';
Expand Down Expand Up @@ -88,12 +94,9 @@ class DioConfiguration {

Future<(String, String)> onRefreshToken({
String oldAccessToken = '',
Function(
String accessToken,
String refreshToken,
)? callback,
TokensCallback? callback,
}) async {
if (oldAccessToken != 'Bearer ${_authLocal.accessToken}') {
if (oldAccessToken != _authLocal.accessToken) {
return (_authLocal.accessToken, _authLocal.refreshToken);
}

Expand All @@ -116,10 +119,7 @@ class DioConfiguration {

// MARK: Private methods
Future<(String, String)> _performRefreshToken({
Function(
String accessToken,
String refreshToken,
)? callback,
TokensCallback? callback,
}) async {
if (_authLocal.refreshToken.isEmpty) {
if (_authLocal.accessToken.isNotEmpty) {
Expand Down
18 changes: 9 additions & 9 deletions lib/core/webrtc/webrtc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
stream: _displayStream!,
);

await _mParticipant?.setScreenSrcObject(_displayStream!);
await _mParticipant?.setSrcObject(_displayStream!, isDisplayStream: true);

_displayStream?.getVideoTracks().first.onEnded = () {
stopScreenSharing();
};

_mParticipant?.isSharingScreen = true;
_mParticipant?.setScreenSharing(true);

_notify(CallbackEvents.shouldBeUpdateState);
_socketEmiter.setScreenSharing(true);
Expand All @@ -99,7 +99,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
Future<void> stopScreenSharing({bool stayInRoom = true}) async {
if (!(_mParticipant?.isSharingScreen ?? true)) return;

_mParticipant?.isSharingScreen = false;
_mParticipant?.setScreenSharing(false);

if (_mParticipant == null) return;

Expand Down Expand Up @@ -132,7 +132,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
track.stop();
}

_mParticipant?.isSharingScreen = false;
_mParticipant?.setScreenSharing(false);
_displayStream?.dispose();
_displayStream = null;

Expand Down Expand Up @@ -216,7 +216,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
participant: _mParticipant!,
);

_nativeService.startCallKit(roomId);
_nativeService.startCallKit(roomId.roomCodeFormatted);
_stats.initialize();
_audioStats.initialize();
}
Expand Down Expand Up @@ -534,7 +534,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {

@override
void setScreenSharing({required String targetId, required bool isSharing}) {
_subscribers[targetId]?.isSharingScreen = isSharing;
_subscribers[targetId]?.setScreenSharing(isSharing);
_notify(CallbackEvents.shouldBeUpdateState);
}

Expand Down Expand Up @@ -590,7 +590,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
}) async {
final MediaStream? segmentedStream = await startVirtualBackground(
backgroundImage: backgroundImage,
textureId: _mParticipant?.renderer?.textureId.toString(),
textureId: _mParticipant?.cameraSource?.textureId.toString(),
);

if (segmentedStream == null) return;
Expand All @@ -614,7 +614,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
_mParticipant = ParticipantSFU(
ownerId: kIsMine,
peerConnection: peerConnection,
onChanged: () => _notify(CallbackEvents.shouldBeUpdateState),
onFirstFrameRendered: () => _notify(CallbackEvents.shouldBeUpdateState),
videoCodec: _callSetting.preferedCodec,
isE2eeEnabled: _callSetting.e2eeEnabled,
stats: _stats,
Expand Down Expand Up @@ -756,7 +756,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
_subscribers[targetId] = ParticipantSFU(
ownerId: targetId,
peerConnection: rtcPeerConnection,
onChanged: () => _notify(CallbackEvents.shouldBeUpdateState),
onFirstFrameRendered: () => _notify(CallbackEvents.shouldBeUpdateState),
isAudioEnabled: audioEnabled,
isVideoEnabled: videoEnabled,
isSharingScreen: isScreenSharing,
Expand Down
2 changes: 2 additions & 0 deletions lib/core/websocket/interfaces/socket_handler_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ abstract class SocketHandler {
void disconnection();

Socket? get socket;

bool get isConnected;
}
22 changes: 17 additions & 5 deletions lib/core/websocket/socket_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ class SocketHandlerImpl extends SocketHandler {
Socket? _socket;

@override
void establishConnection({bool forceConnection = false}) {
void establishConnection({
bool forceConnection = false,
String? forceAccessToken,
}) {
if (_authLocal.accessToken.isEmpty ||
(_socket != null && !forceConnection)) {
return;
}

final String mAccessToken = _authLocal.accessToken;
disconnection();

final String mAccessToken = forceAccessToken ?? _authLocal.accessToken;

_socket = io(
WaterbusSdk.wsUrl,
Expand All @@ -51,10 +56,14 @@ class SocketHandlerImpl extends SocketHandler {
_socket?.onError((data) async {
if (_authLocal.accessToken.isEmpty) return;

final (_, _) =
await _dioConfig.onRefreshToken(oldAccessToken: mAccessToken);
final (String newAccessToken, _) = await _dioConfig.onRefreshToken(
oldAccessToken: mAccessToken,
);

establishConnection();
establishConnection(
forceConnection: true,
forceAccessToken: newAccessToken,
);
});

_socket?.onConnect((_) async {
Expand Down Expand Up @@ -241,4 +250,7 @@ class SocketHandlerImpl extends SocketHandler {

@override
Socket? get socket => _socket;

@override
bool get isConnected => _socket != null && _socket!.connected;
}
7 changes: 5 additions & 2 deletions lib/flutter_waterbus_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:typed_data';

import 'package:flutter_webrtc_plus/flutter_webrtc_plus.dart';

import 'package:waterbus_sdk/core/api/base/base_local_storage.dart';
import 'package:waterbus_sdk/core/webrtc/webrtc_interface.dart';
import 'package:waterbus_sdk/injection/injection_container.dart';
import 'package:waterbus_sdk/types/index.dart';
Expand All @@ -23,7 +24,7 @@ class WaterbusSdk {
WaterbusSdk.onEventChanged = onEventChanged;
}

Future<void> initial({
Future<void> initializeApp({
required String wsUrl,
required String apiUrl,
}) async {
Expand All @@ -32,14 +33,16 @@ class WaterbusSdk {

// Init dependency injection if needed
if (!getIt.isRegistered<WaterbusWebRTCManager>()) {
await BaseLocalData.initialize();

configureDependencies();

if (WebRTC.platformIsIOS) {
_callKitListener.listenerEvents();
}
}

await _sdk.initialize();
await _sdk.initializeApp();
}

// Meeting
Expand Down
Loading

0 comments on commit 777dcf1

Please sign in to comment.