runEventHandler processes events which are received from ARI
(ctx context.Context)
| 269 | |
| 270 | // runEventHandler processes events which are received from ARI |
| 271 | func (s *Server) runEventHandler(ctx context.Context) { |
| 272 | sub := s.ari.Bus().Subscribe(nil, ari.Events.All) |
| 273 | defer sub.Cancel() |
| 274 | |
| 275 | for { |
| 276 | s.Log.Debug("listening for events", "application", s.Application) |
| 277 | select { |
| 278 | case <-ctx.Done(): |
| 279 | return |
| 280 | case e := <-sub.Events(): |
| 281 | s.Log.Debug("event received", "kind", e.GetType()) |
| 282 | |
| 283 | // Publish event to canonical destination |
| 284 | s.publishEvent(fmt.Sprintf("%sevent.%s.%s", s.MBPrefix, s.Application, s.AsteriskID), e) |
| 285 | |
| 286 | // Publish event to any associated dialogs |
| 287 | for _, d := range s.dialogsForEvent(e) { |
| 288 | de := e |
| 289 | de.SetDialog(d) |
| 290 | s.publishEvent(fmt.Sprintf("%sdialogevent.%s", s.MBPrefix, d), de) |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | // pingHandler publishes the server's presence |
| 297 | func (s *Server) pingHandler() { |
no test coverage detected