diff --git a/The49.Twilio.Video.Maui/The49.Twilio.Video.Maui.csproj b/The49.Twilio.Video.Maui/The49.Twilio.Video.Maui.csproj index a00915c..c3dccc4 100644 --- a/The49.Twilio.Video.Maui/The49.Twilio.Video.Maui.csproj +++ b/The49.Twilio.Video.Maui/The49.Twilio.Video.Maui.csproj @@ -33,18 +33,18 @@ - - - True - \ - - - True - \ - - - True - \ - + + + True + \ + + + True + \ + + + True + \ + \ No newline at end of file diff --git a/The49.Twilio.Video.Sample/VideoChatPage.xaml.cs b/The49.Twilio.Video.Sample/VideoChatPage.xaml.cs index e58340a..87b9843 100644 --- a/The49.Twilio.Video.Sample/VideoChatPage.xaml.cs +++ b/The49.Twilio.Video.Sample/VideoChatPage.xaml.cs @@ -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 }); - // Display the local video in the video view - _localVideoTrack.AddSink(localVideoView); + if (_localAudioTrack != null) + builder.AudioTracks(new List { _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 }) - .AudioTracks(new List { _localAudioTrack }) - .Build(); + var options = builder.Build(); _room = TwilioVideoService.Default.Connect(options); @@ -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(); }