func toIngestionRecord()

in AmazonChimeSDK/AmazonChimeSDK/ingestion/IngestionEventConverter.swift [91:138]


    func toIngestionRecord(meetingEvents: [MeetingEventItem], ingestionConfiguration: IngestionConfiguration) -> IngestionRecord {
        if meetingEvents.isEmpty {
            return IngestionRecord(metadata: [:], events: [])
        }
        // TODO: Group by meeting ID won't work since attendees can rejoin with different attendeeID
        let meetingEventsByMeetingId = Dictionary(grouping: meetingEvents,
                                                  by: { $0.data.getMeetingId() })

        let type = ingestionConfiguration.clientConfiguration.tag

        // When sending a batch, server accepts the data as
        // "events": [
        //   {
        //      "metadata": { "meetingId": "meetingId2" } // This overrides record level metadata
        //      "type": "Meet",
        //      "v": 1,
        //      "payloads": []
        //   },
        //   {
        //      "metadata": { "meetingId": "meetingId1" } // This overrides record level metadata
        //      "type": "Meet",
        //      "v": 1,
        //      "payloads": []
        //   },
        // ]
        // This is to group events so that it contains different metadata to override
        let ingestionEvents = meetingEventsByMeetingId.compactMap { (group) -> IngestionEvent? in
            if let sampleMeetingEventItem = group.value.first {
                // TODO: Using first event as sample for retrieveing metadata won't always work, since attendees can rejoin with different attendeeIDs
                let metadata = toIngestionMetadata(ingestionMeetingEvent: sampleMeetingEventItem.data,
                                                   clientConfig: ingestionConfiguration.clientConfiguration)
                let payloads = group.value.map {
                    toIngestionPayload(meetingEventItemId: $0.id,
                                       meetingEvent: $0.data,
                                       dirtyMeetingEventTtl: nil)
                }
                return IngestionEvent(type: type,
                                      metadata: metadata,
                                      payloads: payloads)
            }
            return nil
        }

        let rootMeta = toIngestionMetadata(attributes: EventAttributeUtils.getCommonAttributes(ingestionConfiguration: ingestionConfiguration))

        return IngestionRecord(metadata: rootMeta,
                               events: ingestionEvents)
    }