CallEvent.fromMap constructor

CallEvent.fromMap({
  1. required Map<Object?, Object?> event,
})

Implementation

factory CallEvent.fromMap({required Map<Object?, Object?> event}) {
  final callMap = event["call"] as Map<Object?, Object?>;
  final call = Utils.getCallFromMap(callMap);

  switch (event["event"] as String?) {
    case 'NEW':
      return CallNewEvent(call);
    case 'CONNECTED':
      return CallConnectedEvent(call);
    case 'ON_HOLD':
      return CallOnHoldEvent(call);
    case 'RESUMED':
      return CallResumedEvent(call);
    case 'ERROR':
      final err = CallError.fromString(event["error"] as String?);
      final msg = event["message"] as String?;
      return CallErrorEvent(call, error: err, message: msg ?? "");
    case 'DISCONNECTED':
      return CallDisconnectedEvent(call);
    case 'CONFERENCE':
      return CallConferenceEvent(call);
    case 'MUTE':
      return CallMuteEvent(call);
    default: // fall through
  }
  return CallErrorEvent(call,
      error: CallError.other, message: "Unknown error id");
}