-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclient.go
71 lines (64 loc) · 2.04 KB
/
client.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 nighthawk
import (
//"fmt"
"log"
"net"
)
//The client struct is used to encapsulate a device (OS X or iOS).
type Client struct {
Name string //the name that the client is reporting
RTSPUrl string //the RTSP stream URL
Codec []byte //The video codec info
deviceIP string //The IP of the client
aesKey []byte //crypto keys
aesIV []byte //crypto keys
deviceID string //the Apple device ID a (hex value of the client)
serverLn *udpListener //the server udp listener
controlLn *udpListener //the control udp listener
timeSvr *timeServer //the udp time server
mirrorTimeSvr *timeServer //the udp time server of the screen mirroring
}
//setup the UDP ports. port is the timing port for the timeServer
//returns the 3 udp ports created. server port, then control port, then the time server port
func (c *Client) setup(timePort int, serverHandler func(b []byte, size int)) (int, int, int) {
c.serverLn = createUDPListener()
go c.serverLn.start(func(b []byte, size int, addr *net.Addr) {
//decrypt audio packets
serverHandler(b, size)
})
c.controlLn = createUDPListener()
go c.controlLn.start(func(b []byte, size int, addr *net.Addr) {
//process Sync packets
log.Println("Sync packet!")
})
c.timeSvr = createTimeServer(timePort, c.deviceIP)
return c.serverLn.port, c.controlLn.port, c.timeSvr.listener.port
}
//start the audio stream by starting client's time server
func (c *Client) start() {
go c.timeSvr.start()
}
//start the audio stream
func (c *Client) stop() {
c.timeSvr.stop()
}
//stop the udp listeners and cleanup things
func (c *Client) teardown() {
if c.mirrorTimeSvr != nil {
c.mirrorTimeSvr.stop()
}
if c.timeSvr != nil {
c.timeSvr.stop()
}
if c.controlLn != nil {
c.controlLn.stop()
}
if c.serverLn != nil {
c.serverLn.stop()
}
}
//start the mirroring stream by starting client's time server
func (c *Client) startMirror() {
c.mirrorTimeSvr = createMirrorTimeServer(c.deviceIP)
go c.mirrorTimeSvr.start()
}