muaz-khan / RTCMultiConnection

RTCMultiConnection is a WebRTC JavaScript library for peer-to-peer applications (screen sharing, audio/video conferencing, file sharing, media streaming etc.)
https://muazkhan.com:9001/
MIT License
2.57k stars 1.37k forks source link

initiator can't rejoin a room after leaving connection #428

Open suziesirena opened 7 years ago

suziesirena commented 7 years ago

Hi,

My problem is :

If a participant leaves the connection (by refreshing the page for example), he can reconnect to the same connection.

But if the initiator leaves the connection (by refreshing the page for example), the messages are not sent to the participants until they reconnect themselves (participants array is empty).

Her is the code:

// Initialization
   connection = new RTCMultiConnection(channel_ID)
   connection.socketURL = '/'
   connection.autoCloseEntireSession = false
   connection.onmessage = onmessage
   connection.sessionid = channel_ID
   connection.socketCustomEvent = 'custom-message'
// Connection
   connection.openOrJoin(channel_ID, function() {
    })

Did I missed something?

48ca commented 7 years ago

I get this issue as well... been scratching my head for a while

rayj00 commented 7 years ago

I'm still scratching my head trying to figure out what Muaz's goal is in all of this? Granted, I admire his ambition and him providing all of the neat code, but since there are no comments in the code, and I consider myself very green with WebRTC, I am struggling to get anything to work correctly. Right now I am playing with Multiple-Broadcasters-Many Viewers. Very complex code. It does not work as I might expect and there are major issues. As Muaz rarely answers questions, is it entirely up to us to find and fix bugs? If that's the case, I guess I'm screwed as it will take me quite a long time to figure out the code. Reporting the issues are not getting anywhere. Aren't demos supposed to work by default?

qedawkins commented 7 years ago

I was able to fix this issue for me by changing a line in the Signaling-Server.js file.

if (autoCloseEntireSession == 'false' && sessionid == socket.userid) { socket.shiftModerationControlBeforeLeaving = true; }

Line 97

to

if (autoCloseEntireSession == 'false' && Object.keys(listOfUsers).length == 1) { socket.shiftModerationControlBeforeLeaving = true; }

There is probably a better way to do this but the issue was in essence that the userid recieved from socket.handshake.query wasn't equal to the sessionid for the first user to join at this point in the code (but it does get set to the sessionid later from what I can tell) and instead was a randomly generated userid like everyone who joined afterwards. This will make is so when the initiator leaves, the next user in listOfUsers will inherit the initiator status and when the original initiator joins back it will be like they are joining as a normal user.

This feels like a bit of a hacky solution, and considering that it works properly in the web demos, I'm fairly certain there's a better fix, but this worked for me.

suziesirena commented 7 years ago

thanks @qedawkins,

it works for me.

bhaumikpandhi commented 7 years ago

I'm facing the same problem, joining room is not working.

The program goes infinite giving error "Session-Descriptions not found. Rechecking.."

ajingopi commented 7 years ago
connection.onUserStatusChanged = function(event) {
    if (sessionDetails.userType == "participant" && event.status === 'offline') { //manually set by me for all participants using a cookie
        reCheckRoomPresence(); //window.location.reload(false); this works on chrome/firefox
    }
};

function reCheckRoomPresence(){
    var findWhenCustomerReconnectsToTheRoom = setInterval(function(){
        connection.checkPresence(sessionDetails.token, function(isRoomExists) {
            if(isRoomExists) {
                connection.join(sessionDetails.token); //sessionDetails.token is room-id
                clearInterval(findWhenCustomerReconnectsToTheRoom);
                return;
            }
        });
    }, 1);
}
imail2pankaj commented 6 years ago

@muaz-khan I have also same issue, but here what I want to do is if initiator leaves then another user should become the initiator, if another user leaves the room so on...

How can I achieve this?

muaz-khan commented 6 years ago

This issue will be fixed soon. Just working on that now.

rayj00 commented 6 years ago

I do not believe another should become initiator. That defeats the purpose of being the initiator! However, the original initiator should be able to rejoin the conference for sure. That said, after the conference is started, what does the initiator have to do anyway?

muaz-khan commented 6 years ago

I'm working on storing room-ids on the nodejs as well. So one will join a room based on room-id; not based on initiator's user-id. checkPresence method will also check for room-id instead of initiator's id. So initiator or any person can leave or rejoin without affecting the room on nodejs.

imail2pankaj commented 6 years ago

@rayj00 Thanks for your reply.

Actually I am working on a group chat where number of people can join the room. When room initiator leaves the room the no one is able to join the room as well as initiator.

My only concern is after initiator leaving the room any user can join that room as well as initiator.

ghost commented 6 years ago

@muaz-khan the changes room-id instead of user-id will improve the stability of Multiple Broadcasters for a lot of Viewers?

imail2pankaj commented 6 years ago

Hello @muaz-khan, have you solved the issue of initiator?

ghost commented 6 years ago

@muaz-khan you have a very interesting mechanism for reducing broadkaster load. This allows to connect to the conference a lot of interesting people with weak technical capabilities. Unfortunately, without the automatic connection of the initiator to the chat room I can not yet use RTCMultiConnection in a live conference. Our nongovernmental organization works in a zone with a very unstable internet connection. I look forward to resolving this problem.

layercomp commented 6 years ago

I'm still with the same issue

viro24 commented 6 years ago

Hi there, you can work around this behavior:

hope this helps :]

muaz-khan commented 6 years ago

Please clone RTCMultiConnection and try again. Relevant commit: https://github.com/muaz-khan/RTCMultiConnection/commit/157c9e544f74a49df9ae378c0ea4bf87bd0e1c0c

layercomp commented 6 years ago

I tried the new version but didn't worked yet :(. When I refresh the initiator's window no one can connect.

agam16 commented 6 years ago

Hi @muaz-khan , i am also facing the same issue. If a user creates a room & then he leaves, he is not able to connect. I am scratching my head to get a workaround, Please suggest.

Thanks

duahimanshu100 commented 6 years ago

Any solutions to this yet? Its not working. Moderator can't join the room again. Instead it creates the room again with same name.

48ca commented 6 years ago

The solution is to stop using this library and use WebRTC by itself.

ghost commented 6 years ago

Thanks for fixing the library for automatically join rejoin rooms. It's great! Please tell me how to do automatically rejoin rooms in case of oneway session?

Scenario: Broadcaster communicate with each other in the room. Viewers are connected to this room using an oneway session. Viewers users hear and see everything that happens in the room. What needs to be done so that after Internet disconnection Viewers can automatically join to the room?

athiraaravindan commented 5 years ago

how to get connected users details inside openOrJoin function