Asked by Wilson Edwards
at 2025-01-29 21:04:40
Point:500 Replies:4 POST_ID:829293USER_ID:12108
Topic:
javascript;python3;chrome
Visitors or users may open many page of website to get streaming data ,and they want to open many browser tabs to read different data. That will depend on your Laptop or mobile capiblity how can handle many new socket.io to run on multiple tab at the same time, If limited computer resouce or memory, you will be limited for number of browser tabs display.
If u use socket with Redis /stream event that allow display directly into html page tab (just type https://yourdomain:5051/stream on address bar) or throught javascript parse data into html page but it may only allow 3 tabs running on the same time.
How you can run it on many tabs ?
-----------------------------------------------
1-You can use localStorage(getItem or setItem) to share information between browser tab
Or...you can use
2-
window.addEventListener('blur', notstream);
window.addEventListener('focus', stream);
When the user not read or not focus the tag, close the streaming socketio, then When
that users want to read it again and focus the tag, reconnect the socket. We know users only can read 1 tag at a time only,
function notstrem(){
souce.close();//close the socket.io
}
function stream(){
//user focus the tab again
refresh();// re-run that funation u can stream data before
}
function refresh(){
//Redis
var source = new EventSource("https://yourdomainsocket-site.com"+":5051/stream");
source.addEventListener('publish', function(event) {
dataextract(event.data);
if (typeof ws=='function')ws(event.data);
if (typeof updatechart=='function')updatechart(event.data);
}, false);
source.addEventListener('error', function(event) {
}, false);
return source;
}
let source=null;
jQuery(document).ready(function($) {
console.log("onload");
source=refresh();
});