fromJson static method
Creates instance of CallModel with values read from json
Implementation
static CallModel? fromJson(Map<dynamic, dynamic> jsonMap, ILogsModel? logs) {
//Read required attributes
int? myCallId;
String? accUri, remoteExt;
bool? isIncoming, hasSecureMedia, hasVideo;
jsonMap.forEach((key, value) {
if ((key == 'myCallId') && (value is int)) {
myCallId = value;
} else if ((key == 'accUri') && (value is String)) {
accUri = value;
} else if ((key == 'remoteExt') && (value is String)) {
remoteExt = value;
} else if ((key == 'isIncoming') && (value is bool)) {
isIncoming = value;
} else if ((key == 'hasSecureMedia') && (value is bool)) {
hasSecureMedia = value;
} else if ((key == 'hasVideo') && (value is bool)) {
hasVideo = value;
}
});
//Check if present
if ((myCallId == null) ||
(accUri == null) ||
(remoteExt == null) ||
(isIncoming == null) ||
(hasSecureMedia == null) ||
(hasVideo == null)) {
return null;
}
//Create new inst
CallModel call = CallModel(
myCallId!,
accUri!,
remoteExt!,
isIncoming!,
hasSecureMedia!,
hasVideo!,
logs,
);
//Read the rest values
jsonMap.forEach((key, value) {
if ((key == 'displName') && (value is String)) {
call.displName = value;
} else if ((key == 'receivedDtmf') && (value is String)) {
call._receivedDtmf = value;
} else if ((key == 'response') && (value is String)) {
call._response = value;
} else if ((key == 'state') && (value is int)) {
call._state = CallState.from(value);
} else if ((key == 'holdState') && (value is int)) {
call._holdState = HoldState.from(value);
} else if ((key == 'startTime') && (value is int)) {
call._startTime = DateTime.fromMillisecondsSinceEpoch(value);
}
if ((key == 'playerId') && (value is int)) {
call._playerId = value;
} else if ((key == 'isMicMuted') && (value is bool)) {
call._isMicMuted = value;
} else if ((key == 'isCamMuted') && (value is bool)) {
call._isCamMuted = value;
} else if ((key == 'isRecStarted') && (value is bool)) {
call._isRecStarted = value;
} else if ((key == 'isUpgradingToVideo') && (value is bool)) {
call._isUpgradingToVideo = value;
} else if ((key == 'hasVideoUpgradeRequest') && (value is bool)) {
call._hasVideoUpgradeRequest = value;
}
});
//Update duration
call.calcDuration();
return call;
}