Getting started
diago acts as UAS(User Agent Server) and UAC(User Agent Client). For now it keeps abstractions only where it needs. +Therefore it distincts your dialog control by:
+-
+
- It receives
DialogServerSession
for serving incoming sessions(Call leg)
+ - It creates
DialogClientSession
when it Dials outgoing session(Call leg)
+
Further it is explicit which media stack it uses
+-
+
Answer
-> RTP/UDP
+AnswerWebrtc
-> Webrtc stack SRTP/DTLS
+
Setup diago: +
ua, _ := sipgo.NewUA()
+transportUDP := diago.Transport{
+ Transport: "udp",
+ BindHost: "127.0.0.1",
+ BindPort: 5060,
+}
+
+transportTCP := diago.Transport{
+ Transport: "tcp",
+ BindHost: "127.0.0.1",
+ BindPort: 5060,
+}
+
+d := diago.NewDiago(ua,
+ diago.WithTransport(transportUDP),
+ diago.WithTransport(transportTCP),
+)
Incoming call +
d.Serve(ctx, func(inDialog *diago.DialogServerSession) {
+ // - Do your call routing.
+ switch inDialog.ToUser() {
+ case "answer":
+ case "123456"
+ }
+})
Outgoing +
dialog, err := d.Dial(ctx, recipient sip.Uri, bridge *Bridge, opts sipgo.AnswerOptions)
+dialog.Hangup()
Answering call +
func Answer(inDialog *diago.DialogServerSession) {
+ inDialog.Progress() // Progress -> 100 Trying
+ inDialog.Ringing() // Ringing -> 180 Response
+
+ if err := inDialog.Answer(); err != nil {
+ fmt.Println("Failed to answer", err)
+ return
+ }
+
+ ctx := inDialog.Context()
+ select {
+ case <-ctx.Done():
+ case <-time.After(1 * time.Minute):
+ }
+}
Playing file with Playback +
Playing file is done by playback.
+Supported formats:
+-
+
- wav (PCM) +
func Playback(inDialog *diago.DialogServerSession) {
+ inDialog.Ringing()
+
+ playfile, err := os.Open("demo-instruct.wav")
+ if err != nil {
+ fmt.Println("Failed to open file", err)
+ return
+ }
+
+ pb, err := inDialog.PlaybackCreate()
+ if err != nil {
+ fmt.Println("Failed to create playback", err)
+ return
+ }
+
+ if err := inDialog.Answer(); err != nil {
+ fmt.Println("Failed to answer", err)
+ return
+ }
+
+ if err := pb.Play(playfile, "audio/wav"); err != nil {
+ fmt.Println("Playing failed", err)
+ }
+}