getDeviceName

This commit is contained in:
Dan Ballard 2017-09-18 08:35:24 -07:00
parent 639dbf2ea6
commit 7265e7b7de
2 changed files with 27 additions and 16 deletions

View File

@ -13,7 +13,6 @@ type ODClient struct {
connection.AutoConnectionHandler
connection *connection.Connection
recvMessages chan string
sendMessages chan string
deviceName string
deviceLevel int
batteryLevel string
@ -43,7 +42,6 @@ func (odClient *ODClient) Connect(privateKeyData string, serverAddr string) erro
})
odClient.recvMessages = make(chan string)
odClient.sendMessages = make(chan string)
log.Println("ODClient connecting...")
odClient.connection, err = goricochet.Open(serverAddr)
@ -60,6 +58,7 @@ func (odClient *ODClient) Connect(privateKeyData string, serverAddr string) erro
}
log.Println("go Process")
// TODO: end with breakChannel
go odClient.connection.Process(odClient)
if !known {
@ -70,7 +69,6 @@ func (odClient *ODClient) Connect(privateKeyData string, serverAddr string) erro
}
log.Println("ODClient: Authenticated")
//odClient.connection.RequestOpenChannel("im.ricochet.contact.request", odClient)
log.Println("go")
@ -80,10 +78,8 @@ func (odClient *ODClient) Connect(privateKeyData string, serverAddr string) erro
log.Println("Error: " + err.Error())
}
log.Println("sending greeting message")
odClient.SendMessage("hello from the client")
//log.Println("sending greeting message")
//odClient.SendMessage("hello from the client")
return nil
}
@ -118,6 +114,11 @@ func (odClient *ODClient) SendMessage(message string) {
})
}
func (odClient *ODClient) GetMessage() string {
message := <-odClient.recvMessages
return message
}
/************* Chat Channel Handler ********/
// ChatMessage passes the response to recvMessages.

View File

@ -11,6 +11,10 @@ import (
"github.com/dballard/goRicochetMobile/ODClient"
)
var (
odClient *ODClient.ODClient
)
func GeneratePrivateKey() (string, error) {
privateKey, err := utils.GeneratePrivateKey()
if err != nil {
@ -29,6 +33,21 @@ func GetOnionAddress(privateKey string) string {
return addr
}
func ODClientConnect(privateKey string, serverAddr string) error {
log.Println("ODClientConnect(" + serverAddr + ")")
odClient = new(ODClient.ODClient)
err := odClient.Connect(privateKey, serverAddr)
return err
}
func GetDeviceName() string {
odClient.SendMessage("/name")
name := odClient.GetMessage()
return name
}
/******** Testing by standing up an echobot ******/
func TestNet() (ok bool, ex error) {
_, err := http.Get("http://golang.org/")
if err != nil {
@ -37,15 +56,6 @@ func TestNet() (ok bool, ex error) {
return true, nil
}
func ODClientConnect(privateKey string, serverAddr string) error {
log.Println("ODClientConnect(" + serverAddr + ")")
odClient := new(ODClient.ODClient)
err := odClient.Connect(privateKey, serverAddr)
return err
}
/******** Testing by standing up an echobot ******/
func EchoBot(privateKeyData string) {
privateKey, err := utils.ParsePrivateKey([]byte(privateKeyData))
if err != nil {