0

Background

How can two separate web apps (on different sessions) communicate with each other? For example a user on App1 performs a CRUD action, App2 receives this action and automatically refreshes the relevant UI components.

This technique is easily achievable on mobile apps using push notifications / background services etc. is this possible with web applications? I have no idea where to start looking.

a6547484
  • 81
  • 1
  • 7

2 Answers2

1

You can use web sockets https://socket.io

Both apps should connect to the same backend server. And the server can receive actions from one app and emit events (send messages) to the other app to tell it about the performed actions.

App1

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io('http://localhost');
  socket.emit('action', {action: 'delete'});
</script>

App2

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io('http://localhost');
  socket.on('actionPerformed', function(data) {
    console.log(data);
  });
</script>
faressoft
  • 19,053
  • 44
  • 104
  • 146
0

Looks like you are trying to apply the client side knowledge of mobile apps and background services to server side. I don't think it will scale on the server side.

The web applications are hosted on the server and the client here is the browser that displays it to the user. For server side web apps to scale while communicating with each other, a message hub or a message queue (MQ) is used. You can look at Apache Kafka https://kafka.apache.org/. There are cloud based offering that have embed the technology, like MessageHub (https://console.bluemix.net/docs/services/MessageHub/index.html).

App1 can be a producer of the event and App2 can be the consumer of Kafka. Whenever App1 completes the CRUD operations it can generate an event that's consumed by App2.

Neeraj Krishna
  • 1,527
  • 2
  • 16
  • 22