Unleashing the power of real-time communication with XMPP using AngularJS

I am currently working on transitioning the basic XMPP setup using Strophe and JavaScript to AngularJS.

.controller('loginCtrl', function(xmppAuth) {

    xmppAuth.auth(login, password);

})

and in service:

    .service('xmppAuth', function() {

.return {

    auth: function(login, password) {
       connect = new Strophe.Connection(domain);
       connect.connect(login, password, function (status) {
           if (status === Strophe.Status.CONNECTED) {
               connect.addHandler(on_roster_changed,"jabber:iq:roster", "iq", "set");
               connect.addHandler(on_iq, null, "iq","");
               connect.addHandler(on_presence, null, "presence");
               connect.addHandler(on_message, null, 'message', '');
           }
       }
    }

    }

})

in js file

var on_presence = function(presence){
    code
}

When I run this, there are no errors. However, all handling events like the on_presence() method are only being called once. This is a handler event of the Strophe Connection object. Is there anything missing in this code or what should be done for handling Strophe's events with AngularJS?

I found some guidance on This Link, but unfortunately it did not work for me.

Answer №1

Check out the Strophe.js documentation for addHandler:

The addHandler function should return true if you want it to be invoked again; returning false will remove the handler after it completes.

So, make sure your on_presence code returns true if you want it to continue being called:

var on_presence = function(presence) {
    // do something
    return true;
};

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

What is the best way to fill a "multiselect" element with information from a JSON object?

I'm struggling to populate the multiselect field with data from a JSON object. No matter which multiselect I use, the data shows in inspect mode but not on the frontend. It was supposed to look like this. https://i.sstatic.net/FVz2H.png but it comes ...

Is it possible to initialize the ng-model's value using other values within the scope?

I am attempting to calculate the product of two values entered by the user and then assign that result as the ng-model for a third value. However, I am having trouble getting this code to function properly. <input type="number" ng-model="a"> <inp ...

What is the best way to duplicate a tag that contains multiple other tags with attributes?

My form, named 'myForm', needs a div tag with the id 'original' to be added every time I click a button. Can someone help me figure out how to add these tags? The new tags should appear after the original one, but still within myForm. ...

Generating forms dynamically using JSON data

Currently, I'm using three nested ng-repeat directives to display multiple questions and their corresponding answers. Everything is displaying correctly so far, but now I need to create a form to save the answers. What would be the best approach to ac ...

The FormattedNumber feature in react-intl is not functioning correctly

I am currently attempting to utilize the FormattedNumber component within the react-intl library, but I am encountering difficulties in getting it to function correctly. <IntlProvider locale="en-US" messages={locales['en-US']} > ...

Struggling three.js newcomer faced with initial hurdle: "Function is undefined"

I am encountering a similar issue to the one discussed in this question: Three.js - Uncaught TypeError: undefined is not a function -- and unfortunately, the solutions provided there did not work for me. My journey with three.js began on the Getting Start ...

The array filtering functionality is not functioning as intended

Struggling with correctly filtering data in JavaScript. Here's an example where var1 = 20, var2 = 10, var3 = 30, var4 = 40. This is the code snippet: var variables = ['var1', 'var2', 'var3', 'var4'], values = [ ...

Tips on avoiding a page reload following a form submission using JQuery

Currently developing a website for my app development project, I've encountered an unusual issue. Utilizing some JQuery to transfer form data to a php page called 'process.php' and then add it to my database. The strange part is that the pa ...

Creating a triangle number pattern in JavaScript with a loop

Hi there, I'm currently facing an issue. I am trying to generate a triangular number pattern like the one shown below: Output: 1223334444333221 =22333444433322= ===3334444333=== ======4444====== I attempted to write a program for this, however, ...

JavaScript event listener 'click' not functioning properly

I'm facing an issue with a click event in a script that is associated with a specific div id. When I move the mouse within the div area and click (the cursor remains unchanged), the event listener does not activate. How can I make the div area clickab ...

Having trouble displaying the desired formatting when mapping through nested JSON in Node ES6

Currently working on a project to build a photo gallery using nested JSON data. My goal is to iterate through the data and create a well-structured JavaScript object or a smaller JSON file that includes only the text and image URL nodes. However, my curren ...

Incorporating a JavaScript object into a DataTables JSON structure: A practical guide

I have integrated the datatables jQuery plugin into my project and I am looking to streamline the process by creating a shared function to easily call a datatable from multiple pages without duplicating code. To achieve this, I am attempting to define the ...

"Unleashing the Power of AngularJS: Implementing a Global Error Handler to Display and

When building my website, I have multiple Angular apps that require a global error handler to track and display alerts for errors with codes like 500 and 401. Here is what I have so far: In order to create a global error handler module, I've set up t ...

jade, express, as well as findings from mysql

My goal is to display the results of an SQL query in Jade, which pulls data from a table of banners. Each banner has a unique id and falls under one of three types. Here is my current code : express : connection.query("SELECT * FROM banner_idx ORDER BY ...

Ensure that the date is valid using Joi without transforming it into UTC format

Is there a method to validate a date using @joi/date without converting it to UTC? I need to ensure the date is valid before storing it in the database. Here's what I've attempted: const Joi = require('joi').extend(require('@joi/ ...

To grab a specific CSS attribute from a stylesheet using JavaScript

I am looking for a way to extract the value from a CSS file using a JavaScript function. Take a look at my code snippet below: HTML file -> <link rel="stylesheet" type="text/css" href="test_css.css" /> <script type="text/javascript ...

Angular file upload component with customizable file size limits

I'm currently developing an upload file feature that will transmit the file via nodejs. However, I am encountering an issue related to file size. Whenever the file exceeds a few kilobytes, I encounter the following error: Error: request entity too la ...

Getting the highest level object in a nested Angular component structure

Currently, I am in the process of developing a query builder using Angular that bears resemblance to the JQuery builder. However, I have encountered an issue related to emitting the data. Whenever I click on the addGroup or addRule buttons, a new group is ...

Optimizing your online presence through SEO with the added benefit

My website is created using Angular and I have incorporated angular-gettext to support multiple languages: Rather than changing my site structure with domain-specific subdomains or URLs like https://en.example.com/ or https://www.example.com/en/, I curren ...

The hydration error in next js is causing this code to malfunction

Why am I encountering a hydration error with this code in NextJS? The Items variable is an array of ReactNode's. Any suggestions for an alternative approach? I've searched extensively for information but haven't found anything related to Nex ...