callMemberStateIsExpired method

bool callMemberStateIsExpired(
  1. SDNEvent groupCallMemberStateEvent,
  2. String groupCallId
)

Implementation

bool callMemberStateIsExpired(
    SDNEvent groupCallMemberStateEvent, String groupCallId) {
  final callMemberState =
      IGroupCallRoomMemberState.fromJson(groupCallMemberStateEvent);
  final calls = callMemberState.calls;
  if (calls.isNotEmpty) {
    final call =
        calls.singleWhereOrNull((call) => call.call_id == groupCallId);
    if (call != null) {
      return call.devices.where((device) => device.expires_ts != null).every(
          (device) =>
              device.expires_ts! < DateTime.now().millisecondsSinceEpoch);
    }
  }

  // Last 30 seconds to get yourself together.
  // This saves us from accidentally killing calls which were just created and
  // whose state event we haven't recieved yet in sync.
  // (option 2 was local echo member state events, but reverting them if anything
  // fails sounds pain)

  final expiredfr = groupCallMemberStateEvent.originServerTs
          .add(staleCallCheckerDuration)
          .millisecondsSinceEpoch <
      DateTime.now().millisecondsSinceEpoch;
  if (!expiredfr) {
    Logs().d(
        '[VOIP] Last 30 seconds for state event from ${groupCallMemberStateEvent.senderId}');
  }
  return expiredfr;
}