Skip to content

Commit

Permalink
[FVS-81] lobby logic changes & call api alignment (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanat committed Sep 15, 2023
1 parent 03f57e7 commit 441d1a9
Show file tree
Hide file tree
Showing 28 changed files with 363 additions and 114 deletions.
4 changes: 2 additions & 2 deletions docusaurus/docs/Flutter/01-setup/03-quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Future<void> main() async {
// Set up our call object
final call = StreamVideo.instance.makeCall(type: 'default', id: '345');
// Connect to the call we created
await call.connect();
await call.join();
runApp(
StreamVideoGettingStarted(
Expand Down Expand Up @@ -164,7 +164,7 @@ return StreamCallContent(
call: call,
localParticipant: localParticipant,
),
LeaveCallOption(call: call, onLeaveCallTap: call.disconnect),
LeaveCallOption(call: call, onLeaveCallTap: call.leave),
],
);
},
Expand Down
8 changes: 4 additions & 4 deletions docusaurus/docs/Flutter/02-tutorials/01-video-calling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ return Scaffold(
```

To instantiate a call, you can use the `StreamVideo.makeCall()` method. You then need to create this
on the backend using the `call.getOrCreateCall()` method.
on the backend using the `call.getOrCreate()` method.

Here is how that looks in code:

Expand All @@ -168,7 +168,7 @@ ElevatedButton(
var call = StreamVideo.instance.makeCall(
type: 'default', id: 'demo-call-123');
await call.getOrCreateCall();
await call.getOrCreate();
} catch (e) {
debugPrint('Error joining or creating call: $e');
debugPrint(e.toString());
Expand Down Expand Up @@ -237,7 +237,7 @@ Once you navigate to the `CallScreen` after the button press, this is what you w
![Call Screen UI](../assets/tutorials/vc-ui-2.png)

:::note
When connecting other users, you can use the same process. The `call.getOrCreateCall()` method will create
When connecting other users, you can use the same process. The `call.getOrCreate()` method will create
a call if it doesn't exist, and simply return the existing call if it already does.
:::

Expand Down Expand Up @@ -292,7 +292,7 @@ StreamCallContainer(
LeaveCallOption(
call: call,
onLeaveCallTap: () {
call.disconnect();
call.leave();
},
),
],
Expand Down
4 changes: 2 additions & 2 deletions docusaurus/docs/Flutter/02-tutorials/02-audio-room.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ final room = video.makeCall(
id: const Uuid().v4(),
);
await room.getOrCreateCall();
await room.getOrCreate();
await room.update(
custom: {
'name': title,
Expand Down Expand Up @@ -198,7 +198,7 @@ Future<void> joinRoom(QueriedCall room) async {
final cid = room.call.cid;
final call = video.makeCall(type: cid.type, id: cid.id);
await call.connect();
await call.join();
log('Joining Call: $cid');
Navigator.of(context).push(
AudioRoomScreen.routeTo(call, room.call, user),
Expand Down
8 changes: 4 additions & 4 deletions docusaurus/docs/Flutter/02-tutorials/03-livestreaming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class LiveStreamScreen extends StatelessWidget {
color: Colors.black,
child: GestureDetector(
onTap: () {
currentStream.disconnect();
currentStream.leave();
Navigator.pop(context);
},
child: const Center(
Expand Down Expand Up @@ -295,7 +295,7 @@ To setup WebRTC based livestreaming, we can first make a call using `makeCall` a

Next, we can set some default behaviour for our livestream such as configuring whether the camera and microphone should be enabled by default.

Finally, we can create the call by invoking `getOrCreateCall` on the object we just created. By default, a `livestream` call is started in backstage mode, meaning the call hosts can join and see each other but the call will be invisible to others.
Finally, we can create the call by invoking `getOrCreate` on the object we just created. By default, a `livestream` call is started in backstage mode, meaning the call hosts can join and see each other but the call will be invisible to others.

When the hosts are ready, the can make the call “live” by calling `goLive`.

Expand All @@ -313,9 +313,9 @@ Future<void> _createLivestream() async {
microphone: TrackOption.enabled(),
);
final result = await call.getOrCreateCall(); // Call object is created
final result = await call.getOrCreate(); // Call object is created
if (result.isSuccess) {
await call.connect(); // Our local app user is able to join and recieve events from the call
await call.join(); // Our local app user is able to join and recieve events from the call
await call.goLive(); // Allow others to see and joing the call
print('Joining call ${call.id}');
Navigator.of(context).push(LiveStreamScreen.route(call));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ final call = StreamVideo.instance.makeCall(type: 'default', id: 'Your-call-ID');
```

Calling `makeCall` returns a `Call` object for us to work with. However, it does neither connect nor start transmitting data automatically. To create and join the call, we must then invoke `getOrCreateCall` on the returned object.
Calling `makeCall` returns a `Call` object for us to work with. However, it does neither connect nor start transmitting data automatically. To create and join the call, we must then invoke `getOrCreate` on the returned object.

```dart
final call = StreamVideo.instance.makeCall(type: 'default', id: 'Your-call-ID');
await call.getOrCreateCall(); // New
await call.getOrCreate(); // New
```

Although we are not passing any parameters to `getOrCreateCall` in the above example, it is important to note a few things:
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.
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.

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

### 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.

For example, once a call is created a user can `call.update` the information on the call by adding custom metadata such as a name, description, or any other arbitrary `Map<String, Object>` to the call before `getOrCreateCall` is invoked.
For example, once a call is created a user can `call.update` the information on the call by adding custom metadata such as a name, description, or any other arbitrary `Map<String, Object>` to the call before `getOrCreate` is invoked.

```dart
call.update(custom: {'name': 'My first Call'});
await call.getOrCreateCall();
await call.getOrCreate();
```

Using the update method, a variety of settings can also be applied before the call is created such as:
Expand Down Expand Up @@ -69,7 +69,7 @@ Next, with our class instantiated, we can connect to the call and SFU by invokin

```dart
final call = StreamVideo.instance.makeCall(type: 'default', id: 'My-existing-call-ID');
await call.connect();
await call.join();
```

Expand Down
2 changes: 1 addition & 1 deletion docusaurus/docs/Flutter/04-ui/04-call-content.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class _CallScreenState extends State<CallScreen> {
),
LeaveCallOption(
call: call,
onLeaveCallTap: () => call.disconnect(),
onLeaveCallTap: () => call.leave(),
),
],
);
Expand Down
2 changes: 1 addition & 1 deletion docusaurus/docs/Flutter/04-ui/05-call-controls.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ StreamCallContent(
),
LeaveCallOption(
call: call,
onLeaveCallTap: () => call.disconnect(),
onLeaveCallTap: () => call.leave(),
),
],
);
Expand Down
2 changes: 1 addition & 1 deletion docusaurus/docs/Flutter/05-advanced/01-deeplinking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class _JoinScreenState extends State<JoinScreen> {
type: 'default',
);
await call.connect();
await call.join();
await _navigateToCall(call);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ You can see that as a first step, we need to create a `StreamCallCid` object bas
2. Connect the current user to the call obtained before:

```dart
call.connect();
call.join();
```

That's it. From that point, we can start listening to call state updates. The easiest way to do that is by listening to the stream that can be accessed from the `Call` object:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ Future<Call> _joinCall(BuildContext context, String cid) async {
final id = parts[1];
final call = await StreamVideo.instance.joinCall(type: type, id: id);
await call.connect();
await call.join();
return call;
}
```
Expand Down
4 changes: 2 additions & 2 deletions dogfooding/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class _StreamDogFoodingAppState extends State<StreamDogFoodingApp>
);

final call = StreamVideo.instance.makeCall(type: kCallType, id: callId);
await call.getOrCreateCall();
await call.getOrCreate();

final chatChannel = await widget.appRepository.createChatChannel(
channelId: call.callCid.id,
Expand Down Expand Up @@ -202,7 +202,7 @@ class _StreamDogFoodingAppState extends State<StreamDogFoodingApp>
// widget is detached
break;
case AppLifecycleState.hidden:
// widget is hidden
// widget is hidden
}
}

Expand Down
2 changes: 1 addition & 1 deletion dogfooding/lib/src/screens/call_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class _CallScreenState extends State<CallScreen> {
LeaveCallOption(
call: call,
onLeaveCallTap: () {
call.disconnect();
call.leave();
},
),
],
Expand Down
8 changes: 4 additions & 4 deletions dogfooding/lib/src/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class _HomeScreenState extends State<HomeScreen> {
unawaited(showLoadingIndicator(context));
try {
call = streamVideoClient.makeCall(type: kCallType, id: callId);
await call?.getOrCreateCall();
await call?.getOrCreate();
chatChannel = await appRepo?.createChatChannel(
channelId: call!.callCid.id,
);
Expand Down Expand Up @@ -161,9 +161,9 @@ class _HomeScreenState extends State<HomeScreen> {
}

void _onNavigateToCall(
Call call, {
CallConnectOptions options = const CallConnectOptions(),
}) {
Call call, {
CallConnectOptions options = const CallConnectOptions(),
}) {
Navigator.push(
context,
MaterialPageRoute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:meta/meta.dart';
import '../../errors/video_error.dart';
import '../../models/call_created_data.dart';
import '../../models/call_joined_data.dart';
import '../../models/call_received_data.dart';
import '../../models/call_ringing_data.dart';
import '../internal_action.dart';

Expand Down Expand Up @@ -104,6 +105,12 @@ class CallCreated extends LifecycleStage {
final CallCreatedData data;
}

class CallReceived extends LifecycleStage {
const CallReceived(this.data);

final CallReceivedData data;
}

class CallRinging extends LifecycleStage {
const CallRinging(this.data);

Expand Down
Loading

0 comments on commit 441d1a9

Please sign in to comment.