-
Notifications
You must be signed in to change notification settings - Fork 4
/
default.go
71 lines (58 loc) · 1.8 KB
/
default.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package sip
import (
"github.com/curltech/go-colla-core/config"
"github.com/curltech/go-colla-core/logger"
"github.com/curltech/go-colla-node/webrtc/sip/softphone"
"github.com/pion/sdp/v2"
)
var (
username, _ = config.GetString("sip.username", "1000")
password, _ = config.GetString("sip.password", "")
extension, _ = config.GetString("sip.extension", "9198")
host, _ = config.GetString("sip.host", "")
port, _ = config.GetString("sip.port", "5066")
)
func start() {
if host == "" || port == "" || password == "" {
logger.Sugar.Errorf("-host -port and -password are required")
return
}
conn := softphone.NewSoftPhone(softphone.SIPInfoResponse{
Username: username,
AuthorizationID: username,
Password: password,
Domain: host,
Transport: "ws",
OutboundProxy: host + ":" + port,
})
conn.OnOK(func(okBody string) {
answer := okBody + "a=mid:0\r\n"
logger.Sugar.Infof("%v", answer)
})
offer := ""
conn.Invite(extension, rewriteSDP(offer))
select {}
}
// Apply the following transformations for FreeSWITCH
// * Add fake srflx candidate to each media section
// * Add msid to each media section
// * Make bundle first attribute at session level.
func rewriteSDP(in string) string {
parsed := &sdp.SessionDescription{}
if err := parsed.Unmarshal([]byte(in)); err != nil {
panic(err)
}
// Reverse global attributes
for i, j := 0, len(parsed.Attributes)-1; i < j; i, j = i+1, j-1 {
parsed.Attributes[i], parsed.Attributes[j] = parsed.Attributes[j], parsed.Attributes[i]
}
parsed.MediaDescriptions[0].Attributes = append(parsed.MediaDescriptions[0].Attributes, sdp.Attribute{
Key: "candidate",
Value: "79019993 1 udp 1686052607 1.1.1.1 9 typ srflx",
})
out, err := parsed.Marshal()
if err != nil {
panic(err)
}
return string(out)
}