Skip to content

Commit

Permalink
Merge pull request #58 from pubnub/CE-3347-Atoi-on-ARM-v7
Browse files Browse the repository at this point in the history
Fixes for 32 bit
  • Loading branch information
crimsonred authored Jan 21, 2019
2 parents 95eafa3 + a169dc5 commit 915d0df
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 12 deletions.
12 changes: 11 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
---
changelog:
-
changes:
-
text: "Fixes for 32bit and armv7 systems"
type: improvement
-
text: "QueryParam and State in Presence Heartbeat"
type: improvement
date: Jan 15, 19
version: v4.1.6
-
changes:
-
Expand Down Expand Up @@ -303,4 +313,4 @@ supported-platforms:
- "Mac OS X 10.8 or later, amd64"
- "Windows 7 or later, amd64, 386"
version: "PubNub Go SDK"
version: v4.1.5
version: v4.1.6
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# PubNub 4.1.5 client for Go
# PubNub 4.1.6 client for Go
* Go (1.9+)

# Please direct all Support Questions and Concerns to [email protected]
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.5
4.1.6
9 changes: 8 additions & 1 deletion examples/cli/cli_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,14 @@ func runPresenceRequest(args []string) {
if len(args) > 2 {
groups = strings.Split(args[2], ",")
}
pn.Presence().Connected(connected).Channels(channels).ChannelGroups(groups).Execute()
queryParam := map[string]string{
"q1": "v1",
"q2": "v2",
}
state := map[string]interface{}{
"state": "stateval",
}
pn.Presence().Connected(connected).Channels(channels).QueryParam(queryParam).State(state).ChannelGroups(groups).Execute()
}

func setPresenceTimeout(args []string) {
Expand Down
11 changes: 10 additions & 1 deletion heartbeat_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type HeartbeatManager struct {
ctx Context
runIndependentOfSubscribe bool
hbRunning bool
queryParam map[string]string
state map[string]interface{}
}

func newHeartbeatManager(pn *PubNub, context Context) *HeartbeatManager {
Expand Down Expand Up @@ -156,17 +158,23 @@ func (m *HeartbeatManager) prepareList(subItem map[string]*SubscriptionItem) []s
}

func (m *HeartbeatManager) performHeartbeatLoop() error {
var stateStorage map[string]interface{}

m.RLock()
presenceChannels := m.prepareList(m.heartbeatChannels)
presenceGroups := m.prepareList(m.heartbeatGroups)
stateStorage = m.state
queryParam := m.queryParam
m.pubnub.Config.Log.Println("performHeartbeatLoop: count presenceChannels, presenceGroups", len(presenceChannels), len(presenceGroups))
m.RUnlock()
var stateStorage map[string]interface{}

if (len(presenceChannels) == 0) && (len(presenceGroups) == 0) {
m.pubnub.Config.Log.Println("performHeartbeatLoop: count presenceChannels, presenceGroups nil")
presenceChannels = m.pubnub.subscriptionManager.stateManager.prepareChannelList(false)
presenceGroups = m.pubnub.subscriptionManager.stateManager.prepareGroupList(false)
stateStorage = m.pubnub.subscriptionManager.stateManager.createStatePayload()
queryParam = nil

m.pubnub.Config.Log.Println("performHeartbeatLoop: count sub presenceChannels, presenceGroups", len(presenceChannels), len(presenceGroups))
}

Expand All @@ -180,6 +188,7 @@ func (m *HeartbeatManager) performHeartbeatLoop() error {
Channels(presenceChannels).
ChannelGroups(presenceGroups).
State(stateStorage).
QueryParam(queryParam).
Execute()

if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions heartbeat_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ func newHeartbeatBuilderWithContext(pubnub *PubNub,
return &builder
}

// QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.
func (b *heartbeatBuilder) QueryParam(queryParam map[string]string) *heartbeatBuilder {
b.opts.QueryParam = queryParam

return b
}

// State sets the state for the Heartbeat request.
func (b *heartbeatBuilder) State(state interface{}) *heartbeatBuilder {
b.opts.State = state
Expand Down Expand Up @@ -84,6 +91,7 @@ type heartbeatOpts struct {

Channels []string
ChannelGroups []string
QueryParam map[string]string

ctx Context
}
Expand Down Expand Up @@ -139,6 +147,7 @@ func (o *heartbeatOpts) buildQuery() (*url.Values, error) {
q.Set("state", string(state))
}
}
SetQueryParam(q, o.QueryParam)

return q, nil
}
Expand Down
2 changes: 1 addition & 1 deletion history_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func parseInterface(vv []interface{}, o *historyOpts) []HistoryResponseItem {
s := fmt.Sprintf("%.0f", f)
o.pubnub.Config.Log.Println("s:", s)

if tt, err := strconv.Atoi(s); err == nil {
if tt, err := strconv.ParseInt(s, 10, 64); err == nil {
o.pubnub.Config.Log.Println("tt:", tt)
items[i].Timetoken = int64(tt)
} else {
Expand Down
21 changes: 20 additions & 1 deletion presence_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type presenceOpts struct {
channelGroups []string
connected bool
ctx Context
queryParam map[string]string
state map[string]interface{}
}

func newPresenceBuilder(pubnub *PubNub) *presenceBuilder {
Expand Down Expand Up @@ -59,6 +61,19 @@ func (b *presenceBuilder) Connected(connected bool) *presenceBuilder {
return b
}

// QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.
func (b *presenceBuilder) QueryParam(queryParam map[string]string) *presenceBuilder {
b.opts.queryParam = queryParam

return b
}

// State sets the State for the Set State request.
func (b *presenceBuilder) State(state map[string]interface{}) *presenceBuilder {
b.opts.state = state
return b
}

func (b *presenceBuilder) Execute() {
if b.opts.connected {
for _, ch := range b.opts.channels {
Expand All @@ -77,12 +92,16 @@ func (b *presenceBuilder) Execute() {
b.opts.pubnub.heartbeatManager.heartbeatGroups[cg] = newSubscriptionItem(cg)
b.opts.pubnub.heartbeatManager.Unlock()
}

b.opts.pubnub.heartbeatManager.state = b.opts.state
b.opts.pubnub.heartbeatManager.queryParam = b.opts.queryParam
b.opts.pubnub.heartbeatManager.startHeartbeatTimer(true)
} else {
b.opts.pubnub.heartbeatManager.Lock()
b.opts.pubnub.heartbeatManager.heartbeatChannels = make(map[string]*SubscriptionItem)
b.opts.pubnub.heartbeatManager.heartbeatGroups = make(map[string]*SubscriptionItem)
b.opts.pubnub.heartbeatManager.state = nil
b.opts.pubnub.heartbeatManager.queryParam = nil

b.opts.pubnub.heartbeatManager.Unlock()
// b.opts.pubnub.heartbeatManager.stopHeartbeat(true, true)
}
Expand Down
4 changes: 2 additions & 2 deletions publish_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type publishOpts struct {

// PublishResponse is the response after the execution on Publish and Fire operations.
type PublishResponse struct {
Timestamp int
Timestamp int64
}

type publishBuilder struct {
Expand All @@ -68,7 +68,7 @@ func newPublishResponse(jsonBytes []byte, status StatusResponse) (
if !ok {
return emptyPublishResponse, status, pnerr.NewResponseParsingError(fmt.Sprintf("Error unmarshalling response, %s %v", value[2], value), nil, nil)
}
timestamp, err := strconv.Atoi(timeString)
timestamp, err := strconv.ParseInt(timeString, 10, 64)
if err != nil {
return emptyPublishResponse, status, err
}
Expand Down
2 changes: 1 addition & 1 deletion pubnub.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// Default constants
const (
// Version :the version of the SDK
Version = "4.1.5"
Version = "4.1.6"
// MaxSequence for publish messages
MaxSequence = 65535
)
Expand Down
3 changes: 3 additions & 0 deletions subscription_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ func processSubscribePayload(m *SubscriptionManager, payload subscribeMessage) {
case int:
timestamp = int64(presencePayload["timestamp"].(int))
break
case int64:
timestamp = presencePayload["timestamp"].(int64)
break
case float64:
timestamp = int64(presencePayload["timestamp"].(float64))
break
Expand Down
4 changes: 2 additions & 2 deletions subscription_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func TestProcessSubscribePayload(t *testing.T) {

payload := &map[string]interface{}{
"action": "join",
"timestamp": 15078947309567840,
"timestamp": int64(15078947309567840),
"uuid": "bfce00ff4018fce180438bb04afc8da8",
"occupancy": 1,
}
Expand Down Expand Up @@ -504,7 +504,7 @@ func TestProcessSubscribePayloadSubMatch(t *testing.T) {

payload := &map[string]interface{}{
"action": "join",
"timestamp": 15078947309567840,
"timestamp": int64(15078947309567840),
"uuid": "bfce00ff4018fce180438bb04afc8da8",
"occupancy": 1,
"here_now_refresh": true,
Expand Down

0 comments on commit 915d0df

Please sign in to comment.