Skip to content

Commit

Permalink
Merge branch 'main' into chore/openAPI-regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
Brazol authored Oct 24, 2024
2 parents 927ff7f + 84ff74f commit c2f4521
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 14 deletions.
32 changes: 31 additions & 1 deletion docusaurus/docs/Flutter/03-core-concepts/01-authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ StreamVideo(
);
```

### Anonymous / Guest users
### Guest / Anonymous users

For use-cases like live streaming or guest meeting, you may want to allow users to join a call without creating an account.

#### Guest Users

For these use-cases, the SDK has a guest endpoint which can be used to create a temporary user

```dart
Expand All @@ -142,3 +144,31 @@ final userInfo = client.currentUser;
Please use the generated ID across your app.
:::

#### Anonymous Users

```dart
final anonymous = User.anonymous();
final client = StreamVideo(
apiKey,
user: anonymous,
);
```

Anonymous users don't establish an active web socket connection, therefore they won't receive any events. They are just able to watch a livestream or join a call.

The token for an anonymous user should contain the `call_cids` field, which is an array of the call `cid`'s that the user is allowed to join.

Here's an example JWT token payload for an anonymous user:

```swift
{
"iss": "@stream-io/dashboard",
"iat": 1726406693,
"exp": 1726493093,
"user_id": "!anon",
"role": "viewer",
"call_cids": [
"livestream:123"
]
}
```
7 changes: 7 additions & 0 deletions docusaurus/docs/Flutter/05-advanced/02-ringing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ When creating a `StreamVideo` instance, you need to pass a `pushNotificationMana
```dart
StreamVideo(
// ...
options: const StreamVideoOptions(
// It's important to keep connections alive when the app is in the background to properly handle incoming calls while the app is in the background
keepConnectionsAliveWhenInBackground: true,
),
// Make sure you initialise push notification manager
pushNotificationManagerProvider: StreamVideoPushNotificationManager.create(
iosPushProvider: const StreamVideoPushProvider.apn(
Expand Down Expand Up @@ -297,6 +301,9 @@ void initState() {
}
void _tryConsumingIncomingCallFromTerminatedState() {
// This is only relevant for Android.
if (CurrentPlatform.isIos) return;
if (_navigatorKey.currentContext == null) {
// App is not running yet. Postpone consuming after app is in the foreground
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
Expand Down
2 changes: 2 additions & 0 deletions dogfooding/lib/app/app_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class _StreamDogFoodingAppContentState
}

void _tryConsumingIncomingCallFromTerminatedState() {
if (CurrentPlatform.isIos) return;

if (_router.routerDelegate.navigatorKey.currentContext == null) {
// App is not running yet. Postpone consuming after app is in the foreground
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
Expand Down
2 changes: 2 additions & 0 deletions dogfooding/lib/di/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Future<void> _backgroundVoipCallHandler() async {
logPriority: Priority.verbose,
muteAudioWhenInBackground: true,
muteVideoWhenInBackground: true,
keepConnectionsAliveWhenInBackground: true,
),
pushNotificationManagerProvider: StreamVideoPushNotificationManager.create(
iosPushProvider: const StreamVideoPushProvider.apn(
Expand Down Expand Up @@ -195,6 +196,7 @@ StreamVideo _initStreamVideo(
logPriority: Priority.verbose,
muteAudioWhenInBackground: true,
muteVideoWhenInBackground: true,
keepConnectionsAliveWhenInBackground: true,
),
pushNotificationManagerProvider: StreamVideoPushNotificationManager.create(
iosPushProvider: const StreamVideoPushProvider.apn(
Expand Down
8 changes: 4 additions & 4 deletions dogfooding/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ dependencies:
cupertino_icons: ^1.0.8
device_info_plus: ^10.1.2
envied: ^0.5.4+1
firebase_auth: ^5.2.1
firebase_core: ^3.4.1
firebase_crashlytics: ^4.1.1
firebase_messaging: ^15.1.1
firebase_auth: ^5.3.1
firebase_core: ^3.6.0
firebase_crashlytics: ^4.1.3
firebase_messaging: ^15.1.3
fl_chart: ^0.69.0
flutter:
sdk: flutter
Expand Down
7 changes: 6 additions & 1 deletion packages/stream_video/lib/src/stream_video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class StreamVideo extends Disposable {
/// Connects the user to the Stream Video service.
Future<Result<UserToken>> connect({
bool includeUserDetails = true,
bool registerPushDevice = true,
}) async {
if (currentUserType == UserType.anonymous) {
_logger.w(() => '[connect] rejected (anonymous user)');
Expand All @@ -271,6 +272,7 @@ class StreamVideo extends Disposable {
}
_connectOperation ??= _connect(
includeUserDetails: includeUserDetails,
registerPushDevice: registerPushDevice,
).asCancelable();
return _connectOperation!
.valueOrDefault(Result.error('connect was cancelled'))
Expand All @@ -293,6 +295,7 @@ class StreamVideo extends Disposable {

Future<Result<UserToken>> _connect({
bool includeUserDetails = false,
bool registerPushDevice = true,
}) async {
_logger.i(() => '[connect] currentUser.id: ${_state.currentUser.id}');
if (_connectionState.isConnected) {
Expand Down Expand Up @@ -339,7 +342,9 @@ class StreamVideo extends Disposable {
_subscriptions.add(_idAppState, lifecycle.appState.listen(_onAppState));

// Register device with push notification manager.
pushNotificationManager?.registerDevice();
if (registerPushDevice) {
pushNotificationManager?.registerDevice();
}

if (pushNotificationManager != null) {
_subscriptions.add(
Expand Down
11 changes: 11 additions & 0 deletions packages/stream_video_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## Unreleased

🔄 Dependency updates
* Updated firebase dependencies to fix Xcode 16 build issues

✅ Added
* Added `registerPushDevice` optional parameter (default as true) to `StreamVideo.connect()` method that can prevent automatic push token registration.

🐞 Fixed
* Automatic push token registration done by `StreamVideo` now stores registered token in `SharedPreferences` and will now only perform API call when token changes.

## 0.5.5

🐞 Fixed
Expand Down
4 changes: 2 additions & 2 deletions packages/stream_video_flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ dependencies:
cupertino_icons: ^1.0.5
device_info_plus: ^10.1.2
envied: ^0.3.0+3
firebase_core: ^3.4.0
firebase_messaging: ^15.1.1
firebase_core: ^3.6.0
firebase_messaging: ^15.1.3
flutter:
sdk: flutter
flutter_local_notifications: ^17.1.2
Expand Down
5 changes: 5 additions & 0 deletions packages/stream_video_push_notification/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased

🔄 Dependency updates
* Updated firebase dependencies to fix Xcode 16 build issues

## 0.5.5
* Sync version with `stream_video_flutter` 0.5.5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter_callkit_incoming/entities/entities.dart';
import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart';
import 'package:rxdart/rxdart.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:stream_video/stream_video.dart' hide CallEvent;
import 'package:stream_video_push_notification/stream_video_push_notification_platform_interface.dart';

Expand All @@ -20,6 +21,9 @@ const _idCallRejected = 6;

/// Implementation of [PushNotificationManager] for Stream Video.
class StreamVideoPushNotificationManager implements PushNotificationManager {
static const userDeviceTokenKey = 'io.getstream.userDeviceToken';
static const userDeviceTokenVoIPKey = 'io.getstream.userDeviceTokenVoIP';

/// Factory for creating a new instance of [StreamVideoPushNotificationManager].
/// /// Parameters:
/// * [callerCustomizationCallback] callback providing customized caller data used for call screen and CallKit call. (for iOS this will only work for foreground calls)
Expand Down Expand Up @@ -67,6 +71,8 @@ class StreamVideoPushNotificationManager implements PushNotificationManager {
}) : _client = client {
if (CurrentPlatform.isWeb) return;

SharedPreferences.getInstance().then((prefs) => _sharedPreferences = prefs);

subscribeToEvents() {
_subscriptions.add(
_idCallEnded,
Expand Down Expand Up @@ -155,6 +161,7 @@ class StreamVideoPushNotificationManager implements PushNotificationManager {
final StreamVideoPushParams pushParams;
final CallerCustomizationFunction? callerCustomizationCallback;
final bool registerApnDeviceToken;
late SharedPreferences _sharedPreferences;

final _logger = taggedLogger(tag: 'SV:PNManager');
bool? _wasWsConnected;
Expand All @@ -174,13 +181,24 @@ class StreamVideoPushNotificationManager implements PushNotificationManager {
return;
}

void registerDevice(String token, bool isVoIP) {
_client.createDevice(
void registerDevice(String token, bool isVoIP) async {
final tokenKey = isVoIP ? userDeviceTokenVoIPKey : userDeviceTokenKey;

final storedToken = _sharedPreferences.getString(tokenKey);
if (storedToken == token) return;

_client
.createDevice(
id: token,
voipToken: isVoIP,
pushProvider: pushProvider.type,
pushProviderName: pushProvider.name,
);
)
.then((result) {
if (result is Success) {
_sharedPreferences.setString(tokenKey, token);
}
});
}

if (CurrentPlatform.isIos && registerApnDeviceToken) {
Expand All @@ -197,6 +215,11 @@ class StreamVideoPushNotificationManager implements PushNotificationManager {
.listen((token) => registerDevice(token, true)));
}

Future<void> removedStoredTokens() async {
await _sharedPreferences.remove(userDeviceTokenKey);
await _sharedPreferences.remove(userDeviceTokenVoIPKey);
}

@override
void unregisterDevice() async {
final token = await getDevicePushTokenVoIP();
Expand All @@ -209,6 +232,8 @@ class StreamVideoPushNotificationManager implements PushNotificationManager {
if (apnToken != null) {
_client.deleteDevice(id: apnToken);
}

removedStoredTokens();
}

@override
Expand Down
7 changes: 4 additions & 3 deletions packages/stream_video_push_notification/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ environment:

dependencies:
collection: ^1.17.1
firebase_core: ^3.4.0
firebase_messaging: ^15.1.1
firebase_core: ^3.6.0
firebase_messaging: ^15.1.3
flutter:
sdk: flutter
flutter_webrtc: ^0.11.7
Expand All @@ -24,7 +24,8 @@ dependencies:
rxdart: ^0.28.0
stream_video: ^0.5.5
uuid: ^4.2.1

shared_preferences: ^2.3.2

dev_dependencies:
build_runner: ^2.4.4
flutter_lints: ^2.0.2
Expand Down

0 comments on commit c2f4521

Please sign in to comment.