start work on od client, classes and interface fulfilment
This commit is contained in:
parent
032f06dad1
commit
5085a1d08c
|
@ -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) {
|
||||
|
|
|
@ -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() {
|
||||
}
|
Loading…
Reference in New Issue