Hello! I´m struggling with an issue: When I print out the event object of “streamCreated” event.stream.connection.data contains the info of the user who logged in last. I need the data of the user who joined the session last. The problem occurs when a user leaves a session, remains logged in and rejoins. When the user leaves, logs out, logs in and joins again it´s good.
My environment is a NodeJS server and a vanilla JS frontend. I am using the server.js almost unchanged from the tutorial.
Hi Micael. Let´s say I have three users A, B and C in a session. User C logged in last. Now User B leaves the session but does not log out. When user B rejoins the session the event of the “streamCreated” handler returns the data of user C who logged in last instead of user B who just rejoined the session.
session.on('streamCreated', event => {
console.log(event.stream.connection.data); // Should contain data of user who joined last
var subscriber = session.subscribe(event.stream, 'video-container');
subscriber.on('videoElementCreated', event => {
appendUserData(event.element, subscriber.stream.connection);
});
});
Hope that makes it understandable.
And yes, it can be reproduced with the tutorial openvidu-js-node. (Just add a third user publisher3 in server.js mock db)
the streamCreated event is fired when a stream is correctly created. If you join to a created session with participants into it, you will receive as many streamCreated events as there are streams. This is:
You have A, B and C uses connected.
User B leave the session and rejoin
A and C should receive the streamCreated event of user B
B should receive the streamCreated event of Users A and C.
Knowing that, do you mean that user B only receive the streamCreated event of user C?
Did you mean “A and C should receive the streamCreated event of user B”?
Nope, that´s not what I meant. I receive as many streams as there are streams. It is exactly like you described it. The only problem I noticed, is, that event.stream.connection.data of user A and C contains data of C after rejoin of B. But it should contain data of user B. And that is the case since C was the last user that has logged in.
It probably isn´t a bug in openvidu itself, but in the Node server.js file. There I found the following line (near 92 in the login function):
req.session.loggedUser = user;
So loggedUser always contains the last one that logged in. Can this be improved?