Having issues with Pubnub subscription functionality

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.

Answer №1

The issue I encountered was caused by the inconsistency in versions between the pubnub and pubnub-angular as outlined in the tutorial versus the ones installed using bower on my application.

The tutorial specifically focused on sdk v3 while the current version of the sdk is now v4.

For guidance on working with pubnub sdk v4, please check out this link.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Styling CSS for disabled nested elements

In a project I am currently working on, I've noticed that disabled items do not appear disabled enough. My initial plan was to easily address this issue with some CSS. Typically, adjusting the opacity is my go-to solution to achieve the desired effec ...

Develop an array of unique objects with multiple dimensions, ensuring no duplicates are included

Seeking assistance for the following task: I am trying to create a new multidimensional array of objects based on an existing array of objects: [ {number:111, connectedNumber: 112, ...}, {number:112, connectedNumber: 111, ...}, {number:113, connectedNumbe ...

Dealing with a large amount of HTML content following an Ajax request: best practices

I'm currently using a method that works fine, but I can't stop thinking about whether there might be a better way to achieve the same result. The task at hand is to display a user profile in a modal box. When a user clicks on a button or link, a ...

Using the Parallax Effect in React

I'm currently working on implementing a parallax effect in React and I've encountered an error that's giving me trouble: Below is the snippet of JavaScript code I have for the parallax effect: export const parallax = document.getElementsBy ...

Fetching data using JSONRequest sample code

I am new to web development and this is my first attempt at using JSON. On the JSON website (http://www.json.org/JSONRequest.html), they recommend using JSONRequest.get for certain tasks. However, I keep running into an error stating "JSONRequest is not ...

Implementing React with multiple event listeners for a single click event

One of the challenges I'm facing is with a function called playerJoin() in my React app. This function is triggered when a specific button is clicked. It sends data to the server, which then checks if the information matches what is stored. If there i ...

The second instance of a React Paginate on the same page remains static and does not trigger a

Having a bit of trouble with using react-paginate for pagination - I have two instances on the same page (one at the top and one at the bottom). When a new prop is received, only the top instance gets re-rendered. The code seems to be working fine as all ...

Issue with Vue class binding failing to update when state is modified

I'm attempting to utilize Vue class binding depending on the index within the v-for loop. While I can see that the state in Vue dev tools is changing correctly, the class name itself isn't being updated. <div class="group" v-for= ...

Use jQuery to populate a span element with information that is solely obtainable within a foreach loop during the rendering of buttons

I am currently navigating through learning MVC, and I have hit a roadblock. Working with Web Forms was more familiar to me, so I find myself struggling quite a bit with this new framework. After dedicating most of my day to it, I realize I need some assist ...

Issue: Control with the specified name '0' could not be located

Kindly review this code snippet and assist me in resolving the issue. I have set up a formArray where the label and formControlName do not match, so I have utilized mapping to synchronize them. Upon receiving a response from the API, I initialize the for ...

Having trouble getting the finally clause to work properly in Angular JS version 1.7

In my current project, I am utilizing Angular JS 1.7. Recently, I encountered an issue while using the finally clause within a promise: $http.put( url, null, { headers: { 'Content-Type': 'application/json' } } ).then( ...

Trigger an Event Handler only after ensuring the completion of the previous event handling

When attaching an event handler to a callback, it is important to consider the timing of the actions. For example: $("someSelector").on('click',callBackHandler); function callBackHandler(){ //Some code $.ajax({ //Ajax call with succe ...

Unable to populate data in dropdown using Angular framework?

My datatable displays elements along with an edit button. At the top of the page, there is also an add button. The purpose of the add button is to add elements to the list, while the edit button allows for editing the data in a particular row. When the u ...

Unclear error message encountered with Rails server

Currently using OS X Sierra I'm managing a rails app with front-end and back-end components. The back-end is built on rails 4, while the front-end utilizes Angular. To run the server locally for development or testing purposes, I typically need to ha ...

Utilize array.prototype.reduce() with strings

I'm puzzled about how the reduce operation is carried out on a string. Initially, a new Str instance is created with the desired string as a parameter. Following that, the split method is used to divide the string into an array of strings. A method c ...

merge two structures to create a unified entity

I have been searching in vain, can you please advise me on how to combine these two simple forms into one? I want it to be like a box with a select option and a button. The challenge for me is merging the two different actions, ".asp", into one script fo ...

Next.js is causing me some trouble by adding an unnecessary top margin in my index.js file

I started a new project using next.js by running the command: yarn create next-app However, I noticed that all heading and paragraph tags in my code have default top margins in next.js. index.js import React, { Component } from "react"; import ...

Retrieve information from an array of objects by utilizing a separate array

There are two separate arrays provided below: ages = [20,40,60]; doctors = [{ "name": "Moruu", "age": 18, "sex": "Male", "region": "Africa" }, { "name": "Khol ...

Encountering a 422 ERROR while attempting to send a POST request

Below is the code snippet I am currently using: const url = new URL("https://api.chec.io/v1/products"); const headers = { "X-Authorization": `${process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY_SECRET}`, "Accept": "appl ...

Integrating a Google map into an Ionic Side-Menu application

I am trying to incorporate a Google map into my Ionic app. I followed the code provided in this https://developers.google.com/maps/documentation/javascript/adding-a-google-map and it worked fine in Angular, but not in my side-menu Ionic project. The specif ...