Skip to content

Commit 5286850

Browse files
committed
Added Call.hasVideoUpgradeRequest, Call.acceptVideoUpgrade, Call.onVideoUpgradeRequested
1 parent 633d894 commit 5286850

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

siprix_voip_sdk/lib/calls_model.dart

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class CallModel extends ChangeNotifier {
179179
bool _isCamMuted=false;
180180
bool _isRecStarted=false;
181181
bool _isUpgradingToVideo=false;
182+
bool _hasVideoUpgradeRequest=false;
182183
final ILogsModel? _logs;
183184

184185
/// State of this call
@@ -206,11 +207,16 @@ class CallModel extends ChangeNotifier {
206207
bool get isMicMuted => _isMicMuted;
207208
bool get isCamMuted => _isCamMuted;
208209
bool get isRecStarted => _isRecStarted;
209-
bool get isUpgradingToVideo => _isUpgradingToVideo;
210210
bool get isFilePlaying => _playerId!=0;
211211
bool get hasVideo => _hasVideo;
212212
int get playerId => _playerId;
213213

214+
215+
/// Returns true if app has invoked 'upgradeToVideo' (requested upgrade to video) and is waiting on response
216+
bool get isUpgradingToVideo => _isUpgradingToVideo;
217+
/// Returns true if app received request 'upgrade to video' from remote side (happens only if acc.upgradeToVideo=UpgradeToVideoMode.Manual)
218+
bool get hasVideoUpgradeRequest => _hasVideoUpgradeRequest;
219+
214220
/// Returns true if call put on hold by local side
215221
bool get isLocalHold => (_holdState==HoldState.local)||(_holdState==HoldState.localAndRemote);
216222
/// Returns true if call put on hold by remote side
@@ -415,7 +421,7 @@ class CallModel extends ChangeNotifier {
415421
}
416422
}
417423

418-
/// Upgrade call from audio only to audio+video
424+
/// Send to remote side request 'Upgrade call from audio only to audio+video'
419425
Future<void> upgradeToVideo()async {
420426
_logs?.print('Upgrade callId:$myCallId to audio+video');
421427

@@ -452,6 +458,19 @@ class CallModel extends ChangeNotifier {
452458
}
453459
}
454460

461+
/// Accept request 'upgrade to video' received from remote side. 'withVideo=false' - means [don't allow to start video]
462+
Future<void> acceptVideoUpgrade([bool withVideo=true]) async{
463+
_logs?.print('AcceptVideoUpgrade callId:$myCallId withVideo:$withVideo');
464+
try{
465+
await SiprixVoipSdk().acceptVideoUpgrade(myCallId, withVideo);
466+
_hasVideoUpgradeRequest = false;
467+
notifyListeners();
468+
} on PlatformException catch (err) {
469+
_logs?.print('Can\'t accept video upgrade callId:$myCallId Err: ${err.code} ${err.message}');
470+
return Future.error((err.message==null) ? err.code : err.message!);
471+
}
472+
}
473+
455474
/// Event handlers-------------
456475
457476
/// Handles 1xx responses received from remote side
@@ -470,7 +489,7 @@ class CallModel extends ChangeNotifier {
470489
notifyListeners();
471490
}
472491

473-
/// Handle upgrade to video
492+
/// Handle response of the upgrade to video request
474493
void onVideoUpgraded(bool withVideo, bool isUpgradeModeRecvOnly) {
475494
//Siprix mutes camera when upgrade video request received from remote side AND mode set as recvOnly
476495
if(withVideo && isUpgradeModeRecvOnly && !_isUpgradingToVideo) _isCamMuted = true;
@@ -480,6 +499,13 @@ class CallModel extends ChangeNotifier {
480499
notifyListeners();
481500
}
482501

502+
/// Handle request 'upgrade to video' received from remote side
503+
/// [!] In the event handler app HAS invoke 'acceptVideoUpgrade(true/false)'
504+
void onVideoUpgradeRequested() {
505+
_hasVideoUpgradeRequest = true;
506+
notifyListeners();
507+
}
508+
483509
/// Handle received DTMF tone
484510
void onDtmfReceived(int tone) {
485511
if(tone == 10) { _receivedDtmf += '*'; }else
@@ -783,9 +809,13 @@ class CallsModel extends ChangeNotifier {
783809
_callItems[index].onVideoUpgraded(withVideo, isUpgradeModeRecvOnly);
784810
}
785811

786-
/// Handle upgrade to video request
812+
/// Handle request 'upgrade to video' received from remote side
787813
void onVideoUpgradeRequested(int callId) {
788814
_logs?.print('onVideoUpgradeRequested callId:$callId');
815+
816+
int index = _callItems.indexWhere((c) => c.myCallId==callId);
817+
if(index != -1) _callItems[index].onVideoUpgradeRequested();
818+
789819
onVideoUpgradeRequestReceived?.call(callId);
790820
}
791821

0 commit comments

Comments
 (0)