-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/remove-deprecated-background-package
- Loading branch information
Showing
20 changed files
with
323 additions
and
41 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
docusaurus/docs/Flutter/03-core-concepts/12-participants-sorting.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
slug: /participant-sorting | ||
title: Participant | ||
title: Participant Sorting | ||
sidebar_position: 9 | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
id: screen_sharing | ||
sidebar_position: 3 | ||
sidebar_position: 4 | ||
title: Screen Sharing | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
id: picture_in_picture | ||
sidebar_position: 4 | ||
sidebar_position: 5 | ||
title: Picture in Picture (PiP) | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
title: Custom Data | ||
slug: /custom-data | ||
sidebar_position: 9 | ||
description: Learn how to add and read custom data in the Stream Video Flutter SDK. | ||
--- | ||
|
||
Custom data is additional information that can be added to the default data of Stream. It is a dictionary of key-value pairs that can be attached to users, events, and pretty much almost every domain model in the Stream SDK. | ||
|
||
In the SDK, custom data is represented by the `Map<String, Object>`. This means that the key must be a string and the value can be any object. | ||
|
||
## Adding Custom Data | ||
|
||
Adding extra data can be done through the Server-Side SDKs or through the Client SDKs. In the Flutter Stream Video SDK, you can add extra data when creating/updating a call, updating a user and sending event or reaction. | ||
|
||
###### Example of updating the call custom data | ||
|
||
```dart | ||
call.update(custom: {'mycustomfield': 'mycustomvalue'}); | ||
``` | ||
|
||
###### Example of sending a reaction with custom data | ||
|
||
```dart | ||
call.sendReaction( | ||
reactionType: 'raise-hand', | ||
emojiCode: ':smile:', | ||
custom: {'mycustomfield': 'mycustomvalue'}, | ||
); | ||
``` | ||
|
||
###### Example of sending a custom event with custom data | ||
|
||
```dart | ||
call.sendCustomEvent( | ||
eventType: 'my-custom-event', | ||
custom: {'mycustomfield': 'mycustomvalue'}, | ||
); | ||
``` | ||
|
||
###### Example of updating the user custom data while initializing the StreamVideo | ||
|
||
```dart | ||
StreamVideo( | ||
apiKey, | ||
user: User.regular(userId: 'userId', extraData: {'mycustomfield': 'mycustomvalue'}), | ||
userToken: token, | ||
); | ||
``` | ||
|
||
## Reading Custom Data | ||
| ||
Reading the custom data is as simple as accessing the `custom` field of the object. For example, to read the custom data of a reaction, you can access the `custom` field of the reaction event object. | ||
|
||
```dart | ||
call.callEvents.listen((event) { | ||
if (event is StreamCallReactionEvent) { | ||
final customData = event.custom; | ||
} | ||
}); | ||
``` | ||
|
||
For `Call` object the custom data is stored in call metadata that can be accessed when calling `getOrCreate()` or `get()` method. | ||
|
||
```dart | ||
final result = await call.getOrCreate(); | ||
final customData = result.fold( | ||
success: (success) => success.data.data.metadata.details.custom, | ||
failure: (_) => null, | ||
); | ||
//or | ||
final result = await call.get(); | ||
final customData = result.fold( | ||
success: (success) => success.data.metadata.details.custom, | ||
failure: (_) => null, | ||
); | ||
``` |
163 changes: 163 additions & 0 deletions
163
docusaurus/docs/Flutter/05-advanced/09-push-notifications.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
--- | ||
title: Push Notifications | ||
slug: /push-notifications | ||
sidebar_position: 3 | ||
description: Learn how to enable push notifications in the Stream Video Flutter SDK. | ||
--- | ||
|
||
Apart from the VoIP notifications for call ringing features, Stream Video Flutter SDK also supports standard push notifications. This guide will show you how to enable push notifications in your Flutter app using the Stream Video SDK. | ||
|
||
Push notifications are sent in the following scenarios: | ||
- you create a call with the `ring` value set to true. In this case, a notification that shows a ringing screen is sent. (covered in the [ringing documentation](https://getstream.io/video/docs/flutter/advanced/ringing_and_callkit/)) | ||
- you create a call with the `notify` value set to true. In this case, a regular push notification is sent. | ||
- you haven't answered a call. In this case, a missed call notification is sent (regular push notification). | ||
|
||
## Android and Firebase Cloud Messaging (FCM) | ||
|
||
For FCM the steps taken in [ringing documentation](https://getstream.io/video/docs/flutter/advanced/ringing_and_callkit/) are enough and will also handle standard push notifications. | ||
|
||
In case of missed call the notification will be shown using [flutter_callkit_incoming](https://pub.dev/packages/flutter_callkit_incoming) package. It can be configured by `pushParams` when initializing `StreamVideo`: | ||
|
||
```dart | ||
StreamVideo( | ||
apiKey, | ||
user: user, | ||
pushNotificationManagerProvider: StreamVideoPushNotificationManager.create( | ||
iosPushProvider: const StreamVideoPushProvider.apn( | ||
name: 'apn', | ||
), | ||
androidPushProvider: const StreamVideoPushProvider.firebase( | ||
name: 'firebase', | ||
), | ||
pushParams: const StreamVideoPushParams( | ||
appName: kAppName, | ||
ios: IOSParams(iconName: 'IconMask'), | ||
missedCallNotification: NotificationParams( | ||
showNotification: true, | ||
subtitle: 'Missed Call', | ||
callbackText: 'Call Back', | ||
) | ||
), | ||
), | ||
); | ||
``` | ||
|
||
If you want to handle missed call notification differently or handle the notification about incoming call (when `notify` is set to true) use the existing `_handleRemoteMessage()` method (see [ringing documentation](https://getstream.io/video/docs/flutter/advanced/ringing_and_callkit/)): | ||
|
||
```dart | ||
Future<bool> _handleRemoteMessage(RemoteMessage message) async { | ||
final payload = message.data; | ||
final sender = payload['sender'] as String?; | ||
final type = payload['type'] as String?; | ||
if (sender == 'stream.video' && type == 'call.notification') { | ||
final callCid = payload['call_cid'] as String?; | ||
// Show notification, for example using `flutter_local_notifications` package | ||
} | ||
final streamVideo = locator.get<StreamVideo>(); | ||
return streamVideo.handleVoipPushNotification( | ||
message.data, | ||
handleMissedCall: false, //<-- Add this flag if you dont want a default missed call notification handling | ||
); | ||
} | ||
``` | ||
|
||
## iOS and Apple Push Notification Service (APNs) | ||
|
||
For APNs the standard push notifications have to be handled separately of VoIP notifications. When APN push provider is registered for iOS, both VoIP and standard push notifications are send using APN by Stream Video SDK. | ||
|
||
### Registering APN device token | ||
|
||
First you need to register APN device token as it is separate from the VoIP token (registered out-of-the-box by the Stream Video SDK). To do this just set `registerApnDeviceToken` to true when initializing `StreamVideo` instance: | ||
|
||
```dart | ||
StreamVideo( | ||
apiKey, | ||
user: user, | ||
pushNotificationManagerProvider: StreamVideoPushNotificationManager.create( | ||
iosPushProvider: const StreamVideoPushProvider.apn( | ||
name: 'flutter-apn', | ||
), | ||
androidPushProvider: const StreamVideoPushProvider.firebase( | ||
name: 'flutter-firebase', | ||
), | ||
pushParams: const StreamVideoPushParams( | ||
appName: kAppName, | ||
ios: StreamIOSParams(iconName: 'IconMask'), | ||
), | ||
registerApnDeviceToken: true, // <--- Add this line | ||
), | ||
); | ||
``` | ||
|
||
### Handling standard push notifications | ||
|
||
Next, you need to handle the push notifications in your app. | ||
|
||
To do this, you need to add the following code to your `AppDelegate.swift` file: | ||
|
||
```swift | ||
@objc class AppDelegate: FlutterAppDelegate { | ||
override func application( | ||
_ application: UIApplication, | ||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? | ||
) -> Bool { | ||
GeneratedPluginRegistrant.register(with: self) | ||
|
||
// Register for push notifications. | ||
StreamVideoPKDelegateManager.shared.registerForPushNotifications() // <--- Add will only handle VoIP notifications | ||
UNUserNotificationCenter.current().delegate = self // <--- Add this line to handle standard push notifications | ||
|
||
return super.application(application, didFinishLaunchingWithOptions: launchOptions) | ||
} | ||
|
||
// This method will be called when notification is received | ||
override func userNotificationCenter(_ center: UNUserNotificationCenter, | ||
willPresent notification: UNNotification, | ||
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { | ||
let streamDict = notification.request.content.userInfo["stream"] as? [String: Any] | ||
if(streamDict?["sender"] as? String != "stream.video") { | ||
return completionHandler([]) | ||
} | ||
|
||
if #available(iOS 14.0, *) { | ||
completionHandler([.list, .banner, .sound]) | ||
} else { | ||
completionHandler([.alert]) | ||
} | ||
} | ||
} | ||
``` | ||
|
||
If you want to handle the notification tap event, for example to navigate to the call screen when you `notify` about it, you can add the following code to your `AppDelegate.swift` file: | ||
|
||
```swift | ||
// This method will be called when notification is tapped | ||
override func userNotificationCenter(_ center: UNUserNotificationCenter, | ||
didReceive response: UNNotificationResponse, | ||
withCompletionHandler completionHandler: @escaping () -> Void) { | ||
|
||
let streamDict = response.notification.request.content.userInfo["stream"] as? [String: Any] | ||
if(streamDict?["sender"] as? String != "stream.video") { | ||
return; | ||
} | ||
|
||
if(streamDict?["type"] as? String == "call.notification") { | ||
let callCid = streamDict?["call_cid"] as? String | ||
print("Call notification received with call cid: \(callCid)") | ||
//Navigate to call, for example implementing method channel | ||
} | ||
|
||
completionHandler() | ||
} | ||
``` | ||
|
||
### Push notification permission | ||
|
||
Remember, that in order to receive push notifications, you need to ask the user for relevant permission. One way of doing it is using [permission_handler](https://pub.dev/packages/permission_handler) plugin. | ||
|
||
```dart | ||
Permission.notification.request(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.