Skip to content

emiago/sipgox

Repository files navigation

sipgox

is experimental/extra area to add more functionality on top sipgo lib,

To find out more check GO Documentation


NOTE: All media and phone development is moved to diago lib project. Diago offers more correct way of building phones or servers. Please do not use this. This repo will keep focus only SIP extra things in future, and it will probably remove phone feature.


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

Checkout echome example to see more.

Phone (Deprecated, use diago)

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

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