-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (39 loc) · 1.1 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
package main
import (
"flag"
"log"
"math/rand"
"time"
"github.com/epes/webrtc-server-client/client"
"github.com/epes/webrtc-server-client/common"
"github.com/epes/webrtc-server-client/server"
)
func main() {
rand.Seed(time.Now().Unix())
port := flag.Int("port", 9090, "Port of the webrtc server")
isClient := flag.Bool("c", false, "Is this a client?")
isServer := flag.Bool("s", false, "Is this a server?")
name := flag.String("n", common.RandString(5), "Name of the client")
group := flag.String("g", "example-group", "Group to connect to")
flag.Parse()
if *isClient && *isServer || !*isClient && !*isServer {
log.Fatalln("Define -c for client or -s for server")
return
}
if *isClient {
c(*port, *name, *group)
}
if *isServer {
s(*port)
}
}
func s(port int) {
log.Printf("[server] starting up server on port %d\n", port)
server := server.NewServer(port)
server.Start()
}
func c(port int, name string, group string) {
log.Printf("[client] generating client '%s' connecting to group %s on port %d\n", name, group, port)
client := client.NewClient(name, group, port)
client.Start()
}