|
@@ -77,6 +77,7 @@ func initOriginate(req *OriginateRequest, client *Client) *Originate {
|
|
|
eventChan: client.registerEventListener(req.uuid),
|
|
|
locker: new(sync.RWMutex),
|
|
|
client: client,
|
|
|
+ userEventChan: make(chan Event, 1),
|
|
|
}
|
|
|
go res.listenEvents()
|
|
|
return res
|
|
@@ -88,13 +89,13 @@ type Originate struct {
|
|
|
userEventChan chan Event
|
|
|
locker *sync.RWMutex
|
|
|
finished bool
|
|
|
- err error
|
|
|
client *Client
|
|
|
responseReason byte
|
|
|
hangupCause byte
|
|
|
}
|
|
|
|
|
|
func (s *Originate) listenEvents() {
|
|
|
+ defer log.Println("AMI-LISTENER-ORIGINATE-CLOSED")
|
|
|
for {
|
|
|
e, ok := <-s.eventChan
|
|
|
if !ok {
|
|
@@ -114,6 +115,11 @@ func (s *Originate) listenEvents() {
|
|
|
s.responseReason = byte(reasonVal)
|
|
|
}
|
|
|
log.Println("RREASON", s.responseReason)
|
|
|
+ if s.responseReason == 0 {
|
|
|
+ s.finished = true
|
|
|
+ close(s.userEventChan)
|
|
|
+ return
|
|
|
+ }
|
|
|
//if s.responseReason != 4 {
|
|
|
//s.client.removeEventListener(s.uuid)
|
|
|
//}
|
|
@@ -131,11 +137,5 @@ func (s *Originate) IsFinished() bool {
|
|
|
}
|
|
|
|
|
|
func (s *Originate) Events() (res <-chan Event) {
|
|
|
- s.locker.Lock()
|
|
|
- if s.userEventChan == nil {
|
|
|
- s.userEventChan = make(chan Event)
|
|
|
- }
|
|
|
- res = s.userEventChan
|
|
|
- s.locker.Unlock()
|
|
|
- return
|
|
|
+ return s.userEventChan
|
|
|
}
|