declineCall static method
Future<bool>
declineCall({
- required String url,
- required String deviceId,
- required Object callId,
- String? token,
- TokenProvider? getToken,
- Duration timeout = const Duration(seconds: 10),
- CalloopTransport? transport,
Decline a call without the app's agent: connect, send call:reject, close. For a Decline tapped on the native screen while the app isn't running. The connection is auxiliary (purpose 'decline'): it takes no part in presence, and Calloop doesn't redeliver the ringing call to it.
Implementation
static Future<bool> declineCall({
required String url,
required String deviceId,
required Object callId,
String? token,
TokenProvider? getToken,
Duration timeout = const Duration(seconds: 10),
CalloopTransport? transport,
}) async {
CalloopAgent? agent;
try {
// Not CalloopAgent.connect: on a timeout its agent would be lost, still connecting.
agent = CalloopAgent(
url: url, deviceId: deviceId, token: token, getToken: getToken, media: const _NoMedia(), transport: transport,
purpose: 'decline',
);
await agent.ready.timeout(timeout);
agent.send('call:reject', {'callId': callId});
await Future<void>.delayed(const Duration(milliseconds: 500)); // let the emit leave before closing
return true;
} catch (_) {
return false;
} finally {
agent?.close();
}
}