Documentation
¶
Overview ¶
Package hooks defines optional callbacks for call lifecycle and recording delivery.
No database or ORM types live here — applications implement these interfaces (GORM, object storage, CDR export, etc.) and wire them at gateway/session setup.
Recording split:
- protocol/sipmedia/session keeps lightweight in-memory SN3 RTP capture (RTP timing, transfer-bridge paths). That is SIP/RTP plumbing, not business recording.
- Stereo PCM export, WAV/MP3 encoding, and durable storage are implemented via RecordingSink in protocol/voice or the application layer.
Index ¶
- Variables
- type CallMeta
- type Direction
- type HangupInitiator
- type HangupMeta
- type LifecycleSink
- type NopLifecycle
- func (NopLifecycle) OnBridgeStarted(string, string)
- func (NopLifecycle) OnBye(CallMeta, HangupMeta, RecordingArtifact)
- func (NopLifecycle) OnEstablished(CallMeta)
- func (NopLifecycle) OnFailed(CallMeta, HangupMeta)
- func (NopLifecycle) OnRinging(CallMeta)
- func (NopLifecycle) OnTransferStarted(CallMeta, string)
- type NopRecording
- type RecordingArtifact
- type RecordingChannel
- type RecordingFormat
- type RecordingResult
- type RecordingSink
- type Registry
Constants ¶
This section is empty.
Variables ¶
var DefaultRegistry = Registry{ Lifecycle: NopLifecycle{}, Recording: NopRecording{}, }
DefaultRegistry uses nop sinks until the application replaces them.
Functions ¶
This section is empty.
Types ¶
type CallMeta ¶
type CallMeta struct {
CallID string
CorrelationID string // inbound Call-ID for outbound transfer legs
Direction Direction
Scenario string // e.g. outbound.ScenarioTransferAgent — opaque string avoids import cycles
TenantID uint
RemoteAddr string
LocalIP string
Codec string
StartedAt time.Time
}
CallMeta is the minimal call context passed to lifecycle sinks.
type HangupInitiator ¶
type HangupInitiator string
HangupInitiator identifies who ended the dialog.
const ( HangupLocal HangupInitiator = "local" HangupRemote HangupInitiator = "remote" HangupUnknown HangupInitiator = "unknown" )
type HangupMeta ¶
type HangupMeta struct {
Initiator HangupInitiator
SIPCode int // final SIP status when known (0 if N/A)
Reason string // SIP phrase or internal reason
Duration time.Duration
EndedAt time.Time
}
HangupMeta accompanies OnBye / OnFailed.
type LifecycleSink ¶
type LifecycleSink interface {
// OnRinging is an optional early hook (180/183). No-op default: use NopLifecycle.
OnRinging(meta CallMeta)
// OnEstablished fires after ACK (inbound UAS) or outbound 200+ACK.
OnEstablished(meta CallMeta)
// OnTransferStarted fires when a B2BUA transfer dial begins (REFER or AI transfer).
OnTransferStarted(inbound CallMeta, targetURI string)
// OnBridgeStarted fires when two-leg media bridge is active.
OnBridgeStarted(inboundCallID, outboundCallID string)
// OnBye fires when a dialog ends cleanly (BYE completed or local teardown).
OnBye(meta CallMeta, hangup HangupMeta, recording RecordingArtifact)
// OnFailed fires when setup or transfer fails before a stable bridge.
OnFailed(meta CallMeta, hangup HangupMeta)
}
LifecycleSink receives call state transitions. All methods must be non-blocking or fast; heavy work should be queued by the implementation.
type NopLifecycle ¶
type NopLifecycle struct{}
NopLifecycle is a sink that ignores all events.
func (NopLifecycle) OnBridgeStarted ¶
func (NopLifecycle) OnBridgeStarted(string, string)
func (NopLifecycle) OnBye ¶
func (NopLifecycle) OnBye(CallMeta, HangupMeta, RecordingArtifact)
func (NopLifecycle) OnEstablished ¶
func (NopLifecycle) OnEstablished(CallMeta)
func (NopLifecycle) OnFailed ¶
func (NopLifecycle) OnFailed(CallMeta, HangupMeta)
func (NopLifecycle) OnRinging ¶
func (NopLifecycle) OnRinging(CallMeta)
func (NopLifecycle) OnTransferStarted ¶
func (NopLifecycle) OnTransferStarted(CallMeta, string)
type NopRecording ¶
type NopRecording struct{}
NopRecording ignores all recording hooks.
func (NopRecording) AppendPCM ¶
func (NopRecording) AppendPCM(string, RecordingChannel, []byte)
func (NopRecording) BeginRecording ¶
func (NopRecording) BeginRecording(CallMeta, int, string) bool
func (NopRecording) FinishRecording ¶
func (NopRecording) FinishRecording(context.Context, RecordingArtifact) (RecordingResult, error)
type RecordingArtifact ¶
type RecordingArtifact struct {
CallID string
Format RecordingFormat
Payload []byte // SN3 blob or app-defined PCM container
Codec string
SampleRate int
Channels int // 1 mono taps, 2 when stereo PCM sink merged
}
RecordingArtifact is what the SIP stack can hand off at hangup without knowing storage backend.
type RecordingChannel ¶
type RecordingChannel int
RecordingChannel separates caller vs agent/AI halves in stereo PCM taps.
const ( ChannelCaller RecordingChannel = iota ChannelAgent )
type RecordingFormat ¶
type RecordingFormat string
RecordingFormat identifies in-memory capture encodings produced by the SIP stack.
const ( // FormatSN3 is the session-layer RTP blob (magic "SN3", dir/seq/ts/wallNs/payload frames). FormatSN3 RecordingFormat = "sn3" // FormatStereoPCM is optional live stereo PCM from WriteCallerPCM / WriteAIPCM taps. FormatStereoPCM RecordingFormat = "stereo_pcm" )
type RecordingResult ¶
RecordingResult is an opaque durable handle returned by RecordingSink.
type RecordingSink ¶
type RecordingSink interface {
// BeginRecording returns false to disable taps for this call (SN3 capture may still run in session).
BeginRecording(meta CallMeta, sampleRate int, codec string) bool
// AppendPCM delivers mono PCM16 LE frames during the call (transfer bridge / voice pipeline).
// Implementations must copy pcm if retained beyond the call.
AppendPCM(callID string, ch RecordingChannel, pcm []byte)
// FinishRecording is invoked once at hangup with the SN3 artifact (may be nil/empty).
// Return a durable reference (URL, object key) for LifecycleSink.OnBye if needed.
FinishRecording(ctx context.Context, artifact RecordingArtifact) (RecordingResult, error)
}
RecordingSink receives live PCM taps and/or the final SN3 blob at call end. Implementations may write to object storage, enqueue transcode, or persist CDR URLs.
The SIP stack calls these hooks; it does not encode WAV, upload files, or touch a database.
type Registry ¶
type Registry struct {
Lifecycle LifecycleSink
Recording RecordingSink
}
Registry holds optional sinks wired once at process startup.