Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align: cleanup in member related methods inside Call #509

Merged
merged 5 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,32 @@

Although we are not passing any parameters to `getOrCreate` in the above example, it is important to note a few things:

1. Participants: Upon creation, we can supply a list of user IDs we would like to immediately add to the call.
1. Members: Upon creation, we can supply a list of user IDs we would like to immediately add to the call.
2. Ringing: If ringing is set to `true`, Stream will send a notification to the users on the call, triggering the platform call screen on iOS and Android.

:::note
Depending on call permissions settings, call member may have different permissions than other users joining the call (i.e. call can be configured so only members can join). See [here](#Restricting-access)

Check failure on line 31 in docusaurus/docs/Flutter/03-core-concepts/02-joining-and-creating-calls.mdx

View workflow job for this annotation

GitHub Actions / vale

[vale] docusaurus/docs/Flutter/03-core-concepts/02-joining-and-creating-calls.mdx#L31

[Google.Latin] Use 'that is' instead of 'i.e.'.
Raw output
{"message": "[Google.Latin] Use 'that is' instead of 'i.e.'.", "location": {"path": "docusaurus/docs/Flutter/03-core-concepts/02-joining-and-creating-calls.mdx", "range": {"start": {"line": 31, "column": 121}}}, "severity": "ERROR"}
:::

By default, calling `getOrCreate` assigns `admin` permission to each user who is supplied during creation.

When call is already active you can still manage members:

```dart
final call = client.makeCall(type: 'my-call-type', id: 'my-call-id');
call.getOrCreate(memberIds: ['alice', 'bob']);

// grant access to more users
await call.updateCallMembers(updateMembers: [const UserInfo(id: 'charlie', role: 'call_member')]);
// or
await call.addMembers([const UserInfo(id: 'charlie', role: 'call_member')]);

// remove access from some users
await call.updateCallMembers(removeIds: ['charlie']);
// or
await call.removeMembers(['charlie']);
```

### Call CRUD Operations

With calls, we make it easy to perform basic create, read, update, and delete (CRUD) operations on calls providing the user has sufficient permissions.
Expand Down Expand Up @@ -75,4 +96,20 @@

Unlike the call creation flow and functions, the user must have sufficient permissions to join the call or a `VideoError` will be returned. All users connected via the `join()` function have the permission type of `user` by default and are limited in the actions they can perform.

### Restricting access

You can restrict access to a call by tweaking the [Call Type](https://getstream.io/video/docs/flutter/call-types/) permissions and roles. A typical use case is to restrict access to a call to a specific set of users -> call members.

On our [dashboard](https://dashboard.getstream.io), navigate to the **Video & Audio -> Roles & Permissions** section and select the appropriate role and scope. In this example, we will use `my-call-type` scope.

By default, all users unless specified otherwise, have the `user` role.

We start by removing the `JoinCall` permission from the `user` role for the `my-call-type` scope. It will prevent regular users from joining a call of this type.

![Revoke JoinCall](../assets/core_concepts/user-revoke-joincall.png)

Next, let's ensure that the `call_member` role has the `JoinCall` permission for the `my-call-type` scope. It will allow users with the `call_member` role to join a call of this type.

![Grant JoinCall](../assets/core_concepts/call_member-grant-joincall.png)

That's it. In just a few lines, we have created our first calls, and they are ready for the world to join. To learn how to observe events and the state of a call, please read the next chapter.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions dogfooding/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
dart_vlc
desktop_drop
file_selector_windows
firebase_auth
firebase_core
flutter_webrtc
share_plus
Expand Down
12 changes: 12 additions & 0 deletions packages/stream_video/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## Upcoming

✅ Added

* `removeMembers` and `updateCallMembers` to `Call`

🔄 Changed

Breaking changes 🚧
* renamed `inviteUsers` to `addMembers` in `Call`
* renamed parameter name in `getOrCreateCall` from `participantIds` to `memberIds`

## 0.1.1

* Fixed call join bug
Expand Down
30 changes: 25 additions & 5 deletions packages/stream_video/lib/src/call/call.dart
Original file line number Diff line number Diff line change
Expand Up @@ -831,15 +831,35 @@ class Call {
});
}

Future<Result<None>> inviteUsers(List<UserInfo> users) {
return _coordinatorClient.inviteUsers(
Future<Result<None>> addMembers(List<UserInfo> users) {
return _coordinatorClient.addMembers(
callCid: callCid,
members: users.map((user) {
return MemberRequest(userId: user.id, role: user.role);
}).toList(),
);
}

Future<Result<None>> removeMembers(List<String> userIds) {
return _coordinatorClient.removeMembers(
callCid: callCid,
removeIds: userIds,
);
}

Future<Result<None>> updateCallMembers({
List<UserInfo> updateMembers = const [],
List<String> removeIds = const [],
}) {
return _coordinatorClient.updateCallMembers(
callCid: callCid,
updateMembers: updateMembers.map((user) {
return MemberRequest(userId: user.id, role: user.role);
}).toList(),
removeIds: removeIds,
);
}

/// Receives a call information. You can then use
/// the [CallReceivedData] in order to create a [Call] object.
Future<Result<CallReceivedData>> get({
Expand Down Expand Up @@ -884,12 +904,12 @@ class Call {
/// Receives a call or creates it with given information. You can then use
/// the [CallReceivedOrCreatedData] in order to create a [Call] object.
Future<Result<CallReceivedOrCreatedData>> getOrCreate({
List<String> participantIds = const [],
List<String> memberIds = const [],
bool ringing = false,
}) async {
_logger.d(
() => '[getOrCreate] cid: $callCid, ringing: $ringing, '
'participantIds: $participantIds',
'memberIds: $memberIds',
);

final currentUserId = _getCurrentUserId();
Expand All @@ -901,7 +921,7 @@ class Call {
final response = await _coordinatorClient.getOrCreateCall(
callCid: callCid,
ringing: ringing,
members: participantIds.map((id) {
members: memberIds.map((id) {
return MemberRequest(
userId: id,
role: 'admin',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,20 @@ abstract class CoordinatorClient {
Map<String, Object> custom = const {},
});

Future<Result<None>> inviteUsers({
Future<Result<None>> addMembers({
required StreamCallCid callCid,
required Iterable<open.MemberRequest> members,
bool? ringing,
});

Future<Result<None>> removeMembers({
required StreamCallCid callCid,
required Iterable<String> removeIds,
});

Future<Result<None>> updateCallMembers({
required StreamCallCid callCid,
Iterable<open.MemberRequest> updateMembers = const [],
Iterable<String> removeIds = const [],
});

/// Sends a `call.permission_request` event to all users connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,31 +513,56 @@ class CoordinatorClientOpenApi extends CoordinatorClient {

/// Sends invite to people for an existing call.
@override
Future<Result<None>> inviteUsers({
Future<Result<None>> addMembers({
required StreamCallCid callCid,
required Iterable<open.MemberRequest> members,
bool? ringing,
}) async {
_logger.d(
() => '[addMembers] cid: $callCid, members: $members',
);

return updateCallMembers(callCid: callCid, updateMembers: members);
}

@override
Future<Result<None>> removeMembers({
required StreamCallCid callCid,
required Iterable<String> removeIds,
}) async {
_logger.d(
() => '[removeMembers] cid: $callCid, removeIds: $removeIds',
);

return updateCallMembers(callCid: callCid, removeIds: removeIds);
}

@override
Future<Result<None>> updateCallMembers({
required StreamCallCid callCid,
Iterable<open.MemberRequest> updateMembers = const [],
Iterable<String> removeIds = const [],
}) async {
try {
_logger.d(
() =>
'[inviteUsers] cid: $callCid, members: $members, ringing: $ringing',
'[updateCallMembers] cid: $callCid, updateMembers: $updateMembers, removeIds: $removeIds',
);
final connectionResult = await _waitUntilConnected();
if (connectionResult is Failure) {
_logger.e(() => '[inviteUsers] no connection established');
_logger.e(() => '[updateCallMembers] no connection established');
return connectionResult;
}
final result = await _defaultApi.updateCallMembers(
callCid.type,
callCid.id,
open.UpdateCallMembersRequest(
updateMembers: members.toList(),
updateMembers: updateMembers.toList(),
removeMembers: removeIds.toList(),
),
);
_logger.v(() => '[inviteUsers] completed: $result');
_logger.v(() => '[updateCallMembers] completed: $result');
if (result == null) {
return Result.error('inviteUsers result is null');
return Result.error('updateCallMembers result is null');
}
return const Result.success(none);
} catch (e, stk) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,51 @@ class CoordinatorClientRetry extends CoordinatorClient {
}

@override
Future<Result<None>> inviteUsers({
Future<Result<None>> addMembers({
required StreamCallCid callCid,
required Iterable<open.MemberRequest> members,
bool? ringing,
}) {
return _retryManager.execute(
() => _delegate.inviteUsers(
() => _delegate.addMembers(
callCid: callCid,
members: members,
ringing: ringing,
),
(error, nextAttemptDelay) async {
_logRetry('inviteUsers', error, nextAttemptDelay);
_logRetry('addMembers', error, nextAttemptDelay);
},
);
}

@override
Future<Result<None>> removeMembers({
required StreamCallCid callCid,
required Iterable<String> removeIds,
}) async {
return _retryManager.execute(
() => _delegate.removeMembers(
callCid: callCid,
removeIds: removeIds,
),
(error, nextAttemptDelay) async {
_logRetry('removeMembers', error, nextAttemptDelay);
},
);
}

@override
Future<Result<None>> updateCallMembers({
required StreamCallCid callCid,
Iterable<open.MemberRequest> updateMembers = const [],
Iterable<String> removeIds = const [],
}) {
return _retryManager.execute(
() => _delegate.updateCallMembers(
callCid: callCid,
updateMembers: updateMembers,
removeIds: removeIds,
),
(error, nextAttemptDelay) async {
_logRetry('updateCallMembers', error, nextAttemptDelay);
},
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class _StartCallTabState extends State<StartCallTab>
final call = StreamVideo.instance.makeCall(type: 'default', id: callId);
final result = await call.getOrCreate(
ringing: _ringingCall,
participantIds: [
memberIds: [
for (final user in _selectedUsers) user.id,
],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class StreamInviteUserListController extends ValueNotifier<CallInviteState> {
final users = value.users;
final selectedUsers = value.selectedUsers;

await call.inviteUsers(selectedUsers.values.toList());
await call.addMembers(selectedUsers.values.toList());
users.removeWhere((user) => selectedUsers.containsKey(user.id));
selectedUsers.clear();
notifyListeners();
Expand Down
Loading