Skip to content

Commit 58e564c

Browse files
authored
fix: prevent some actions impossible on desktop (#863)
1 parent 35248b5 commit 58e564c

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

dogfooding/lib/app/app_content.dart

+28-24
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class _StreamDogFoodingAppContentState
118118
}
119119

120120
void _tryConsumingIncomingCallFromTerminatedState() {
121-
if (CurrentPlatform.isIos) return;
121+
if (!CurrentPlatform.isAndroid) return;
122122

123123
if (_router.routerDelegate.navigatorKey.currentContext == null) {
124124
// App is not running yet. Postpone consuming after app is in the foreground
@@ -143,32 +143,36 @@ class _StreamDogFoodingAppContentState
143143
void _observeCallKitEvents() {
144144
final streamVideo = locator.get<StreamVideo>();
145145

146-
_compositeSubscription.add(
147-
streamVideo.observeCoreCallKitEvents(
148-
onCallAccepted: (callToJoin) {
149-
// Navigate to the call screen.
150-
final extra = (
151-
call: callToJoin,
152-
connectOptions: null,
153-
);
154-
155-
_router.push(CallRoute($extra: extra).location, extra: extra);
156-
},
157-
),
158-
);
146+
// On mobile we depend on call kit notifications.
147+
// On desktop and web they are (currently) not available, so we depend on a
148+
// websocket which can receive a call when the app is open.
149+
if (CurrentPlatform.isMobile) {
150+
_compositeSubscription.add(
151+
streamVideo.observeCoreCallKitEvents(
152+
onCallAccepted: (callToJoin) {
153+
// Navigate to the call screen.
154+
final extra = (
155+
call: callToJoin,
156+
connectOptions: null,
157+
);
159158

160-
// UNCOMMENT THIS TO SHOW IN-APP INCOMING SCREEN
161-
// _compositeSubscription.add(streamVideo.state.incomingCall.listen((call) {
162-
// if (call == null) return;
159+
_router.push(CallRoute($extra: extra).location, extra: extra);
160+
},
161+
),
162+
);
163+
} else {
164+
_compositeSubscription.add(streamVideo.state.incomingCall.listen((call) {
165+
if (call == null) return;
163166

164-
// // Navigate to the call screen.
165-
// final extra = (
166-
// call: call,
167-
// connectOptions: null,
168-
// );
167+
// Navigate to the call screen.
168+
final extra = (
169+
call: call,
170+
connectOptions: null,
171+
);
169172

170-
// _router.push(CallRoute($extra: extra).location, extra: extra);
171-
// }));
173+
_router.push(CallRoute($extra: extra).location, extra: extra);
174+
}));
175+
}
172176
}
173177

174178
_observeFcmMessages() {

dogfooding/lib/screens/home_screen.dart

+8-6
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ class _HomeScreenState extends State<HomeScreen> {
4040

4141
@override
4242
void initState() {
43-
[
44-
Permission.notification,
45-
Permission.camera,
46-
Permission.microphone,
47-
].request();
43+
if (CurrentPlatform.isMobile || CurrentPlatform.isWeb) {
44+
[
45+
Permission.notification,
46+
Permission.camera,
47+
Permission.microphone,
48+
].request();
4849

49-
StreamVideoPushNotificationManager.ensureFullScreenIntentPermission();
50+
StreamVideoPushNotificationManager.ensureFullScreenIntentPermission();
51+
}
5052

5153
StreamBackgroundService.init(
5254
StreamVideo.instance,

packages/stream_video_push_notification/lib/src/stream_video_push_notification.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class StreamVideoPushNotificationManager implements PushNotificationManager {
6767
this.callerCustomizationCallback,
6868
this.registerApnDeviceToken = false,
6969
}) : _client = client {
70-
if (CurrentPlatform.isWeb) return;
70+
if (!CurrentPlatform.isMobile) return;
7171

7272
SharedPreferences.getInstance().then((prefs) => _sharedPreferences = prefs);
7373

@@ -363,7 +363,7 @@ class StreamVideoPushNotificationManager implements PushNotificationManager {
363363

364364
@override
365365
Future<List<CallData>> activeCalls() async {
366-
if (CurrentPlatform.isWeb) return [];
366+
if (!CurrentPlatform.isMobile) return [];
367367

368368
final activeCalls = await FlutterCallkitIncoming.activeCalls();
369369
if (activeCalls is! List) return [];
@@ -395,7 +395,7 @@ class StreamVideoPushNotificationManager implements PushNotificationManager {
395395
.toList();
396396

397397
// This is a workaround for the issue in flutter_callkit_incoming
398-
// where second CallKit call overrids data in showCallkitIncoming native method
398+
// where second CallKit call overrides data in showCallkitIncoming native method
399399
// and it's not possible to end the call by callCid
400400
if (activeCalls.length == calls.length) {
401401
await endAllCalls();

0 commit comments

Comments
 (0)