onRoomStateChanged method

Future<void> onRoomStateChanged(
  1. SDNEvent event
)

Implementation

Future<void> onRoomStateChanged(SDNEvent event) async {
  final eventType = event.type;
  final roomId = event.roomId;
  if (eventType == EventTypes.GroupCallPrefix) {
    final groupCallId = event.stateKey;
    final content = event.content;
    final currentGroupCall = groupCalls[groupCallId];
    if (currentGroupCall == null && content['m.terminated'] == null) {
      await createGroupCallFromRoomStateEvent(event);
    } else if (currentGroupCall != null &&
        currentGroupCall.groupCallId == groupCallId) {
      if (content['m.terminated'] != null) {
        await currentGroupCall.terminate(emitStateEvent: false);
      } else if (content['m.type'] != currentGroupCall.type) {
        // TODO: Handle the callType changing when the room state changes
        Logs().w(
            'The group call type changed for room: $roomId. Changing the group call type is currently unsupported.');
      }
    } else if (currentGroupCall != null &&
        currentGroupCall.groupCallId != groupCallId) {
      // TODO: Handle new group calls and multiple group calls
      Logs().w(
          'Multiple group calls detected for room: $roomId. Multiple group calls are currently unsupported.');
    }
  } else if (eventType == EventTypes.GroupCallMemberPrefix) {
    final groupCall = groupCalls[roomId];
    if (groupCall == null) {
      return;
    }
    await groupCall.onMemberStateChanged(event);
  }
}