Skip to content

Commit

Permalink
Using chat presence on clien sample
Browse files Browse the repository at this point in the history
  • Loading branch information
andrebires committed Mar 28, 2022
1 parent ba7571e commit 63d4623
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (cmd *RequestCommand) SetURI(uri *URI) *RequestCommand {
// SetURIString try parse the provided string to a URI and sets it to the request command.
// It fails silently in case of any parsing error.
func (cmd *RequestCommand) SetURIString(s string) *RequestCommand {
if uri, err := ParseLimeURI(s); err != nil {
if uri, err := ParseLimeURI(s); err == nil {
return cmd.SetURI(uri)
}
return cmd
Expand Down
38 changes: 11 additions & 27 deletions examples/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/tls"
"fmt"
"github.com/takenet/lime-go"
"github.com/takenet/lime-go/chat"
"log"
"net"
"os"
Expand Down Expand Up @@ -50,38 +51,21 @@ func main() {

log.Println("Session established")

presenceUri, _ := lime.ParseLimeURI("/presence")
reqCmd := &lime.RequestCommand{}
reqCmd.SetURIString("/presence").
SetResource(&chat.Presence{
Status: chat.PresenceStatusAvailable,
RoutingRule: chat.RoutingRuleIdentity}).
SetMethod(lime.CommandMethodSet).
SetID(lime.NewEnvelopeID())

presence := lime.JsonDocument{
"status": "available",
"routingRule": "identity",
}

cmd, err := client.ProcessCommand(ctx, &lime.RequestCommand{
Command: lime.Command{
Envelope: lime.Envelope{
ID: lime.NewEnvelopeID(),
To: lime.Node{
Identity: lime.Identity{Name: "postmaster", Domain: "msging.net"},
Instance: "",
},
},
Method: lime.CommandMethodSet,
Type: &lime.MediaType{
Type: "application",
Subtype: "vnd.lime.presence",
Suffix: "json",
},
Resource: &presence,
},
URI: presenceUri,
})
respCmd, err := client.ProcessCommand(ctx, reqCmd)
if err != nil {
log.Fatalln(err)
}

if cmd != nil {
log.Printf("Command response received - ID: %v - Status: %v\n", cmd.ID, cmd.Status)
if respCmd != nil {
log.Printf("Command response received - ID: %v - Status: %v\n", respCmd.ID, respCmd.Status)
}

scanner := bufio.NewScanner(os.Stdin)
Expand Down

0 comments on commit 63d4623

Please sign in to comment.