66using StreamVideo . Core . StatefulModels ;
77using StreamVideo . Libs . Utils ;
88using UnityEngine ;
9- #if UNITY_ANDROID
10- using UnityEngine . Android ;
11- #endif
129
1310namespace StreamVideo . ExampleProject . UI
1411{
@@ -19,76 +16,10 @@ public class UIManager : MonoBehaviour
1916 public VideoResolution SenderVideoResolution => new VideoResolution ( _senderVideoWidth , _senderVideoHeight ) ;
2017 public int SenderVideoFps => _senderVideoFps ;
2118
22- public void RequestCameraPermissions ( Action onGranted = null , Action onDenied = null )
23- {
24- #if UNITY_ANDROID
25- var callbacks = new PermissionCallbacks ( ) ;
26- Permission . RequestUserPermission ( Permission . Camera , callbacks ) ;
27-
28- callbacks . PermissionGranted += _ => { onGranted ? . Invoke ( ) ; } ;
29- callbacks . PermissionDenied += permissionName =>
30- {
31- onDenied ? . Invoke ( ) ;
32- Debug . LogError ( $ "{ permissionName } permission was not granted. Video capturing will not work.") ;
33- } ;
34- callbacks . PermissionDeniedAndDontAskAgain += ( permissionName ) =>
35- {
36- onDenied ? . Invoke ( ) ;
37- Debug . LogError ( $ "{ permissionName } permission was not granted. Video capturing will not work.") ;
38- } ;
39- #elif UNITY_IOS
40- Debug . LogError ( $ "Handling permissions not implemented for platform: " + Application . platform ) ;
41- #endif
42- }
43-
44- public bool HasUserAuthorizedCameraPermission ( )
45- {
46- #if UNITY_STANDALONE
47- return true ; //StreamTodo: check if this is true for all platforms
48- #elif UNITY_ANDROID
49- return Permission . HasUserAuthorizedPermission ( Permission . Camera ) ;
50- #else
51- Debug . LogError ( $ "Handling permissions not implemented for platform: " + Application . platform ) ;
52- #endif
53- }
54-
55- public void RequestMicrophonePermissions ( Action onGranted = null , Action onDenied = null )
56- {
57- #if UNITY_ANDROID
58- var callbacks = new PermissionCallbacks ( ) ;
59-
60- callbacks . PermissionGranted += _ => { onGranted ? . Invoke ( ) ; } ;
61- callbacks . PermissionDenied += permissionName =>
62- {
63- onDenied ? . Invoke ( ) ;
64- Debug . LogError ( $ "{ permissionName } permission was not granted. Video capturing will not work.") ;
65- } ;
66- callbacks . PermissionDeniedAndDontAskAgain += ( permissionName ) =>
67- {
68- onDenied ? . Invoke ( ) ;
69- Debug . LogError ( $ "{ permissionName } permission was not granted. Video capturing will not work.") ;
70- } ;
71-
72- Permission . RequestUserPermission ( Permission . Microphone , callbacks ) ;
73-
74- #else
75- Debug . LogError ( $ "Handling permissions not implemented for platform: " + Application . platform ) ;
76- #endif
77- }
78-
79- public bool HasUserAuthorizedMicrophonePermission ( )
80- {
81- #if UNITY_STANDALONE
82- return true ; //StreamTodo: check if this is true for all platforms
83- #elif UNITY_ANDROID
84- return Permission . HasUserAuthorizedPermission ( Permission . Microphone ) ;
85- #else
86- Debug . LogError ( $ "Handling permissions not implemented for platform: " + Application . platform ) ;
87- #endif
88- }
89-
9019 protected void Awake ( )
9120 {
21+ _permissionsManager = new PermissionsManager ( this ) ;
22+
9223 _videoManager . Init ( ) ;
9324
9425 _videoManager . CallStarted += OnCallStarted ;
@@ -100,9 +31,10 @@ protected void Awake()
10031 _portraitModeUIScreensSet . Init ( _videoManager , uiManager : this ) ;
10132 _landscapeModeUIScreensSet . Init ( _videoManager , uiManager : this ) ;
10233
103- if ( ! HasUserAuthorizedCameraPermission ( ) )
34+ if ( ! _permissionsManager . HasPermission ( PermissionsManager . PermissionType . Camera ) )
10435 {
105- RequestCameraPermissions ( onGranted : ( ) => { SelectFirstWorkingCameraOrDefaultAsync ( ) . LogIfFailed ( ) ; } ,
36+ _permissionsManager . RequestPermission ( PermissionsManager . PermissionType . Camera ,
37+ onGranted : ( ) => { SelectFirstWorkingCameraOrDefaultAsync ( ) . LogIfFailed ( ) ; } ,
10638 onDenied : ( )
10739 => Debug . LogError ( "Camera permission was not granted. Video capturing will not work." ) ) ;
10840 }
@@ -111,9 +43,10 @@ protected void Awake()
11143 SelectFirstWorkingCameraOrDefaultAsync ( ) . LogIfFailed ( ) ;
11244 }
11345
114- if ( ! HasUserAuthorizedMicrophonePermission ( ) )
46+ if ( ! _permissionsManager . HasPermission ( PermissionsManager . PermissionType . Microphone ) )
11547 {
116- RequestMicrophonePermissions ( onGranted : SelectFirstMicrophone ,
48+ _permissionsManager . RequestPermission ( PermissionsManager . PermissionType . Microphone ,
49+ onGranted : SelectFirstMicrophone ,
11750 onDenied : ( )
11851 => Debug . LogError ( "Microphone permission was not granted. Audio capturing will not work." ) ) ;
11952 }
@@ -151,13 +84,15 @@ protected void OnDestroy()
15184
15285 [ SerializeField ]
15386 private UIScreensSet _landscapeModeUIScreensSet ;
154-
87+
15588 [ SerializeField ]
15689 private UIScreensSet _portraitModeUIScreensSet ;
157-
90+
15891 [ SerializeField ]
15992 private bool _forceTestPortraitMode ;
16093
94+ private PermissionsManager _permissionsManager ;
95+
16196 private void OnCallStarted ( IStreamCall call ) => ShowCallScreen ( call ) ;
16297
16398 private void OnCallEnded ( ) => ShowMainScreen ( ) ;
@@ -242,10 +177,10 @@ private void SelectFirstMicrophone()
242177 private UIScreensSet GetCurrentScreenSet ( )
243178 {
244179 var isPortraitMode = IsPotraitMode ( ) ;
245-
180+
246181 _portraitModeUIScreensSet . gameObject . SetActive ( isPortraitMode ) ;
247182 _landscapeModeUIScreensSet . gameObject . SetActive ( ! isPortraitMode ) ;
248-
183+
249184 return isPortraitMode ? _portraitModeUIScreensSet : _landscapeModeUIScreensSet ;
250185 }
251186
0 commit comments