Skip to content

Commit

Permalink
cleanup in member related methods inside Call
Browse files Browse the repository at this point in the history
  • Loading branch information
Brazol committed Oct 26, 2023
1 parent 2b57a78 commit a4e20a8
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,32 @@ await call.getOrCreate(); // New

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 @@ await call.join();

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.
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
14 changes: 12 additions & 2 deletions packages/stream_video/lib/src/coordinator/coordinator_client.dart
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,15 +513,39 @@ 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(
() => '[inviteUsers] 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, members: $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) {
Expand All @@ -532,12 +556,13 @@ class CoordinatorClientOpenApi extends CoordinatorClient {
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,23 +175,56 @@ 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);
},
);
}

@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('removeMembers', error, nextAttemptDelay);
},
);
}

@override
Future<Result<CoordinatorJoined>> joinCall({
required StreamCallCid callCid,
Expand Down

0 comments on commit a4e20a8

Please sign in to comment.