XMPP Multiple tabs synchronize sent message - session

I am implementing an Openfire chat client in a web site with Strophe.js. I managed to get multiple sessions and multiple windows reloading page and reconnecting back. Now I have challenge in restoring the chat history.
But the first issue I am stuck at when a user opens two tabs of our site it creates two xmpp sessions with different resource ID's but now say
a#example.com/tab1 sent a message to friend this should be synchronized in tab2
Example if you send chat message from gtalk user sent message will be updated and showin in gmail chat window.
Any one has any idea.
Thanks you very much for the time and help.

The routing logic for multiple resources is up to the server implementation. The GTalk server routes messages sent to bare Jids to all connected resources. Many other servers (also Openfire) send messages to bare Jids to the most available resource, which is the one with the highest priority.
If each of your tabs has its own resource then I suggest to send the messages to each resource (full jid) manual. You get all connected resources of your subscribed contacts with the presence.

Yes, there is. Have a look at XEP-0280: Message Carbons ( http://xmpp.org/extensions/xep-0280.html )
Both your client as well as your server have to support it in order to fully work.
Source : https://superuser.com/questions/866785/is-there-a-way-to-sync-xmpp-messages-across-different-devices-with-standard-xmp

Related

Can we replicate a HTTP SESSION idea in a MQTT architecture?

Roughly speaking a HTTP SESSION is a kind of secret that the server sends to the client (ex browser) after user's credentials is checked. This secret is passed trough all subsequents HTTP requests and will identify the user. This is important because HTTP are stateless - source.
Now I have a scenario where there is a communication between a machine and a MQTT broker inside the AWS-IoT core. The machine displays some screens. The first screen is the login and password.
The idea here is that after the first screen, IF the credentials are validated, the server should generate a "session" and we should send this "session" across the screen pages. The machine should send this "SESSION" in all subsequent messages and the server must to validate this string before any action. This is a request created by an electrical engineering team.
Me, in the software development side it seems that make no sense since all machines to be connected in the AWS IoT-Core broker (MQTT) must to use a certificate - with is the validation already.
Beside of that, the MQTT broker offers the SESSION persistence capabilities. I know that the SESSIONs (QoS 0/1) in the broker side are related to idea of confidence of delivery and reception of a message.
That being said is it possible to use session persistence in MQTT to behavior like a sessions in HTTP in order to identify users across screens in devices? If yes how?
No, HTTP Session concept is not in any way similar to the MQTT session. The only thing held in a MQTT clients session is the list of subscribed topics, a HTTP session can hold arbitrary data.
Also MQTT messages hold NO information about the user or even the client that published the message when it is delivered to the subscriber, the ONLY information present is the message payload and the topic it was published to.
While MQTTv5 adds the option to include more metadata, trying to add the concept of users sessions is like trying to make a square peg fit in round hole.
If you want to implement something as part of the message payload then that is entirely up to you, but it is nothing to do with the transport protocol.

Interact with slack bot without a public accessible server

For some security reasons that I can't have a public accessible server to receive data from slack.
So, this is what I'm planning to do:
Inbound message from slack: using RTM API
Outbound message to slack: using RTM API or Web API
Questions:
Any better alternatives?
Any restrictions? (AFAIK, buttons and drop downs can't work)
If Web API reach rate limit, can I use incoming webhook as a backup plan?
RTM only approach
Yes, that would work. With only the RTM API you are limited to:
receiving and responding to messages
Other RTM events.
You can't use any interactive functionality like:
Interactive components (buttons, menus, datepickers)
Dialogs
Rate limit on message posting
Using the webhook as "backup" to circumvent the rate limit is not an option, since the rate limit of posting max 1 message per second applies to all form of message posting.
From the documentation:
In general, apps may post no more than one message per second per
channel, whether a message is posted via chat.postMessage, an incoming
webhook, or one of the many other ways to send messages in to Slack.
Alternatives
You did not give any details about the reasons why your app can't expose an endpoint to the public Internet. But you might want to consider using a VPN tunnel like ngrok.
Yes! Socket Mode
There is a new alternative from slack, Socket Mode, which doesn't require a publicly accessible server.
Note: this is only for private apps.
With Socket Mode you have an API token and your server uses it to communicate with Slack's servers and create a two way socket connection. This means your Slack Bot's code can run on a machine behind a firewall and not require any inbound ports to be opened.
Slack message delivery requires an acknowledgement once you get the message, or else they may retry to deliver it.
Limitations
Socket Mode has two main limitations:
Apps using Socket Mode are not currently allowed in the public Slack App Directory.
Socket Mode is only available for apps using new, granular permissions. If you created your app on or after December of 2019, good news: your app already uses the new permissions. Otherwise, you may have to migrate your classic Slack app to use granular permissions before turning on Socket Mode.

WebSocket client disconnect due to network loss doesn't get intercepted by Spring server

I have an application in which clients use websockets to connect to a server which is running Spring Boot Tomcat.
My question is if there is a way for the server to detect a client disconnect due to a network loss.
Thanks.
if you are using stomp , check SessionDisconnectEvent.
For raw Websocket connections, you can use :
WebSocketHandler-->afterConnectionClosed
I have searched before for this and the solution I was able to find was to implement a ping-pong mechanism between the server and the clients.
For example, each few seconds send a dummy message to the client on a specific topic and receive back another dummy reply, if you didn't get a reply for a configured period you can consider the client disconnected.
As mentioned here,
STOMP and Spring also allow us to set up topics, where every
subscriber will receive the same message. This is going to be very
useful for tracking active users. In the UI, each user subscribes to a
topic that reports back which users are active, and in our example
that topic will produce a message every 2 seconds. The client will
reply to every message containing a list of users with its own
heartbeat, which then updates the message being sent to other clients.
If a client hasn't checked in for more than 5 seconds (i.e. missed two
heartbeats), we consider them offline. This gives us near real time
resolution of users being available to chat. Users will appear in a
box on the left hand side of the screen, clicking on a name will pull
up a chat window for them, and names with an envelope next to them
have new messages.

How do I connect random users with Websockets?

I have made an up and running chat application using websockets. I have a VPS where I want to host this application on. The application is working all fine, but it would be great if I could connect two random users (now it is like 1 chatroom, where a shitload of people could chat in). How do you keep track of who's online? Should I check with AJAX every x seconds? SetTimeOut would overload my server, I'm afraid...How does Omegle do that? I am thinking of solutions, but the AJAX solution is the only one I can think of, but I don't want to overload the server...
You cannot connect two users directly with WebSockets, but you may with WebRTC data channels : http://www.html5rocks.com/en/tutorials/webrtc/datachannels/
With WebSockets, both need to be connected to the server. Then your app should send messages to the server indicating to which room are you talking with, or to which chat user. When a user disconnects, the server should inform the users with common chat rooms or private chats opened that such user disconnected.
The server is the one responsible of broadcasts the messages of a user the right places, keep track of which users are in which chat rooms, etc...
So rather than send just text messages, send JSON objects with more data like:
{ cls: "join", room: "whatever", nick: "vtortola" }
{ message: "hi", cls: "msg", room: "whatever" }
And the server should send events to the clients as well informing of users joining/leaving and also the messages.
I wrote a very simple chat, but maybe the event handling could give you ideas.
If you are building a real chat system, you should use a chat protocol, e.g., XMPP (there are others). This gives you deeper chat semantics that using low-level WebSocket, which is a transport protocol, not really an application-level protocol. If you want to chat over the web, then you need XMPP to use either HTTP (using BOSH, which is HTTP-based) or WebSocket (search for XMPP over WebSocket).

duplicated JabberId resource on multiple devices

XMPP sends messages only to highest priority resources of a given JID. See 1, 2 and 3
I want to create a client that will check all my current resources (home, work, mobile)
the client will be able to announce itself with one of those existing resources
the hope is that the client will be able to receive messages into multiple devices. This should work.... unless for some reason the service doesn't accept multiple clients with the same resource? is that something specified in the protocol? or something that implementations might choose to allow/forbid?
The full JID is a unique identifier, so you cannot be logged in twice with the same one.
If you want more than one client to receive messages, then this can be accomplished by having both of them (different resources) with the same priority and using a server which supports this type of routing. This is an option under the spec.
XMPP sends messages only to highest priority resources of a given JID.
This depeds on your server configuration or server software. There is also server software wich routes messages to bare jids to all resources.
You get all connected resources f your contacts with the presence. So you could also manual send the message to each resource directly.

Resources