(dispatchID string)
| 900 | } |
| 901 | |
| 902 | func (r *Room) DeleteAgentDispatch(dispatchID string) (*livekit.AgentDispatch, error) { |
| 903 | r.lock.Lock() |
| 904 | ad := r.agentDispatches[dispatchID] |
| 905 | if ad == nil { |
| 906 | r.lock.Unlock() |
| 907 | return nil, psrpc.NewErrorf(psrpc.NotFound, "dispatch ID not found") |
| 908 | } |
| 909 | |
| 910 | delete(r.agentDispatches, dispatchID) |
| 911 | r.lock.Unlock() |
| 912 | |
| 913 | // Should Delete be synchronous instead? |
| 914 | go func() { |
| 915 | ad.waitForPendingJobs() |
| 916 | |
| 917 | var jobs []*livekit.Job |
| 918 | r.lock.RLock() |
| 919 | if ad.State != nil { |
| 920 | jobs = ad.State.Jobs |
| 921 | } |
| 922 | r.lock.RUnlock() |
| 923 | |
| 924 | for _, j := range jobs { |
| 925 | state, err := r.agentClient.TerminateJob(context.Background(), j.Id, rpc.JobTerminateReason_TERMINATION_REQUESTED) |
| 926 | if err != nil { |
| 927 | continue |
| 928 | } |
| 929 | if state.ParticipantIdentity != "" { |
| 930 | r.lock.RLock() |
| 931 | agentJob := r.agentParticpants[livekit.ParticipantIdentity(state.ParticipantIdentity)] |
| 932 | p := r.participants[livekit.ParticipantIdentity(state.ParticipantIdentity)] |
| 933 | r.lock.RUnlock() |
| 934 | |
| 935 | if p != nil { |
| 936 | if agentJob != nil { |
| 937 | err := agentJob.waitForParticipantLeaving() |
| 938 | if err == ErrJobShutdownTimeout { |
| 939 | r.logger.Infow("Agent Worker did not disconnect after 3s") |
| 940 | } |
| 941 | } |
| 942 | r.RemoveParticipant(p.Identity(), p.ID(), types.ParticipantCloseReasonServiceRequestRemoveParticipant) |
| 943 | } |
| 944 | } |
| 945 | r.lock.Lock() |
| 946 | j.State = state |
| 947 | r.lock.Unlock() |
| 948 | } |
| 949 | }() |
| 950 | |
| 951 | return ad.AgentDispatch, nil |
| 952 | } |
| 953 | |
| 954 | func (r *Room) OnRoomUpdated(f func()) { |
| 955 | r.onRoomUpdated = f |
nothing calls this directly
no test coverage detected