Add adds a message to the cache if there is a gap between the last sequence number and cached messages then return the cache State: - MigrationDataCacheStateWaiting: waiting for the next packet (lastSeq + 1) of last sequence from old node - MigrationDataCacheStateTimeout: the next packet is not rece
(pkt *livekit.DataPacket)
| 34 | // continue to process the reliable messages, subscribers will see the gap after the publisher migration |
| 35 | // - MigrationDataCacheStateDone: the next packet is received, participant can continue to process the reliable messages |
| 36 | func (c *MigrationDataCache) Add(pkt *livekit.DataPacket) MigrationDataCacheState { |
| 37 | if c.state == MigrationDataCacheStateDone || c.state == MigrationDataCacheStateTimeout { |
| 38 | return c.state |
| 39 | } |
| 40 | |
| 41 | if pkt.Sequence <= c.lastSeq { |
| 42 | return c.state |
| 43 | } |
| 44 | |
| 45 | if pkt.Sequence == c.lastSeq+1 { |
| 46 | c.state = MigrationDataCacheStateDone |
| 47 | return c.state |
| 48 | } |
| 49 | |
| 50 | c.pkts = append(c.pkts, pkt) |
| 51 | if time.Now().After(c.expiredAt) { |
| 52 | c.state = MigrationDataCacheStateTimeout |
| 53 | } |
| 54 | return c.state |
| 55 | } |
| 56 | |
| 57 | func (c *MigrationDataCache) Get() []*livekit.DataPacket { |
| 58 | return c.pkts |
no outgoing calls