Skip to content

emiago/sipgox

Repository files navigation

sipgox

is experimental/extra area to add more functionality on top sipgo lib, more specifically, to fill gap for building user agents with media. This allows much more easier voip testing or faster way to create UAC/UAS.

To find out more, read also article about E2E testing and check GO Documentation

NOTE: Media package (github.com/emiago/media) is now seperate repo.

If you find it useful, support sipgo lib, open issue etc...

Tools using this lib:

Features:

  • Simple API for UA/phone build with dial answer register actions
  • Minimal SDP package for audio
  • RTP/RTCP receiving and logging
  • Extendable MediaSession handling for RTP/RTCP handling (ex microphone,speaker)
  • Hangup control on caller
  • Timeouts handling
  • Digest auth
  • Transfers on phone answer, dial
  • DTMF on phone with simple API
  • ... who knows

Checkout echome example to see more.

Phone

Phone is wrapper that allows you to build phone in couple of lines. Then you can quickly create/receive SIP call, handle RTP/RTCP, etc... It uses sipgo.Dialog and media package.

NOTE: It has specific design for testing, and it can not be used for full softphone build.

Dialer

ua, _ := sipgo.NewUA()
defer ua.Close()

// Create a phone
phone := sipgox.NewPhone(ua) 

// Run dial
ctx, _ := context.WithTimeout(context.Background(), 60*time.Second)

// Blocks until call is answered
dialog, err := phone.Dial(ctx, sip.Uri{User:"bob", Host: "localhost", Port:5060}, sipgox.DialOptions{})
if err != nil {
    // handle error
    return
}
defer dialog.Close() // Close dialog for cleanup

select {
case <-dialog.Done():
    return
case <-time.After(5 *time.Second):
    dialog.Hangup(context.TODO())
}

Receiver

ctx, _ := context.WithCancel(context.Background())

ua, _ := sipgo.NewUA()
defer ua.Close()

// Create a phone
phone := sipgox.NewPhone(ua)

// Blocks until call is answered
dialog, err := phone.Answer(ctx, sipgox.AnswerOptions{
    Ringtime:  5* time.Second,
})
if err != nil {
    //handle error
    return
}
defer dialog.Close() // Close dialog for cleanup

select {
case <-dialog.Done():
    return
case <-time.After(10 *time.Second):
    dialog.Hangup(context.TODO())
}

Reading/Writing RTP/RTCP on dialog

After you Answer or Dial on phone, you receive dialog.

RTP

buf := make([]byte, media.RTPBufSize) // Has MTU size
pkt := rtp.Packet{}
err := dialog.ReadRTP(buf, &pkt)

err := dialog.WriteRTP(pkt)

similar is for RTCP