diff --git a/internal/asterisk/call.go b/internal/asterisk/call.go index 88eee26..a9c9bde 100644 --- a/internal/asterisk/call.go +++ b/internal/asterisk/call.go @@ -122,7 +122,9 @@ func dialWithClient(ctx context.Context, client ari.Client, request NativeDial) if call.subscription == nil { return nil, &NativeCallFailure{Phase: "subscribe", Cause: errors.New("native ARI channel subscription unavailable before origination")} } - call.outbound, err = client.Channel().Originate(key, originate) + // The reference key is an existing originator, not the new channel ID. + // ChannelID in originate already fixes this call's identity. + call.outbound, err = client.Channel().Originate(nil, originate) if err != nil { // The HTTP response can be lost after Asterisk has created the // channel. Do not originate again: try to stop the same identity. diff --git a/internal/asterisk/call_test.go b/internal/asterisk/call_test.go index a89ede9..e3d51bc 100644 --- a/internal/asterisk/call_test.go +++ b/internal/asterisk/call_test.go @@ -36,6 +36,7 @@ type testChannels struct { ari.Channel events chan ari.Event originate ari.OriginateRequest + originateRef *ari.Key media ari.ExternalMediaOptions issued int originateErr error @@ -44,8 +45,9 @@ type testChannels struct { mediaPeerIP string } -func (c *testChannels) Originate(_ *ari.Key, request ari.OriginateRequest) (*ari.ChannelHandle, error) { +func (c *testChannels) Originate(reference *ari.Key, request ari.OriginateRequest) (*ari.ChannelHandle, error) { c.issued++ + c.originateRef = reference c.originate = request if c.originateErr != nil { return nil, c.originateErr @@ -143,6 +145,7 @@ func TestNativeCallUsesOneARIOriginateAndActualRTPBridge(t *testing.T) { } if call.Media == nil || client.channels.issued != 1 || client.channels.originate.Endpoint != "PJSIP/708915000000001@shuqi" || client.channels.originate.CallerID != "BD1234" || client.channels.originate.ChannelID != "exec-1" || + client.channels.originateRef != nil || client.channels.originate.Originator != "" || client.channels.media.Format != "slin16" || client.channels.media.App != "go-sip-agent" || len(client.bridges.attached) != 2 || client.bridges.attached[0] != "exec-1" { t.Fatal("native channel/ExternalMedia was not attached exactly once to the approved bridge")