Skip to content

Commit 6b10755

Browse files
authored
fixes for ringing on iOS terminated state (#750)
1 parent 8e3b607 commit 6b10755

File tree

6 files changed

+23
-45
lines changed

6 files changed

+23
-45
lines changed

dogfooding/lib/app/app_content.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ class _StreamDogFoodingAppContentState
109109
}
110110

111111
Future<void> _consumeIncomingCall() async {
112-
final calls =
113-
await StreamVideo.instance.pushNotificationManager?.activeCalls();
112+
if (!locator.isRegistered<StreamVideo>()) return;
113+
114+
final streamVideo = locator.get<StreamVideo>();
115+
final calls = await streamVideo.pushNotificationManager?.activeCalls();
114116

115117
if (calls == null || calls.isEmpty) return;
116118

117-
final callResult = await StreamVideo.instance.consumeIncomingCall(
119+
final callResult = await streamVideo.consumeIncomingCall(
118120
uuid: calls.first.uuid!,
119121
cid: calls.first.callCid!,
120122
);

dogfooding/lib/screens/home_screen.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class _HomeScreenState extends State<HomeScreen> {
6565
await _call!.getOrCreate(
6666
memberIds: memberIds,
6767
ringing: isRinging,
68+
video: true,
6869
);
6970
} catch (e, stk) {
7071
debugPrint('Error joining or creating call: $e');

packages/stream_video/lib/src/call/call.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,24 +403,27 @@ class Call {
403403

404404
Future<Result<None>> accept() async {
405405
final state = this.state.value;
406-
_logger.i(() => '[reject] ${_status.value}; state: $state');
406+
_logger.i(() => '[accept] ${_status.value}; state: $state');
407+
407408
final status = state.status;
408409
if (status is! CallStatusIncoming || status.acceptedByMe) {
409-
_logger.w(() => '[acceptCall] rejected (invalid status): $status');
410+
_logger.w(() => '[accept] rejected (invalid status): $status');
410411
return Result.error('invalid status: $status');
411412
}
412413

413414
final outgoingCall = _getOutgoingCall();
414-
if (outgoingCall?.callCid != callCid) {
415-
await outgoingCall?.reject(reason: CallRejectReason.cancel());
416-
await outgoingCall?.leave();
415+
if (outgoingCall != null && outgoingCall.callCid != callCid) {
416+
_logger.i(() => '[accept] canceling outgoing call: $outgoingCall');
417+
await outgoingCall.reject(reason: CallRejectReason.cancel());
418+
await outgoingCall.leave();
417419
await _setOutgoingCall(null);
418420
}
419421

420422
final activeCall = _getActiveCall();
421-
if (activeCall?.callCid != callCid) {
422-
await activeCall?.reject(reason: CallRejectReason.cancel());
423-
await activeCall?.leave();
423+
if (activeCall != null && activeCall.callCid != callCid) {
424+
_logger.i(() => '[accept] canceling another active call: $activeCall');
425+
await activeCall.reject(reason: CallRejectReason.cancel());
426+
await activeCall.leave();
424427
await _setActiveCall(null);
425428
}
426429

packages/stream_video/lib/src/call/session/call_session.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ class CallSession extends Disposable {
115115
sfu_models.Device? device;
116116
sfu_models.Browser? browser;
117117

118-
var os = sfu_models.OS(
119-
name: SysInfo.operatingSystemName,
120-
version: SysInfo.operatingSystemVersion,
121-
architecture: SysInfo.rawKernelArchitecture,
122-
);
118+
var os = sfu_models.OS();
123119

124120
if (CurrentPlatform.isAndroid) {
125121
final deviceInfo = await DeviceInfoPlugin().androidInfo;

packages/stream_video_push_notification/ios/Classes/StreamVideoPKDelegateManager.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,7 @@ public class StreamVideoPKDelegateManager: NSObject, PKPushRegistryDelegate, UNU
129129
fromPushKit: true
130130
)
131131

132-
// Complete after a delay to ensure that the incoming call notification
133-
// is displayed before completing the push notification handling.
134-
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
135-
completion()
136-
}
132+
completion()
137133
}
138134

139135
}

packages/stream_video_push_notification/lib/src/stream_video_push_notification.dart

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,7 @@ class StreamVideoPushNotificationManager implements PushNotificationManager {
7878
_idCallRejected,
7979
client.events.on<CoordinatorCallRejectedEvent>(
8080
(event) async {
81-
final callRingingState = await streamVideo.getCallRingingState(
82-
callType: event.callCid.type, id: event.callCid.id);
83-
84-
switch (callRingingState) {
85-
case CallRingingState.accepted:
86-
case CallRingingState.rejected:
87-
case CallRingingState.ended:
88-
endCallByCid(event.callCid.toString());
89-
case CallRingingState.ringing:
90-
break;
91-
}
81+
endCallByCid(event.callCid.toString());
9282
},
9383
),
9484
);
@@ -97,19 +87,9 @@ class StreamVideoPushNotificationManager implements PushNotificationManager {
9787
_idCallAccepted,
9888
client.events.on<CoordinatorCallAcceptedEvent>(
9989
(event) async {
100-
final callRingingState = await streamVideo.getCallRingingState(
101-
callType: event.callCid.type, id: event.callCid.id);
102-
103-
switch (callRingingState) {
104-
case CallRingingState.accepted:
105-
case CallRingingState.rejected:
106-
case CallRingingState.ended:
107-
await FlutterCallkitIncoming.silenceEvents();
108-
await endCallByCid(event.callCid.toString());
109-
await Future<void>.delayed(const Duration(milliseconds: 300));
110-
await FlutterCallkitIncoming.unsilenceEvents();
111-
case CallRingingState.ringing:
112-
break;
90+
if (streamVideo.activeCall?.state.value.status
91+
is! CallStatusActive) {
92+
await endCallByCid(event.callCid.toString());
11393
}
11494
},
11595
),

0 commit comments

Comments
 (0)