How does gmail check gtalk statuses in real time? - gmail

How is it that if I have thousands of contacts (let's suppose) all around the world and one of them changes their status to away or becomes idol that it will change immediately in my browser?

It isn't instant really, there is a small delay, basically when you load the gmail page in your browser you also download a javascript file that refreshes the content dynamically via ajax. Similarly if a contact of yours changes gtalk status and you're using the gtalk client in gmail that change will be reflected after the next time the page you're viewing asks the server for updates. It's just constantly checking with the server for changes (the event oriented paradigm isn't really prevalent on the web).

I'm not sure of the exact mechanism gmail uses, but a fairly dumb way would be to have the page poll (via XMLHTTPRequest, aka AJAX call) the servers every X seconds for a change in contact statuses since N seconds ago... then apply those changes.

Google chat system is based upon XMPP protocol and Gmail chat block is just like another XMPP client (similar to gtalk,pidgin,psi for desktops). XMPP runs over browser using Bosh extension. Though i m sure google must have hacked to get it working in their own way, but underlying idea is still the same.
In short, when one of your contact update his/her status, it is being pushed to the google chat xmpp servers which in turn pushes that information to your gmail chat client.

Related

No XEP-0333 Chat Markers in XMMPP Openfire backend - how to solve it?

We have an Openfire XMPP/Jabber server setup (with a NodeJs backend and React frontend).
Chat is a feature embedded in the app (NOT an overlay or window that is always visible). So the user has to navigate to a specific page to access the chat interface.
It is working via websockets and messaging sending is working fine. We have a React frontend.
The challenge is that XEP-0333 Chat Markers is not supported by Openfire (the spec never become production ready).
Therefore we need to know how can we implement this feature so that :
A users knows when they are online that they have an unread message (and later, how many unread message they have). For example, if they are not in the chat window and messages are arriving, we need to indicate that in the header of the app so they see it)
if a user goes offline, and comes back online but NOT into the chat window, how can we know if they have unread messages and notify them of that?
My understanding is that somehow we have to keep track of unread messages (eg perhaps in indexedb or local storage or even in postgres backend) and after the user reads a message, we delete it from storage. If the storage still has records for that user then clearly those are the unread messages.
Obviously we don't know if they actually READ the message, but we can assume that if the chat window is open and visible (ie. active tab in their browser) that any messages delivered have been read.
So if our application tab is active, but user is not in chat, and a message arrives, we store it. When they open chat and click on the sender, we remove it from storage.
Has anyone solved it this way? (looking for links to React or JS/TS code)
Is there a better way? (links to other solutions would be helpful, esp. code)

How to get instant changes in background from private api in mobile app?

I am planning to create a mobile application for android and ios users, i think i will take a try with xamarin since i will be alone on this project and i don't have a lots of time.
I want that the mobile app for both platform get datas from the api, then if there is new datas available we notify the user by a notification.
How the mobile will work in that kind of project? I mean should i make a background service then check every x seconds/minutes by http request? In that case which time interval? Should i use websockets instead for this case?
The app might be used by many people, so i would to know the scenario in this kind of project: Getting very fast changes, without overload the server due to too many connects or whatever else.
I'm confused about this and i need some lights around, any mobile application/server experiences related would be apprecied!
EDIT:
As suggered by an user, here additional infos:
The api is homemade, restful using JWT made in NodeJS.
Each users on their device should get messages from server asap, even when the app is in background/closed.
Maybe in the future a way to send messages between users themselves.
You have to implement push notification.
It is quite easy to implement this in xamarin. just send the push notification to the device and on the notification received call back send the API request to retrieve the updated data.
Here is the document for sending push notification from custom API.
https://learn.microsoft.com/en-us/appcenter/push/pushapi
I'm not a mobile developer, so take this with a grain of salt.
The answer to this really depends on what you're doing, which informs how often to check the API. If it's a messaging app, for example, you could have it check every couple minutes to see if there are undelivered messages, then check more frequently for the next X minutes (to facilitate a conversation in real time).
If it's a GPS navigation app to be used while driving, you'd need much more frequent requests.
As for the API, that also depends on what type of API and the number of requests you can make to it. Is it a commercial API that you get x number of calls per hour on? Is it an API that you built? Etc.
Basically, you need to give more information in order to get more specific answers.

Which technique is best suited for chat-like app

I want to develop a mobile app where a registered user can search among other registred users. User A can chat with user B. User A can view user B's profile. Upon this, user B have to be informed that user A is watching him.
So its some kind of chatroom where the server should be able to be notified when a user watched/contact another user, and let the latter know about this.
My first idea was to use node.js. But I begun to read a lot on XMPP-protocol. Do you think an XMPP-server would be more adequate to this kind of app? What I udnerstand you can customize your xmpp-server, write plugins so it can behave the way you want. Is this correct?
This is a perfect use case for socket IO using NodeJS. In fact, I have implemented exactly what you are describing with an iOS client and node backend in less than 50 lines of code. See https://github.com/MegaBits/SIOSocket for the iOS library, and http://socket.io/ for SocketIO.
XMPP is much heavier and verbose, and you'll be spending a lot of time parsing/building XML when you could just be communicating in JSON all the way. Take a look at my repo here:
https://github.com/alhill10/chatapp3/blob/master/View%20Control%20App/ChatView.m#L34
You can see on the viewDidLoad method it simply opens a websocket connection and listens for events from the server, then updates the tableview being used as a chat window with any new incoming messages in real time.
Then, look here https://github.com/alhill10/simplechat/blob/master/app.js for a simple example of the Socket IO backend that receives and relays the messages, as well as maintaining the state of current users online. You could trivially add in user authentication and .

XMPP component presence

I have just discovered how awesome XMPP is and I am experimenting with developing multiplayer games as XMPP components (XEP-0114).
However, I am having trouble with indicating presence for the component. Is it true, that the component will need to respond to <presence> stanzas itself?
Sure it can do that, but not if it is down for maintenance. Also, who does the component notify when it is back up? It could of course register all interested users in a database, but if it is down for five minutes, then that list surely will have changed. Users that were not previously interested will be now, and users who were interested won't be any more.
Also, if it crashes (could happen), it cannot send out 'unavailable' presence indications.
Can't this work somehow be offloaded to the server?
When your component receives <presence type='probe'/>, it should reply with your component's current presence.
When your component receives <presence type='subscribe'/>, it should save the from address in a some sort of storage mechanism, then reply with <presence type='subscribed'/>.
When your component comes online, it should send presence to each of the subscribers saved in step 2.
Always make sure to put both a to address and a from address on all stanzas sent by your component. If you are used to writing clients, you're likely to forget that in step 3.

Can I build an addin for Gmail?

Is there a way I can create an addin for my Gmail account? Is GreaseMonkey the only real way?
I use Gmail for customer service, and I'd like to create a tool that looks up the customer and preps a response to them based upon who it is in my database... instead of looking by hand for the client and typing it out.
You can add gadgets (same as iGoogle and wave) and add them to the side bar in GMail, but you will not have access to the e-mails themselves. You could create small lookup forms and such, though.
I don't see how else you could do it. You won't be able to run your own app on Google's backend, so that leaves the client (with javascript and something like GreaseMonkey) and your server (perhaps communicating with the client via AJAX).

Resources