Connect to ejabberd server and application server - angularjs

I have an ejabberd server and I am trying to build a chat module in my Angular/NodeJS app.
Currenlty, my Angular app connects directly to the chat server. Assume my roster has 100 contacts comprising of online and offline contacts. I need to map all the 100 contacts with the users in my application server to get more details like companyId, email, contact, etc.
Do I have to loop through each contact and call an API to the application server? Wouldn't that put a lot of load on the frontend? Is there a better way of achieving this?
Apologies if my question is silly. I am new to XMPP.

There are several way´s of doing this.
You could go and fetch every single user from your API, cache them so the next you don´t have to fetch all the data, but that´s not the optimal solution.
The other solution would be to get all contacts with one single call by passing all id´s to your node application. Then the node app can fetch all needed data from your database and pass it back with one Request and not 100.

With more or less the same problem I used a jabber search getting up all the users and stored on client for the entire session.
My requsite it's "all users can chat with all other users" (about 100 users on server),
if your is not, I suggest you to create a custom IQ and let server cache the Jabber search (updating after each user registration) and reply with only required datas in a single call, async.

Related

Chat with React and Realtime database firebase. Do I need backend? How can I structure my data?

I'm working on a project using React 18 with Firebase Authentication and Realtime Database.
The project is a real-time chat between two users, I wan't this project to be very secure and protect messages/conversations. I have the following "cases" or "rules" to specify this chat functions:
User with profile Volunteer can chat with maximum 10 users with the simple-user profile.
Volunteer can see previous messages or the "history" with a registered simple-user but simple-user can't see previous messages. I need to protect chats for simple-user.
All the active "chats" between one volunteer and maximum 10 simple-users have to be seen just for the Volunteer profile. The simple-user just send and receive messages with a random Volunteer.
I search on the Internet which database fit better with my project model and Realtime Database looks like the better option. But now I would like to have your opinions about how can I handle the database to get the data and connection that I need according to the previous rules I wrote.
I know Firebase is a No-SQL database, but I create this diagram to know if the data structure for this chat could work.
If I store different information like the image above, could I get the information I need from each chat?
Turn is the working shift time that "volunteer" is working on the chat platform.
Session is the information of the turn of that volunteer and simple-users that they talk.
Chat is the "conversation" or the instance to generate messages between two different users.
My questions are:
Do I need a backend project such as nodejs? This backend would be for store the endpoints to firestore and apply some logic rules for queries this way I can have a React project without logic
If I structure my database like the image above, can I be able to get the information to achieve the "rules" that I need?
Do you have any suggestion to build a chat like this? In the future this project could be huge with a lot of data store and multiple users chatting with each other. Right now I have just the UI code and firebase connection. No other code yet.
Thanks for your contributions!

how to integrate react application with filemaker server as backend

My job has tasked me to create a login page with username, password, reset password, sign in and sign up. When you login you are sent to a landing page. All should be done with react but i have to use filemaker server as a backend that stores usernames and passwords in a database. I've never used filemaker before and i don't know where to start. Any advise will be appreciated
Use Filemaker Data Api:
https://help.claris.com/en/data-api-guide/
Login call to get the token
Make a POST request to
{yourServerUrl}/fmi/data/version/databases/{database-name}/layouts/{layout-name}/records
to write the new record into the database.
Assuming your company is on a recent version of FileMaker (version 16 or later, I believe) then FileMaker Server has a feature called the Data API that publishes all FM data in a more standard-manner than going through the trials of ODBC or the PHP API.
The requirements are essentially just clicking the checkbox in the Server Admin control panel:
That feature has tiered pricing associated with it, but it includes a base amount of requests as part of having a server license and most likely you will find it to be the best avenue. If, for some reason, you can't use the Data API, going in via the PHP API which produces a more verbose XML output and is tied to fields visible on layouts is another avenue.

Web3JS - Front or backend

I have a question about web3js.
If my site will load data directly from blockchain (MetaMask) without loading them into the database, and immediately through js bring them to the site then:
1. If a large number of events (1-10 kk) then analyze them on the side of the browser is a bad idea? Need to record everything in the database and the user to publish the analyzed information from the database?
2. When a user enters the site, then in fact his browser parses the information out of the blockchain (if using MetaMask)? Not my server. And I do not care how many connections go through web3js at the same time
What the best?
1. Get all data with web3js and show them on site.
2. Or get all data and writing to database, then use ajax for dinamic show data?

What is the best practices for building REST API with different subscribers (companies)?

What is the best design approach in term of security, performance and maintenance for REST API that has many subscribers (companies)?
What is the best approach to use?:
Build a general API and sub APIs for each subscriber (company), when request come we check the request and forward it to the sub API using (API Key) then retrieve data to general API then to client.
Should we make single API and many databases for storing each subscribe(company) data (because each company has huge records that why we suggested to separated databases to improve performance)? when request come we verify it and change database Connection String based on client request.
Should we make one API and one big database that handle all subscribes data?
Do you suggest any new approach to solve this problem? We used Web API and MS SQL Server and Azure Cloud.
In the past I've had one API, the API is secured using OAuth/JWT in the token we have a company id. When a request comes in we read the company id from the JWT and perform a lookup in a master database, this database holds global information such a connection strings for each company. We then create a unit of work that has the company's conneciton string associated with it and any database lookups use that.
This mean that you can start with one master and one node database, when the node database starts getting overloaded you can bring up another one and either add new companies to that or move existing companies to take pressure off. Essentially you're just scaling out when the need arises.
We had no performance issues with this setup.
Depends on the transaction volume and nature of data, you can go for a single database or separate database for each company.
Option 2 would be the best , if you have complex data model
I don't see any advantage of going for option 1, because , anyway general API will call for each request.
You can use the ClientID verification while issuing access tokes.
What I understood from your question is, you want an rest API for multiple consumers(companies). Logically the employees from that company will consume your API, employees may be admin, HR etc. So what I suggested for such scenario you must go with single Rest API for providing the services to your consumers and for security you have to use OpenId on the top of OAuth 2. This resolves the authentication and authorization for you.

Integrating notifications/messages to the client in an AngularJS + ASP.NET Web API app

I'm creating a SPA application with AngularJS at the client side and ASP.NET Web API as backend. My database is SQL Server 2012. There will be users which have a favourite sports team and a simple icon in the UI displaying the number of new articles/news/comments added or whatever connected to their favourite teams.
What I'd like to achieve is the following: Whenever a record about their team is inserted (record with TeamID column value for example equal to the user's favourite team ID), that notifications count icon should be updated immediately (just like Facebook's notifications - it's updated when a friend has posted on your wall or has tagged you and so on). How can I best achieve this?
What I'm thinking of for now is just setting an interval function in AngularJS to check every 30 seconds, let's say, if there are new records in the database making a request to a Web API controller. Of course this suggests a lot of checking for when the user is logging out - when was the last check, what will be the date to check against next time he/she logs in and so on.
You can use signalR for this. It's a framework for real time communication. Check out this to get if you want to get started. It can easily be used together with angularJS.
What you are looking for is push
Sadly i never used it so i don't know much about it, but i think you should use technologies like pusher

Resources