Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
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();
});
Author: Wilson Edwards replied at 2025-01-29 21:16:36
Just example code for Event /stream with socket, u can use https://yourdomain:5051/stream or https://yourdomain:5051
var lnk="https://yourdomain.com:5051";
socket = io.connect(lnk, {reconnection:false});
var socket_id=socket.on("connect", ()=>{
socket.emit("join-room", {"room_id":"question"});
});
socket.on("streamdata", (event)=>{
data_extract(JS(event.data));
});
}
Server python3 code
--------------------------
socketio = SocketIO(app,cors_allowed_origins='*')
@socketio.on("connect")
def on_connect():
sid = request.sid
print("---------------------------------")
print("New socket connected ", sid)
@socketio.on("join-room")
def on_join_room(data):
print("-------##############------")
#sid = request.sid
room_id = 'question'
join_room(room_id)
# your socketio.emit() function here
#for example: if use schedule
def server_side_event():
""" Function to publish server side event """
with app.app_context():
try:
arr=get_data()
if len(arr) >0:
sse.publish(arr, type='publish')
socketio.emit("streamdata", {"data":arr},broadcast=True,include_self=True,room="question")
print("Event Scheduled at ",datetime.datetime.now())
except:
pass
sched = BackgroundScheduler(daemon=True)
sched.add_job(server_side_event,'interval',seconds=get_schd_time())
sched.start()
Author: Wilson Edwards replied at 2025-01-28 21:50:56
Using
var source = new EventSource("https://yourdomainsocket-site.com"+":5051/stream");
that may not be better;
try to use classical python socket and javascript socket.io is better, and don't use /stream Event
For example:
var lnk="https://computer28.com:5051";
socket = io.connect(lnk, {reconnection:false});
That u can open many browser tab as u want to get socket data in real-time at the same time