Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closing connection and start new one #32

Open
shahabt24 opened this issue Sep 3, 2021 · 0 comments
Open

closing connection and start new one #32

shahabt24 opened this issue Sep 3, 2021 · 0 comments

Comments

@shahabt24
Copy link

Hello,
In my app, I have several rooms to talk in live mode, a user comes to one of the rooms and now wants to leave and connect to new room OR completly leave the connection, how can I achieve this?
I couldn't close the current connection, poof
Please help
Here is my code:

let socket = io(`https://${url}`);
const peerServer = new Peer(undefined, {
    host: url,
    secure: true,
    port: '443',
    path: '/peerjs',
    config: {
      debug: 3,
      iceServers: [
        {urls: ['stun:stun1.l.google.com:19302']},
        {
          username: 'epz-hBZGVrdW5sZTE=',
          credential: 'c531d3-a2e6-0242a140004',
          credentialType: 'password',
          urls: [
            'turn:us-turn4.xirsys.com:80?transport=udp',
            'turn:us-turn4.xirsys.com:3478?transport=udp',
            'turn:us-turn4.xirsys.com:80?transport=tcp',
            'turn:us-turn4.xirsys.com:3478?transport=tcp',
            'turns:us-turn4.xirsys.com:443?transport=tcp',
            'turns:us-turn4.xirsys.com:5349?transport=tcp',
          ],
        },
      ],
    },
  });
            peerServer.on('open', (userId: any) => {
              let roomId = '7b22dc91-3638-4964-95f2-d32b61541b66';
              socket.emit('join-room', roomId, userId);
            });

            socket.on('user-connected', (localPeer: any) => {
              const call = peerServer.call(localPeer, stream);
              call.on('stream', (audioStream: any) => {
                setStreams([...streams, audioStream]);
              });
            });

            peerServer.on('call', (call: any) => {
              call.answer(stream);
              call.on('stream', (userStream: any) => {
                setUserStreams([...userStreams, userStream]);
              });
            });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant