forked from loreste/siprec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sipgo.go
48 lines (37 loc) · 1.06 KB
/
test_sipgo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Package test_sipgo provides a test for the sipgo API
// To use this test, rename the package to main and run with go run test_sipgo.go
package test_sipgo
import (
"fmt"
"net"
"github.com/emiago/sipgo"
"github.com/emiago/sipgo/sip"
"github.com/sirupsen/logrus"
)
// TestSipGo tests the sipgo API
func TestSipGo() {
fmt.Println("Testing sipgo API")
logger := logrus.New()
// Create IP addresses for SIP listening
hostIPs := []net.IP{net.ParseIP("127.0.0.1")}
// Create user agent - v0.30.0 style
ua, err := sipgo.NewUA()
if err != nil {
logger.Fatalf("Failed to create user agent: %s", err)
}
// Set logger manually if needed
// ua.Log = logger
// Create server
server, err := sipgo.NewServer(ua)
if err != nil {
logger.Fatalf("Failed to create server: %s", err)
}
// Print types
fmt.Printf("UA type: %T\n", ua)
fmt.Printf("Server type: %T\n", server)
// Register a handler directly on server
server.OnInvite(func(req *sip.Request, tx sip.ServerTransaction) {
fmt.Println("Got INVITE")
})
fmt.Println("SipGo API test completed")
}