Coder Social home page Coder Social logo

Comments (3)

alexandrevicenzi avatar alexandrevicenzi commented on July 23, 2024

Your question does not make a lot of sense. Each tab will be an individual connection, there's no sharing of resources, each tab is a new socket.

There are two things that you can do this way:

  • Each tab get the same messages if they are connected in the same channel
  • Each tab get a set of messages if they are in a separate channel

If you want the same messages use the same channel.

e = new EventSource('/events/shared-channel');
e.onmessage = function(event) {
    console.log(event.data);
};

If you want to send a set message per-tab use a different channel per tab.

var tabId = sessionStorage.tabID;
e = new EventSource(`/events/channel-{tabId}`);
e.onmessage = function(event) {
    console.log(event.data);
};

The above code is just an example, it may not work.

from go-sse.

siredwin avatar siredwin commented on July 23, 2024

I tried your second example and it did not work.
I ended up converting the payload message into a JSON string with both the message and tab id and it is working.
I am only listening to one channel
Let me know if this approach is ok?

from go-sse.

alexandrevicenzi avatar alexandrevicenzi commented on July 23, 2024

If you have multiple channels you need to publish the message on multiple channels in the server side as well.

from go-sse.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.