forked from percipia/eslgo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
unicast.go
54 lines (50 loc) · 1.48 KB
/
unicast.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
/*
* Copyright (c) 2020 Percipia
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* Contributor(s):
* Andrew Querol <aquerol@percipia.com>
*/
package call
import (
"net"
"net/textproto"
"github.com/AkronimBlack/eslgo/command"
)
/*
* unicast is used to hook up mod_spandsp for faxing over a socket.
* Note:
* That is a nice way for a script or app that uses the socket interface to get at the media.
* It's good because then spandsp isn't living inside of FreeSWITCH and it can run on a box sitting next to it. It scales better.
*/
type Unicast struct {
UUID string
Local net.Addr
Remote net.Addr
Flags string
Sync bool
SyncPri bool
}
func (u Unicast) BuildMessage() string {
sendMsg := command.SendMessage{
UUID: u.UUID,
Headers: make(textproto.MIMEHeader),
Sync: u.Sync,
SyncPri: u.SyncPri,
}
localHost, localPort, _ := net.SplitHostPort(u.Local.String())
remoteHost, remotePort, _ := net.SplitHostPort(u.Remote.String())
sendMsg.Headers.Set("call-command", "unicast")
sendMsg.Headers.Set("local-ip", localHost)
sendMsg.Headers.Set("local-port", localPort)
sendMsg.Headers.Set("remote-ip", remoteHost)
sendMsg.Headers.Set("remote-port", remotePort)
sendMsg.Headers.Set("transport", u.Local.Network())
if len(u.Flags) > 0 {
sendMsg.Headers.Set("flags", u.Flags)
}
return sendMsg.BuildMessage()
}