I am trying to get data (state) object in the presence event as documented in Pubnub Documentation.
Here's my code :-
// Subscribe to messages channel
Pubnub.subscribe({
channel: $scope.channel,
triggerEvents: ['callback','presence','message'],
state: {
username : $scope.username,
membershipType : $scope.membershipType,
memberDealsIn : $scope.memberDealsIn
}
});
//Track online users
Pubnub.here_now({
channel : $scope.channel,
state: true,
callback : function(m){
$scope.$apply(function() {
$scope.onlineUsers.push(m['uuids'])
});
}
});
//User's State
Pubnub.state({
channel : $scope.channel,
state : {
username : $scope.username,
membershipType : $scope.membershipType,
memberDealsIn : $scope.memberDealsIn
},
callback : function(m){
//console.log(m)
},
error : function(m){
//console.log(m)
}
});
I am calling it from the Pubnub's getPresenceEventNameFor method as :-
$scope.$on(Pubnub.getPresenceEventNameFor($scope.channel), function (ngEvent, pnEvent) {
console.log("pnEvent: ", pnEvent);
}
Here's my output :-
pnEvent: Object {action: "join", uuid: "1310974", timestamp: 1467719168, occupancy: 3}
As you can see everything else is just fine but I cannot get data in it. Whereas the Documentation says it should have data too, like :-
{
"action" : "join",
"timestamp" : 1345546797,
"uuid" : "175c2c67-b2a9-470d-8f4b-1db94f90e39e",
"occupancy" : 2,
"data" : {
"age" : 67,
"full" : "RobertPlant",
"country" : "UK",
"appstate" : "foreground",
"latlong" : "51.5072°N,0.1275°W"
}
}
I have been stuck with this thing for a while now. :(
Please tell me what I am doing wrong here. Why isn't the state being set in the presence event.
Thanks for your help.