diff --git a/goRicochetMobile.go b/goRicochetMobile.go index 43c07e0..c56078c 100644 --- a/goRicochetMobile.go +++ b/goRicochetMobile.go @@ -6,9 +6,9 @@ import ( "log" "net/http" "time" - "github.com/s-rah/go-ricochet/connection" "github.com/yawning/bulb/utils/pkcs1" "crypto/rsa" + "github.com/s-rah/go-ricochet/channels" ) func GeneratePrivateKey() (string, error) { @@ -37,14 +37,31 @@ func TestNet() (ok bool, ex error) { return true, nil } -type ODClient struct { - connection.AutoConnectionHandler - messages chan string - deviceName string - deviceLevel int - batteryLevel string +func ODClientConnect(privateKeyData string, serverAddr string) { + privateKey, err := utils.ParsePrivateKey([]byte(privateKeyData)) + if err != nil { + log.Fatal("error parsing private key: %v", err) + } + + odClient := new(ODClient) + odClient.Init(privateKey, serverAddr) + + odClient.RegisterChannelHandler("im.ricochet.contact.request", func() channels.Handler { + contact := new(channels.ContactRequestChannel) + contact.Handler = odClient + return contact + }) + + odClient.RegisterChannelHandler("im.ricochet.chat", func() channels.Handler { + chat := new(channels.ChatChannel) + chat.Handler = odClient + return chat + }) + + } + /******** Testing by standing up an echobot ******/ func EchoBot(privateKeyData string) { diff --git a/odClient.go b/odClient.go new file mode 100644 index 0000000..c9dd0ce --- /dev/null +++ b/odClient.go @@ -0,0 +1,52 @@ +package goRicochetMobile + +import ( + "github.com/s-rah/go-ricochet/connection" + "time" + "log" +) + +type ODClient struct { + connection.AutoConnectionHandler + messages chan string + deviceName string + deviceLevel int + batteryLevel string +} + +/************* Chat Channel Handler ********/ + +// ChatMessage passes the response to messages. +func (odc *ODClient) ChatMessage(messageID uint32, when time.Time, message string) bool { + log.Printf("Received Message: %s", message) + odc.messages <- message + return true +} + +// ChatMessageAck does nothing. +func (odc *ODClient) ChatMessageAck(messageID uint32) { +} + +/************* Contact Channel Handler ********/ + +// GetContactDetails is purposely empty +func (odc *ODClient) GetContactDetails() (string, string) { + return "", "" +} + +// ContactRequest denies any contact request. +func (odc *ODClient) ContactRequest(name string, message string) string { + return "Rejected" +} + +// ContactRequestRejected purposly does nothing. +func (odc *ODClient) ContactRequestRejected() { +} + +// ContactRequestAccepted purposly does nothing. +func (odc *ODClient) ContactRequestAccepted() { +} + +// ContactRequestError purposly does nothing. +func (odc *ODClient) ContactRequestError() { +} \ No newline at end of file