Watch
1
0
Fork
You've already forked arc
0
forked from hesabix/arc
arc/hesabixUI/hesabix_ui/lib/services/telephony/softphone_ringtone_io.dart
2026-08-09 02:35:57 +03:30

40 lines
994 B
Dart

import 'dart:async';
import 'package:flutter/services.dart';
/// زنگ ورودی روی موبایل/دسکتاپ — هشدار سیستم + ویبره.
class SoftphoneRingtone {
Timer? _cadence;
bool _playing = false;
bool get isPlaying => _playing;
Future<void> start() async {
if (_playing) return;
_playing = true;
await _burst();
_cadence?.cancel();
_cadence = Timer.periodic(const Duration(milliseconds: 2800), (_) {
if (_playing) unawaited(_burst());
});
}
Future<void> _burst() async {
try {
await SystemSound.play(SystemSoundType.alert);
} catch (_) {}
try {
await HapticFeedback.heavyImpact();
await Future<void>.delayed(const Duration(milliseconds: 180));
await HapticFeedback.mediumImpact();
} catch (_) {}
}
Future<void> stop() async {
_playing = false;
_cadence?.cancel();
_cadence = null;
}
}
SoftphoneRingtone createPlatformSoftphoneRingtone() => SoftphoneRingtone();