Skip to content

Commit

Permalink
Update comments. Client roles in separate file.
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Sep 30, 2019
1 parent 4b8fc1a commit 96d8c23
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 42 deletions.
54 changes: 12 additions & 42 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,6 @@ const (
CBOR = serialize.CBOR
)

// Features supported by nexus client.
var clientRoles = wamp.Dict{
"publisher": wamp.Dict{
"features": wamp.Dict{
"subscriber_blackwhite_listing": true,
"publisher_exclusion": true,
},
},
"subscriber": wamp.Dict{
"features": wamp.Dict{
"pattern_based_subscription": true,
"publisher_identification": true,
},
},
"callee": wamp.Dict{
"features": wamp.Dict{
"pattern_based_registration": true,
"shared_registration": true,
"call_canceling": true,
"call_timeout": true,
"caller_identification": true,
"progressive_call_results": true,
},
},
"caller": wamp.Dict{
"features": wamp.Dict{
"call_canceling": true,
"call_timeout": true,
"caller_identification": true,
"progressive_call_results": true,
},
},
}

// A Client routes messages to/from a WAMP router.
type Client struct {
sess *wamp.Session
Expand Down Expand Up @@ -229,6 +195,8 @@ func (c *Client) Subscribe(topic string, fn EventHandler, options wamp.Dict) err
}
}

// SubscribeChan subscribes the client to the specified topic or topic pattern.
// Events are written to the provided channel.
func (c *Client) SubscribeChan(topic string, events chan<- *wamp.Event, options wamp.Dict) error {
handler := func(ev *wamp.Event) { events <- ev }
return c.Subscribe(topic, handler, options)
Expand Down Expand Up @@ -325,17 +293,19 @@ func (c *Client) Publish(topic string, options wamp.Dict, args wamp.List, kwargs
return ErrNotConn
}

id := c.idGen.Next()

var pubAck bool
if options == nil {
options = make(wamp.Dict)
options = wamp.Dict{}
} else {
// Check if the client is asking for a PUBLISHED response.
pubAck, _ = options[wamp.OptAcknowledge].(bool)
if pubAck {
c.expectReply(id)
}
}

// Check if the client is asking for a PUBLISHED response.
pubAck, _ := options[wamp.OptAcknowledge].(bool)

id := c.idGen.Next()
if pubAck {
c.expectReply(id)
}
c.sess.Send(&wamp.Publish{
Request: id,
Options: options,
Expand Down
37 changes: 37 additions & 0 deletions client/roles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package client

import "github.com/gammazero/nexus/v3/wamp"

// Features supported by nexus client.
var clientRoles = wamp.Dict{
"publisher": wamp.Dict{
"features": wamp.Dict{
"subscriber_blackwhite_listing": true,
"publisher_exclusion": true,
},
},
"subscriber": wamp.Dict{
"features": wamp.Dict{
"pattern_based_subscription": true,
"publisher_identification": true,
},
},
"callee": wamp.Dict{
"features": wamp.Dict{
"pattern_based_registration": true,
"shared_registration": true,
"call_canceling": true,
"call_timeout": true,
"caller_identification": true,
"progressive_call_results": true,
},
},
"caller": wamp.Dict{
"features": wamp.Dict{
"call_canceling": true,
"call_timeout": true,
"caller_identification": true,
"progressive_call_results": true,
},
},
}

0 comments on commit 96d8c23

Please sign in to comment.