-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
45 lines (41 loc) · 896 Bytes
/
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
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"github.com/nmorenor/chezmoi-net/chatclient"
"github.com/nmorenor/chezmoi-net/client"
"github.com/nmorenor/chezmoi-net/net"
)
/**
* Initialize
* @method app
* @return
*/
func app(hostMode bool) {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
currentClient := client.NewClient(net.NewWebSocket("ws://localhost:8080/ws"))
hostClient := chatclient.NewChatClient(currentClient, hostMode)
if hostClient.Host {
fmt.Println("Starting as Host")
} else {
fmt.Println("Starting as Participant")
}
go func() {
<-hostClient.Client.Interrupt
interrupt <- os.Kill
}()
currentClient.Connect()
<-interrupt
log.Println("Interrupt")
currentClient.Close()
log.Println("Exiting")
}
func main() {
joinMode := flag.Bool("join", false, "Join as participant")
flag.Parse()
app(!*joinMode)
}