WebSocketAnnotation.fromAnnotation constructor
WebSocketAnnotation.fromAnnotation(})
Implementation
factory WebSocketAnnotation.fromAnnotation(
DartObject annotation, {
required String name,
required String? path,
}) {
final modeRaw = getFieldObjectFromDartObject(annotation, 'mode');
final modeName = modeRaw?.getField('_name')?.toStringValue();
var mode = WebSocketMode.twoWay;
if (modeName != null) {
mode = WebSocketMode.values.byName(modeName);
}
Duration? ping;
if (getFieldObjectFromDartObject(annotation, 'ping') case final pingRaw?) {
if (pingRaw.getField('_duration')?.toIntValue() case final duration?) {
ping = Duration(microseconds: duration);
}
}
final triggerOnConnect =
getFieldObjectFromDartObject(annotation, 'triggerOnConnect')
?.toBoolValue() ??
false;
return WebSocketAnnotation(
name,
mode: mode,
ping: ping,
path: path,
triggerOnConnect: triggerOnConnect,
);
}