Skip to content

Commit 63d4623

Browse files
committed
Using chat presence on clien sample
1 parent ba7571e commit 63d4623

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (cmd *RequestCommand) SetURI(uri *URI) *RequestCommand {
9696
// SetURIString try parse the provided string to a URI and sets it to the request command.
9797
// It fails silently in case of any parsing error.
9898
func (cmd *RequestCommand) SetURIString(s string) *RequestCommand {
99-
if uri, err := ParseLimeURI(s); err != nil {
99+
if uri, err := ParseLimeURI(s); err == nil {
100100
return cmd.SetURI(uri)
101101
}
102102
return cmd

examples/client/main.go

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/tls"
77
"fmt"
88
"github.com/takenet/lime-go"
9+
"github.com/takenet/lime-go/chat"
910
"log"
1011
"net"
1112
"os"
@@ -50,38 +51,21 @@ func main() {
5051

5152
log.Println("Session established")
5253

53-
presenceUri, _ := lime.ParseLimeURI("/presence")
54+
reqCmd := &lime.RequestCommand{}
55+
reqCmd.SetURIString("/presence").
56+
SetResource(&chat.Presence{
57+
Status: chat.PresenceStatusAvailable,
58+
RoutingRule: chat.RoutingRuleIdentity}).
59+
SetMethod(lime.CommandMethodSet).
60+
SetID(lime.NewEnvelopeID())
5461

55-
presence := lime.JsonDocument{
56-
"status": "available",
57-
"routingRule": "identity",
58-
}
59-
60-
cmd, err := client.ProcessCommand(ctx, &lime.RequestCommand{
61-
Command: lime.Command{
62-
Envelope: lime.Envelope{
63-
ID: lime.NewEnvelopeID(),
64-
To: lime.Node{
65-
Identity: lime.Identity{Name: "postmaster", Domain: "msging.net"},
66-
Instance: "",
67-
},
68-
},
69-
Method: lime.CommandMethodSet,
70-
Type: &lime.MediaType{
71-
Type: "application",
72-
Subtype: "vnd.lime.presence",
73-
Suffix: "json",
74-
},
75-
Resource: &presence,
76-
},
77-
URI: presenceUri,
78-
})
62+
respCmd, err := client.ProcessCommand(ctx, reqCmd)
7963
if err != nil {
8064
log.Fatalln(err)
8165
}
8266

83-
if cmd != nil {
84-
log.Printf("Command response received - ID: %v - Status: %v\n", cmd.ID, cmd.Status)
67+
if respCmd != nil {
68+
log.Printf("Command response received - ID: %v - Status: %v\n", respCmd.ID, respCmd.Status)
8569
}
8670

8771
scanner := bufio.NewScanner(os.Stdin)

0 commit comments

Comments
 (0)