Comments (3)
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.
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.
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)
- Conditional logging HOT 3
- Javascript client is receiving messages by batch HOT 1
- obsolete CloseNotifier() HOT 1
- Using with Echo? HOT 3
- "welcome" event HOT 11
- Add HTTP/2 support HOT 1
- Data races HOT 10
- Send SSE data only when it received POST method HOT 1
- Last Event ID HOT 3
- panic on graceful shutdown HOT 4
- gofmt your code HOT 2
- Does not work with gzip.DefaultCompression
- Message retry always 0?
- Not safe for concurrent use HOT 3
- *middleware.compressResponseWriter is not http.CloseNotifier: HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-sse.