Skip to content
Open
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
26 changes: 13 additions & 13 deletions The49.Twilio.Video.Maui/The49.Twilio.Video.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
<!--<PackageReference Include="The49.Twilio.Video.iOS" />-->
<ProjectReference Include="..\The49.Twilio.Video.iOS\The49.Twilio.Video.iOS.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="..\LICENSE.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\logo.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\NUGET-README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<ItemGroup>
<None Include="..\LICENSE.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\logo.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\NUGET-README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
</Project>
54 changes: 38 additions & 16 deletions The49.Twilio.Video.Sample/VideoChatPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,37 @@ protected async override void OnAppearing()
// Create the local audio track
_localAudioTrack = LocalAudioTrack.Create(true);

// Capture the video from the camera. We pick the front facing camera for now
var cameraCapturer = CameraCapturer.Create(CameraPosition.Front);
// Check if we have a virtual device. The iOS simulator does not have a camera
if (DeviceInfo.Current.DeviceType == DeviceType.Physical
|| DeviceInfo.Current.Platform == DevicePlatform.Android)
{
// Capture the video from the camera. We pick the front facing camera for now
var cameraCapturer = CameraCapturer.Create(CameraPosition.Front);

// Create the local video track from the camera capturer
_localVideoTrack = LocalVideoTrack.Create(true, cameraCapturer);

// Display the local video in the video view
_localVideoTrack.AddSink(localVideoView);

} else
{
_ = DisplayAlert("No Camera",
"iOS Simulator does not provide a camera. You will still see incoming video.",
"OK");
}

// Configure the connection options. Pass the token and the tracks we want to send to remote participants
var builder = new ConnectOptions.Builder(token)
.RoomName(RoomName);

// Create the local video track from the camera capturer
_localVideoTrack = LocalVideoTrack.Create(true, cameraCapturer);
if (_localVideoTrack != null)
builder.VideoTracks(new List<LocalVideoTrack> { _localVideoTrack });

// Display the local video in the video view
_localVideoTrack.AddSink(localVideoView);
if (_localAudioTrack != null)
builder.AudioTracks(new List<LocalAudioTrack> { _localAudioTrack });

// Configure the connection options. Pass the token and the tracks we want to send to remote participants
var options = new ConnectOptions.Builder(token)
.RoomName(RoomName)
.VideoTracks(new List<LocalVideoTrack> { _localVideoTrack })
.AudioTracks(new List<LocalAudioTrack> { _localAudioTrack })
.Build();
var options = builder.Build();

_room = TwilioVideoService.Default.Connect(options);

Expand All @@ -71,10 +87,16 @@ protected async override void OnAppearing()

protected override void OnDisappearing()
{
base.OnDisappearing();

_localVideoTrack.Release();
_localAudioTrack.Release();
base.OnDisappearing();

// remove events so we don't leak anything
_room.ConnectFailure -= OnRoomConnectFailure;
_room.Connected -= OnRoomConnected;
_room.ParticipantConnected -= OnParticipantConnected;

// null check
_localVideoTrack?.Release();
_localAudioTrack?.Release();
_room.Disconnect();
}

Expand Down