-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
89 lines (74 loc) · 2.94 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"time"
"go.nanomsg.org/mangos/v3"
"go.nanomsg.org/mangos/v3/protocol/pull"
// register transports
_ "go.nanomsg.org/mangos/v3/transport/all"
log "github.com/sirupsen/logrus"
)
func main() {
var udid = flag.String( "udid" , "" , "Device UDID" )
var streamCmd = flag.Bool( "stream" , false , "Stream jpegs" )
var pullSpec = flag.String( "pullSpec" , "tcp://127.0.0.1:7879", "NanoMsg spec to pull jpeg frames from" )
var iface = flag.String( "interface", "none" , "Network interface to listen on" )
var port = flag.String( "port" , "8000" , "Network port to listen on" )
var verbose = flag.Bool( "v" , false , "Verbose Debugging" )
var secure = flag.Bool( "secure" , false , "Secure HTTPS mode" )
var cert = flag.String( "cert" , "https-server.crt" , "Cert for HTTP" )
var key = flag.String( "key" , "https-server.key" , "Key for HTTPS" )
var coordinator= flag.String( "coordinator", "127.0.0.1:8027" , "Coordinator control address" )
flag.Parse()
log.SetFormatter(&log.JSONFormatter{})
if *verbose {
log.Info("Set Debug mode")
log.SetLevel(log.DebugLevel)
}
if *streamCmd {
stream( *pullSpec, *udid, *iface, *port, *secure, *cert, *key, *coordinator )
} else {
flag.Usage()
}
}
func stream( pullSpec string, udid string, tunName string, port string, secure bool, cert string, key string, coordinator string ) {
pullSock := setup_nanomsg_sockets( pullSpec )
stopChannel := make( chan bool )
stopChannel2 := make( chan bool )
waitForSigInt( stopChannel, stopChannel2 )
startJpegServer( pullSock, stopChannel2, port, tunName, secure, cert, key, coordinator, udid )
<- stopChannel
}
func setup_nanomsg_sockets( pullSpec string ) ( pullSock mangos.Socket ) {
var err error
if pullSock, err = pull.NewSocket(); err != nil {
log.WithFields( log.Fields{
"type": "err_socket_new",
"zmq_spec": pullSpec,
"err": err,
} ).Fatal("Socket new error")
}
pullSock.SetOption( mangos.OptionRecvDeadline, time.Duration.Seconds( 1 ) )
if err = pullSock.Listen(pullSpec); err != nil {
log.WithFields( log.Fields{
"type": "err_socket_bind",
"spec": pullSpec,
"err": err,
} ).Fatal("Socket bind error")
}
return pullSock
}
func waitForSigInt( stopChannel chan bool, stopChannel2 chan bool ) {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for sig := range c {
fmt.Printf("Got signal %s\n", sig)
go func() { stopChannel2 <- true }()
stopChannel <- true
}
}()
}