telegabber/calls/signaling/xmppsig/callee.go
2026-05-27 08:37:47 -07:00

75 lines
1.8 KiB
Go

package xmppsig
import (
"context"
"dev.narayana.im/narayana/telegabber/calls/signaling"
"dev.narayana.im/narayana/telegabber/xmpp/jingle"
log "github.com/sirupsen/logrus"
)
// xmpp-side Callee for XMPP-originated calls; the gateway is the JMI responder
type Callee struct {
xmppBase
}
func (c *Callee) Ringing() {
sess := c.sessionRef()
if sess == nil || sess.State() != jingle.StateRinging {
return
}
if err := sess.Ringing(context.Background()); err != nil {
log.WithField("remote", c.remote).WithError(err).Debug("xmppsig.Callee.Ringing: send failed")
}
}
func (c *Callee) Accept() {
sess := c.sessionRef()
if sess == nil {
return
}
if err := sess.AcceptProposal(context.Background()); err != nil {
log.WithField("remote", c.remote).WithError(err).Error("xmppsig.Callee.Accept: AcceptProposal failed")
if b := c.bridgeRef(); b != nil {
go b.Terminate(signaling.ReasonUnknown)
}
}
}
// pick the right verb for the current session state: Close, Decline, or
// session-terminate
func (c *Callee) Terminate(reason signaling.TerminationReason) {
sess := c.sessionRef()
cond := mapReason(reason)
var err error
switch sess.State() {
case jingle.StateNew:
err = sess.Close()
case jingle.StateRinging:
err = sess.Decline(context.Background(), cond)
case jingle.StateTerminated:
// already torn down
default:
err = sess.Terminate(context.Background(), cond)
}
if err != nil {
log.WithError(err).Debug("xmppsig.Callee.Terminate: tear-down send failed")
}
c.cleanup()
}
// never fire on the responder side
func (c *Callee) OnRinging(_ string) {}
func (c *Callee) OnProceeded(_ string) {}
func (c *Callee) OnRemoteDescriptionApplied(sdp string) {
c.onRemoteDescription(sdp)
}
func (c *Callee) OnTerminated(reason string) {
if b := c.bridgeRef(); b != nil {
go b.Terminate(reasonFromCondition(reason))
}
c.cleanup()
}