diff --git a/config.go b/config.go index f08dc3b..d2cbc5f 100644 --- a/config.go +++ b/config.go @@ -33,7 +33,7 @@ var customUsage = func() { fmt.Println("") fmt.Println("EXAMPLES:") fmt.Println("") - fmt.Println(os.Args[0] + "--hostname test.hostname.wit.com") + fmt.Println(os.Args[0] + " --hostname test.hostname.wit.com") fmt.Println("") } @@ -128,31 +128,14 @@ func parseConfig(defaultConfig string) { // always override the debugging flag from the command line config.Set("debugging", *debugging) - for _, addr := range config.Strings("arr1") { - log.Println("addr =", addr) - } - - map1 := config.StringMap("map1") - fmt.Printf("%#v\n",map1) - - log.Println(config.String("map1.key1.jwc1")) - for account, _ := range config.StringMap("cloud") { port := config.String("accounts." + account + ".port") proto := config.String("accounts." + account + ".proto") hostname := config.String("accounts." + account + ".hostname") - fmt.Println(account, hostname, port, proto) + log.Println(account, hostname, port, proto) } if (config.String("nogui") == "true") { log.Println("DO NOT DISPLAY THE GUI") } - - if (config.String("debugging") == "true") { - log.Println("ENABLE DEBUG", config.String("debugging")) - log.Println("ENABLE DEBUG", config.Bool("debugging")) - } else { - log.Println("DISABLE DEBUG", config.String("debugging")) - log.Println("DISABLE DEBUG", config.Bool("debugging")) - } } diff --git a/eventChannel.go b/eventChannel.go index fa4abe3..3ba1515 100644 --- a/eventChannel.go +++ b/eventChannel.go @@ -58,6 +58,7 @@ func processEvents() { if (currentMessage.Type == pb.Event_DEMO) { log.Println("processEvents() do Event DEMO") } else { + log.Println("processEvents() NEW PROTOBUF") gui.Data.State = "NEW PROTOBUF" } log.Println("processEvents() END on channel") diff --git a/gorilla.go b/gorilla.go index 5de8225..30626d5 100644 --- a/gorilla.go +++ b/gorilla.go @@ -15,9 +15,9 @@ import pb "git.wit.com/wit/witProtobuf" var gorillaConn *websocket.Conn -func readGorillaConn(conn *websocket.Conn) { +func gorillaReadProtobuf(conn *websocket.Conn) { for { - log.Println("gorilla START readGorillaConn()", time.Now()) + log.Println("gorilla START gorillaReadProtobuf()", time.Now()) mytype, message, err := conn.ReadMessage() if err != nil { log.Println("read:", err) @@ -29,25 +29,28 @@ func readGorillaConn(conn *websocket.Conn) { if (err != nil) { log.Printf("readConn() something fucked up happened in Unmarshal") } - log.Printf("readGorillaConn() successfully read protobuf from gorilla websocket") + log.Printf("gorillaReadProtobuf() successfully read protobuf from gorilla websocket") addEvent(protobufMsg) } else { log.Printf("recv: %s", message) // log.Printf("type, err = ", mytype, err) } time.Sleep(time.Second) - log.Println("gorilla END readGorillaConn()", time.Now()) + log.Println("gorilla END gorillaReadProtobuf()", time.Now()) } } -func gorillaSendProtobuf() { +func gorillaSendProtobuf(msg *pb.Event) { + log.Println("gorillaSendProtobuf() START", time.Now()) if (gorillaConn == nil) { log.Println("gorillaSendProtobuf() gorillaConn == nil") log.Println("Need to re-open connection here") return } + /* msg := pb.CreateSampleEvent() msg.Name = "test echo over gorilla websocket" + */ data, _ := proto.Marshal(msg) err2 := gorillaConn.WriteMessage(websocket.BinaryMessage, data) if err2 != nil { @@ -93,7 +96,7 @@ func gorillaDial(hostname string) { gorillaConn = conn // handle inbound messages on the channel - readGorillaConn(conn) + gorillaReadProtobuf(conn) closeGorillaConn() } diff --git a/main.go b/main.go index 5dd4304..9f20468 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,9 @@ import "runtime/debug" import "github.com/gookit/config" import "github.com/gobuffalo/packr" +// import "github.com/golang/protobuf/proto" +import pb "git.wit.com/wit/witProtobuf" + import "git.wit.com/wit/gui" var GITCOMMIT string // this is passed in as an ldflag @@ -155,8 +158,9 @@ func buttonClick(b *gui.ButtonMap) { } if (b.Note == "SHOW") { log.Println("\tTRIGGER DISPLAY ACCOUNT") - gui.Data.State = "READ WEBSOCKET" + gui.Data.State = "SEND WEBSOCKET" gui.Data.AccNick = b.AccNick + count := 0 for { log.Println("Sleep() in buttonClick() gui.Data.State =", gui.Data.State) time.Sleep(200 * time.Millisecond) @@ -178,6 +182,13 @@ func buttonClick(b *gui.ButtonMap) { } return } + count += 1 + if (count > 10) { + log.Println("ERROR: waited too long for a resposne") + currentMessage = nil + gui.Data.State = "done" + return + } } } if (b.Note == "BMATH") { @@ -229,14 +240,21 @@ func watchGUI() { log.Println("\tTRIGGERING BMATH HERE") log.Println("\tTRIGGERING BMATH HERE") log.Println("\tTRIGGERING BMATH HERE") - gorillaSendProtobuf() + event := pb.MakeGetEvent() + gorillaSendProtobuf(event) } - if (gui.Data.State == "READ WEBSOCKET") { + if (gui.Data.State == "SEND WEBSOCKET") { log.Println("\tTRIGGERING WEBSOCKET HERE on AccNick =", gui.Data.AccNick) log.Println("\tTRIGGERING WEBSOCKET HERE on AccNick =", gui.Data.AccNick) log.Println("\tTRIGGERING WEBSOCKET HERE on AccNick =", gui.Data.AccNick) + + event := pb.MakeGetEvent() + event.Token = config.String("accounts." + gui.Data.AccNick + ".token") + log.Println("\tTRIGGERING WEBSOCKET HERE with event.Token =", event.Token) + if (gui.Data.AccNick == "bmath") { - gorillaSendProtobuf() + gorillaSendProtobuf(event) + gui.Data.State = "READ PROTOBUF" } else { gui.Data.State = "NEW PROTOBUF" } diff --git a/resources/test.json b/resources/test.json index 35502a3..9b2564b 100644 --- a/resources/test.json +++ b/resources/test.json @@ -8,6 +8,7 @@ "hostname": "v000185.testing.com.customers.wprod.wit.com", "username": "bmath@wit.com", "port": 9000, + "token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjoyLCJyIjoiIiwiY3NyZiI6Ik9rR0JWenphV2cxQjVlN0R5YjRXSzIyWCIsImV4cCI6MTU1OTE4NTc1MiwiaXNzIjoid2l0Iiwic3ViIjoiYm1hdGhAd2l0LmNvbSJ9.vdOAXyt3VIovqEIbivgt6upqR8glZv2UdzFcyudzCmGV-msdZWi_9TZaATyQMxEaVD3K6gRunakyOWK0jw4xxeDUbQym86IKMU2UOjp0tN0z72OmH822NmQ8_AgWiKNI", "proto": "tcp" }, "jcarr": { @@ -16,6 +17,7 @@ "username": "jcarr@wit.com", "port": 3333, "proto": "tcp", + "token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjoyLCJyIjoiIiwiY3NyZiI6Ik9rR0JWenphV2cxQjVlN0R5YjRXSzIyWCIsImV4cCI6MTU1OTE4NTc1MiwiaXNzIjoid2l0Iiwic3ViIjoiYm1hdGhAd2l0LmNvbSJ9.vdOAXyt3VIovqEIbivgt6upqR8glZv2UdzFcyudzCmGV-msdZWi_9TZaATyQMxEaVD3K6gRunakyOWK0jw4xxeDUbQym86IKMU2UOjp0tN0z72OmH822NmQ8_AgWiKNI", "rows": 18 }, "jcarr2": {