40 lines
1.4 KiB
Go
40 lines
1.4 KiB
Go
package sipcall
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"git.ipao.vip/rogee/go-sip/internal/asterisk"
|
|
"git.ipao.vip/rogee/go-sip/internal/callflow"
|
|
)
|
|
|
|
type nativeAIActiveCall struct {
|
|
call *asterisk.NativeCall
|
|
}
|
|
|
|
func (c *nativeAIActiveCall) MediaSession() callflow.MediaSession { return c.call.Media }
|
|
func (c *nativeAIActiveCall) Done() context.Context { return c.call.Context }
|
|
func (c *nativeAIActiveCall) Close() error { return c.call.Close() }
|
|
func (c *nativeAIActiveCall) EndConfirmed() bool { return c.call.EndConfirmed() }
|
|
func (c *nativeAIActiveCall) AnsweredAt() time.Time { return c.call.AnsweredAt() }
|
|
func (c *nativeAIActiveCall) ConnectedEndedAt() time.Time { return c.call.ConnectedEndedAt() }
|
|
|
|
// DialAI uses the existing full-media Agent ARI originate path. The line-test
|
|
// ARI application is closed first while the host lock remains held; CheckIdle
|
|
// already proved no other application was active before switching apps.
|
|
func (h *nativeHost) DialAI(ctx context.Context, request asterisk.NativeDial) (aiActiveCall, error) {
|
|
if h.client != nil {
|
|
h.client.Close()
|
|
h.client = nil
|
|
}
|
|
call, err := (asterisk.Loader{ConfigDir: h.config.ConfigDir}).Originate(ctx, request)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if call == nil {
|
|
return nil, errors.New("native AI originate returned no call")
|
|
}
|
|
return &nativeAIActiveCall{call: call}, nil
|
|
}
|