sendEventToEndpoint method

Future<void> sendEventToEndpoint(
  1. List<VideoEvent> childEvents
)

Implementation

Future<void> sendEventToEndpoint(List<VideoEvent> childEvents) async {
  final uri = Uri.parse(CLD_ANALYTICS_ENDPOINT_PRODUCTION_URL);
  final request = http.MultipartRequest('POST', uri);

  final boundary = 'Boundary-${VideoAnalyticsHelper.generateUuid()}';
  request.headers['Content-Type'] = 'multipart/form-data; boundary=$boundary';
  request.headers['User-Agent'] = 'ios_video_player_analytics_test';

  // Add events data as a file
  final eventsFile = await buildEventsData(childEvents);
  request.files.add(eventsFile);

  // Add other fields if needed
  request.fields['userId'] = userId;
  request.fields['viewId'] = viewId;

  final response = await http.Response.fromStream(await request.send());

  if (response.statusCode >= 200 && response.statusCode < 300) {
    print('Event sent successfully');
  } else {
    print('Failed to send event. Response: ${response.body}');
  }
}