MCPcopy Create free account
hub / github.com/CyCoreSystems/ari-proxy / channelHandler

Function channelHandler

_examples/stasisStart/main.go:84–133  ·  view source on GitHub ↗
(h *ari.ChannelHandle, startEvent *ari.StasisStart)

Source from the content-addressed store, hash-verified

82}
83
84func channelHandler(h *ari.ChannelHandle, startEvent *ari.StasisStart) {
85 log.Info("Running channel handler")
86
87 // Subscribe to channel state changes
88 stateChange := h.Subscribe(ari.Events.ChannelStateChange)
89 defer stateChange.Cancel()
90
91 // Subscribe to StasisEnd events (channel leaving ARI app)
92 end := h.Subscribe(ari.Events.StasisEnd)
93 defer end.Cancel()
94
95 // Pull the current channel data
96 data, err := h.Data()
97 if err != nil {
98 log.Error("Error getting data", "error", err)
99 return
100 }
101 log.Info("Channel State", "state", data.State)
102
103 var wg sync.WaitGroup
104
105 wg.Add(1)
106 go func() {
107 log.Info("Waiting for channel events")
108
109 defer wg.Done()
110
111 for {
112 select {
113 case <-end.Events():
114 log.Info("Got stasis end")
115 return
116 case e := <-stateChange.Events():
117 v, ok := e.(*ari.ChannelStateChange)
118 if !ok {
119 log.Error("failed to interpret event as ChannelStateChange", "error", err)
120 return
121 }
122
123 log.Info("New Channel State", "state", v.Channel.State)
124 }
125 }
126 }()
127
128 h.Answer()
129
130 wg.Wait()
131
132 h.Hangup()
133}

Callers

nothing calls this directly

Calls 10

InfoMethod · 0.80
CancelMethod · 0.80
DoneMethod · 0.80
EventsMethod · 0.80
AnswerMethod · 0.80
HangupMethod · 0.80
SubscribeMethod · 0.45
DataMethod · 0.45
ErrorMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected