Currently, I am in the process of incorporating a basic chat feature into my web application using AngularJs 1.4.5
and pubnub
.
To do this, I am following the instructions outlined in the pubnub tutorial.
$scope.channel = 'chat_for_trial';
$scope.uuid = 'user1';
Pubnub.init({
publishKey: 'demo',
subscribeKey: 'demo',
uuid: $scope.uuid
});
// Sending messages via PubNub Network
$scope.messageContent = {message: ''};
$scope.sendMessage = function() {
// $scope.messageContent = data;
// Ensure non-empty message is being sent
if (!$scope.messageContent.message || $scope.messageContent.message === '') {
return;
}
Pubnub.publish({
channel: $scope.channel,
message: {
content: $scope.messageContent.message,
sender_uuid: $scope.uuid,
date: new Date()
},
callback: function(m) {
console.log(m);
}
});
// Resetting the messageContent input
$scope.messageContent.message = '';
};
//fetching messages
$scope.messageContent.messages = [];
// Subscribing to the ‘messages-channel’ and triggering the message callback
Pubnub.subscribe({
channel: $scope.channel,
triggerEvents: ['callback']
});
// Listening for the callbacks
$scope.$on(Pubnub.getMessageEventNameFor($scope.channel), function (ngEvent, m) {
$scope.$apply(function () {
console.log("i am here")
$scope.messageContent.messages.push(m)
});
});
Even though I can successfully send messages to the channel chat_for_trial
, when checking the occupancy in the pubnub console, the subscribed uuid
does not appear.
Messages sent from the console are not displayed in the web app, but those sent from the web app show up in the pubnub console.
The versions I am working with are pubnub: 4.20.1
, pubnub-angular: 4.1.0
, angularjs: 1.4.5
I would like assistance in figuring out what might be missing in my implementation.