Skip to content

Commit 2e2b86d

Browse files
authored
FVS-84: update docs (except sample apps) (#492)
1 parent 6d543d0 commit 2e2b86d

File tree

3 files changed

+71
-61
lines changed

3 files changed

+71
-61
lines changed

docusaurus/docs/Flutter/01-setup/03-quickstart.mdx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ Future<void> main() async {
2121
// Ensure Flutter is able to communicate with Plugins
2222
WidgetsFlutterBinding.ensureInitialized();
2323
24-
// Initialize Stream video and set the API key for our app.
25-
StreamVideo.init('YOUR-API-KEY', logPriority: Priority.info);
26-
27-
// Connect a user by calling to our application
28-
await StreamVideo.instance.connectUser(
29-
const UserInfo(id: 'testing', role: 'admin', name: 'Test User'),
30-
'YOUR-TOKEN',
24+
// Initialize Stream video and set the API key along with the user for our app.
25+
final client = StreamVideo(
26+
'YOUR-API-KEY',
27+
user: User.regular(userId: 'testing', name: 'Test User'),
28+
userToken: 'YOUR-USER-TOKEN',
29+
options: const StreamVideoOptions(
30+
logPriority: Priority.info,
31+
),
3132
);
3233
3334
// Set up our call object
34-
final call = StreamVideo.instance.makeCall(type: 'default', id: '345');
35+
final call = client.makeCall(type: 'default', id: '345');
3536
// Connect to the call we created
3637
await call.join();
3738

docusaurus/docs/Flutter/02-tutorials/01-video-calling.mdx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ The [stream_video_flutter_background] package adds background capabilities for t
6060
6161
### Initialising Stream Video
6262
63-
To start adding the SDK to your app, initialise the Stream Video SDK and connect a user:
63+
To start adding the SDK to your app, initialise the Stream Video SDK with a user:
6464
6565
```dart
6666
import 'package:flutter/material.dart';
@@ -69,15 +69,14 @@ import 'package:stream_video_flutter/stream_video_flutter.dart';
6969
void main() async {
7070
WidgetsFlutterBinding.ensureInitialized();
7171

72-
StreamVideo.init(
72+
final client = StreamVideo(
7373
'hd8szvscpxvd',
74+
user: User.regular(userId: 'vasil', role: 'admin', name: 'Willard Hessel'),
75+
userToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoidmFzaWwifQ.N44i27-o800njeSlcvH2HGlBfTl8MH4vQl0ddkq5BVI',
7476
);
7577

76-
// This step is usually done later
77-
await StreamVideo.instance.connectUser(
78-
const UserInfo(id: 'vasil', role: 'admin', name: 'Willard Hessel'),
79-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoidmFzaWwifQ.N44i27-o800njeSlcvH2HGlBfTl8MH4vQl0ddkq5BVI',
80-
);
78+
// Right after creation client connects to the backend and authenticates the user
79+
// To access the client you can simply use `StreamVideo.instance`.
8180

8281
runApp(const MyApp());
8382
}

docusaurus/docs/Flutter/03-core-concepts/01-authentication.mdx

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,66 @@ Before users are able to join or create a call, the client must first be configu
1212
The initialization constructor for `StreamVideo` also exposes many customization options which can be overridden based on the project needs such as the logging level, SDP policy, retry policy, etc.
1313

1414
```dart
15-
static StreamVideo init(
16-
String apiKey, {
17-
LatencySettings latencySettings = const LatencySettings(),
18-
RetryPolicy retryPolicy = const RetryPolicy(),
19-
SdpPolicy sdpPolicy = _defaultSdpPolicy,
20-
Priority logPriority = Priority.none,
21-
LogHandlerFunction logHandlerFunction = _defaultLogHandler,
22-
})
15+
factory StreamVideo(
16+
String apiKey, {
17+
StreamVideoOptions options = StreamVideoOptions(
18+
coordinatorRpcUrl: _defaultCoordinatorRpcUrl,
19+
coordinatorWsUrl: _defaultCoordinatorWsUrl,
20+
latencySettings: const LatencySettings(),
21+
sdpPolicy: const SdpPolicy(),
22+
retryPolicy: const RetryPolicy(),
23+
logPriority: Priority.none,
24+
logHandlerFunction: _defaultLogHandler,
25+
muteVideoWhenInBackground: false,
26+
muteAudioWhenInBackground: false,
27+
autoConnect: true,
28+
),
29+
required User user,
30+
String? userToken,
31+
TokenLoader? tokenLoader,
32+
OnTokenUpdated? onTokenUpdated,
33+
bool failIfSingletonExists = true,
34+
PNManagerProvider? pushNotificationManagerProvider,
35+
});
2336
```
2437

2538
### Working with Tokens
2639

2740
All tokens must be generated via a backend SDK and cannot be created from a frontend client. This step is typically included whenever a new user is registered on your backend.
2841

29-
There are a few ways in which users can connect using our SDK. We support both long lived tokens and dynamic tokens via two constructors accessible on the `StreamVideo` class:
42+
There are a few ways in which users can connect using our SDK. We support both long lived tokens and dynamic tokens via two parameters accessible on the `StreamVideo` class:
3043

31-
- `connectUser(UserInfo user, String token)`
32-
- `connectUserWithProvider(user, tokenProvider)`
44+
- `StreamVideo(apiKey, user: User, userToken: String)`
45+
- `StreamVideo(apiKey, user: User, tokenLoader: TokenLoader)`
3346

34-
For situations where your backend does not require tokens to be refreshed, `connectUser` can be used by simply passing in a `UserInfo` object and the token as a `String`.
47+
For situations where your backend does not require tokens to be refreshed, the first variant can be used by simply passing in a `User` object and the `userToken` as a `String`.
3548

3649
*Dynamic tokens*
3750

38-
Using `connectUserWithProvider`, a Token Provider can be used to dynamically load a token from a server. On expiration, the SDK automatically calls the Token Provider to obtain a new token.
51+
Using the second variant, a Token Loader can be used to dynamically load a token from a server. On expiration, the SDK automatically calls the Token Loader to obtain a new token.
3952

40-
As long as your handler returns a `String` it will satisfy the contract of `TokenProvider`
53+
As long as your handler returns a `String` it will satisfy the contract of `TokenLoader`
4154

4255
```dart
4356
Future<String> _tokenLoader(String userId) async {
44-
final token = await backend.loadToken(
45-
apiKey: Env.apiKey,
46-
userId: userId,
47-
);
48-
return token;
49-
}
57+
final token = await backend.loadToken(
58+
apiKey: Env.apiKey,
59+
userId: userId,
60+
);
61+
return token;
62+
}
5063
```
5164

5265
```dart
53-
await streamVideo.connectUserWithProvider(
54-
user,
55-
tokenProvider: TokenProvider.dynamic(_tokenLoader, (token) async {
56-
// Callback function with the token
57-
}),
58-
);
66+
StreamVideo(
67+
apiKey,
68+
user: user,
69+
tokenLoader: _tokenLoader,
70+
onTokenUpdated: (token) async {
71+
// Callback function with the token.
72+
// Called when the token is updated.
73+
},
74+
);
5975
```
6076

6177
### Anonymous users
@@ -65,25 +81,19 @@ For use-cases like live streaming or guest meeting, you may want to allow users
6581
For these use-cases, the SDK has a guest endpoint which can be used to create a temporary user
6682

6783
```dart
68-
final guest = await streamVideo.createGuest(
69-
id: guestId,
70-
name: guestId,
71-
image: imageUrl,
72-
);
73-
final data = guest.getDataOrNull();
74-
if (data == null) {
75-
throw Exception();
76-
}
77-
78-
final userInfo = UserInfo(
79-
id: data.user.id,
80-
image: data.user.image,
81-
name: data.user.name ?? '',
82-
teams: data.user.teams ?? [],
83-
role: data.user.role,
84-
);
85-
86-
await streamVideo.connectUser(userInfo, data.accessToken);
84+
final guest = User.guest(userId: guestId, name: guestName, image: guestImage);
85+
final client = StreamVideo(
86+
apiKey,
87+
user: guest,
88+
);
89+
90+
final result = await client.connect();
91+
// if result wasn't successful, then result will return null
92+
final userToken = result.getDataOrNull();
93+
final userInfo = client.currentUser;
8794
```
95+
:::note
96+
`userInfo.id` will be slightly different from what you passed in. This is because the SDK will generate a unique ID for the user.
97+
Please user the generated ID across your app.
98+
:::
8899

89-
`createGuest` returns user information and a token which can be used to construct information about the user and connect to the API.

0 commit comments

Comments
 (0)